[5752f930] | 1 | /* |
---|
[c73b8ac2] | 2 | * This file contains the generic console driver shell used |
---|
| 3 | * by all console drivers using libchip. |
---|
[5752f930] | 4 | * |
---|
| 5 | * This driver uses the termios pseudo driver. |
---|
| 6 | * |
---|
| 7 | * COPYRIGHT (c) 1989-1997. |
---|
| 8 | * On-Line Applications Research Corporation (OAR). |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
[0c9fa21c] | 12 | * http://www.rtems.com/license/LICENSE. |
---|
[5752f930] | 13 | * |
---|
| 14 | * $Id$ |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include <bsp.h> |
---|
| 18 | #include <rtems/libio.h> |
---|
| 19 | #include <stdlib.h> |
---|
| 20 | #include <assert.h> |
---|
| 21 | #include <termios.h> |
---|
| 22 | |
---|
[29e214e] | 23 | #include <rtems/termiostypes.h> |
---|
[5752f930] | 24 | #include <libchip/serial.h> |
---|
| 25 | |
---|
| 26 | /* |
---|
[acac0e8] | 27 | * Configuration Information |
---|
[5752f930] | 28 | */ |
---|
| 29 | |
---|
| 30 | extern console_data Console_Port_Data[]; |
---|
| 31 | extern unsigned long Console_Port_Count; |
---|
| 32 | extern rtems_device_minor_number Console_Port_Minor; |
---|
| 33 | |
---|
| 34 | /*PAGE |
---|
| 35 | * |
---|
| 36 | * console_open |
---|
| 37 | * |
---|
| 38 | * open a port as a termios console. |
---|
| 39 | * |
---|
| 40 | */ |
---|
| 41 | |
---|
| 42 | rtems_device_driver console_open( |
---|
| 43 | rtems_device_major_number major, |
---|
| 44 | rtems_device_minor_number minor, |
---|
| 45 | void * arg |
---|
| 46 | ) |
---|
| 47 | { |
---|
| 48 | rtems_status_code status; |
---|
| 49 | rtems_libio_open_close_args_t *args = arg; |
---|
| 50 | rtems_libio_ioctl_args_t IoctlArgs; |
---|
| 51 | struct termios Termios; |
---|
| 52 | rtems_termios_callbacks Callbacks; |
---|
| 53 | console_tbl *cptr; |
---|
[29e214e] | 54 | struct rtems_termios_tty *current_tty; |
---|
[5752f930] | 55 | |
---|
| 56 | /* |
---|
| 57 | * Verify the port number is valid. |
---|
| 58 | */ |
---|
| 59 | if ( minor > Console_Port_Count ) { |
---|
| 60 | return RTEMS_INVALID_NUMBER; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /* |
---|
| 64 | * Open the port as a termios console driver. |
---|
| 65 | */ |
---|
| 66 | |
---|
| 67 | cptr = &Console_Port_Tbl[minor]; |
---|
| 68 | Callbacks.firstOpen = cptr->pDeviceFns->deviceFirstOpen; |
---|
| 69 | Callbacks.lastClose = cptr->pDeviceFns->deviceLastClose; |
---|
| 70 | Callbacks.pollRead = cptr->pDeviceFns->deviceRead; |
---|
| 71 | Callbacks.write = cptr->pDeviceFns->deviceWrite; |
---|
| 72 | Callbacks.setAttributes = cptr->pDeviceFns->deviceSetAttributes; |
---|
| 73 | Callbacks.stopRemoteTx = cptr->pDeviceFlow->deviceStopRemoteTx; |
---|
| 74 | Callbacks.startRemoteTx = cptr->pDeviceFlow->deviceStartRemoteTx; |
---|
| 75 | Callbacks.outputUsesInterrupts = cptr->pDeviceFns->deviceOutputUsesInterrupts; |
---|
| 76 | |
---|
| 77 | /* XXX what about |
---|
| 78 | * Console_Port_Tbl[minor].ulMargin, |
---|
| 79 | * Console_Port_Tbl[minor].ulHysteresis); |
---|
| 80 | */ |
---|
| 81 | |
---|
| 82 | status = rtems_termios_open ( major, minor, arg, &Callbacks ); |
---|
| 83 | Console_Port_Data[minor].termios_data = args->iop->data1; |
---|
[29e214e] | 84 | |
---|
| 85 | /* Get tty pointeur from the Console_Port_Data */ |
---|
| 86 | current_tty = Console_Port_Data[minor].termios_data; |
---|
| 87 | |
---|
| 88 | if ( (current_tty->refcount == 1) ) { |
---|
| 89 | /* |
---|
| 90 | * If it's the first open, modified, if need, the port parameters |
---|
| 91 | */ |
---|
| 92 | if (minor!=Console_Port_Minor) { |
---|
| 93 | /* |
---|
| 94 | * If this is not the console we do not want ECHO and |
---|
| 95 | * so forth |
---|
| 96 | */ |
---|
| 97 | IoctlArgs.iop=args->iop; |
---|
| 98 | IoctlArgs.command=RTEMS_IO_GET_ATTRIBUTES; |
---|
| 99 | IoctlArgs.buffer=&Termios; |
---|
| 100 | rtems_termios_ioctl(&IoctlArgs); |
---|
| 101 | Termios.c_lflag=ICANON; |
---|
| 102 | IoctlArgs.command=RTEMS_IO_SET_ATTRIBUTES; |
---|
| 103 | rtems_termios_ioctl(&IoctlArgs); |
---|
| 104 | } |
---|
[5752f930] | 105 | } |
---|
| 106 | |
---|
| 107 | if ( (args->iop->flags&LIBIO_FLAGS_READ) && |
---|
| 108 | Console_Port_Tbl[minor].pDeviceFlow && |
---|
| 109 | Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx) { |
---|
| 110 | Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx(minor); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | return status; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /*PAGE |
---|
| 117 | * |
---|
| 118 | * console_close |
---|
| 119 | * |
---|
| 120 | * This routine closes a port that has been opened as console. |
---|
| 121 | */ |
---|
| 122 | |
---|
| 123 | rtems_device_driver console_close( |
---|
| 124 | rtems_device_major_number major, |
---|
| 125 | rtems_device_minor_number minor, |
---|
| 126 | void * arg |
---|
| 127 | ) |
---|
| 128 | { |
---|
| 129 | rtems_libio_open_close_args_t *args = arg; |
---|
| 130 | |
---|
| 131 | if ( (args->iop->flags&LIBIO_FLAGS_READ) && |
---|
| 132 | Console_Port_Tbl[minor].pDeviceFlow && |
---|
| 133 | Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) { |
---|
| 134 | Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | return rtems_termios_close (arg); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /*PAGE |
---|
| 141 | * |
---|
| 142 | * console_read |
---|
| 143 | * |
---|
| 144 | * This routine uses the termios driver to read a character. |
---|
| 145 | */ |
---|
| 146 | |
---|
| 147 | rtems_device_driver console_read( |
---|
| 148 | rtems_device_major_number major, |
---|
| 149 | rtems_device_minor_number minor, |
---|
| 150 | void * arg |
---|
| 151 | ) |
---|
| 152 | { |
---|
| 153 | return rtems_termios_read (arg); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | /*PAGE |
---|
| 157 | * |
---|
| 158 | * console_write |
---|
| 159 | * |
---|
| 160 | * this routine uses the termios driver to write a character. |
---|
| 161 | */ |
---|
| 162 | |
---|
| 163 | rtems_device_driver console_write( |
---|
| 164 | rtems_device_major_number major, |
---|
| 165 | rtems_device_minor_number minor, |
---|
| 166 | void * arg |
---|
| 167 | ) |
---|
| 168 | { |
---|
| 169 | return rtems_termios_write (arg); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /*PAGE |
---|
| 173 | * |
---|
| 174 | * console_control |
---|
| 175 | * |
---|
| 176 | * this routine uses the termios driver to process io |
---|
| 177 | */ |
---|
| 178 | |
---|
| 179 | rtems_device_driver console_control( |
---|
| 180 | rtems_device_major_number major, |
---|
| 181 | rtems_device_minor_number minor, |
---|
| 182 | void * arg |
---|
| 183 | ) |
---|
| 184 | { |
---|
| 185 | return rtems_termios_ioctl (arg); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | /*PAGE |
---|
| 189 | * |
---|
| 190 | * console_initialize |
---|
| 191 | * |
---|
| 192 | * Routine called to initialize the console device driver. |
---|
| 193 | */ |
---|
| 194 | |
---|
| 195 | rtems_device_driver console_initialize( |
---|
| 196 | rtems_device_major_number major, |
---|
[acac0e8] | 197 | rtems_device_minor_number minor_arg, |
---|
[5752f930] | 198 | void *arg |
---|
| 199 | ) |
---|
| 200 | { |
---|
[acac0e8] | 201 | rtems_status_code status; |
---|
| 202 | rtems_device_minor_number minor; |
---|
[5752f930] | 203 | |
---|
| 204 | /* |
---|
| 205 | * initialize the termio interface. |
---|
| 206 | */ |
---|
| 207 | |
---|
| 208 | rtems_termios_initialize(); |
---|
| 209 | |
---|
[acac0e8] | 210 | for (minor=0; minor < Console_Port_Count ; minor++) { |
---|
[5752f930] | 211 | /* |
---|
| 212 | * First perform the configuration dependent probe, then the |
---|
| 213 | * device dependent probe |
---|
| 214 | */ |
---|
| 215 | |
---|
| 216 | if ((!Console_Port_Tbl[minor].deviceProbe || |
---|
| 217 | Console_Port_Tbl[minor].deviceProbe(minor)) && |
---|
| 218 | Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) { |
---|
| 219 | /* |
---|
| 220 | * Use this device for the console |
---|
| 221 | */ |
---|
| 222 | break; |
---|
| 223 | } |
---|
| 224 | } |
---|
[870284d] | 225 | if ( minor == Console_Port_Count ) { |
---|
[5752f930] | 226 | /* |
---|
| 227 | * Failed to find a working device |
---|
| 228 | */ |
---|
| 229 | rtems_fatal_error_occurred(RTEMS_IO_ERROR); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | Console_Port_Minor=minor; |
---|
| 233 | |
---|
| 234 | /* |
---|
| 235 | * Register Device Names |
---|
| 236 | */ |
---|
| 237 | status = rtems_io_register_name("/dev/console", major, Console_Port_Minor ); |
---|
| 238 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 239 | rtems_fatal_error_occurred(status); |
---|
| 240 | } |
---|
| 241 | Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(Console_Port_Minor); |
---|
| 242 | |
---|
| 243 | for (minor++;minor<Console_Port_Count;minor++) { |
---|
| 244 | /* |
---|
| 245 | * First perform the configuration dependent probe, then the |
---|
| 246 | * device dependent probe |
---|
| 247 | */ |
---|
| 248 | |
---|
| 249 | if ( (!Console_Port_Tbl[minor].deviceProbe || |
---|
| 250 | Console_Port_Tbl[minor].deviceProbe(minor)) && |
---|
| 251 | Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) { |
---|
| 252 | status = rtems_io_register_name( |
---|
| 253 | Console_Port_Tbl[minor].sDeviceName, |
---|
| 254 | major, |
---|
| 255 | minor ); |
---|
| 256 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 257 | rtems_fatal_error_occurred(status); |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | /* |
---|
| 261 | * Initialize the hardware device. |
---|
| 262 | */ |
---|
| 263 | |
---|
| 264 | Console_Port_Tbl[minor].pDeviceFns->deviceInitialize(minor); |
---|
| 265 | |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | return RTEMS_SUCCESSFUL; |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | |
---|
| 273 | |
---|