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