[8ef3818] | 1 | /* |
---|
| 2 | * console.c |
---|
| 3 | * |
---|
| 4 | * This file contains the MBX8xx termios serial I/O package. |
---|
| 5 | * Only asynchronous I/O is supported. |
---|
| 6 | * |
---|
| 7 | * The SCCs and SMCs are assigned as follows |
---|
| 8 | * |
---|
| 9 | * Channel Device Minor Note |
---|
| 10 | * SMC1 /dev/tty0 0 |
---|
| 11 | * SMC2 /dev/tty1 1 |
---|
| 12 | * SCC1 2 N/A. Hardwired as ethernet port |
---|
| 13 | * SCC2 /dev/tty2 3 |
---|
| 14 | * SCC3 /dev/tty3 4 |
---|
| 15 | * SCC4 /dev/tty4 5 |
---|
| 16 | * |
---|
[59d4d513] | 17 | * All ports support termios. The use of termios is recommended for real-time |
---|
| 18 | * applications. Termios provides buffering and input processing. When not |
---|
| 19 | * using termios, processing is limited to the substitution of LF for CR on |
---|
| 20 | * input, and the output of a CR following the output of a LF character. |
---|
| 21 | * Note that the terminal should not send CR/LF pairs when the return key |
---|
| 22 | * is pressed, and that output lines are terminated with LF/CR, not CR/LF |
---|
| 23 | * (although that would be easy to change). |
---|
| 24 | * |
---|
| 25 | * I/O may be interrupt-driven (recommended for real-time applications) or |
---|
| 26 | * polled. Polled I/O may be performed by this device driver entirely, or |
---|
| 27 | * in part by EPPCBug. With EPPCBug 1.1, polled I/O is limited to the |
---|
| 28 | * EPPCBug debug console. This is a limitation of the firmware. Later |
---|
| 29 | * firmware may be able to do I/O through any port. This code assumes |
---|
| 30 | * that the EPPCBug console is the default: SMC1. If the console and |
---|
| 31 | * printk ports are set to anything else with EPPCBug polled I/O, the |
---|
| 32 | * system will hang. Only port SMC1 is usable with EPPCBug polled I/O. |
---|
| 33 | * |
---|
| 34 | * LIMITATIONS: |
---|
| 35 | * |
---|
| 36 | * It is not possible to use different I/O modes on the different ports. The |
---|
| 37 | * exception is with printk. The printk port can use a different mode from |
---|
| 38 | * the other ports. If this is done, it is important not to open the printk |
---|
| 39 | * port from an RTEMS application. |
---|
| 40 | * |
---|
| 41 | * Currently, the I/O modes are determined at build time. It would be much |
---|
| 42 | * better to have the mode selected at boot time based on parameters in |
---|
| 43 | * NVRAM. |
---|
| 44 | * |
---|
| 45 | * Interrupt-driven I/O requires termios. |
---|
| 46 | * |
---|
| 47 | * TESTS: |
---|
[8ef3818] | 48 | * |
---|
[59d4d513] | 49 | * TO RUN THE TESTS, USE POLLED I/O WITHOUT TERMIOS SUPPORT. Some tests |
---|
| 50 | * play with the interrupt masks and turn off I/O. Those tests will hang |
---|
| 51 | * when interrupt-driven I/O is used. Other tests, such as cdtest, do I/O |
---|
| 52 | * from the static constructors before the console is open. This test |
---|
| 53 | * will not work with interrupt-driven I/O. Because of the buffering |
---|
| 54 | * performed in termios, test output may not be in sequence.The tests |
---|
| 55 | * should all be fixed to work with interrupt-driven I/O and to |
---|
| 56 | * produce output in the expected sequence. Obviously, the termios test |
---|
| 57 | * requires termios support in the driver. |
---|
[8ef3818] | 58 | * |
---|
| 59 | * Set CONSOLE_MINOR to the appropriate device minor number in the |
---|
| 60 | * config file. This allows the RTEMS application console to be different |
---|
[59d4d513] | 61 | * from the EPPBug debug console or the GDB port. |
---|
[8ef3818] | 62 | * |
---|
| 63 | * This driver handles all five available serial ports: it distinguishes |
---|
| 64 | * the sub-devices using minor device numbers. It is not possible to have |
---|
| 65 | * other protocols running on the other ports when this driver is used as |
---|
| 66 | * currently written. |
---|
| 67 | * |
---|
| 68 | * Based on code (alloc860.c in eth_comm port) by |
---|
| 69 | * Jay Monkman (jmonkman@frasca.com), |
---|
| 70 | * Copyright (C) 1998 by Frasca International, Inc. |
---|
| 71 | * |
---|
| 72 | * Modifications by Darlene Stewart <Darlene.Stewart@iit.nrc.ca> |
---|
| 73 | * and Charles-Antoine Gauthier <charles.gauthier@iit.nrc.ca>. |
---|
[59d4d513] | 74 | * Copyright (c) 2000, National Research Council of Canada |
---|
[8ef3818] | 75 | * |
---|
| 76 | */ |
---|
| 77 | #include <stdarg.h> |
---|
| 78 | #include <stdio.h> |
---|
| 79 | #include <bsp.h> /* Must be before libio.h */ |
---|
[59d4d513] | 80 | #include <bspIo.h> |
---|
[8ef3818] | 81 | #include <rtems/libio.h> |
---|
| 82 | #include <termios.h> |
---|
| 83 | |
---|
| 84 | static int _EPPCBug_pollRead( int minor ); |
---|
| 85 | static int _EPPCBug_pollWrite( int minor, const char *buf, int len ); |
---|
[59d4d513] | 86 | static void _BSP_output_char( char c ); |
---|
[00ff4cd] | 87 | static rtems_status_code do_poll_read( rtems_device_major_number major, rtems_device_minor_number minor, void * arg); |
---|
| 88 | static rtems_status_code do_poll_write( rtems_device_major_number major, rtems_device_minor_number minor, void * arg); |
---|
| 89 | |
---|
[59d4d513] | 90 | |
---|
| 91 | BSP_output_char_function_type BSP_output_char = _BSP_output_char; |
---|
[8ef3818] | 92 | |
---|
| 93 | |
---|
| 94 | /* |
---|
| 95 | * _EPPCBug_pollRead |
---|
| 96 | * |
---|
| 97 | * Read a character from the EPPCBug console, and return it. Return -1 |
---|
| 98 | * if there is no character in the input FIFO. |
---|
| 99 | * |
---|
| 100 | * Input parameters: |
---|
| 101 | * minor - selected channel |
---|
| 102 | * |
---|
| 103 | * Output parameters: NONE |
---|
| 104 | * |
---|
| 105 | * Return value: char returned as positive signed int |
---|
| 106 | * -1 if no character is present in the input FIFO. |
---|
| 107 | */ |
---|
[00ff4cd] | 108 | static int _EPPCBug_pollRead( |
---|
[8ef3818] | 109 | int minor |
---|
| 110 | ) |
---|
| 111 | { |
---|
| 112 | extern volatile m8xx_t m8xx; |
---|
| 113 | |
---|
| 114 | char c; |
---|
| 115 | volatile int simask; /* We must read and write m8xx.simask */ |
---|
| 116 | int retval; |
---|
| 117 | ISR_Level level; |
---|
| 118 | |
---|
| 119 | struct { |
---|
| 120 | int clun; |
---|
| 121 | int dlun; |
---|
| 122 | char * inbuf; |
---|
| 123 | int nbytes_requested; |
---|
| 124 | int reserved; |
---|
| 125 | } volatile input_params; |
---|
| 126 | |
---|
| 127 | struct { |
---|
| 128 | int status; |
---|
| 129 | union { |
---|
| 130 | struct { |
---|
| 131 | int input_char_available; |
---|
| 132 | int output_possible; |
---|
| 133 | int break_detected; |
---|
| 134 | int modem_status; |
---|
| 135 | } stat; |
---|
| 136 | struct { |
---|
| 137 | int nbytes_received; |
---|
| 138 | } read; |
---|
| 139 | } u; |
---|
| 140 | } volatile output_params; |
---|
| 141 | |
---|
| 142 | retval = -1; |
---|
| 143 | |
---|
| 144 | input_params.clun = 0; |
---|
[59d4d513] | 145 | |
---|
| 146 | switch( minor ) { |
---|
| 147 | case SMC1_MINOR: |
---|
| 148 | input_params.dlun = 0; /* Should be 4, but doesn't work with EPPCBug 1.1 */ |
---|
| 149 | break; |
---|
| 150 | case SMC2_MINOR: |
---|
| 151 | input_params.dlun = 5; |
---|
| 152 | break; |
---|
| 153 | case SCC2_MINOR: |
---|
| 154 | input_params.dlun = 1; |
---|
| 155 | break; |
---|
| 156 | #ifdef mpc860 |
---|
| 157 | case SCC3_MINOR: |
---|
| 158 | input_params.dlun = 2; |
---|
| 159 | break; |
---|
| 160 | case SCC4_MINOR: |
---|
| 161 | input_params.dlun = 3; |
---|
| 162 | break; |
---|
| 163 | #endif |
---|
| 164 | default: |
---|
| 165 | input_params.dlun = 0; |
---|
| 166 | break; |
---|
| 167 | } |
---|
[8ef3818] | 168 | |
---|
| 169 | _ISR_Disable( level ); |
---|
| 170 | simask = m8xx.simask; |
---|
| 171 | |
---|
| 172 | /* Check for a char in the input FIFO using .CIO_STAT */ |
---|
| 173 | asm volatile( "li 10,0x202 |
---|
| 174 | mr 3, %0 |
---|
| 175 | mr 4, %1 |
---|
| 176 | sc" |
---|
| 177 | :: "g" (&input_params), "g" (&output_params) : "3", "4", "10" ); |
---|
| 178 | |
---|
| 179 | if ( (output_params.status == 0) && output_params.u.stat.input_char_available) { |
---|
| 180 | |
---|
| 181 | /* Read the char and return it */ |
---|
| 182 | input_params.inbuf = &c; |
---|
| 183 | input_params.nbytes_requested = 1; |
---|
| 184 | |
---|
| 185 | asm volatile( "li 10,0x200 /* Code for .CIO_READ */ |
---|
| 186 | mr 3, %0 /* Address of input_params */ |
---|
| 187 | mr 4, %1 /* Address of output_params */ |
---|
| 188 | sc" /* Call EPPCBUG */ |
---|
| 189 | :: "g" (&input_params), "g" (&output_params) : "3", "4", "10" ); |
---|
| 190 | |
---|
| 191 | if ( (output_params.status == 0) && output_params.u.read.nbytes_received) |
---|
| 192 | retval = (int)c; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | m8xx.simask = simask; |
---|
| 196 | _ISR_Enable( level ); |
---|
| 197 | return retval; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | /* |
---|
| 202 | * _EPPCBug_pollWrite |
---|
| 203 | * |
---|
| 204 | * Output buffer through EPPCBug. Returns only once every character has been |
---|
| 205 | * sent (polled output). |
---|
| 206 | * |
---|
| 207 | * Input parameters: |
---|
| 208 | * minor - selected channel |
---|
| 209 | * buf - output buffer |
---|
| 210 | * len - number of chars to output |
---|
| 211 | * |
---|
| 212 | * Output parameters: NONE |
---|
| 213 | * |
---|
| 214 | * Return value: IGNORED |
---|
| 215 | */ |
---|
[00ff4cd] | 216 | static int _EPPCBug_pollWrite( |
---|
[8ef3818] | 217 | int minor, |
---|
| 218 | const char *buf, |
---|
| 219 | int len |
---|
| 220 | ) |
---|
| 221 | { |
---|
| 222 | extern volatile m8xx_t m8xx; |
---|
| 223 | |
---|
| 224 | volatile int simask; |
---|
| 225 | int i, retval; |
---|
| 226 | ISR_Level level; |
---|
| 227 | |
---|
| 228 | struct { |
---|
| 229 | int clun; |
---|
| 230 | int dlun; |
---|
| 231 | const char * outbuf; |
---|
| 232 | int nbytes_to_output; |
---|
| 233 | int reserved; |
---|
| 234 | } volatile input_params; |
---|
| 235 | |
---|
| 236 | struct { |
---|
| 237 | int status; |
---|
| 238 | union { |
---|
| 239 | struct { |
---|
| 240 | int input_char_available; |
---|
| 241 | int output_possible; |
---|
| 242 | int break_detected; |
---|
| 243 | int modem_status; |
---|
| 244 | } stat; |
---|
| 245 | struct { |
---|
| 246 | int nbytes_sent; |
---|
| 247 | } write; |
---|
| 248 | } u; |
---|
| 249 | } volatile output_params; |
---|
| 250 | |
---|
| 251 | retval = -1; |
---|
| 252 | |
---|
| 253 | input_params.clun = 0; |
---|
| 254 | input_params.reserved = 0; |
---|
[59d4d513] | 255 | |
---|
| 256 | switch( minor ) { |
---|
| 257 | case SMC1_MINOR: |
---|
| 258 | input_params.dlun = 0; /* Should be 4, but doesn't work with EPPCBug 1.1 */ |
---|
| 259 | break; |
---|
| 260 | case SMC2_MINOR: |
---|
| 261 | input_params.dlun = 5; |
---|
| 262 | break; |
---|
| 263 | case SCC2_MINOR: |
---|
| 264 | input_params.dlun = 1; |
---|
| 265 | break; |
---|
| 266 | #ifdef mpc860 |
---|
| 267 | case SCC3_MINOR: |
---|
| 268 | input_params.dlun = 2; |
---|
| 269 | break; |
---|
| 270 | case SCC4_MINOR: |
---|
| 271 | input_params.dlun = 3; |
---|
| 272 | break; |
---|
| 273 | #endif |
---|
| 274 | default: |
---|
| 275 | input_params.dlun = 0; |
---|
| 276 | break; |
---|
| 277 | } |
---|
[8ef3818] | 278 | |
---|
| 279 | i = 0; |
---|
| 280 | |
---|
| 281 | _ISR_Disable( level ); |
---|
| 282 | simask = m8xx.simask; |
---|
| 283 | |
---|
| 284 | while (i < len) { |
---|
| 285 | /* Wait for space in the output buffer */ |
---|
| 286 | do { |
---|
| 287 | /* Check for space in the output FIFO */ |
---|
| 288 | asm volatile( "li 10,0x202 /* Code for .CIO_STAT */ |
---|
| 289 | mr 3, %0 /* Address of input_params */ |
---|
| 290 | mr 4, %1 /* Address of output_params */ |
---|
| 291 | sc" /* Call EPPCBUG */ |
---|
| 292 | :: "g" (&input_params), "g" (&output_params) : "3", "4", "10" ); |
---|
| 293 | |
---|
| 294 | if (output_params.status) |
---|
| 295 | goto error; |
---|
| 296 | } while (!output_params.u.stat.output_possible); |
---|
| 297 | |
---|
| 298 | /* Output the characters until done */ |
---|
| 299 | input_params.outbuf = &buf[i]; |
---|
| 300 | input_params.nbytes_to_output = len - i; |
---|
| 301 | |
---|
| 302 | asm volatile( "li 10,0x201 /* Code for .CIO_WRITE */ |
---|
| 303 | mr 3, %0 /* Address of input_params */ |
---|
| 304 | mr 4, %1 /* Address of output_params */ |
---|
[59d4d513] | 305 | sc" /* Call EPPCBUG */ |
---|
[8ef3818] | 306 | :: "g" (&input_params), "g" (&output_params) : "3", "4", "10" ); |
---|
| 307 | |
---|
| 308 | if (output_params.status) |
---|
| 309 | goto error; |
---|
| 310 | |
---|
| 311 | i += output_params.u.write.nbytes_sent; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | /* Return something */ |
---|
| 315 | m8xx.simask = simask; |
---|
| 316 | _ISR_Enable( level ); |
---|
| 317 | return RTEMS_SUCCESSFUL; |
---|
| 318 | |
---|
| 319 | error: |
---|
| 320 | m8xx.simask = simask; |
---|
| 321 | _ISR_Enable( level ); |
---|
| 322 | return -1; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | |
---|
[00ff4cd] | 326 | /* |
---|
| 327 | * do_poll_read |
---|
| 328 | * |
---|
| 329 | * Input characters through polled I/O. Returns has soon as a character has |
---|
| 330 | * been received. Otherwise, if we wait for the number of requested characters, |
---|
| 331 | * we could be here forever! |
---|
| 332 | * |
---|
| 333 | * CR is converted to LF on input. The terminal should not send a CR/LF pair |
---|
| 334 | * when the return or enter key is pressed. |
---|
| 335 | * |
---|
| 336 | * Input parameters: |
---|
| 337 | * major - ignored. Should be the major number for this driver. |
---|
| 338 | * minor - selected channel. |
---|
| 339 | * arg->buffer - where to put the received characters. |
---|
| 340 | * arg->count - number of characters to receive before returning--Ignored. |
---|
| 341 | * |
---|
| 342 | * Output parameters: |
---|
| 343 | * arg->bytes_moved - the number of characters read. Always 1. |
---|
| 344 | * |
---|
| 345 | * Return value: RTEMS_SUCCESSFUL |
---|
| 346 | * |
---|
| 347 | * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! |
---|
| 348 | */ |
---|
| 349 | static rtems_status_code do_poll_read( |
---|
| 350 | rtems_device_major_number major, |
---|
| 351 | rtems_device_minor_number minor, |
---|
| 352 | void * arg |
---|
| 353 | ) |
---|
| 354 | { |
---|
| 355 | rtems_libio_rw_args_t *rw_args = arg; |
---|
| 356 | int c; |
---|
| 357 | |
---|
| 358 | #if NVRAM_CONFIGURE == 1 |
---|
| 359 | |
---|
| 360 | int (*pollRead)( int minor ); |
---|
| 361 | |
---|
| 362 | if ( (nvram->console_mode & 0x06) == 0x04 ) |
---|
| 363 | pollRead = _EPPCBug_pollRead; |
---|
| 364 | else |
---|
| 365 | pollRead = m8xx_uart_pollRead; |
---|
| 366 | |
---|
| 367 | while( (c = (*pollRead)(minor)) == -1 ); |
---|
| 368 | rw_args->buffer[0] = (unsigned8)c; |
---|
| 369 | if( rw_args->buffer[0] == '\r' ) |
---|
| 370 | rw_args->buffer[0] = '\n'; |
---|
| 371 | rw_args->bytes_moved = 1; |
---|
| 372 | return RTEMS_SUCCESSFUL; |
---|
| 373 | |
---|
| 374 | #else |
---|
| 375 | |
---|
| 376 | #if UARTS_IO_MODE == 2 |
---|
| 377 | #define BSP_READ _EPPCBug_pollRead |
---|
| 378 | #else |
---|
| 379 | #define BSP_READ m8xx_uart_pollRead |
---|
| 380 | #endif |
---|
| 381 | |
---|
| 382 | while( (c = BSP_READ(minor)) == -1 ); |
---|
| 383 | rw_args->buffer[0] = (unsigned8)c; |
---|
| 384 | if( rw_args->buffer[0] == '\r' ) |
---|
| 385 | rw_args->buffer[0] = '\n'; |
---|
| 386 | rw_args->bytes_moved = 1; |
---|
| 387 | return RTEMS_SUCCESSFUL; |
---|
| 388 | |
---|
| 389 | #endif |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | |
---|
| 393 | /* |
---|
| 394 | * do_poll_write |
---|
| 395 | * |
---|
| 396 | * Output characters through polled I/O. Returns only once every character has |
---|
| 397 | * been sent. |
---|
| 398 | * |
---|
| 399 | * CR is transmitted AFTER a LF on output. |
---|
| 400 | * |
---|
| 401 | * Input parameters: |
---|
| 402 | * major - ignored. Should be the major number for this driver. |
---|
| 403 | * minor - selected channel |
---|
| 404 | * arg->buffer - where to get the characters to transmit. |
---|
| 405 | * arg->count - the number of characters to transmit before returning. |
---|
| 406 | * |
---|
| 407 | * Output parameters: |
---|
| 408 | * arg->bytes_moved - the number of characters read |
---|
| 409 | * |
---|
| 410 | * Return value: RTEMS_SUCCESSFUL |
---|
| 411 | * |
---|
| 412 | * CANNOT BE COMBINED WITH INTERRUPT DRIVEN I/O! |
---|
| 413 | */ |
---|
| 414 | static rtems_status_code do_poll_write( |
---|
| 415 | rtems_device_major_number major, |
---|
| 416 | rtems_device_minor_number minor, |
---|
| 417 | void * arg |
---|
| 418 | ) |
---|
| 419 | { |
---|
| 420 | rtems_libio_rw_args_t *rw_args = arg; |
---|
| 421 | unsigned32 i; |
---|
| 422 | char cr ='\r'; |
---|
| 423 | |
---|
| 424 | #if NVRAM_CONFIGURE == 1 |
---|
| 425 | |
---|
| 426 | int (*pollWrite)(int minor, const char *buf, int len); |
---|
| 427 | |
---|
| 428 | if ( (nvram->console_mode & 0x06) == 0x04 ) |
---|
| 429 | pollWrite = _EPPCBug_pollWrite; |
---|
| 430 | else |
---|
| 431 | pollWrite = m8xx_uart_pollWrite; |
---|
| 432 | |
---|
| 433 | for( i = 0; i < rw_args->count; i++ ) { |
---|
| 434 | (*pollWrite)(minor, &(rw_args->buffer[i]), 1); |
---|
| 435 | if ( rw_args->buffer[i] == '\n' ) |
---|
| 436 | (*pollWrite)(minor, &cr, 1); |
---|
| 437 | } |
---|
| 438 | rw_args->bytes_moved = i; |
---|
| 439 | return RTEMS_SUCCESSFUL; |
---|
| 440 | |
---|
| 441 | #else |
---|
| 442 | |
---|
| 443 | #if UARTS_IO_MODE == 2 |
---|
| 444 | #define BSP_WRITE _EPPCBug_pollWrite |
---|
| 445 | #else |
---|
| 446 | #define BSP_WRITE m8xx_uart_pollWrite |
---|
| 447 | #endif |
---|
| 448 | |
---|
| 449 | for( i = 0; i < rw_args->count; i++ ) { |
---|
| 450 | BSP_WRITE(minor, &(rw_args->buffer[i]), 1); |
---|
| 451 | if ( rw_args->buffer[i] == '\n' ) |
---|
| 452 | BSP_WRITE(minor, &cr, 1); |
---|
| 453 | } |
---|
| 454 | rw_args->bytes_moved = i; |
---|
| 455 | return RTEMS_SUCCESSFUL; |
---|
| 456 | |
---|
| 457 | #endif |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | |
---|
[8ef3818] | 461 | /* |
---|
[59d4d513] | 462 | * Print functions prototyped in bspIo.h |
---|
[8ef3818] | 463 | */ |
---|
| 464 | |
---|
[00ff4cd] | 465 | static void _BSP_output_char( char c ) |
---|
[8ef3818] | 466 | { |
---|
[59d4d513] | 467 | char cr = '\r'; |
---|
| 468 | |
---|
[00ff4cd] | 469 | /* |
---|
| 470 | * Can't rely on console_initialize having been called before this function |
---|
| 471 | * is used, so it may fail unless output is done through EPPC-Bug. |
---|
| 472 | */ |
---|
| 473 | #if NVRAM_CONFIGURE == 1 |
---|
| 474 | |
---|
| 475 | rtems_device_minor_number printk_minor; |
---|
| 476 | |
---|
| 477 | /* Use NVRAM info for configuration */ |
---|
| 478 | printk_minor = (nvram->console_printk_port & 0x70) >> 4; |
---|
| 479 | if( (nvram->console_mode & 0x30) == 0x20 ) { |
---|
| 480 | _EPPCBug_pollWrite( printk_minor, &c, 1 ); |
---|
| 481 | if( c == '\n' ) |
---|
| 482 | _EPPCBug_pollWrite( printk_minor, &cr, 1 ); |
---|
| 483 | } |
---|
| 484 | else { |
---|
| 485 | m8xx_uart_pollWrite( printk_minor, &c, 1 ); |
---|
| 486 | if( c == '\n' ) |
---|
| 487 | m8xx_uart_pollWrite( PRINTK_MINOR, &cr, 1 ); |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | #else |
---|
| 491 | |
---|
| 492 | #if PRINTK_IO_MODE == 2 |
---|
| 493 | #define PRINTK_WRITE _EPPCBug_pollWrite |
---|
| 494 | #else |
---|
| 495 | #define PRINTK_WRITE m8xx_uart_pollWrite |
---|
| 496 | #endif |
---|
| 497 | |
---|
| 498 | PRINTK_WRITE( PRINTK_MINOR, &c, 1 ); |
---|
[59d4d513] | 499 | if( c == '\n' ) |
---|
[00ff4cd] | 500 | PRINTK_WRITE( PRINTK_MINOR, &cr, 1 ); |
---|
| 501 | |
---|
| 502 | #endif |
---|
[8ef3818] | 503 | } |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | /* |
---|
| 507 | *************** |
---|
| 508 | * BOILERPLATE * |
---|
| 509 | *************** |
---|
| 510 | * |
---|
| 511 | * All these functions are prototyped in rtems/c/src/lib/include/console.h. |
---|
| 512 | */ |
---|
| 513 | |
---|
| 514 | /* |
---|
| 515 | * Initialize and register the device |
---|
| 516 | */ |
---|
| 517 | rtems_device_driver console_initialize( |
---|
| 518 | rtems_device_major_number major, |
---|
| 519 | rtems_device_minor_number minor, |
---|
| 520 | void *arg |
---|
| 521 | ) |
---|
| 522 | { |
---|
| 523 | rtems_status_code status; |
---|
[00ff4cd] | 524 | rtems_device_minor_number console_minor; |
---|
| 525 | |
---|
| 526 | /* |
---|
| 527 | * Set up TERMIOS if needed |
---|
| 528 | */ |
---|
| 529 | #if NVRAM_CONFIGURE == 1 |
---|
| 530 | /* Use NVRAM info for configuration */ |
---|
| 531 | console_minor = nvram->console_printk_port & 0x07; |
---|
| 532 | |
---|
| 533 | if ( nvram->console_mode & 0x01 ) |
---|
| 534 | /* termios */ |
---|
| 535 | rtems_termios_initialize (); |
---|
| 536 | |
---|
| 537 | /* |
---|
| 538 | * Do common initialization. |
---|
| 539 | */ |
---|
| 540 | m8xx_uart_initialize(); |
---|
[8ef3818] | 541 | |
---|
| 542 | /* |
---|
[00ff4cd] | 543 | * Do device-specific initialization |
---|
[8ef3818] | 544 | */ |
---|
[00ff4cd] | 545 | if ( !nvram->eppcbug_smc1 && |
---|
| 546 | ( ((nvram->console_mode & 0x30) != 0x20) || |
---|
| 547 | (((nvram->console_printk_port & 0x30) >> 4) != SMC1_MINOR) ) ) |
---|
| 548 | m8xx_uart_smc_initialize(SMC1_MINOR); /* /dev/tty0 */ |
---|
| 549 | |
---|
| 550 | if ( ((nvram->console_mode & 0x30) != 0x20) || |
---|
| 551 | (((nvram->console_printk_port & 0x30) >> 4) != SMC2_MINOR) ) |
---|
| 552 | m8xx_uart_smc_initialize(SMC2_MINOR); /* /dev/tty1 */ |
---|
| 553 | |
---|
| 554 | if ( ((nvram->console_mode & 0x30) != 0x20) || |
---|
| 555 | (((nvram->console_printk_port & 0x30) >> 4) != SCC2_MINOR) ) |
---|
| 556 | m8xx_uart_scc_initialize(SCC2_MINOR); /* /dev/tty2 */ |
---|
| 557 | |
---|
| 558 | #ifdef mpc860 |
---|
| 559 | |
---|
| 560 | if ( ((nvram->console_mode & 0x30) != 0x20) || |
---|
| 561 | (((nvram->console_printk_port & 0x30) >> 4) != SCC3_MINOR) ) |
---|
| 562 | m8xx_uart_scc_initialize(SCC3_MINOR); /* /dev/tty3 */ |
---|
| 563 | |
---|
| 564 | if ( ((nvram->console_mode & 0x30) != 0x20) || |
---|
| 565 | (((nvram->console_printk_port & 0x30) >> 4) != SCC4_MINOR) ) |
---|
| 566 | m8xx_uart_scc_initialize(SCC4_MINOR); /* /dev/tty4 */ |
---|
| 567 | |
---|
| 568 | #endif /* mpc860 */ |
---|
| 569 | |
---|
| 570 | #else /* NVRAM_CONFIGURE != 1 */ |
---|
| 571 | |
---|
| 572 | console_minor = CONSOLE_MINOR; |
---|
| 573 | |
---|
[59d4d513] | 574 | #if UARTS_USE_TERMIOS == 1 |
---|
[00ff4cd] | 575 | |
---|
| 576 | rtems_termios_initialize (); |
---|
| 577 | |
---|
| 578 | #endif /* UARTS_USE_TERMIOS */ |
---|
| 579 | |
---|
[8ef3818] | 580 | /* |
---|
| 581 | * Do common initialization. |
---|
| 582 | */ |
---|
| 583 | m8xx_uart_initialize(); |
---|
| 584 | |
---|
| 585 | /* |
---|
| 586 | * Do device-specific initialization |
---|
| 587 | */ |
---|
[59d4d513] | 588 | #if !defined(EPPCBUG_SMC1) && ( PRINTK_IO_MODE != 2 || PRINTK_MINOR != SMC1_MINOR ) |
---|
[8ef3818] | 589 | m8xx_uart_smc_initialize(SMC1_MINOR); /* /dev/tty0 */ |
---|
[59d4d513] | 590 | #endif |
---|
[8ef3818] | 591 | |
---|
[59d4d513] | 592 | #if PRINTK_IO_MODE != 2 || PRINTK_MINOR != SMC2_MINOR |
---|
[8ef3818] | 593 | m8xx_uart_smc_initialize(SMC2_MINOR); /* /dev/tty1 */ |
---|
[59d4d513] | 594 | #endif |
---|
| 595 | |
---|
| 596 | #if PRINTK_IO_MODE != 2 || PRINTK_MINOR != SCC2_MINOR |
---|
[8ef3818] | 597 | m8xx_uart_scc_initialize(SCC2_MINOR); /* /dev/tty2 */ |
---|
[59d4d513] | 598 | #endif |
---|
| 599 | |
---|
[8ef3818] | 600 | #ifdef mpc860 |
---|
[59d4d513] | 601 | |
---|
| 602 | #if PRINTK_IO_MODE != 2 || PRINTK_MINOR != SCC3_MINOR |
---|
[8ef3818] | 603 | m8xx_uart_scc_initialize(SCC3_MINOR); /* /dev/tty3 */ |
---|
[59d4d513] | 604 | #endif |
---|
| 605 | |
---|
| 606 | #if PRINTK_IO_MODE != 2 || PRINTK_MINOR != SCC4_MINOR |
---|
[8ef3818] | 607 | m8xx_uart_scc_initialize(SCC4_MINOR); /* /dev/tty4 */ |
---|
[59d4d513] | 608 | #endif |
---|
| 609 | |
---|
[8ef3818] | 610 | #endif /* mpc860 */ |
---|
| 611 | |
---|
[00ff4cd] | 612 | #endif /* NVRAM_CONFIGURE != 1 */ |
---|
| 613 | |
---|
| 614 | |
---|
[8ef3818] | 615 | /* |
---|
| 616 | * Set up interrupts |
---|
| 617 | */ |
---|
| 618 | m8xx_uart_interrupts_initialize(); |
---|
| 619 | |
---|
| 620 | status = rtems_io_register_name ("/dev/tty0", major, SMC1_MINOR); |
---|
| 621 | if (status != RTEMS_SUCCESSFUL) |
---|
| 622 | rtems_fatal_error_occurred (status); |
---|
| 623 | |
---|
| 624 | status = rtems_io_register_name ("/dev/tty1", major, SMC2_MINOR); |
---|
| 625 | if (status != RTEMS_SUCCESSFUL) |
---|
| 626 | rtems_fatal_error_occurred (status); |
---|
| 627 | |
---|
| 628 | status = rtems_io_register_name ("/dev/tty2", major, SCC2_MINOR); |
---|
| 629 | if (status != RTEMS_SUCCESSFUL) |
---|
| 630 | rtems_fatal_error_occurred (status); |
---|
| 631 | |
---|
| 632 | #ifdef mpc860 |
---|
| 633 | status = rtems_io_register_name ("/dev/tty3", major, SCC3_MINOR); |
---|
| 634 | if (status != RTEMS_SUCCESSFUL) |
---|
| 635 | rtems_fatal_error_occurred (status); |
---|
| 636 | |
---|
| 637 | status = rtems_io_register_name ("/dev/tty4", major, SCC4_MINOR); |
---|
| 638 | if (status != RTEMS_SUCCESSFUL) |
---|
| 639 | rtems_fatal_error_occurred (status); |
---|
| 640 | |
---|
| 641 | #endif /* mpc860 */ |
---|
| 642 | |
---|
| 643 | /* Now register the RTEMS console */ |
---|
[00ff4cd] | 644 | status = rtems_io_register_name ("/dev/console", major, console_minor); |
---|
[8ef3818] | 645 | if (status != RTEMS_SUCCESSFUL) |
---|
| 646 | rtems_fatal_error_occurred (status); |
---|
| 647 | |
---|
| 648 | return RTEMS_SUCCESSFUL; |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | |
---|
| 652 | /* |
---|
| 653 | * Open the device |
---|
| 654 | */ |
---|
| 655 | rtems_device_driver console_open( |
---|
| 656 | rtems_device_major_number major, |
---|
| 657 | rtems_device_minor_number minor, |
---|
| 658 | void *arg |
---|
| 659 | ) |
---|
| 660 | { |
---|
| 661 | /* Used to track termios private data for callbacks */ |
---|
| 662 | extern struct rtems_termios_tty *ttyp[]; |
---|
[00ff4cd] | 663 | |
---|
[59d4d513] | 664 | rtems_libio_open_close_args_t *args = arg; |
---|
[8ef3818] | 665 | rtems_status_code sc; |
---|
[00ff4cd] | 666 | |
---|
[8ef3818] | 667 | static const rtems_termios_callbacks sccEPPCBugCallbacks = { |
---|
| 668 | NULL, /* firstOpen */ |
---|
| 669 | NULL, /* lastClose */ |
---|
| 670 | _EPPCBug_pollRead, /* pollRead */ |
---|
| 671 | _EPPCBug_pollWrite, /* write */ |
---|
| 672 | NULL, /* stopRemoteTx */ |
---|
| 673 | NULL, /* startRemoteTx */ |
---|
| 674 | 0 /* outputUsesInterrupts */ |
---|
[59d4d513] | 675 | }; |
---|
[00ff4cd] | 676 | |
---|
[8ef3818] | 677 | static const rtems_termios_callbacks intrCallbacks = { |
---|
| 678 | NULL, /* firstOpen */ |
---|
| 679 | NULL, /* lastClose */ |
---|
[59d4d513] | 680 | NULL, /* pollRead */ |
---|
| 681 | m8xx_uart_write, /* write */ |
---|
[8ef3818] | 682 | m8xx_uart_setAttributes, /* setAttributes */ |
---|
| 683 | NULL, /* stopRemoteTx */ |
---|
| 684 | NULL, /* startRemoteTx */ |
---|
| 685 | 1 /* outputUsesInterrupts */ |
---|
| 686 | }; |
---|
[00ff4cd] | 687 | |
---|
[8ef3818] | 688 | static const rtems_termios_callbacks pollCallbacks = { |
---|
| 689 | NULL, /* firstOpen */ |
---|
| 690 | NULL, /* lastClose */ |
---|
[59d4d513] | 691 | m8xx_uart_pollRead, /* pollRead */ |
---|
| 692 | m8xx_uart_pollWrite, /* write */ |
---|
| 693 | m8xx_uart_setAttributes, /* setAttributes */ |
---|
[8ef3818] | 694 | NULL, /* stopRemoteTx */ |
---|
| 695 | NULL, /* startRemoteTx */ |
---|
| 696 | 0 /* outputUsesInterrupts */ |
---|
| 697 | }; |
---|
[59d4d513] | 698 | |
---|
| 699 | if ( minor > NUM_PORTS-1 ) |
---|
[8ef3818] | 700 | return RTEMS_INVALID_NUMBER; |
---|
| 701 | |
---|
[00ff4cd] | 702 | #if NVRAM_CONFIGURE == 1 |
---|
| 703 | |
---|
| 704 | /* Use NVRAM info for configuration */ |
---|
| 705 | if ( nvram->console_mode & 0x01 ) { |
---|
| 706 | /* Use termios */ |
---|
| 707 | if ( (nvram->console_mode & 0x06) == 0x02 ) { |
---|
| 708 | /* interrupt-driven I/O */ |
---|
| 709 | sc = rtems_termios_open( major, minor, arg, &intrCallbacks ); |
---|
| 710 | ttyp[minor] = args->iop->data1; /* Keep cookie returned by termios_open */ |
---|
| 711 | return sc; |
---|
| 712 | } |
---|
| 713 | else if ( (nvram->console_mode & 0x06) == 0x04 ) |
---|
| 714 | /* polled I/O through EPPC-Bug, better be through SMC1 */ |
---|
| 715 | return rtems_termios_open( major, minor, arg, &sccEPPCBugCallbacks ); |
---|
| 716 | else |
---|
| 717 | /* normal polled I/O */ |
---|
| 718 | return rtems_termios_open( major, minor, arg, &pollCallbacks ); |
---|
| 719 | } |
---|
| 720 | else |
---|
| 721 | /* no termios -- default to polled I/O */ |
---|
| 722 | return RTEMS_SUCCESSFUL; |
---|
| 723 | |
---|
| 724 | #else /* NVRAM_CONFIGURE != 1 */ |
---|
| 725 | |
---|
[59d4d513] | 726 | #if UARTS_USE_TERMIOS == 1 |
---|
| 727 | |
---|
| 728 | #if UARTS_IO_MODE == 2 /* EPPCBug polled I/O with termios */ |
---|
[00ff4cd] | 729 | sc = rtems_termios_open( major, minor, arg, &sccEPPCBugCallbacks ); |
---|
[59d4d513] | 730 | #elif UARTS_IO_MODE == 1 /* RTEMS interrupt-driven I/O with termios */ |
---|
[00ff4cd] | 731 | sc = rtems_termios_open( major, minor, arg, &intrCallbacks ); |
---|
[8ef3818] | 732 | ttyp[minor] = args->iop->data1; /* Keep cookie returned by termios_open */ |
---|
[59d4d513] | 733 | #else /* RTEMS polled I/O with termios */ |
---|
[00ff4cd] | 734 | sc = rtems_termios_open( major, minor, arg, &pollCallbacks ); |
---|
[59d4d513] | 735 | #endif |
---|
| 736 | |
---|
[00ff4cd] | 737 | #else /* UARTS_USE_TERMIOS != 1 */ |
---|
| 738 | /* no termios -- default to polled I/O */ |
---|
[59d4d513] | 739 | sc = RTEMS_SUCCESSFUL; |
---|
[00ff4cd] | 740 | #endif /* UARTS_USE_TERMIOS != 1 */ |
---|
[59d4d513] | 741 | |
---|
[8ef3818] | 742 | return sc; |
---|
[00ff4cd] | 743 | |
---|
| 744 | #endif /* NVRAM_CONFIGURE != 1 */ |
---|
[8ef3818] | 745 | } |
---|
| 746 | |
---|
| 747 | |
---|
| 748 | /* |
---|
| 749 | * Close the device |
---|
| 750 | */ |
---|
| 751 | rtems_device_driver console_close( |
---|
| 752 | rtems_device_major_number major, |
---|
| 753 | rtems_device_minor_number minor, |
---|
| 754 | void *arg |
---|
| 755 | ) |
---|
| 756 | { |
---|
[59d4d513] | 757 | if ( minor > NUM_PORTS-1 ) |
---|
| 758 | return RTEMS_INVALID_NUMBER; |
---|
| 759 | |
---|
[00ff4cd] | 760 | #if NVRAM_CONFIGURE == 1 |
---|
| 761 | |
---|
| 762 | /* Use NVRAM info for configuration */ |
---|
| 763 | if ( nvram->console_mode & 0x01 ) |
---|
| 764 | /* use termios */ |
---|
| 765 | return rtems_termios_close( arg ); |
---|
| 766 | else |
---|
| 767 | /* no termios */ |
---|
| 768 | return RTEMS_SUCCESSFUL; |
---|
| 769 | |
---|
| 770 | #else /* NVRAM_CONFIGURE != 1 */ |
---|
| 771 | |
---|
[59d4d513] | 772 | #if UARTS_USE_TERMIOS == 1 |
---|
[00ff4cd] | 773 | return rtems_termios_close( arg ); |
---|
[59d4d513] | 774 | #else |
---|
| 775 | return RTEMS_SUCCESSFUL; |
---|
| 776 | #endif |
---|
[00ff4cd] | 777 | |
---|
| 778 | #endif /* NVRAM_CONFIGURE != 1 */ |
---|
[8ef3818] | 779 | } |
---|
| 780 | |
---|
| 781 | |
---|
| 782 | /* |
---|
| 783 | * Read from the device |
---|
| 784 | */ |
---|
| 785 | rtems_device_driver console_read( |
---|
| 786 | rtems_device_major_number major, |
---|
| 787 | rtems_device_minor_number minor, |
---|
| 788 | void *arg |
---|
| 789 | ) |
---|
| 790 | { |
---|
[59d4d513] | 791 | if ( minor > NUM_PORTS-1 ) |
---|
| 792 | return RTEMS_INVALID_NUMBER; |
---|
| 793 | |
---|
[00ff4cd] | 794 | #if NVRAM_CONFIGURE == 1 |
---|
[59d4d513] | 795 | |
---|
[00ff4cd] | 796 | /* Use NVRAM info for configuration */ |
---|
| 797 | if ( nvram->console_mode & 0x01 ) |
---|
| 798 | /* use termios */ |
---|
| 799 | return rtems_termios_read( arg ); |
---|
| 800 | else |
---|
| 801 | /* no termios -- default to polled */ |
---|
| 802 | return do_poll_read( major, minor, arg ); |
---|
[59d4d513] | 803 | |
---|
[00ff4cd] | 804 | #else |
---|
[59d4d513] | 805 | |
---|
[00ff4cd] | 806 | #if UARTS_USE_TERMIOS == 1 |
---|
| 807 | return rtems_termios_read( arg ); |
---|
| 808 | #else |
---|
| 809 | return do_poll_read( major, minor, arg ); |
---|
[59d4d513] | 810 | #endif |
---|
| 811 | |
---|
| 812 | #endif |
---|
[8ef3818] | 813 | } |
---|
| 814 | |
---|
| 815 | |
---|
| 816 | /* |
---|
| 817 | * Write to the device |
---|
| 818 | */ |
---|
| 819 | rtems_device_driver console_write( |
---|
| 820 | rtems_device_major_number major, |
---|
| 821 | rtems_device_minor_number minor, |
---|
| 822 | void *arg |
---|
| 823 | ) |
---|
| 824 | { |
---|
[59d4d513] | 825 | if ( minor > NUM_PORTS-1 ) |
---|
| 826 | return RTEMS_INVALID_NUMBER; |
---|
| 827 | |
---|
[00ff4cd] | 828 | #if NVRAM_CONFIGURE == 1 |
---|
[59d4d513] | 829 | |
---|
[00ff4cd] | 830 | /* Use NVRAM info for configuration */ |
---|
| 831 | if ( nvram->console_mode & 0x01 ) |
---|
| 832 | /* use termios */ |
---|
| 833 | return rtems_termios_write( arg ); |
---|
| 834 | else |
---|
| 835 | /* no termios -- default to polled */ |
---|
| 836 | return do_poll_write( major, minor, arg ); |
---|
[59d4d513] | 837 | |
---|
[00ff4cd] | 838 | #else |
---|
[59d4d513] | 839 | |
---|
[00ff4cd] | 840 | #if UARTS_USE_TERMIOS == 1 |
---|
| 841 | return rtems_termios_write( arg ); |
---|
| 842 | #else |
---|
| 843 | /* no termios -- default to polled */ |
---|
| 844 | return do_poll_write( major, minor, arg ); |
---|
[59d4d513] | 845 | #endif |
---|
| 846 | |
---|
| 847 | #endif |
---|
[8ef3818] | 848 | } |
---|
| 849 | |
---|
| 850 | |
---|
| 851 | /* |
---|
| 852 | * Handle ioctl request. |
---|
| 853 | */ |
---|
| 854 | rtems_device_driver console_control( |
---|
| 855 | rtems_device_major_number major, |
---|
| 856 | rtems_device_minor_number minor, |
---|
| 857 | void *arg |
---|
| 858 | ) |
---|
| 859 | { |
---|
[59d4d513] | 860 | if ( minor > NUM_PORTS-1 ) |
---|
| 861 | return RTEMS_INVALID_NUMBER; |
---|
| 862 | |
---|
[00ff4cd] | 863 | #if NVRAM_CONFIGURE == 1 |
---|
| 864 | |
---|
| 865 | /* Uuse NVRAM info for configuration */ |
---|
| 866 | if ( nvram->console_mode & 0x01 ) |
---|
| 867 | /* termios */ |
---|
| 868 | return rtems_termios_ioctl( arg ); |
---|
| 869 | else |
---|
| 870 | /* no termios -- default to polled */ |
---|
| 871 | return RTEMS_SUCCESSFUL; |
---|
| 872 | |
---|
| 873 | #else |
---|
| 874 | |
---|
[59d4d513] | 875 | #if UARTS_USE_TERMIOS == 1 |
---|
[00ff4cd] | 876 | return rtems_termios_ioctl( arg ); |
---|
[59d4d513] | 877 | #else |
---|
| 878 | return RTEMS_SUCCESSFUL; |
---|
| 879 | #endif |
---|
[00ff4cd] | 880 | |
---|
| 881 | #endif |
---|
[8ef3818] | 882 | } |
---|
| 883 | |
---|