[229bcca8] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief The generic libchip serial driver interface |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | |
---|
[ee3b242b] | 8 | /* |
---|
| 9 | * This file contains the TTY driver table definition |
---|
| 10 | * |
---|
| 11 | * This driver uses the termios pseudo driver. |
---|
| 12 | * |
---|
[08311cc3] | 13 | * COPYRIGHT (c) 1989-1999. |
---|
[009c235] | 14 | * On-Line Applications Research Corporation (OAR). |
---|
[ee3b242b] | 15 | * |
---|
[009c235] | 16 | * The license and distribution terms for this file may be |
---|
| 17 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 18 | * http://www.rtems.org/license/LICENSE. |
---|
[ee3b242b] | 19 | */ |
---|
| 20 | |
---|
| 21 | #ifndef __LIBCHIP_SERIAL_h |
---|
| 22 | #define __LIBCHIP_SERIAL_h |
---|
| 23 | |
---|
[5ae415b] | 24 | #include <termios.h> |
---|
[ee3b242b] | 25 | |
---|
[6cb084d9] | 26 | #include <rtems.h> |
---|
| 27 | |
---|
[7e72d51] | 28 | #ifdef __cplusplus |
---|
| 29 | extern "C" { |
---|
| 30 | #endif |
---|
| 31 | |
---|
[36152b0e] | 32 | /* |
---|
| 33 | * Types for get and set register routines |
---|
| 34 | */ |
---|
| 35 | |
---|
[229bcca8] | 36 | /** |
---|
| 37 | * @typedef getRegister_f |
---|
| 38 | * |
---|
| 39 | * This type function provides a hook for the bsp specific method |
---|
| 40 | * that gets register data from the given port and register. |
---|
| 41 | */ |
---|
[642c500] | 42 | typedef uint8_t (*getRegister_f)(uintptr_t port, uint8_t reg); |
---|
[229bcca8] | 43 | |
---|
| 44 | /** |
---|
| 45 | * @typedef setData_f |
---|
| 46 | * |
---|
| 47 | * This type function provides a hook for the bsp specific method |
---|
| 48 | * that sets register data from the given port and register to the |
---|
| 49 | * given value. |
---|
| 50 | */ |
---|
[642c500] | 51 | typedef void (*setRegister_f)(uintptr_t port, uint8_t reg, uint8_t value); |
---|
[229bcca8] | 52 | |
---|
| 53 | /** |
---|
| 54 | * @typedef getData_f |
---|
| 55 | * |
---|
| 56 | * This type function provides a hook for the bsp specific method |
---|
| 57 | * that gets data from the specified port. |
---|
| 58 | */ |
---|
[642c500] | 59 | typedef uint8_t (*getData_f)(uintptr_t port); |
---|
[229bcca8] | 60 | |
---|
| 61 | /** |
---|
| 62 | * @typedef setData_f |
---|
| 63 | * |
---|
| 64 | * This type function provides a hook for the bsp specific method |
---|
| 65 | * that writes value to the specified port. |
---|
| 66 | */ |
---|
[642c500] | 67 | typedef void (*setData_f)(uintptr_t port, uint8_t value); |
---|
[36152b0e] | 68 | |
---|
[229bcca8] | 69 | /** |
---|
| 70 | * @typedef _console_fns |
---|
| 71 | * |
---|
| 72 | * This type definition provides a structure of functions each |
---|
| 73 | * methood provides an interfce to the serial por to do a specific |
---|
| 74 | * function. |
---|
| 75 | */ |
---|
[ee3b242b] | 76 | typedef struct _console_fns { |
---|
[6640459d] | 77 | bool (*deviceProbe)(int minor); |
---|
[58b1e95] | 78 | int (*deviceFirstOpen)(int major, int minor, void *arg); |
---|
| 79 | int (*deviceLastClose)(int major, int minor, void *arg); |
---|
| 80 | int (*deviceRead)(int minor); |
---|
[3ed964f9] | 81 | ssize_t (*deviceWrite)(int minor, const char *buf, size_t len); |
---|
[58b1e95] | 82 | void (*deviceInitialize)(int minor); |
---|
| 83 | void (*deviceWritePolled)(int minor, char cChar); |
---|
[8a2d4f2b] | 84 | int (*deviceSetAttributes)(int minor, const struct termios *t); |
---|
[6640459d] | 85 | bool deviceOutputUsesInterrupts; |
---|
[ee3b242b] | 86 | } console_fns; |
---|
| 87 | |
---|
[229bcca8] | 88 | /** |
---|
| 89 | * @typedef _console_flow |
---|
| 90 | * |
---|
| 91 | * This type definition provides a structure of functions |
---|
| 92 | * that provide flow control for the transmit buffer. |
---|
| 93 | */ |
---|
[ee3b242b] | 94 | typedef struct _console_flow { |
---|
[424e23ee] | 95 | int (*deviceStopRemoteTx)(int minor); |
---|
| 96 | int (*deviceStartRemoteTx)(int minor); |
---|
[ee3b242b] | 97 | } console_flow; |
---|
| 98 | |
---|
[229bcca8] | 99 | |
---|
| 100 | /** |
---|
| 101 | * This type defination provides an enumerated type of all |
---|
| 102 | * supported libchip console drivers. |
---|
| 103 | */ |
---|
[c0573d7] | 104 | typedef enum { |
---|
| 105 | SERIAL_MC68681, /* Motorola MC68681 or Exar 88681 */ |
---|
| 106 | SERIAL_NS16550, /* National Semiconductor NS16550 */ |
---|
[c39148d6] | 107 | SERIAL_NS16550_WITH_FDR, /* National Semiconductor NS16550 |
---|
| 108 | with Fractional Divider Register (FDR) */ |
---|
[c0573d7] | 109 | SERIAL_Z85C30, /* Zilog Z85C30 */ |
---|
| 110 | SERIAL_CUSTOM /* BSP specific driver */ |
---|
| 111 | } console_devs; |
---|
| 112 | |
---|
[229bcca8] | 113 | /** |
---|
| 114 | * This type defination provides an structure that is used to |
---|
| 115 | * uniquely identify a specific serial port. |
---|
[5ae415b] | 116 | */ |
---|
[ee3b242b] | 117 | typedef struct _console_tbl { |
---|
[229bcca8] | 118 | /** This is the name of the device. */ |
---|
[e310dcd] | 119 | const char *sDeviceName; |
---|
[229bcca8] | 120 | /** This indicates the chip type. It is especially important when |
---|
| 121 | * multiple devices share the same interrupt vector and must be |
---|
| 122 | * distinguished. |
---|
| 123 | */ |
---|
[c0573d7] | 124 | console_devs deviceType; |
---|
[229bcca8] | 125 | /** pDeviceFns This is a pointer to the set of driver routines to use. */ |
---|
[c8bd3cd] | 126 | const console_fns *pDeviceFns; |
---|
[229bcca8] | 127 | /** This value is passed to the serial device driver for use. In termios |
---|
| 128 | * itself the number is ignored. |
---|
| 129 | */ |
---|
[6640459d] | 130 | bool (*deviceProbe)(int minor); |
---|
[229bcca8] | 131 | /** This is a pointer to the set of flow control routines to |
---|
| 132 | * use. Serial device drivers will typically supply RTSCTS |
---|
| 133 | * and DTRCTS handshake routines for DCE to DCE communication, |
---|
| 134 | * however for DCE to DTE communication, no such routines |
---|
| 135 | * should be necessary as RTS will be driven automatically |
---|
| 136 | * when the transmitter is active. |
---|
| 137 | */ |
---|
[c8bd3cd] | 138 | const console_flow *pDeviceFlow; |
---|
[229bcca8] | 139 | /** The high water mark in the input buffer is set to the buffer |
---|
| 140 | * size less ulMargin. Once this level is reached, the driver's |
---|
| 141 | * flow control routine used to stop the remote transmitter will |
---|
| 142 | * be called. This figure should be greater than or equal to |
---|
| 143 | * the number of stages of FIFO between the transmitter and |
---|
| 144 | * receiver. |
---|
| 145 | * |
---|
| 146 | * @note At the current time, this parameter is hard coded |
---|
| 147 | * in termios and this number is ignored. |
---|
| 148 | */ |
---|
[ee4f57d] | 149 | uint32_t ulMargin; |
---|
[229bcca8] | 150 | /** After the high water mark specified by ulMargin has been |
---|
| 151 | * reached, the driver's routine to re-start the remote |
---|
| 152 | * transmitter will be called once the level in the input |
---|
| 153 | * buffer has fallen by ulHysteresis bytes. |
---|
| 154 | * |
---|
| 155 | * @note At the current time, this parameter is hard coded in termios. |
---|
| 156 | */ |
---|
[ee4f57d] | 157 | uint32_t ulHysteresis; |
---|
[229bcca8] | 158 | /** This contains either device specific data or a pointer to a |
---|
| 159 | * device specific structure containing additional information |
---|
| 160 | * not provided in this table. |
---|
| 161 | */ |
---|
[58b1e95] | 162 | void *pDeviceParams; |
---|
[229bcca8] | 163 | /** This is the primary control port number for the device. This |
---|
| 164 | * may be used to specify different instances of the same device type. |
---|
| 165 | */ |
---|
[ee4f57d] | 166 | uint32_t ulCtrlPort1; |
---|
[229bcca8] | 167 | /** This is the secondary control port number, of use when a given |
---|
| 168 | * device has more than one available channel. |
---|
| 169 | */ |
---|
[ee4f57d] | 170 | uint32_t ulCtrlPort2; |
---|
[229bcca8] | 171 | /** This is the port number for the data port of the device */ |
---|
[ee4f57d] | 172 | uint32_t ulDataPort; |
---|
[229bcca8] | 173 | /** This is the routine used to read register values. */ |
---|
[36152b0e] | 174 | getRegister_f getRegister; |
---|
[229bcca8] | 175 | /** This is the routine used to write register values. */ |
---|
[36152b0e] | 176 | setRegister_f setRegister; |
---|
[229bcca8] | 177 | /** This is the routine used to read the data register (RX). */ |
---|
[36152b0e] | 178 | getData_f getData; |
---|
[229bcca8] | 179 | /* This is the routine used to write the data register (TX). */ |
---|
[36152b0e] | 180 | setData_f setData; |
---|
[229bcca8] | 181 | /** This is the baud rate clock speed.*/ |
---|
[ee4f57d] | 182 | uint32_t ulClock; |
---|
[229bcca8] | 183 | /** This encodes the interrupt vector of the device. */ |
---|
[58b1e95] | 184 | unsigned int ulIntVector; |
---|
[ee3b242b] | 185 | } console_tbl; |
---|
| 186 | |
---|
[229bcca8] | 187 | /** |
---|
| 188 | * This type defination provides data for the console port. |
---|
| 189 | */ |
---|
[ee3b242b] | 190 | typedef struct _console_data { |
---|
[58b1e95] | 191 | void *termios_data; |
---|
[6640459d] | 192 | volatile bool bActive; |
---|
[229bcca8] | 193 | /** This field may be used for any purpose required by the driver */ |
---|
[58b1e95] | 194 | void *pDeviceContext; |
---|
[ee3b242b] | 195 | } console_data; |
---|
| 196 | |
---|
[229bcca8] | 197 | /** |
---|
| 198 | * This is a dynamically sized set of tables containing the serial |
---|
| 199 | * port information. |
---|
| 200 | */ |
---|
| 201 | extern console_tbl **Console_Port_Tbl; |
---|
| 202 | /** |
---|
| 203 | * This is the number of serial ports defined in the Console_Port_Tbl. |
---|
| 204 | */ |
---|
| 205 | extern unsigned long Console_Port_Count; |
---|
| 206 | |
---|
| 207 | /** |
---|
| 208 | * The statically configured serial port information tables which |
---|
| 209 | * are used to initially populate the dynamic tables. |
---|
| 210 | */ |
---|
| 211 | extern console_tbl Console_Configuration_Ports[]; |
---|
| 212 | /** |
---|
| 213 | * The number of serial ports defined in Console_Configuration_Ports |
---|
| 214 | * */ |
---|
| 215 | extern unsigned long Console_Configuration_Count; |
---|
| 216 | |
---|
| 217 | /** |
---|
| 218 | * This is an array of per port information. |
---|
| 219 | */ |
---|
| 220 | extern console_data *Console_Port_Data; |
---|
[ee3b242b] | 221 | |
---|
[6cb084d9] | 222 | extern rtems_device_minor_number Console_Port_Minor; |
---|
| 223 | |
---|
[7306578] | 224 | /** |
---|
| 225 | * @brief Selects the minor number of the console device. |
---|
| 226 | * |
---|
| 227 | * @see Console_Port_Minor. |
---|
| 228 | */ |
---|
| 229 | void bsp_console_select(void); |
---|
| 230 | |
---|
[7e72d51] | 231 | #ifdef __cplusplus |
---|
| 232 | } |
---|
| 233 | #endif |
---|
| 234 | |
---|
[ee3b242b] | 235 | #endif |
---|