[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 | | ************************************************************************** |
---|
| 24 | | * COPYRIGHT (c) 1989-1998. |
---|
| 25 | | * On-Line Applications Research Corporation (OAR). |
---|
| 26 | | * Copyright assigned to U.S. Government, 1994. |
---|
| 27 | | * |
---|
| 28 | | * The license and distribution terms for this file may be |
---|
| 29 | | * found in found in the file LICENSE in this distribution or at |
---|
| 30 | | * http://www.OARcorp.com/rtems/license.html. |
---|
| 31 | | ************************************************************************** |
---|
| 32 | | |
---|
| 33 | | $Id$ |
---|
| 34 | +--------------------------------------------------------------------------*/ |
---|
| 35 | |
---|
| 36 | #include <stdio.h> |
---|
| 37 | #include <stdlib.h> |
---|
| 38 | #include <assert.h> |
---|
[752cd8f] | 39 | |
---|
[0ebbf66] | 40 | /* workaround for gcc development tools */ |
---|
| 41 | #undef __assert |
---|
| 42 | void __assert (const char *file, int line, const char *msg); |
---|
[752cd8f] | 43 | |
---|
[6c58b6f] | 44 | #include <bsp.h> |
---|
[0ebbf66] | 45 | #include <irq.h> |
---|
[6c58b6f] | 46 | #include <rtems/libio.h> |
---|
[0ebbf66] | 47 | #include <termios.h> |
---|
| 48 | #include <uart.h> |
---|
| 49 | #include <libcpu/cpuModel.h> |
---|
[752cd8f] | 50 | |
---|
[0ebbf66] | 51 | /* |
---|
| 52 | * Possible value for console input/output : |
---|
| 53 | * BSP_UART_COM1 |
---|
| 54 | * BSP_UART_COM2 |
---|
| 55 | * BSP_CONSOLE_PORT_CONSOLE is not valid in this BSP. |
---|
| 56 | * All references to either keyboard or video handling have been removed. |
---|
[752cd8f] | 57 | */ |
---|
| 58 | |
---|
[0ebbf66] | 59 | int BSPConsolePort = BSP_UART_COM2; |
---|
| 60 | int BSPBaseBaud = 781250; |
---|
| 61 | int BSP_poll_read(int); |
---|
| 62 | |
---|
| 63 | extern BSP_polling_getchar_function_type BSP_poll_char; |
---|
[752cd8f] | 64 | |
---|
[0ebbf66] | 65 | static int conSetAttr(int minor, const struct termios *); |
---|
| 66 | static void isr_on(const rtems_irq_connect_data *); |
---|
| 67 | static void isr_off(const rtems_irq_connect_data *); |
---|
| 68 | static int isr_is_on(const rtems_irq_connect_data *); |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | * Change references to com2 if required. |
---|
| 72 | */ |
---|
[752cd8f] | 73 | |
---|
[0ebbf66] | 74 | static rtems_irq_connect_data console_isr_data = |
---|
| 75 | { BSP_UART_COM2_IRQ, |
---|
| 76 | BSP_uart_termios_isr_com2, |
---|
| 77 | isr_on, |
---|
| 78 | isr_off, |
---|
| 79 | isr_is_on}; |
---|
[752cd8f] | 80 | |
---|
[0ebbf66] | 81 | static void |
---|
| 82 | isr_on(const rtems_irq_connect_data *unused) |
---|
| 83 | { |
---|
| 84 | return; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | static void |
---|
| 88 | isr_off(const rtems_irq_connect_data *unused) |
---|
| 89 | { |
---|
| 90 | return; |
---|
[752cd8f] | 91 | } |
---|
| 92 | |
---|
[0ebbf66] | 93 | static int |
---|
| 94 | isr_is_on(const rtems_irq_connect_data *irq) |
---|
| 95 | { |
---|
| 96 | return BSP_irq_enabled_at_i8259s(irq->name); |
---|
| 97 | } |
---|
[752cd8f] | 98 | |
---|
[0ebbf66] | 99 | void console_reserve_resources(rtems_configuration_table *conf) |
---|
[752cd8f] | 100 | { |
---|
[0ebbf66] | 101 | rtems_termios_reserve_resources(conf, 1); |
---|
| 102 | return; |
---|
| 103 | } |
---|
[6c58b6f] | 104 | |
---|
[0ebbf66] | 105 | void __assert (const char *file, int line, const char *msg) |
---|
| 106 | { |
---|
| 107 | static char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot..."; |
---|
| 108 | unsigned char ch; |
---|
| 109 | |
---|
[6c58b6f] | 110 | /* |
---|
[0ebbf66] | 111 | * Note we cannot call exit or printf from here, |
---|
| 112 | * assert can fail inside ISR too |
---|
[6c58b6f] | 113 | */ |
---|
| 114 | |
---|
[0ebbf66] | 115 | /* |
---|
| 116 | * Close console |
---|
| 117 | */ |
---|
[97d6366] | 118 | close(2); |
---|
| 119 | close(1); |
---|
| 120 | close(0); |
---|
[0ebbf66] | 121 | |
---|
| 122 | printk("\nassert failed: %s: ", file); |
---|
| 123 | printk("%d: ", line); |
---|
| 124 | printk("%s\n\n", msg); |
---|
| 125 | printk(exit_msg); |
---|
| 126 | ch = BSP_poll_char(); |
---|
| 127 | printk("\nShould jump to reset now!\n"); |
---|
| 128 | } |
---|
[6c58b6f] | 129 | |
---|
[0ebbf66] | 130 | |
---|
| 131 | /*-------------------------------------------------------------------------+ |
---|
| 132 | | Console device driver INITIALIZE entry point. |
---|
| 133 | +--------------------------------------------------------------------------+ |
---|
| 134 | | Initilizes the I/O console (keyboard + VGA display) driver. |
---|
| 135 | +--------------------------------------------------------------------------*/ |
---|
| 136 | rtems_device_driver |
---|
| 137 | console_initialize(rtems_device_major_number major, |
---|
| 138 | rtems_device_minor_number minor, |
---|
| 139 | void *arg) |
---|
| 140 | { |
---|
| 141 | rtems_status_code status; |
---|
| 142 | |
---|
| 143 | /* |
---|
| 144 | * Set up TERMIOS |
---|
| 145 | */ |
---|
| 146 | rtems_termios_initialize (); |
---|
| 147 | |
---|
| 148 | /* |
---|
| 149 | * Do device-specific initialization |
---|
| 150 | */ |
---|
| 151 | |
---|
| 152 | /* 9600-8-N-1, no hardware flow control */ |
---|
| 153 | BSP_uart_init(BSPConsolePort, 9600, 0); |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | /* Set interrupt handler */ |
---|
| 157 | if(BSPConsolePort == BSP_UART_COM1) |
---|
| 158 | { |
---|
| 159 | console_isr_data.name = BSP_UART_COM1_IRQ; |
---|
| 160 | console_isr_data.hdl = BSP_uart_termios_isr_com1; |
---|
| 161 | |
---|
| 162 | } |
---|
| 163 | else |
---|
| 164 | { |
---|
| 165 | assert(BSPConsolePort == BSP_UART_COM2); |
---|
| 166 | console_isr_data.name = BSP_UART_COM2_IRQ; |
---|
| 167 | console_isr_data.hdl = BSP_uart_termios_isr_com2; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | status = BSP_install_rtems_irq_handler(&console_isr_data); |
---|
| 171 | |
---|
| 172 | if (!status){ |
---|
| 173 | printk("Error installing serial console interrupt handler!\n"); |
---|
[6c58b6f] | 174 | rtems_fatal_error_occurred(status); |
---|
[0ebbf66] | 175 | } |
---|
| 176 | /* |
---|
| 177 | * Register the device |
---|
| 178 | */ |
---|
| 179 | status = rtems_io_register_name ("/dev/console", major, 0); |
---|
| 180 | if (status != RTEMS_SUCCESSFUL) |
---|
| 181 | { |
---|
| 182 | printk("Error registering console device!\n"); |
---|
| 183 | rtems_fatal_error_occurred (status); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | if(BSPConsolePort == BSP_UART_COM1) |
---|
| 187 | { |
---|
| 188 | printk("Initialized console on port COM1 9600-8-N-1\n\n"); |
---|
| 189 | } |
---|
| 190 | else |
---|
| 191 | { |
---|
| 192 | printk("Initialized console on port COM2 9600-8-N-1\n\n"); |
---|
| 193 | } |
---|
[6c58b6f] | 194 | |
---|
| 195 | return RTEMS_SUCCESSFUL; |
---|
[0ebbf66] | 196 | } /* console_initialize */ |
---|
[752cd8f] | 197 | |
---|
| 198 | |
---|
[0ebbf66] | 199 | static int console_open_count = 0; |
---|
[752cd8f] | 200 | |
---|
[0ebbf66] | 201 | static int console_last_close(int major, int minor, void *arg) |
---|
[752cd8f] | 202 | { |
---|
[0ebbf66] | 203 | BSP_remove_rtems_irq_handler (&console_isr_data); |
---|
[752cd8f] | 204 | |
---|
[0ebbf66] | 205 | return 0; |
---|
[752cd8f] | 206 | } |
---|
| 207 | |
---|
[0ebbf66] | 208 | /*-------------------------------------------------------------------------+ |
---|
| 209 | | Console device driver OPEN entry point |
---|
| 210 | +--------------------------------------------------------------------------*/ |
---|
| 211 | rtems_device_driver |
---|
| 212 | console_open(rtems_device_major_number major, |
---|
| 213 | rtems_device_minor_number minor, |
---|
| 214 | void *arg) |
---|
[bd8c8b2a] | 215 | { |
---|
[0ebbf66] | 216 | rtems_status_code status; |
---|
| 217 | static rtems_termios_callbacks cb = |
---|
| 218 | { |
---|
| 219 | NULL, /* firstOpen */ |
---|
| 220 | console_last_close, /* lastClose */ |
---|
| 221 | NULL, /* poll read */ |
---|
| 222 | BSP_uart_termios_write_com2, /* write */ |
---|
| 223 | conSetAttr, /* setAttributes */ |
---|
| 224 | NULL, /* stopRemoteTx */ |
---|
| 225 | NULL, /* startRemoteTx */ |
---|
| 226 | 1 /* outputUsesInterrupts */ |
---|
| 227 | }; |
---|
| 228 | |
---|
| 229 | if(BSPConsolePort == BSP_UART_COM2) |
---|
| 230 | { |
---|
| 231 | cb.write = BSP_uart_termios_write_com2; |
---|
| 232 | } |
---|
[752cd8f] | 233 | |
---|
[0ebbf66] | 234 | status = rtems_termios_open (major, minor, arg, &cb); |
---|
[752cd8f] | 235 | |
---|
[0ebbf66] | 236 | if(status != RTEMS_SUCCESSFUL) |
---|
| 237 | { |
---|
| 238 | printk("Error openning console device\n"); |
---|
| 239 | return status; |
---|
| 240 | } |
---|
[752cd8f] | 241 | |
---|
[0ebbf66] | 242 | /* |
---|
| 243 | * Pass data area info down to driver |
---|
| 244 | */ |
---|
| 245 | BSP_uart_termios_set(BSPConsolePort, |
---|
| 246 | ((rtems_libio_open_close_args_t *)arg)->iop->data1); |
---|
| 247 | |
---|
| 248 | /* Enable interrupts on channel */ |
---|
| 249 | BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS); |
---|
[752cd8f] | 250 | |
---|
[0ebbf66] | 251 | return RTEMS_SUCCESSFUL; |
---|
[752cd8f] | 252 | } |
---|
| 253 | |
---|
[0ebbf66] | 254 | /*-------------------------------------------------------------------------+ |
---|
| 255 | | Console device driver CLOSE entry point |
---|
| 256 | +--------------------------------------------------------------------------*/ |
---|
| 257 | rtems_device_driver |
---|
| 258 | console_close(rtems_device_major_number major, |
---|
| 259 | rtems_device_minor_number minor, |
---|
| 260 | void *arg) |
---|
[752cd8f] | 261 | { |
---|
| 262 | |
---|
[0ebbf66] | 263 | return (rtems_termios_close (arg)); |
---|
[752cd8f] | 264 | |
---|
[0ebbf66] | 265 | } /* console_close */ |
---|
[752cd8f] | 266 | |
---|
[0ebbf66] | 267 | |
---|
| 268 | /*-------------------------------------------------------------------------+ |
---|
| 269 | | Console device driver READ entry point. |
---|
| 270 | +--------------------------------------------------------------------------+ |
---|
| 271 | | Read characters from the I/O console. We only have stdin. |
---|
| 272 | +--------------------------------------------------------------------------*/ |
---|
| 273 | rtems_device_driver |
---|
| 274 | console_read(rtems_device_major_number major, |
---|
| 275 | rtems_device_minor_number minor, |
---|
| 276 | void *arg) |
---|
| 277 | { |
---|
| 278 | rtems_status_code sc; |
---|
| 279 | printf("read the console\n"); |
---|
[752cd8f] | 280 | |
---|
[0ebbf66] | 281 | sc = rtems_termios_read (arg); |
---|
[752cd8f] | 282 | |
---|
[0ebbf66] | 283 | if ( sc != RTEMS_SUCCESSFUL ) |
---|
| 284 | printf("console_read: fails %s\n",rtems_status_text(sc)); |
---|
[752cd8f] | 285 | |
---|
[0ebbf66] | 286 | return sc; |
---|
| 287 | |
---|
| 288 | } /* console_read */ |
---|
[6c58b6f] | 289 | |
---|
[0ebbf66] | 290 | |
---|
| 291 | /*-------------------------------------------------------------------------+ |
---|
| 292 | | Console device driver WRITE entry point. |
---|
| 293 | +--------------------------------------------------------------------------+ |
---|
| 294 | | Write characters to the I/O console. Stderr and stdout are the same. |
---|
| 295 | +--------------------------------------------------------------------------*/ |
---|
| 296 | rtems_device_driver |
---|
| 297 | console_write(rtems_device_major_number major, |
---|
| 298 | rtems_device_minor_number minor, |
---|
| 299 | void * arg) |
---|
[752cd8f] | 300 | { |
---|
[0ebbf66] | 301 | return rtems_termios_write (arg); |
---|
[6c58b6f] | 302 | |
---|
[0ebbf66] | 303 | } /* console_write */ |
---|
| 304 | |
---|
| 305 | |
---|
[6c58b6f] | 306 | |
---|
| 307 | /* |
---|
[0ebbf66] | 308 | * Handle ioctl request. |
---|
[6c58b6f] | 309 | */ |
---|
[0ebbf66] | 310 | rtems_device_driver |
---|
| 311 | console_control(rtems_device_major_number major, |
---|
| 312 | rtems_device_minor_number minor, |
---|
| 313 | void * arg |
---|
[6c58b6f] | 314 | ) |
---|
[0ebbf66] | 315 | { |
---|
| 316 | return rtems_termios_ioctl (arg); |
---|
[752cd8f] | 317 | } |
---|
| 318 | |
---|
[0ebbf66] | 319 | static int |
---|
| 320 | conSetAttr(int minor, const struct termios *t) |
---|
[752cd8f] | 321 | { |
---|
[0ebbf66] | 322 | int baud; |
---|
| 323 | |
---|
| 324 | switch (t->c_cflag & CBAUD) |
---|
| 325 | { |
---|
| 326 | case B50: |
---|
| 327 | baud = 50; |
---|
| 328 | break; |
---|
| 329 | case B75: |
---|
| 330 | baud = 75; |
---|
| 331 | break; |
---|
| 332 | case B110: |
---|
| 333 | baud = 110; |
---|
| 334 | break; |
---|
| 335 | case B134: |
---|
| 336 | baud = 134; |
---|
| 337 | break; |
---|
| 338 | case B150: |
---|
| 339 | baud = 150; |
---|
| 340 | break; |
---|
| 341 | case B200: |
---|
| 342 | baud = 200; |
---|
| 343 | break; |
---|
| 344 | case B300: |
---|
| 345 | baud = 300; |
---|
| 346 | break; |
---|
| 347 | case B600: |
---|
| 348 | baud = 600; |
---|
| 349 | break; |
---|
| 350 | case B1200: |
---|
| 351 | baud = 1200; |
---|
| 352 | break; |
---|
| 353 | case B1800: |
---|
| 354 | baud = 1800; |
---|
| 355 | break; |
---|
| 356 | case B2400: |
---|
| 357 | baud = 2400; |
---|
| 358 | break; |
---|
| 359 | case B4800: |
---|
| 360 | baud = 4800; |
---|
| 361 | break; |
---|
| 362 | case B9600: |
---|
| 363 | baud = 9600; |
---|
| 364 | break; |
---|
| 365 | case B19200: |
---|
| 366 | baud = 19200; |
---|
| 367 | break; |
---|
| 368 | case B38400: |
---|
| 369 | baud = 38400; |
---|
| 370 | break; |
---|
| 371 | case B57600: |
---|
| 372 | baud = 57600; |
---|
| 373 | break; |
---|
| 374 | case B115200: |
---|
| 375 | baud = 115200; |
---|
| 376 | break; |
---|
| 377 | default: |
---|
| 378 | baud = 0; |
---|
| 379 | rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR); |
---|
| 380 | return 0; |
---|
[752cd8f] | 381 | } |
---|
[0ebbf66] | 382 | |
---|
| 383 | BSP_uart_set_baud(BSPConsolePort, baud); |
---|
| 384 | |
---|
[6c58b6f] | 385 | return 0; |
---|
| 386 | } |
---|
[0ebbf66] | 387 | |
---|
[6c58b6f] | 388 | /* |
---|
[0ebbf66] | 389 | * BSP initialization |
---|
[6c58b6f] | 390 | */ |
---|
[bd8c8b2a] | 391 | |
---|
[0ebbf66] | 392 | BSP_output_char_function_type BSP_output_char = |
---|
| 393 | (BSP_output_char_function_type) BSP_output_char_via_serial; |
---|
| 394 | |
---|
| 395 | BSP_polling_getchar_function_type BSP_poll_char = |
---|
| 396 | (BSP_polling_getchar_function_type) BSP_poll_char_via_serial; |
---|
[bd8c8b2a] | 397 | |
---|
[0ebbf66] | 398 | int BSP_poll_read(int ttyMinor){ |
---|
| 399 | |
---|
| 400 | return BSP_poll_char_via_serial(); |
---|
| 401 | } |
---|