[fcee56c0] | 1 | /* |
---|
| 2 | * console.c -- console I/O package |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 1999 Eric Valette. valette@crf.canon.fr |
---|
| 5 | * |
---|
| 6 | * This code is based on the pc386 BSP console.c so the following |
---|
| 7 | * copyright also applies : |
---|
| 8 | * |
---|
| 9 | * (C) Copyright 1997 - |
---|
| 10 | * - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
| 11 | * |
---|
[69ed59f] | 12 | * Till Straumann, <strauman@slac.stanford.edu>, 12/20/2001 |
---|
| 13 | * separate BSP specific stuff from generics... |
---|
| 14 | * |
---|
[fcee56c0] | 15 | * http://pandora.ist.utl.pt |
---|
| 16 | * |
---|
| 17 | * Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
| 18 | * The license and distribution terms for this file may be |
---|
[0c875c6a] | 19 | * found in the file LICENSE in this distribution or at |
---|
[e831de8] | 20 | * http://www.rtems.com/license/LICENSE. |
---|
[fcee56c0] | 21 | * |
---|
| 22 | * $Id$ |
---|
| 23 | */ |
---|
[6128a4a] | 24 | |
---|
[ba46ffa6] | 25 | #include <stdlib.h> |
---|
| 26 | #include <assert.h> |
---|
[93180ea2] | 27 | #include <stdlib.h> |
---|
| 28 | |
---|
[ba46ffa6] | 29 | #include <bsp.h> |
---|
| 30 | #include <bsp/irq.h> |
---|
[20603d1] | 31 | #include <rtems/bspIo.h> |
---|
[ba46ffa6] | 32 | #include <rtems/libio.h> |
---|
[8e861444] | 33 | #include <rtems/termiostypes.h> |
---|
[ba46ffa6] | 34 | #include <termios.h> |
---|
| 35 | #include <bsp/uart.h> |
---|
[923dd7a] | 36 | #include <rtems/bspIo.h> /* printk */ |
---|
[ba46ffa6] | 37 | |
---|
| 38 | /* Definitions for BSPConsolePort */ |
---|
| 39 | /* |
---|
| 40 | * Possible value for console input/output : |
---|
[923dd7a] | 41 | * BSP_CONSOLE_PORT_CONSOLE |
---|
| 42 | * BSP_UART_COM1 |
---|
| 43 | * BSP_UART_COM2 |
---|
[ba46ffa6] | 44 | */ |
---|
[69ed59f] | 45 | int BSPConsolePort = BSP_CONSOLE_PORT; |
---|
[ba46ffa6] | 46 | |
---|
[69ed59f] | 47 | int BSPBaseBaud = BSP_UART_BAUD_BASE; |
---|
[ba46ffa6] | 48 | |
---|
[8e861444] | 49 | /* |
---|
| 50 | * TERMIOS_OUTPUT_MODE should be a 'bspopts.h/configure'-able option; |
---|
| 51 | * we could even make it a link-time option (but that would require |
---|
| 52 | * small changes)... |
---|
| 53 | */ |
---|
| 54 | #ifndef TERMIOS_OUTPUT_MODE |
---|
[923dd7a] | 55 | #if 1 |
---|
| 56 | #define TERMIOS_OUTPUT_MODE TERMIOS_IRQ_DRIVEN |
---|
| 57 | #else |
---|
| 58 | #define TERMIOS_OUTPUT_MODE TERMIOS_TASK_DRIVEN |
---|
| 59 | #endif |
---|
[8e861444] | 60 | #endif |
---|
| 61 | |
---|
| 62 | #if ! defined(USE_POLLED_IO) && (TERMIOS_OUTPUT_MODE == TERMIOS_POLLED) |
---|
[923dd7a] | 63 | #define USE_POLLED_IO |
---|
[8e861444] | 64 | #endif |
---|
| 65 | |
---|
[ba46ffa6] | 66 | /*-------------------------------------------------------------------------+ |
---|
| 67 | | External Prototypes |
---|
| 68 | +--------------------------------------------------------------------------*/ |
---|
| 69 | |
---|
| 70 | static int conSetAttr(int minor, const struct termios *); |
---|
| 71 | |
---|
[69ed59f] | 72 | typedef struct TtySTblRec_ { |
---|
[923dd7a] | 73 | char *name; |
---|
| 74 | rtems_irq_hdl isr; |
---|
[ac7af4a] | 75 | } TtySTblRec, *TtySTbl; |
---|
[69ed59f] | 76 | |
---|
| 77 | static TtySTblRec ttyS[]={ |
---|
[923dd7a] | 78 | { "/dev/ttyS0", |
---|
[69ed59f] | 79 | #ifdef BSP_UART_IOBASE_COM1 |
---|
[923dd7a] | 80 | BSP_uart_termios_isr_com1 |
---|
[69ed59f] | 81 | #else |
---|
[923dd7a] | 82 | 0 |
---|
[69ed59f] | 83 | #endif |
---|
[923dd7a] | 84 | }, |
---|
| 85 | { "/dev/ttyS1", |
---|
[69ed59f] | 86 | #ifdef BSP_UART_IOBASE_COM2 |
---|
[923dd7a] | 87 | BSP_uart_termios_isr_com2 |
---|
[69ed59f] | 88 | #else |
---|
[923dd7a] | 89 | 0 |
---|
[69ed59f] | 90 | #endif |
---|
[923dd7a] | 91 | }, |
---|
[69ed59f] | 92 | }; |
---|
| 93 | |
---|
[ba46ffa6] | 94 | /*-------------------------------------------------------------------------+ |
---|
| 95 | | Console device driver INITIALIZE entry point. |
---|
| 96 | +--------------------------------------------------------------------------+ |
---|
| 97 | | Initilizes the I/O console (keyboard + VGA display) driver. |
---|
| 98 | +--------------------------------------------------------------------------*/ |
---|
[923dd7a] | 99 | rtems_device_driver console_initialize( |
---|
| 100 | rtems_device_major_number major, |
---|
| 101 | rtems_device_minor_number minor, |
---|
| 102 | void *arg |
---|
| 103 | ) |
---|
[ba46ffa6] | 104 | { |
---|
| 105 | rtems_status_code status; |
---|
| 106 | |
---|
| 107 | /* |
---|
| 108 | * The video was initialized in the start.s code and does not need |
---|
| 109 | * to be reinitialized. |
---|
| 110 | */ |
---|
| 111 | |
---|
| 112 | /* |
---|
| 113 | * Set up TERMIOS |
---|
| 114 | */ |
---|
[923dd7a] | 115 | rtems_termios_initialize(); |
---|
[6128a4a] | 116 | |
---|
[ba46ffa6] | 117 | /* |
---|
| 118 | * Do device-specific initialization |
---|
| 119 | */ |
---|
| 120 | |
---|
[69ed59f] | 121 | /* RTEMS calls this routine once with 'minor'==0; loop through |
---|
| 122 | * all known instances... |
---|
[ba46ffa6] | 123 | */ |
---|
[6128a4a] | 124 | |
---|
[69ed59f] | 125 | for (minor=0; minor < sizeof(ttyS)/sizeof(ttyS[0]); minor++) { |
---|
[923dd7a] | 126 | char *nm; |
---|
| 127 | /* |
---|
| 128 | * Skip ports (possibly not supported by BSP...) we have no ISR for |
---|
| 129 | */ |
---|
| 130 | if ( ! ttyS[minor].isr ) |
---|
| 131 | continue; |
---|
| 132 | /* |
---|
| 133 | * Register the device |
---|
| 134 | */ |
---|
| 135 | status = rtems_io_register_name ((nm=ttyS[minor].name), major, minor); |
---|
| 136 | if ( RTEMS_SUCCESSFUL==status && BSPConsolePort == minor) { |
---|
| 137 | printk("Registering /dev/console as minor %d (==%s)\n", |
---|
| 138 | minor, |
---|
| 139 | ttyS[minor].name); |
---|
| 140 | /* also register an alias */ |
---|
| 141 | status = rtems_io_register_name ( (nm="/dev/console"), major, minor); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 145 | printk("Error registering %s!\n",nm); |
---|
| 146 | rtems_fatal_error_occurred (status); |
---|
| 147 | } |
---|
[69ed59f] | 148 | } |
---|
[e79a1947] | 149 | |
---|
[ba46ffa6] | 150 | return RTEMS_SUCCESSFUL; |
---|
| 151 | } /* console_initialize */ |
---|
| 152 | |
---|
[69ed59f] | 153 | static int console_first_open(int major, int minor, void *arg) |
---|
| 154 | { |
---|
| 155 | rtems_status_code status; |
---|
| 156 | |
---|
[923dd7a] | 157 | /* must not open a minor device we have no ISR for */ |
---|
| 158 | assert( minor>=0 && minor < sizeof(ttyS)/sizeof(ttyS[0]) && ttyS[minor].isr ); |
---|
| 159 | |
---|
| 160 | /* 9600-8-N-1 */ |
---|
| 161 | BSP_uart_init(minor, 9600, 0); |
---|
| 162 | status = BSP_uart_install_isr(minor, ttyS[minor].isr); |
---|
| 163 | if (!status) { |
---|
| 164 | printk("Error installing serial console interrupt handler for '%s'!\n", |
---|
| 165 | ttyS[minor].name); |
---|
| 166 | rtems_fatal_error_occurred(status); |
---|
| 167 | } |
---|
[1f8ac4a] | 168 | |
---|
| 169 | /* |
---|
| 170 | * Pass data area info down to driver |
---|
| 171 | */ |
---|
| 172 | BSP_uart_termios_set(minor, ((rtems_libio_open_close_args_t *)arg)->iop->data1); |
---|
| 173 | |
---|
| 174 | /* Enable interrupts on channel */ |
---|
| 175 | BSP_uart_intr_ctrl(minor, BSP_UART_INTR_CTRL_TERMIOS); |
---|
| 176 | |
---|
[923dd7a] | 177 | return 0; |
---|
[69ed59f] | 178 | } |
---|
| 179 | |
---|
[ba46ffa6] | 180 | static int console_last_close(int major, int minor, void *arg) |
---|
| 181 | { |
---|
[69ed59f] | 182 | BSP_uart_remove_isr(minor, ttyS[minor].isr); |
---|
[ba46ffa6] | 183 | return 0; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /*-------------------------------------------------------------------------+ |
---|
| 187 | | Console device driver OPEN entry point |
---|
| 188 | +--------------------------------------------------------------------------*/ |
---|
[923dd7a] | 189 | rtems_device_driver console_open( |
---|
| 190 | rtems_device_major_number major, |
---|
| 191 | rtems_device_minor_number minor, |
---|
| 192 | void *arg |
---|
| 193 | ) |
---|
[ba46ffa6] | 194 | { |
---|
| 195 | rtems_status_code status; |
---|
[6128a4a] | 196 | static rtems_termios_callbacks cb = |
---|
[e79a1947] | 197 | #if defined(USE_POLLED_IO) |
---|
[ac7af4a] | 198 | { |
---|
[e79a1947] | 199 | NULL, /* firstOpen */ |
---|
| 200 | NULL, /* lastClose */ |
---|
| 201 | NULL, /* pollRead */ |
---|
| 202 | BSP_uart_termios_write_polled, /* write */ |
---|
| 203 | conSetAttr, /* setAttributes */ |
---|
| 204 | NULL, /* stopRemoteTx */ |
---|
| 205 | NULL, /* startRemoteTx */ |
---|
[8e861444] | 206 | TERMIOS_POLLED /* outputUsesInterrupts */ |
---|
[ba46ffa6] | 207 | }; |
---|
[e79a1947] | 208 | #else |
---|
[ac7af4a] | 209 | { |
---|
[e79a1947] | 210 | console_first_open, /* firstOpen */ |
---|
| 211 | console_last_close, /* lastClose */ |
---|
[8e861444] | 212 | #if ( TERMIOS_OUTPUT_MODE == TERMIOS_TASK_DRIVEN ) |
---|
| 213 | BSP_uart_termios_read_com, /* pollRead */ |
---|
| 214 | #else |
---|
[e79a1947] | 215 | NULL, /* pollRead */ |
---|
[8e861444] | 216 | #endif |
---|
[e79a1947] | 217 | BSP_uart_termios_write_com, /* write */ |
---|
| 218 | conSetAttr, /* setAttributes */ |
---|
| 219 | NULL, /* stopRemoteTx */ |
---|
| 220 | NULL, /* startRemoteTx */ |
---|
[8e861444] | 221 | TERMIOS_OUTPUT_MODE /* outputUsesInterrupts */ |
---|
[e79a1947] | 222 | }; |
---|
| 223 | #endif |
---|
[ba46ffa6] | 224 | |
---|
| 225 | status = rtems_termios_open (major, minor, arg, &cb); |
---|
| 226 | |
---|
[923dd7a] | 227 | if (status != RTEMS_SUCCESSFUL) { |
---|
| 228 | printk("Error opening console device\n"); |
---|
| 229 | return status; |
---|
| 230 | } |
---|
[ba46ffa6] | 231 | |
---|
| 232 | return RTEMS_SUCCESSFUL; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /*-------------------------------------------------------------------------+ |
---|
| 236 | | Console device driver CLOSE entry point |
---|
| 237 | +--------------------------------------------------------------------------*/ |
---|
| 238 | rtems_device_driver |
---|
[923dd7a] | 239 | console_close( |
---|
| 240 | rtems_device_major_number major, |
---|
| 241 | rtems_device_minor_number minor, |
---|
| 242 | void *arg |
---|
| 243 | ) |
---|
[ba46ffa6] | 244 | { |
---|
| 245 | rtems_device_driver res = RTEMS_SUCCESSFUL; |
---|
| 246 | |
---|
| 247 | res = rtems_termios_close (arg); |
---|
[6128a4a] | 248 | |
---|
[ba46ffa6] | 249 | return res; |
---|
| 250 | } /* console_close */ |
---|
| 251 | |
---|
| 252 | /*-------------------------------------------------------------------------+ |
---|
| 253 | | Console device driver READ entry point. |
---|
| 254 | +--------------------------------------------------------------------------+ |
---|
| 255 | | Read characters from the I/O console. We only have stdin. |
---|
| 256 | +--------------------------------------------------------------------------*/ |
---|
[923dd7a] | 257 | rtems_device_driver console_read( |
---|
| 258 | rtems_device_major_number major, |
---|
| 259 | rtems_device_minor_number minor, |
---|
| 260 | void *arg |
---|
| 261 | ) |
---|
[ba46ffa6] | 262 | { |
---|
| 263 | return rtems_termios_read (arg); |
---|
| 264 | } /* console_read */ |
---|
[6128a4a] | 265 | |
---|
[ba46ffa6] | 266 | /*-------------------------------------------------------------------------+ |
---|
| 267 | | Console device driver WRITE entry point. |
---|
| 268 | +--------------------------------------------------------------------------+ |
---|
| 269 | | Write characters to the I/O console. Stderr and stdout are the same. |
---|
| 270 | +--------------------------------------------------------------------------*/ |
---|
[923dd7a] | 271 | rtems_device_driver console_write( |
---|
| 272 | rtems_device_major_number major, |
---|
| 273 | rtems_device_minor_number minor, |
---|
| 274 | void *arg |
---|
| 275 | ) |
---|
[ba46ffa6] | 276 | { |
---|
| 277 | return rtems_termios_write (arg); |
---|
| 278 | } /* console_write */ |
---|
| 279 | |
---|
| 280 | /* |
---|
| 281 | * Handle ioctl request. |
---|
| 282 | */ |
---|
[923dd7a] | 283 | rtems_device_driver console_control( |
---|
| 284 | rtems_device_major_number major, |
---|
| 285 | rtems_device_minor_number minor, |
---|
| 286 | void *arg |
---|
| 287 | ) |
---|
[6128a4a] | 288 | { |
---|
[4f3e4f33] | 289 | /* does the BSP support break callbacks ? */ |
---|
| 290 | #if defined(BIOCSETBREAKCB) && defined(BIOCGETBREAKCB) |
---|
[923dd7a] | 291 | rtems_libio_ioctl_args_t *ioa=arg; |
---|
| 292 | switch (ioa->command) { |
---|
| 293 | case BIOCSETBREAKCB: return BSP_uart_set_break_cb(minor, ioa); |
---|
| 294 | case BIOCGETBREAKCB: return BSP_uart_get_break_cb(minor, ioa); |
---|
| 295 | default: break; |
---|
| 296 | } |
---|
[4f3e4f33] | 297 | #endif |
---|
[ba46ffa6] | 298 | return rtems_termios_ioctl (arg); |
---|
| 299 | } |
---|
| 300 | |
---|
[923dd7a] | 301 | static int conSetAttr( |
---|
| 302 | int minor, |
---|
| 303 | const struct termios *t |
---|
| 304 | ) |
---|
[ba46ffa6] | 305 | { |
---|
[b0484c1] | 306 | rtems_termios_baud_t baud; |
---|
[ba46ffa6] | 307 | |
---|
[b0484c1] | 308 | baud = rtems_termios_baud_to_number(t->c_cflag & CBAUD); |
---|
[923dd7a] | 309 | if ( baud > 115200 ) |
---|
| 310 | rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR); |
---|
[ba46ffa6] | 311 | |
---|
[69ed59f] | 312 | BSP_uart_set_baud(minor, baud); |
---|
[ba46ffa6] | 313 | |
---|
| 314 | return 0; |
---|
| 315 | } |
---|