summaryrefslogtreecommitdiffstats
path: root/c/src/libchip/serial/ns16550.h
blob: 4f1b98bf0bbe99bf8f1f87be4b4e058df9dd7b65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
 *  @file
 *  
 */

/*
 *  COPYRIGHT (c) 1998 by Radstone Technology
 *
 *  THIS FILE IS PROVIDED TO YOU, THE USER, "AS IS", WITHOUT WARRANTY OF ANY
 *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK
 *  AS TO THE QUALITY AND PERFORMANCE OF ALL CODE IN THIS FILE IS WITH YOU.
 *
 *  You are hereby granted permission to use, copy, modify, and distribute
 *  this file, provided that this notice, plus the above copyright notice
 *  and disclaimer, appears in all copies. Radstone Technology will provide
 *  no support for this code.
 *
 *  COPYRIGHT (c) 1989-2012.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifndef _NS16550_H_
#define _NS16550_H_

#include <rtems/termiostypes.h>
#include <libchip/serial.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Driver function table
 */

extern const console_fns ns16550_fns;
extern const console_fns ns16550_fns_polled;

/*
 * Flow control function tables
 */

extern const console_flow ns16550_flow_RTSCTS;
extern const console_flow ns16550_flow_DTRCTS;

/*
 *  Helpers for printk
 */
void ns16550_outch_polled(console_tbl *c, char out);
int ns16550_inch_polled(console_tbl *c);

/* Alternative NS16550 driver using the Termios device context */

typedef uint8_t (*ns16550_get_reg)(uintptr_t port, uint8_t reg);

typedef void (*ns16550_set_reg)(uintptr_t port, uint8_t reg, uint8_t value);

typedef struct {
  rtems_termios_device_context base;
  ns16550_get_reg get_reg;
  ns16550_set_reg set_reg;
  uintptr_t port;
  rtems_vector_number irq;
  uint32_t clock;
  uint32_t initial_baud;
  bool has_fractional_divider_register;
  uint8_t modem_control;
  uint8_t line_control;
  uint32_t baud_divisor;
  size_t out_total;
  size_t out_remaining;
  size_t out_current;
  const char *out_buf;
  rtems_termios_tty *tty;
} ns16550_context;

extern const rtems_termios_device_handler ns16550_handler_interrupt;
extern const rtems_termios_device_handler ns16550_handler_polled;
extern const rtems_termios_device_handler ns16550_handler_task;

extern const rtems_termios_device_flow ns16550_flow_rtscts;
extern const rtems_termios_device_flow ns16550_flow_dtrcts;

void ns16550_polled_putchar(rtems_termios_device_context *base, char out);

int ns16550_polled_getchar(rtems_termios_device_context *base);

bool ns16550_probe(rtems_termios_device_context *base);

#ifdef __cplusplus
}
#endif

#endif /* _NS16550_H_ */