[0ebbf66] | 1 | /*-------------------------------------------------------------------------+ |
---|
| 2 | | console.c v1.1 - i386ex BSP - 1997/08/07 |
---|
| 3 | +--------------------------------------------------------------------------+ |
---|
| 4 | | This file contains the i386ex console I/O package. It is just a termios |
---|
| 5 | | wrapper. |
---|
| 6 | +--------------------------------------------------------------------------+ |
---|
| 7 | | (C) Copyright 1997 - |
---|
| 8 | | - NavIST Group - Real-Time Distributed Systems and Industrial Automation |
---|
| 9 | | |
---|
| 10 | | http://pandora.ist.utl.pt |
---|
| 11 | | |
---|
| 12 | | Instituto Superior Tecnico * Lisboa * PORTUGAL |
---|
| 13 | +--------------------------------------------------------------------------+ |
---|
| 14 | | Disclaimer: |
---|
| 15 | | |
---|
| 16 | | This file is provided "AS IS" without warranty of any kind, either |
---|
| 17 | | expressed or implied. |
---|
| 18 | +--------------------------------------------------------------------------+ |
---|
| 19 | | This code is based on: |
---|
| 20 | | console.c,v 1.4 1995/12/19 20:07:23 joel Exp - go32 BSP |
---|
| 21 | | console.c,v 1.15 pc386 BSP |
---|
| 22 | | With the following copyright notice: |
---|
| 23 | | ************************************************************************** |
---|
[08311cc3] | 24 | | * COPYRIGHT (c) 1989-1999. |
---|
[0ebbf66] | 25 | | * On-Line Applications Research Corporation (OAR). |
---|
| 26 | | * |
---|
| 27 | | * The license and distribution terms for this file may be |
---|
| 28 | | * found in found in the file LICENSE in this distribution or at |
---|
[6ff7e2c] | 29 | | * http://www.rtems.com/license/LICENSE. |
---|
[0ebbf66] | 30 | | ************************************************************************** |
---|
| 31 | | |
---|
| 32 | | $Id$ |
---|
| 33 | +--------------------------------------------------------------------------*/ |
---|
| 34 | |
---|
| 35 | #include <stdio.h> |
---|
| 36 | #include <stdlib.h> |
---|
| 37 | #include <assert.h> |
---|
[752cd8f] | 38 | |
---|
[6c58b6f] | 39 | #include <bsp.h> |
---|
[0ebbf66] | 40 | #include <irq.h> |
---|
[6c58b6f] | 41 | #include <rtems/libio.h> |
---|
[844de99] | 42 | #include <rtems/error.h> |
---|
[0ebbf66] | 43 | #include <termios.h> |
---|
| 44 | #include <uart.h> |
---|
| 45 | #include <libcpu/cpuModel.h> |
---|
[752cd8f] | 46 | |
---|
[0ebbf66] | 47 | /* |
---|
| 48 | * Possible value for console input/output : |
---|
| 49 | * BSP_UART_COM1 |
---|
| 50 | * BSP_UART_COM2 |
---|
| 51 | * BSP_CONSOLE_PORT_CONSOLE is not valid in this BSP. |
---|
| 52 | * All references to either keyboard or video handling have been removed. |
---|
[752cd8f] | 53 | */ |
---|
| 54 | |
---|
[0ebbf66] | 55 | int BSPConsolePort = BSP_UART_COM2; |
---|
| 56 | int BSPBaseBaud = 781250; |
---|
| 57 | int BSP_poll_read(int); |
---|
| 58 | |
---|
| 59 | extern BSP_polling_getchar_function_type BSP_poll_char; |
---|
[752cd8f] | 60 | |
---|
[0ebbf66] | 61 | static int conSetAttr(int minor, const struct termios *); |
---|
| 62 | static void isr_on(const rtems_irq_connect_data *); |
---|
| 63 | static void isr_off(const rtems_irq_connect_data *); |
---|
| 64 | static int isr_is_on(const rtems_irq_connect_data *); |
---|
| 65 | |
---|
| 66 | /* |
---|
| 67 | * Change references to com2 if required. |
---|
| 68 | */ |
---|
[752cd8f] | 69 | |
---|
[0ebbf66] | 70 | static rtems_irq_connect_data console_isr_data = |
---|
| 71 | { BSP_UART_COM2_IRQ, |
---|
| 72 | BSP_uart_termios_isr_com2, |
---|
| 73 | isr_on, |
---|
| 74 | isr_off, |
---|
| 75 | isr_is_on}; |
---|
[752cd8f] | 76 | |
---|
[0ebbf66] | 77 | static void |
---|
| 78 | isr_on(const rtems_irq_connect_data *unused) |
---|
| 79 | { |
---|
| 80 | return; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | static void |
---|
| 84 | isr_off(const rtems_irq_connect_data *unused) |
---|
| 85 | { |
---|
| 86 | return; |
---|
[752cd8f] | 87 | } |
---|
| 88 | |
---|
[0ebbf66] | 89 | static int |
---|
| 90 | isr_is_on(const rtems_irq_connect_data *irq) |
---|
| 91 | { |
---|
| 92 | return BSP_irq_enabled_at_i8259s(irq->name); |
---|
| 93 | } |
---|
[752cd8f] | 94 | |
---|
[0ebbf66] | 95 | /*-------------------------------------------------------------------------+ |
---|
| 96 | | Console device driver INITIALIZE entry point. |
---|
| 97 | +--------------------------------------------------------------------------+ |
---|
| 98 | | Initilizes the I/O console (keyboard + VGA display) driver. |
---|
| 99 | +--------------------------------------------------------------------------*/ |
---|
| 100 | rtems_device_driver |
---|
| 101 | console_initialize(rtems_device_major_number major, |
---|
| 102 | rtems_device_minor_number minor, |
---|
| 103 | void *arg) |
---|
| 104 | { |
---|
| 105 | rtems_status_code status; |
---|
| 106 | |
---|
| 107 | /* |
---|
| 108 | * Set up TERMIOS |
---|
| 109 | */ |
---|
| 110 | rtems_termios_initialize (); |
---|
| 111 | |
---|
| 112 | /* |
---|
| 113 | * Do device-specific initialization |
---|
| 114 | */ |
---|
| 115 | |
---|
| 116 | /* 9600-8-N-1, no hardware flow control */ |
---|
[cf5be833] | 117 | BSP_uart_init(BSPConsolePort, 9600, CHR_8_BITS, 0, 0, 0); |
---|
[0ebbf66] | 118 | |
---|
| 119 | |
---|
| 120 | /* Set interrupt handler */ |
---|
| 121 | if(BSPConsolePort == BSP_UART_COM1) |
---|
| 122 | { |
---|
| 123 | console_isr_data.name = BSP_UART_COM1_IRQ; |
---|
| 124 | console_isr_data.hdl = BSP_uart_termios_isr_com1; |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | else |
---|
| 128 | { |
---|
| 129 | assert(BSPConsolePort == BSP_UART_COM2); |
---|
| 130 | console_isr_data.name = BSP_UART_COM2_IRQ; |
---|
| 131 | console_isr_data.hdl = BSP_uart_termios_isr_com2; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | status = BSP_install_rtems_irq_handler(&console_isr_data); |
---|
| 135 | |
---|
| 136 | if (!status){ |
---|
| 137 | printk("Error installing serial console interrupt handler!\n"); |
---|
[6c58b6f] | 138 | rtems_fatal_error_occurred(status); |
---|
[0ebbf66] | 139 | } |
---|
| 140 | /* |
---|
| 141 | * Register the device |
---|
| 142 | */ |
---|
| 143 | status = rtems_io_register_name ("/dev/console", major, 0); |
---|
| 144 | if (status != RTEMS_SUCCESSFUL) |
---|
| 145 | { |
---|
| 146 | printk("Error registering console device!\n"); |
---|
| 147 | rtems_fatal_error_occurred (status); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | if(BSPConsolePort == BSP_UART_COM1) |
---|
| 151 | { |
---|
| 152 | printk("Initialized console on port COM1 9600-8-N-1\n\n"); |
---|
| 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | printk("Initialized console on port COM2 9600-8-N-1\n\n"); |
---|
| 157 | } |
---|
[6c58b6f] | 158 | |
---|
| 159 | return RTEMS_SUCCESSFUL; |
---|
[0ebbf66] | 160 | } /* console_initialize */ |
---|
[752cd8f] | 161 | |
---|
| 162 | |
---|
[0ebbf66] | 163 | static int console_last_close(int major, int minor, void *arg) |
---|
[752cd8f] | 164 | { |
---|
[0ebbf66] | 165 | BSP_remove_rtems_irq_handler (&console_isr_data); |
---|
[752cd8f] | 166 | |
---|
[0ebbf66] | 167 | return 0; |
---|
[752cd8f] | 168 | } |
---|
| 169 | |
---|
[0ebbf66] | 170 | /*-------------------------------------------------------------------------+ |
---|
| 171 | | Console device driver OPEN entry point |
---|
| 172 | +--------------------------------------------------------------------------*/ |
---|
| 173 | rtems_device_driver |
---|
| 174 | console_open(rtems_device_major_number major, |
---|
| 175 | rtems_device_minor_number minor, |
---|
| 176 | void *arg) |
---|
[bd8c8b2a] | 177 | { |
---|
[0ebbf66] | 178 | rtems_status_code status; |
---|
| 179 | static rtems_termios_callbacks cb = |
---|
| 180 | { |
---|
| 181 | NULL, /* firstOpen */ |
---|
| 182 | console_last_close, /* lastClose */ |
---|
| 183 | NULL, /* poll read */ |
---|
| 184 | BSP_uart_termios_write_com2, /* write */ |
---|
| 185 | conSetAttr, /* setAttributes */ |
---|
| 186 | NULL, /* stopRemoteTx */ |
---|
| 187 | NULL, /* startRemoteTx */ |
---|
| 188 | 1 /* outputUsesInterrupts */ |
---|
| 189 | }; |
---|
| 190 | |
---|
| 191 | if(BSPConsolePort == BSP_UART_COM2) |
---|
| 192 | { |
---|
| 193 | cb.write = BSP_uart_termios_write_com2; |
---|
| 194 | } |
---|
[752cd8f] | 195 | |
---|
[0ebbf66] | 196 | status = rtems_termios_open (major, minor, arg, &cb); |
---|
[752cd8f] | 197 | |
---|
[0ebbf66] | 198 | if(status != RTEMS_SUCCESSFUL) |
---|
| 199 | { |
---|
| 200 | printk("Error openning console device\n"); |
---|
| 201 | return status; |
---|
| 202 | } |
---|
[752cd8f] | 203 | |
---|
[0ebbf66] | 204 | /* |
---|
| 205 | * Pass data area info down to driver |
---|
| 206 | */ |
---|
| 207 | BSP_uart_termios_set(BSPConsolePort, |
---|
| 208 | ((rtems_libio_open_close_args_t *)arg)->iop->data1); |
---|
| 209 | |
---|
| 210 | /* Enable interrupts on channel */ |
---|
| 211 | BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS); |
---|
[752cd8f] | 212 | |
---|
[0ebbf66] | 213 | return RTEMS_SUCCESSFUL; |
---|
[752cd8f] | 214 | } |
---|
| 215 | |
---|
[0ebbf66] | 216 | /*-------------------------------------------------------------------------+ |
---|
| 217 | | Console device driver CLOSE entry point |
---|
| 218 | +--------------------------------------------------------------------------*/ |
---|
| 219 | rtems_device_driver |
---|
| 220 | console_close(rtems_device_major_number major, |
---|
| 221 | rtems_device_minor_number minor, |
---|
| 222 | void *arg) |
---|
[752cd8f] | 223 | { |
---|
| 224 | |
---|
[0ebbf66] | 225 | return (rtems_termios_close (arg)); |
---|
[752cd8f] | 226 | |
---|
[0ebbf66] | 227 | } /* console_close */ |
---|
[752cd8f] | 228 | |
---|
[0ebbf66] | 229 | |
---|
| 230 | /*-------------------------------------------------------------------------+ |
---|
| 231 | | Console device driver READ entry point. |
---|
| 232 | +--------------------------------------------------------------------------+ |
---|
| 233 | | Read characters from the I/O console. We only have stdin. |
---|
| 234 | +--------------------------------------------------------------------------*/ |
---|
| 235 | rtems_device_driver |
---|
| 236 | console_read(rtems_device_major_number major, |
---|
| 237 | rtems_device_minor_number minor, |
---|
| 238 | void *arg) |
---|
| 239 | { |
---|
| 240 | rtems_status_code sc; |
---|
| 241 | printf("read the console\n"); |
---|
[752cd8f] | 242 | |
---|
[0ebbf66] | 243 | sc = rtems_termios_read (arg); |
---|
[752cd8f] | 244 | |
---|
[0ebbf66] | 245 | if ( sc != RTEMS_SUCCESSFUL ) |
---|
| 246 | printf("console_read: fails %s\n",rtems_status_text(sc)); |
---|
[752cd8f] | 247 | |
---|
[0ebbf66] | 248 | return sc; |
---|
| 249 | |
---|
| 250 | } /* console_read */ |
---|
[6c58b6f] | 251 | |
---|
[0ebbf66] | 252 | |
---|
| 253 | /*-------------------------------------------------------------------------+ |
---|
| 254 | | Console device driver WRITE entry point. |
---|
| 255 | +--------------------------------------------------------------------------+ |
---|
| 256 | | Write characters to the I/O console. Stderr and stdout are the same. |
---|
| 257 | +--------------------------------------------------------------------------*/ |
---|
| 258 | rtems_device_driver |
---|
| 259 | console_write(rtems_device_major_number major, |
---|
| 260 | rtems_device_minor_number minor, |
---|
| 261 | void * arg) |
---|
[752cd8f] | 262 | { |
---|
[0ebbf66] | 263 | return rtems_termios_write (arg); |
---|
[6c58b6f] | 264 | |
---|
[0ebbf66] | 265 | } /* console_write */ |
---|
| 266 | |
---|
| 267 | |
---|
[6c58b6f] | 268 | |
---|
| 269 | /* |
---|
[0ebbf66] | 270 | * Handle ioctl request. |
---|
[6c58b6f] | 271 | */ |
---|
[0ebbf66] | 272 | rtems_device_driver |
---|
| 273 | console_control(rtems_device_major_number major, |
---|
| 274 | rtems_device_minor_number minor, |
---|
| 275 | void * arg |
---|
[6c58b6f] | 276 | ) |
---|
[0ebbf66] | 277 | { |
---|
| 278 | return rtems_termios_ioctl (arg); |
---|
[752cd8f] | 279 | } |
---|
| 280 | |
---|
[0ebbf66] | 281 | static int |
---|
| 282 | conSetAttr(int minor, const struct termios *t) |
---|
[752cd8f] | 283 | { |
---|
[0ebbf66] | 284 | int baud; |
---|
| 285 | |
---|
| 286 | switch (t->c_cflag & CBAUD) |
---|
| 287 | { |
---|
| 288 | case B50: |
---|
| 289 | baud = 50; |
---|
| 290 | break; |
---|
| 291 | case B75: |
---|
| 292 | baud = 75; |
---|
| 293 | break; |
---|
| 294 | case B110: |
---|
| 295 | baud = 110; |
---|
| 296 | break; |
---|
| 297 | case B134: |
---|
| 298 | baud = 134; |
---|
| 299 | break; |
---|
| 300 | case B150: |
---|
| 301 | baud = 150; |
---|
| 302 | break; |
---|
| 303 | case B200: |
---|
| 304 | baud = 200; |
---|
| 305 | break; |
---|
| 306 | case B300: |
---|
| 307 | baud = 300; |
---|
| 308 | break; |
---|
| 309 | case B600: |
---|
| 310 | baud = 600; |
---|
| 311 | break; |
---|
| 312 | case B1200: |
---|
| 313 | baud = 1200; |
---|
| 314 | break; |
---|
| 315 | case B1800: |
---|
| 316 | baud = 1800; |
---|
| 317 | break; |
---|
| 318 | case B2400: |
---|
| 319 | baud = 2400; |
---|
| 320 | break; |
---|
| 321 | case B4800: |
---|
| 322 | baud = 4800; |
---|
| 323 | break; |
---|
| 324 | case B9600: |
---|
| 325 | baud = 9600; |
---|
| 326 | break; |
---|
| 327 | case B19200: |
---|
| 328 | baud = 19200; |
---|
| 329 | break; |
---|
| 330 | case B38400: |
---|
| 331 | baud = 38400; |
---|
| 332 | break; |
---|
| 333 | case B57600: |
---|
| 334 | baud = 57600; |
---|
| 335 | break; |
---|
| 336 | case B115200: |
---|
| 337 | baud = 115200; |
---|
| 338 | break; |
---|
| 339 | default: |
---|
| 340 | baud = 0; |
---|
| 341 | rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR); |
---|
| 342 | return 0; |
---|
[752cd8f] | 343 | } |
---|
[0ebbf66] | 344 | |
---|
| 345 | BSP_uart_set_baud(BSPConsolePort, baud); |
---|
| 346 | |
---|
[6c58b6f] | 347 | return 0; |
---|
| 348 | } |
---|
[0ebbf66] | 349 | |
---|
[6c58b6f] | 350 | /* |
---|
[0ebbf66] | 351 | * BSP initialization |
---|
[6c58b6f] | 352 | */ |
---|
[bd8c8b2a] | 353 | |
---|
[0ebbf66] | 354 | BSP_output_char_function_type BSP_output_char = |
---|
| 355 | (BSP_output_char_function_type) BSP_output_char_via_serial; |
---|
| 356 | |
---|
| 357 | BSP_polling_getchar_function_type BSP_poll_char = |
---|
| 358 | (BSP_polling_getchar_function_type) BSP_poll_char_via_serial; |
---|
[bd8c8b2a] | 359 | |
---|
[0ebbf66] | 360 | int BSP_poll_read(int ttyMinor){ |
---|
| 361 | |
---|
| 362 | return BSP_poll_char_via_serial(); |
---|
| 363 | } |
---|