[aecfa2b] | 1 | /* |
---|
| 2 | * This file contains the PowerPC 403GA console IO package. |
---|
| 3 | * |
---|
| 4 | * Author: Andrew Bray <andy@i-cubed.co.uk> |
---|
| 5 | * |
---|
| 6 | * COPYRIGHT (c) 1995 by i-cubed ltd. |
---|
| 7 | * |
---|
| 8 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 9 | * without any express or implied warranty: |
---|
| 10 | * permission to use, copy, modify, and distribute this file |
---|
| 11 | * for any purpose is hereby granted without fee, provided that |
---|
| 12 | * the above copyright notice and this notice appears in all |
---|
| 13 | * copies, and that the name of i-cubed limited not be used in |
---|
| 14 | * advertising or publicity pertaining to distribution of the |
---|
| 15 | * software without specific, written prior permission. |
---|
| 16 | * i-cubed limited makes no representations about the suitability |
---|
| 17 | * of this software for any purpose. |
---|
| 18 | * |
---|
| 19 | * Derived from c/src/lib/libbsp/no_cpu/no_bsp/console/console.c: |
---|
| 20 | * |
---|
[08311cc3] | 21 | * COPYRIGHT (c) 1989-1999. |
---|
[aecfa2b] | 22 | * On-Line Applications Research Corporation (OAR). |
---|
| 23 | * |
---|
| 24 | * The license and distribution terms for this file may be |
---|
| 25 | * found in the file LICENSE in this distribution or at |
---|
[21e1c44] | 26 | * http://www.rtems.com/license/LICENSE. |
---|
[aecfa2b] | 27 | * |
---|
| 28 | * $Id$ |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | #define NO_BSP_INIT |
---|
| 32 | |
---|
[f817b02] | 33 | #include <rtems.h> |
---|
[aecfa2b] | 34 | #include <rtems/libio.h> |
---|
| 35 | |
---|
| 36 | struct async { |
---|
| 37 | /*-----------------------------------------------------------------------------+ |
---|
| 38 | | Line Status Register. |
---|
| 39 | +-----------------------------------------------------------------------------*/ |
---|
| 40 | unsigned char SPLS; |
---|
| 41 | unsigned char SPLSset; |
---|
| 42 | #define LSRDataReady 0x80 |
---|
| 43 | #define LSRFramingError 0x40 |
---|
| 44 | #define LSROverrunError 0x20 |
---|
| 45 | #define LSRParityError 0x10 |
---|
| 46 | #define LSRBreakInterrupt 0x08 |
---|
| 47 | #define LSRTxHoldEmpty 0x04 |
---|
| 48 | #define LSRTxShiftEmpty 0x02 |
---|
| 49 | |
---|
| 50 | /*-----------------------------------------------------------------------------+ |
---|
| 51 | | Handshake Status Register. |
---|
| 52 | +-----------------------------------------------------------------------------*/ |
---|
| 53 | unsigned char SPHS; |
---|
| 54 | unsigned char SPHSset; |
---|
| 55 | #define HSRDsr 0x80 |
---|
| 56 | #define HSRCts 0x40 |
---|
| 57 | |
---|
| 58 | /*-----------------------------------------------------------------------------+ |
---|
| 59 | | Baud rate divisor registers |
---|
| 60 | +-----------------------------------------------------------------------------*/ |
---|
| 61 | unsigned char BRDH; |
---|
| 62 | unsigned char BRDL; |
---|
| 63 | |
---|
| 64 | /*-----------------------------------------------------------------------------+ |
---|
| 65 | | Control Register. |
---|
| 66 | +-----------------------------------------------------------------------------*/ |
---|
| 67 | unsigned char SPCTL; |
---|
| 68 | #define CRNormal 0x00 |
---|
| 69 | #define CRLoopback 0x40 |
---|
| 70 | #define CRAutoEcho 0x80 |
---|
| 71 | #define CRDtr 0x20 |
---|
| 72 | #define CRRts 0x10 |
---|
| 73 | #define CRWordLength7 0x00 |
---|
| 74 | #define CRWordLength8 0x08 |
---|
| 75 | #define CRParityDisable 0x00 |
---|
| 76 | #define CRParityEnable 0x04 |
---|
| 77 | #define CREvenParity 0x00 |
---|
| 78 | #define CROddParity 0x02 |
---|
| 79 | #define CRStopBitsOne 0x00 |
---|
| 80 | #define CRStopBitsTwo 0x01 |
---|
| 81 | #define CRDisableDtrRts 0x00 |
---|
| 82 | |
---|
| 83 | /*-----------------------------------------------------------------------------+ |
---|
| 84 | | Receiver Command Register. |
---|
| 85 | +-----------------------------------------------------------------------------*/ |
---|
| 86 | unsigned char SPRC; |
---|
| 87 | #define RCRDisable 0x00 |
---|
| 88 | #define RCREnable 0x80 |
---|
| 89 | #define RCRIntDisable 0x00 |
---|
| 90 | #define RCRIntEnabled 0x20 |
---|
| 91 | #define RCRDMACh2 0x40 |
---|
| 92 | #define RCRDMACh3 0x60 |
---|
| 93 | #define RCRErrorInt 0x10 |
---|
| 94 | #define RCRPauseEnable 0x08 |
---|
| 95 | |
---|
| 96 | /*-----------------------------------------------------------------------------+ |
---|
| 97 | | Transmitter Command Register. |
---|
| 98 | +-----------------------------------------------------------------------------*/ |
---|
| 99 | unsigned char SPTC; |
---|
| 100 | #define TCRDisable 0x00 |
---|
| 101 | #define TCREnable 0x80 |
---|
| 102 | #define TCRIntDisable 0x00 |
---|
| 103 | #define TCRIntEnabled 0x20 |
---|
| 104 | #define TCRDMACh2 0x40 |
---|
| 105 | #define TCRDMACh3 0x60 |
---|
| 106 | #define TCRTxEmpty 0x10 |
---|
| 107 | #define TCRErrorInt 0x08 |
---|
| 108 | #define TCRStopPause 0x04 |
---|
| 109 | #define TCRBreakGen 0x02 |
---|
| 110 | |
---|
| 111 | /*-----------------------------------------------------------------------------+ |
---|
| 112 | | Miscellanies defines. |
---|
| 113 | +-----------------------------------------------------------------------------*/ |
---|
| 114 | unsigned char SPTB; |
---|
| 115 | #define SPRB SPTB |
---|
| 116 | }; |
---|
| 117 | |
---|
| 118 | #define XOFFchar 0x13 |
---|
| 119 | #define XONchar 0x11 |
---|
| 120 | |
---|
| 121 | typedef volatile struct async *pasync; |
---|
| 122 | static const pasync port = (pasync)0x40000000; |
---|
| 123 | |
---|
| 124 | /* console_initialize |
---|
| 125 | * |
---|
| 126 | * This routine initializes the console IO driver. |
---|
| 127 | * |
---|
| 128 | * Input parameters: NONE |
---|
| 129 | * |
---|
| 130 | * Output parameters: NONE |
---|
| 131 | * |
---|
| 132 | * Return values: |
---|
| 133 | */ |
---|
| 134 | |
---|
| 135 | rtems_device_driver console_initialize( |
---|
| 136 | rtems_device_major_number major, |
---|
| 137 | rtems_device_minor_number minor, |
---|
| 138 | void *arg |
---|
| 139 | ) |
---|
| 140 | { |
---|
| 141 | rtems_status_code status; |
---|
| 142 | register unsigned tmp; |
---|
| 143 | |
---|
| 144 | /* Initialise the serial port */ |
---|
| 145 | asm volatile ("mfdcr %0, 0xa0" : "=r" (tmp)); /* IOCR */ |
---|
| 146 | tmp &= ~3; |
---|
[458bd34] | 147 | tmp |= (rtems_cpu_configuration_get_serial_external_clock() ? 2 : 0) | |
---|
| 148 | (rtems_cpu_configuration_get_serial_cts_rts() ? 1 : 0); |
---|
[aecfa2b] | 149 | asm volatile ("mtdcr 0xa0, %0" : "=r" (tmp) : "0" (tmp)); /* IOCR */ |
---|
| 150 | port->SPLS = (LSRDataReady | LSRFramingError | LSROverrunError | |
---|
| 151 | LSRParityError | LSRBreakInterrupt); |
---|
[458bd34] | 152 | tmp = rtems_cpu_configuration_get_serial_per_sec() / |
---|
| 153 | rtems_cpu_configuration_get_serial_rate(); |
---|
[aecfa2b] | 154 | #if 0 /* replaced by IMD... */ |
---|
| 155 | tmp = ((tmp + 8) >> 4) - 1; |
---|
| 156 | port->BRDL = tmp & 0x255; |
---|
| 157 | port->BRDH = tmp >> 8; |
---|
| 158 | #else |
---|
| 159 | tmp = ((tmp) >> 4) - 1; |
---|
| 160 | port->BRDL = tmp & 0xff; |
---|
| 161 | port->BRDH = tmp >> 8; |
---|
| 162 | #endif |
---|
| 163 | port->SPCTL = (CRNormal | CRDtr | CRRts | CRWordLength8 | CRParityDisable | |
---|
| 164 | CRStopBitsOne); |
---|
| 165 | port->SPRC = (RCREnable | RCRIntDisable | RCRPauseEnable); |
---|
| 166 | port->SPTC = (TCREnable | TCRIntDisable); |
---|
| 167 | port->SPHS = (HSRDsr | HSRCts); |
---|
| 168 | |
---|
| 169 | status = rtems_io_register_name( |
---|
| 170 | "/dev/console", |
---|
| 171 | major, |
---|
| 172 | (rtems_device_minor_number) 0 |
---|
| 173 | ); |
---|
| 174 | |
---|
| 175 | if (status != RTEMS_SUCCESSFUL) |
---|
| 176 | rtems_fatal_error_occurred(status); |
---|
| 177 | |
---|
| 178 | return RTEMS_SUCCESSFUL; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | /* is_character_ready |
---|
| 183 | * |
---|
| 184 | * This routine returns TRUE if a character is available. |
---|
| 185 | * |
---|
| 186 | * Input parameters: NONE |
---|
| 187 | * |
---|
| 188 | * Output parameters: NONE |
---|
| 189 | * |
---|
| 190 | * Return values: |
---|
| 191 | */ |
---|
| 192 | |
---|
| 193 | rtems_boolean is_character_ready( |
---|
| 194 | char *ch |
---|
| 195 | ) |
---|
| 196 | { |
---|
| 197 | unsigned char status; |
---|
| 198 | |
---|
| 199 | if ((status = port->SPLS) & LSRDataReady) |
---|
| 200 | { |
---|
| 201 | *ch = port->SPRB; |
---|
| 202 | return(TRUE); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | /* Clean any dodgy status */ |
---|
| 206 | if ((status & (LSRFramingError | LSROverrunError | LSRParityError | |
---|
| 207 | LSRBreakInterrupt)) != 0) |
---|
| 208 | { |
---|
| 209 | port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError | |
---|
| 210 | LSRBreakInterrupt); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | return FALSE; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | /* inbyte |
---|
| 217 | * |
---|
| 218 | * This routine reads a character from the SOURCE. |
---|
| 219 | * |
---|
| 220 | * Input parameters: NONE |
---|
| 221 | * |
---|
| 222 | * Output parameters: NONE |
---|
| 223 | * |
---|
| 224 | * Return values: |
---|
| 225 | * character read from SOURCE |
---|
| 226 | */ |
---|
| 227 | |
---|
| 228 | char inbyte( void ) |
---|
| 229 | { |
---|
| 230 | unsigned char status; |
---|
| 231 | |
---|
| 232 | while (1) |
---|
| 233 | { |
---|
| 234 | if ((status = port->SPLS) & LSRDataReady) |
---|
| 235 | break; |
---|
| 236 | |
---|
| 237 | /* Clean any dodgy status */ |
---|
| 238 | if ((status & (LSRFramingError | LSROverrunError | LSRParityError | |
---|
| 239 | LSRBreakInterrupt)) != 0) |
---|
| 240 | { |
---|
| 241 | port->SPLS = (LSRFramingError | LSROverrunError | LSRParityError | |
---|
| 242 | LSRBreakInterrupt); |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | return port->SPRB; |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | /* outbyte |
---|
| 250 | * |
---|
| 251 | * This routine transmits a character out the SOURCE. It may support |
---|
| 252 | * XON/XOFF flow control. |
---|
| 253 | * |
---|
| 254 | * Input parameters: |
---|
| 255 | * ch - character to be transmitted |
---|
| 256 | * |
---|
| 257 | * Output parameters: NONE |
---|
| 258 | */ |
---|
| 259 | |
---|
| 260 | void outbyte( |
---|
| 261 | char ch |
---|
| 262 | ) |
---|
| 263 | { |
---|
| 264 | unsigned char status; |
---|
| 265 | |
---|
| 266 | while (port->SPHS) |
---|
| 267 | port->SPHS = (HSRDsr | HSRCts); |
---|
| 268 | |
---|
| 269 | while (1) |
---|
| 270 | { |
---|
| 271 | status = port->SPLS; |
---|
| 272 | |
---|
| 273 | if (port->SPHS) |
---|
| 274 | port->SPHS = (HSRDsr | HSRCts); |
---|
| 275 | else if (status & LSRTxHoldEmpty) |
---|
| 276 | break; |
---|
| 277 | } |
---|
| 278 | |
---|
[458bd34] | 279 | if (rtems_cpu_configuration_get_serial_xon_xoff()) |
---|
[aecfa2b] | 280 | while (is_character_ready(&status)) |
---|
| 281 | { |
---|
| 282 | if (status == XOFFchar) |
---|
| 283 | do { |
---|
| 284 | while (!is_character_ready(&status)); |
---|
| 285 | } while (status != XONchar); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | port->SPTB = ch; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | /* |
---|
| 292 | * Open entry point |
---|
| 293 | */ |
---|
| 294 | |
---|
| 295 | rtems_device_driver console_open( |
---|
| 296 | rtems_device_major_number major, |
---|
| 297 | rtems_device_minor_number minor, |
---|
| 298 | void * arg |
---|
| 299 | ) |
---|
| 300 | { |
---|
| 301 | return RTEMS_SUCCESSFUL; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | /* |
---|
| 305 | * Close entry point |
---|
| 306 | */ |
---|
| 307 | |
---|
| 308 | rtems_device_driver console_close( |
---|
| 309 | rtems_device_major_number major, |
---|
| 310 | rtems_device_minor_number minor, |
---|
| 311 | void * arg |
---|
| 312 | ) |
---|
| 313 | { |
---|
| 314 | return RTEMS_SUCCESSFUL; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | /* |
---|
| 318 | * read bytes from the serial port. We only have stdin. |
---|
| 319 | */ |
---|
| 320 | |
---|
| 321 | rtems_device_driver console_read( |
---|
| 322 | rtems_device_major_number major, |
---|
| 323 | rtems_device_minor_number minor, |
---|
| 324 | void * arg |
---|
| 325 | ) |
---|
| 326 | { |
---|
| 327 | rtems_libio_rw_args_t *rw_args; |
---|
| 328 | char *buffer; |
---|
| 329 | int maximum; |
---|
| 330 | int count = 0; |
---|
| 331 | |
---|
| 332 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 333 | |
---|
| 334 | buffer = rw_args->buffer; |
---|
| 335 | maximum = rw_args->count; |
---|
| 336 | |
---|
| 337 | for (count = 0; count < maximum; count++) { |
---|
| 338 | buffer[ count ] = inbyte(); |
---|
| 339 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 340 | buffer[ count++ ] = '\n'; |
---|
| 341 | buffer[ count ] = 0; |
---|
| 342 | break; |
---|
| 343 | } |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | rw_args->bytes_moved = count; |
---|
| 347 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | /* |
---|
| 351 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
| 352 | */ |
---|
| 353 | |
---|
| 354 | rtems_device_driver console_write( |
---|
| 355 | rtems_device_major_number major, |
---|
| 356 | rtems_device_minor_number minor, |
---|
| 357 | void * arg |
---|
| 358 | ) |
---|
| 359 | { |
---|
| 360 | int count; |
---|
| 361 | int maximum; |
---|
| 362 | rtems_libio_rw_args_t *rw_args; |
---|
| 363 | char *buffer; |
---|
| 364 | |
---|
| 365 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 366 | |
---|
| 367 | buffer = rw_args->buffer; |
---|
| 368 | maximum = rw_args->count; |
---|
| 369 | |
---|
| 370 | for (count = 0; count < maximum; count++) { |
---|
| 371 | if ( buffer[ count ] == '\n') { |
---|
| 372 | outbyte('\r'); |
---|
| 373 | } |
---|
| 374 | outbyte( buffer[ count ] ); |
---|
| 375 | } |
---|
| 376 | return maximum; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | /* |
---|
| 380 | * IO Control entry point |
---|
| 381 | */ |
---|
| 382 | |
---|
| 383 | rtems_device_driver console_control( |
---|
| 384 | rtems_device_major_number major, |
---|
| 385 | rtems_device_minor_number minor, |
---|
| 386 | void * arg |
---|
| 387 | ) |
---|
| 388 | { |
---|
| 389 | return RTEMS_SUCCESSFUL; |
---|
| 390 | } |
---|
| 391 | |
---|