[9c448e1] | 1 | /* |
---|
| 2 | * This file contains the TTY driver for the serial ports on the SCORE603e. |
---|
| 3 | * |
---|
| 4 | * This driver uses the termios pseudo driver. |
---|
| 5 | * |
---|
| 6 | * Currently only polled mode is supported. |
---|
| 7 | * |
---|
[42b6dd2a] | 8 | * COPYRIGHT (c) 1989-2009. |
---|
[9c448e1] | 9 | * On-Line Applications Research Corporation (OAR). |
---|
| 10 | * |
---|
| 11 | * The license and distribution terms for this file may be |
---|
| 12 | * found in the file LICENSE in this distribution or at |
---|
[b14e2f2] | 13 | * http://www.rtems.com/license/LICENSE. |
---|
[9c448e1] | 14 | * |
---|
| 15 | * $Id$ |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #include <bsp.h> |
---|
| 19 | #include <rtems/libio.h> |
---|
| 20 | #include <stdlib.h> |
---|
| 21 | #include <assert.h> |
---|
| 22 | |
---|
| 23 | #include "consolebsp.h" |
---|
[bb41881e] | 24 | #include <rtems/bspIo.h> |
---|
[9c448e1] | 25 | |
---|
| 26 | /* |
---|
[6128a4a] | 27 | * The Port Used for the Console interface is based upon which |
---|
| 28 | * debugger is being used. The SDS debugger uses a binary |
---|
[9c448e1] | 29 | * interface on port 0 as part of the debugger. Thus port 0 can |
---|
| 30 | * not be used as the console port for the SDS debugger. |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | #define USE_FOR_CONSOLE_DEF 0 |
---|
| 34 | int USE_FOR_CONSOLE = USE_FOR_CONSOLE_DEF; |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * |
---|
| 38 | * Console Device Driver Entry Points |
---|
| 39 | */ |
---|
[6128a4a] | 40 | |
---|
[9c448e1] | 41 | /* PAGE |
---|
| 42 | * |
---|
[6128a4a] | 43 | * console_inbyte_nonblocking |
---|
[9c448e1] | 44 | * |
---|
| 45 | * Console Termios polling input entry point. |
---|
| 46 | */ |
---|
| 47 | |
---|
[6128a4a] | 48 | int console_inbyte_nonblocking( |
---|
| 49 | int minor |
---|
[9c448e1] | 50 | ) |
---|
| 51 | { |
---|
| 52 | int port = minor; |
---|
| 53 | |
---|
[6128a4a] | 54 | /* |
---|
| 55 | * verify port Number |
---|
[9c448e1] | 56 | */ |
---|
| 57 | assert ( port < NUM_Z85C30_PORTS ); |
---|
[6128a4a] | 58 | |
---|
[9c448e1] | 59 | /* |
---|
| 60 | * return a character from the 85c30 port. |
---|
| 61 | */ |
---|
| 62 | return inbyte_nonblocking_85c30( &Ports_85C30[ port ] ); |
---|
| 63 | } |
---|
[6128a4a] | 64 | |
---|
[9c448e1] | 65 | rtems_device_driver console_close( |
---|
| 66 | rtems_device_major_number major, |
---|
| 67 | rtems_device_minor_number minor, |
---|
| 68 | void * arg |
---|
| 69 | ) |
---|
| 70 | { |
---|
| 71 | return rtems_termios_close (arg); |
---|
| 72 | } |
---|
[6128a4a] | 73 | |
---|
[9c448e1] | 74 | rtems_device_driver console_read( |
---|
| 75 | rtems_device_major_number major, |
---|
| 76 | rtems_device_minor_number minor, |
---|
| 77 | void * arg |
---|
| 78 | ) |
---|
| 79 | { |
---|
| 80 | return rtems_termios_read (arg); |
---|
| 81 | } |
---|
[6128a4a] | 82 | |
---|
[9c448e1] | 83 | rtems_device_driver console_write( |
---|
| 84 | rtems_device_major_number major, |
---|
| 85 | rtems_device_minor_number minor, |
---|
| 86 | void * arg |
---|
| 87 | ) |
---|
| 88 | { |
---|
| 89 | return rtems_termios_write (arg); |
---|
| 90 | } |
---|
[6128a4a] | 91 | |
---|
[9c448e1] | 92 | rtems_device_driver console_control( |
---|
| 93 | rtems_device_major_number major, |
---|
| 94 | rtems_device_minor_number minor, |
---|
| 95 | void * arg |
---|
| 96 | ) |
---|
| 97 | { |
---|
| 98 | return rtems_termios_ioctl (arg); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * Interrupt driven console IO |
---|
| 103 | */ |
---|
| 104 | |
---|
| 105 | #if CONSOLE_USE_INTERRUPTS |
---|
| 106 | |
---|
| 107 | rtems_isr console_isr( |
---|
| 108 | rtems_vector_number vector |
---|
| 109 | ) |
---|
| 110 | { |
---|
| 111 | int i; |
---|
[6128a4a] | 112 | |
---|
[9c448e1] | 113 | for (i=0; i < NUM_Z85C30_PORTS; i++){ |
---|
| 114 | ISR_85c30_Async( &Ports_85C30[i] ); |
---|
[6128a4a] | 115 | } |
---|
[9c448e1] | 116 | } |
---|
| 117 | |
---|
| 118 | void console_exit() |
---|
| 119 | { |
---|
| 120 | int i; |
---|
| 121 | volatile Ring_buffer_t *buffer; |
---|
[dac4208] | 122 | uint32_t ch; |
---|
[9c448e1] | 123 | |
---|
| 124 | for ( i=0 ; i < NUM_Z85C30_PORTS ; i++ ) { |
---|
[6128a4a] | 125 | |
---|
[9c448e1] | 126 | buffer = &( Ports_85C30[i].Protocol->TX_Buffer); |
---|
| 127 | |
---|
| 128 | while ( !Ring_buffer_Is_empty( buffer ) ) { |
---|
| 129 | Ring_buffer_Remove_character( buffer, ch ); |
---|
[6128a4a] | 130 | outbyte_polled_85c30( Ports_85C30[i].ctrl, ch ); |
---|
[9c448e1] | 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | void console_initialize_interrupts( void ) |
---|
| 136 | { |
---|
| 137 | volatile Ring_buffer_t *buffer; |
---|
| 138 | Console_Protocol *protocol; |
---|
| 139 | int i; |
---|
[6128a4a] | 140 | |
---|
[9c448e1] | 141 | for ( i=0 ; i < NUM_Z85C30_PORTS ; i++ ) { |
---|
| 142 | protocol = Ports_85C30[i].Protocol; |
---|
| 143 | |
---|
| 144 | /* |
---|
| 145 | * Initialize the ring buffer and set to not transmitting. |
---|
| 146 | */ |
---|
| 147 | buffer = &protocol->TX_Buffer; |
---|
| 148 | Ring_buffer_Initialize( buffer ); |
---|
[3551166d] | 149 | protocol->Is_TX_active = false; |
---|
[9c448e1] | 150 | } |
---|
| 151 | |
---|
[6128a4a] | 152 | /* |
---|
[9c448e1] | 153 | * Connect each vector to the interupt service routine. |
---|
| 154 | */ |
---|
| 155 | for (i=0; i < NUM_Z85C30_CHIPS; i++) |
---|
| 156 | set_vector( console_isr, Chips_85C30[i].vector, 1 ); |
---|
[9345c7d] | 157 | #warning "Install interrupts using proper method for PIC vectors." |
---|
[6128a4a] | 158 | |
---|
[9c448e1] | 159 | atexit( console_exit ); |
---|
[6128a4a] | 160 | |
---|
[9c448e1] | 161 | } |
---|
| 162 | void console_outbyte_interrupts( |
---|
| 163 | const Port_85C30_info *Port, |
---|
| 164 | char ch |
---|
| 165 | ); |
---|
| 166 | |
---|
| 167 | #endif |
---|
| 168 | |
---|
| 169 | /* PAGE |
---|
| 170 | * |
---|
| 171 | * console_initialize |
---|
| 172 | * |
---|
| 173 | * Routine called to initialize the console device driver. |
---|
| 174 | */ |
---|
| 175 | rtems_device_driver console_initialize( |
---|
| 176 | rtems_device_major_number major, |
---|
| 177 | rtems_device_minor_number minor, |
---|
| 178 | void *arg |
---|
| 179 | ) |
---|
| 180 | { |
---|
| 181 | rtems_status_code status; |
---|
| 182 | rtems_device_minor_number console; |
---|
| 183 | int port, chip, p0,p1; |
---|
| 184 | |
---|
| 185 | /* |
---|
| 186 | * initialize the termio interface. |
---|
| 187 | */ |
---|
| 188 | rtems_termios_initialize(); |
---|
| 189 | |
---|
| 190 | /* |
---|
| 191 | * Register Device Names |
---|
| 192 | */ |
---|
| 193 | console = USE_FOR_CONSOLE; |
---|
| 194 | status = rtems_io_register_name( "/dev/console", major, console ); |
---|
| 195 | if (status != RTEMS_SUCCESSFUL) |
---|
| 196 | rtems_fatal_error_occurred(status); |
---|
| 197 | |
---|
| 198 | /* |
---|
| 199 | * Initialize Hardware |
---|
| 200 | */ |
---|
| 201 | |
---|
| 202 | /* |
---|
| 203 | * INITIALIZE_COM_PORTS is defined in the linker script. If it is |
---|
| 204 | * true all serial chips on the board are to be reset at startup |
---|
| 205 | * otherwise the reset is assumed to occur elsewhere (ie. in the |
---|
| 206 | * debugger...) |
---|
| 207 | */ |
---|
| 208 | #if ( INITIALIZE_COM_PORTS ) |
---|
| 209 | /* |
---|
| 210 | * Force to perform a hardware reset w/o |
---|
| 211 | * Master interrupt enable via register 9 |
---|
| 212 | */ |
---|
[6128a4a] | 213 | |
---|
[9c448e1] | 214 | for (port=0; port<NUM_Z85C30_PORTS; port++){ |
---|
| 215 | p0 = port; |
---|
| 216 | port++; |
---|
| 217 | p1 = port; |
---|
| 218 | Reset_85c30_chip( Ports_85C30[p0].ctrl, Ports_85C30[p1].ctrl ); |
---|
| 219 | } |
---|
| 220 | #else |
---|
[6128a4a] | 221 | /* TEMP - To see if this makes a diff with the new ports. |
---|
[9c448e1] | 222 | * Never reset chip 1 when using the chip as a monitor |
---|
| 223 | */ |
---|
| 224 | for (port=2; port<NUM_Z85C30_PORTS; port++){ |
---|
| 225 | p0 = port; |
---|
| 226 | port++; |
---|
| 227 | p1 = port; |
---|
| 228 | Reset_85c30_chip( Ports_85C30[p0].ctrl, Ports_85C30[p1].ctrl ); |
---|
| 229 | } |
---|
| 230 | #endif |
---|
| 231 | |
---|
[6128a4a] | 232 | /* |
---|
[9c448e1] | 233 | * Initialize each port. |
---|
| 234 | * Note: the ports are numbered such that 0,1 are on the first chip |
---|
| 235 | * 2,3 are on the second .... |
---|
| 236 | */ |
---|
| 237 | |
---|
[40e7ae2] | 238 | for (port=1; port<NUM_Z85C30_PORTS; port++) { |
---|
| 239 | chip = port >> 1; |
---|
[9c448e1] | 240 | initialize_85c30_port( &Ports_85C30[port] ); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | #if CONSOLE_USE_INTERRUPTS |
---|
| 244 | console_initialize_interrupts(); |
---|
| 245 | #endif |
---|
| 246 | |
---|
| 247 | return RTEMS_SUCCESSFUL; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | /* PAGE |
---|
| 251 | * |
---|
| 252 | * console_write_support |
---|
| 253 | * |
---|
| 254 | * Console Termios output entry point. |
---|
| 255 | * |
---|
| 256 | */ |
---|
| 257 | int console_write_support( |
---|
[6128a4a] | 258 | int minor, |
---|
| 259 | const char *buf, |
---|
[9c448e1] | 260 | int len) |
---|
| 261 | { |
---|
| 262 | int nwrite = 0; |
---|
[dac4208] | 263 | volatile uint8_t *csr; |
---|
[9c448e1] | 264 | int port = minor; |
---|
| 265 | |
---|
[6128a4a] | 266 | /* |
---|
| 267 | * verify port Number |
---|
[9c448e1] | 268 | */ |
---|
| 269 | assert ( port < NUM_Z85C30_PORTS ); |
---|
| 270 | |
---|
| 271 | /* |
---|
| 272 | * Set the csr based upon the port number. |
---|
| 273 | */ |
---|
| 274 | csr = Ports_85C30[ port ].ctrl; |
---|
| 275 | |
---|
| 276 | /* |
---|
| 277 | * poll each byte in the string out of the port. |
---|
| 278 | */ |
---|
| 279 | while (nwrite < len) { |
---|
| 280 | #if (CONSOLE_USE_INTERRUPTS) |
---|
| 281 | console_outbyte_interrupts( &Ports_85C30[ port ], *buf++ ); |
---|
| 282 | #else |
---|
| 283 | outbyte_polled_85c30( csr, *buf++ ); |
---|
| 284 | #endif |
---|
| 285 | nwrite++; |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | /* |
---|
| 289 | * return the number of bytes written. |
---|
| 290 | */ |
---|
| 291 | return nwrite; |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | /* PAGE |
---|
| 295 | * |
---|
| 296 | * console_open |
---|
| 297 | * |
---|
| 298 | * open a port as a termios console. |
---|
| 299 | * |
---|
| 300 | */ |
---|
| 301 | rtems_device_driver console_open( |
---|
| 302 | rtems_device_major_number major, |
---|
| 303 | rtems_device_minor_number minor, |
---|
| 304 | void * arg |
---|
| 305 | ) |
---|
| 306 | { |
---|
| 307 | rtems_status_code sc; |
---|
| 308 | int port = minor; |
---|
| 309 | #if (CONSOLE_USE_INTERRUPTS) |
---|
| 310 | rtems_libio_open_close_args_t *args = arg; |
---|
| 311 | static const rtems_termios_callbacks intrCallbacks = { |
---|
| 312 | NULL, /* firstOpen */ |
---|
| 313 | NULL, /* lastClose */ |
---|
| 314 | NULL, /* pollRead */ |
---|
| 315 | console_write_support, /* write */ |
---|
| 316 | NULL, /* setAttributes */ |
---|
| 317 | NULL, /* stopRemoteTx */ |
---|
| 318 | NULL, /* startRemoteTx */ |
---|
| 319 | 1 /* outputUsesInterrupts */ |
---|
| 320 | }; |
---|
| 321 | #else |
---|
| 322 | static const rtems_termios_callbacks pollCallbacks = { |
---|
| 323 | NULL, /* firstOpen */ |
---|
| 324 | NULL, /* lastClose */ |
---|
| 325 | console_inbyte_nonblocking, /* pollRead */ |
---|
| 326 | console_write_support, /* write */ |
---|
| 327 | NULL, /* setAttributes */ |
---|
| 328 | NULL, /* stopRemoteTx */ |
---|
| 329 | NULL, /* startRemoteTx */ |
---|
| 330 | 0 /* outputUsesInterrupts */ |
---|
| 331 | }; |
---|
| 332 | #endif |
---|
| 333 | |
---|
| 334 | /* |
---|
| 335 | * Verify the minor number is valid. |
---|
| 336 | */ |
---|
| 337 | if (minor < 0) |
---|
| 338 | return RTEMS_INVALID_NUMBER; |
---|
| 339 | |
---|
| 340 | if ( port > NUM_Z85C30_PORTS ) |
---|
| 341 | return RTEMS_INVALID_NUMBER; |
---|
| 342 | |
---|
| 343 | /* |
---|
| 344 | * open the port as a termios console driver. |
---|
| 345 | */ |
---|
| 346 | |
---|
| 347 | #if (CONSOLE_USE_INTERRUPTS) |
---|
| 348 | sc = rtems_termios_open( major, minor, arg, &intrCallbacks ); |
---|
| 349 | |
---|
| 350 | Ports_85C30[ minor ].Protocol->console_termios_data = args->iop->data1; |
---|
| 351 | #else |
---|
| 352 | sc = rtems_termios_open( major, minor, arg, &pollCallbacks ); |
---|
| 353 | #endif |
---|
| 354 | |
---|
| 355 | return sc; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | #if (CONSOLE_USE_INTERRUPTS) |
---|
| 359 | |
---|
| 360 | /* |
---|
| 361 | * console_outbyte_interrupts |
---|
| 362 | * |
---|
| 363 | * This routine transmits a character out. |
---|
| 364 | * |
---|
| 365 | * Input parameters: |
---|
| 366 | * port - port to transmit character to |
---|
| 367 | * ch - character to be transmitted |
---|
| 368 | * |
---|
| 369 | * Output parameters: NONE |
---|
| 370 | * |
---|
| 371 | * Return values: NONE |
---|
| 372 | */ |
---|
| 373 | void console_outbyte_interrupts( |
---|
| 374 | const Port_85C30_info *Port, |
---|
| 375 | char ch |
---|
| 376 | ) |
---|
| 377 | { |
---|
| 378 | Console_Protocol *protocol; |
---|
[dac4208] | 379 | uint32_t isrlevel; |
---|
[9c448e1] | 380 | |
---|
| 381 | protocol = Port->Protocol; |
---|
[6128a4a] | 382 | |
---|
[9c448e1] | 383 | /* |
---|
| 384 | * If this is the first character then we need to prime the pump |
---|
| 385 | */ |
---|
| 386 | |
---|
[3551166d] | 387 | if ( protocol->Is_TX_active == false ) { |
---|
[9c448e1] | 388 | |
---|
| 389 | rtems_interrupt_disable( isrlevel ); |
---|
[3551166d] | 390 | protocol->Is_TX_active = true; |
---|
[9c448e1] | 391 | outbyte_polled_85c30( Port->ctrl, ch ); |
---|
| 392 | rtems_interrupt_enable( isrlevel ); |
---|
| 393 | |
---|
| 394 | return; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | while ( Ring_buffer_Is_full( &protocol->TX_Buffer ) ); |
---|
[6128a4a] | 398 | |
---|
[9c448e1] | 399 | Ring_buffer_Add_character( &protocol->TX_Buffer, ch ); |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | #endif |
---|
[bb41881e] | 403 | |
---|
| 404 | /* const char arg to be compatible with BSP_output_char decl. */ |
---|
| 405 | void |
---|
| 406 | debug_putc_onlcr(const char c) |
---|
| 407 | { |
---|
| 408 | int console; |
---|
| 409 | volatile uint8_t *csr; |
---|
| 410 | uint32_t isrlevel; |
---|
| 411 | |
---|
| 412 | console = USE_FOR_CONSOLE; |
---|
| 413 | csr = Ports_85C30[ console ].ctrl; |
---|
| 414 | |
---|
[40e7ae2] | 415 | if ('\n'==c){ |
---|
| 416 | rtems_interrupt_disable( isrlevel ); |
---|
| 417 | outbyte_polled_85c30( csr, '\r' ); |
---|
| 418 | asm volatile("isync"); |
---|
[42b6dd2a] | 419 | rtems_interrupt_enable( isrlevel ); |
---|
[40e7ae2] | 420 | } |
---|
| 421 | |
---|
[bb41881e] | 422 | rtems_interrupt_disable( isrlevel ); |
---|
| 423 | outbyte_polled_85c30( csr, c ); |
---|
[42b6dd2a] | 424 | asm volatile("isync"); |
---|
[bb41881e] | 425 | rtems_interrupt_enable( isrlevel ); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | BSP_output_char_function_type BSP_output_char = debug_putc_onlcr; |
---|
| 429 | /* const char arg to be compatible with BSP_output_char decl. */ |
---|
| 430 | |
---|