[0836603] | 1 | /* |
---|
| 2 | * This file contains the template for a console IO package. |
---|
| 3 | * |
---|
[03f2154e] | 4 | * COPYRIGHT (c) 1989-1997. |
---|
[0836603] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 6 | * Copyright assigned to U.S. Government, 1994. |
---|
[0836603] | 7 | * |
---|
[98e4ebf5] | 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
[0836603] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define NO_BSP_INIT |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | /* only one of the following can be defined */ |
---|
| 19 | #define SERIAL_INPUT /* use serial input */ |
---|
| 20 | /* #define HIF_INPUT */ /* use HIF input */ |
---|
| 21 | |
---|
| 22 | #if defined(SERIAL_INPUT) && defined(HIF_INPUT) |
---|
| 23 | #error SERIAL_INPUT and HIF_INPUT cannot both be defined!!! |
---|
| 24 | #endif |
---|
| 25 | |
---|
| 26 | /* both of the following can be defined */ |
---|
| 27 | #define SERIAL_OUTPUT /* remove to disable serial port console output */ |
---|
| 28 | /* #define HIF_OUTPUT */ /* remove to disable HIF console output */ |
---|
| 29 | |
---|
| 30 | #include <bsp.h> |
---|
| 31 | #include <rtems/libio.h> |
---|
| 32 | #include "serial.h" |
---|
| 33 | #include "concntl.h" |
---|
| 34 | |
---|
| 35 | #ifndef lint |
---|
| 36 | static char _sccsid[] = "@(#)console.c 09/12/96 1.13\n"; |
---|
| 37 | #endif |
---|
| 38 | |
---|
| 39 | /* console_initialize |
---|
| 40 | * |
---|
| 41 | * This routine initializes the console IO driver. |
---|
| 42 | * |
---|
| 43 | * Input parameters: NONE |
---|
| 44 | * |
---|
| 45 | * Output parameters: NONE |
---|
| 46 | * |
---|
| 47 | * Return values: |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | rtems_device_driver console_initialize( |
---|
| 51 | rtems_device_major_number major, |
---|
| 52 | rtems_device_minor_number minor, |
---|
| 53 | void *arg |
---|
| 54 | ) |
---|
| 55 | { |
---|
| 56 | rtems_status_code status; |
---|
| 57 | |
---|
| 58 | if ( arg ) |
---|
| 59 | { |
---|
| 60 | if ( console_duartinit(minor,*(unsigned32*)arg) ) |
---|
| 61 | return RTEMS_INVALID_NUMBER; |
---|
| 62 | } |
---|
| 63 | else |
---|
| 64 | { |
---|
| 65 | if ( console_duartinit(1,9600) || console_duartinit(0,9600) ) |
---|
| 66 | { |
---|
| 67 | return RTEMS_INVALID_NUMBER; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | status = rtems_io_register_name( |
---|
| 72 | "/dev/console", |
---|
| 73 | major, |
---|
| 74 | (rtems_device_minor_number) 0 |
---|
| 75 | ); |
---|
| 76 | |
---|
| 77 | if (status != RTEMS_SUCCESSFUL) |
---|
| 78 | rtems_fatal_error_occurred(status); |
---|
| 79 | |
---|
| 80 | return RTEMS_SUCCESSFUL; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /* is_character_ready |
---|
| 85 | * |
---|
| 86 | * This routine returns TRUE if a character is available. |
---|
| 87 | * |
---|
| 88 | * Input parameters: NONE |
---|
| 89 | * |
---|
| 90 | * Output parameters: NONE |
---|
| 91 | * |
---|
| 92 | * Return values: |
---|
| 93 | */ |
---|
| 94 | |
---|
| 95 | rtems_boolean is_character_ready( |
---|
| 96 | char *ch |
---|
| 97 | ) |
---|
| 98 | { |
---|
| 99 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
| 100 | return(TRUE); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | /* inbyte |
---|
| 104 | * |
---|
| 105 | * This routine reads a character from the SOURCE. |
---|
| 106 | * |
---|
| 107 | * Input parameters: NONE |
---|
| 108 | * |
---|
| 109 | * Output parameters: NONE |
---|
| 110 | * |
---|
| 111 | * Return values: |
---|
| 112 | * character read from SOURCE |
---|
| 113 | */ |
---|
| 114 | |
---|
| 115 | char inbyte( unsigned int minor ) |
---|
| 116 | { |
---|
| 117 | /* |
---|
| 118 | * If polling, wait until a character is available. |
---|
| 119 | */ |
---|
| 120 | #ifdef HIF_INPUT |
---|
| 121 | char retch; |
---|
| 122 | _read( 1, &retch, 1 ); |
---|
| 123 | return retch; |
---|
| 124 | #endif |
---|
| 125 | #ifdef SERIAL_INPUT |
---|
| 126 | return console_sps_getc( minor ); |
---|
| 127 | #endif |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /* outbyte |
---|
| 131 | * |
---|
| 132 | * This routine transmits a character out the SOURCE. It may support |
---|
| 133 | * XON/XOFF flow control. |
---|
| 134 | * |
---|
| 135 | * Input parameters: |
---|
| 136 | * ch - character to be transmitted |
---|
| 137 | * |
---|
| 138 | * Output parameters: NONE |
---|
| 139 | */ |
---|
| 140 | |
---|
| 141 | void outbyte( unsigned int minor, |
---|
| 142 | char ch |
---|
| 143 | ) |
---|
| 144 | { |
---|
| 145 | /* |
---|
| 146 | * If polling, wait for the transmitter to be ready. |
---|
| 147 | * Check for flow control requests and process. |
---|
| 148 | * Then output the character. |
---|
| 149 | */ |
---|
| 150 | |
---|
| 151 | #ifdef SERIAL_OUTPUT |
---|
| 152 | console_sps_putc( minor, ch ); |
---|
| 153 | #endif |
---|
| 154 | |
---|
| 155 | /* |
---|
| 156 | * Carriage Return/New line translation. |
---|
| 157 | */ |
---|
| 158 | |
---|
| 159 | if ( ch == '\n' ) |
---|
| 160 | outbyte( minor, '\r' ); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | /* |
---|
| 165 | * Open entry point |
---|
| 166 | */ |
---|
| 167 | |
---|
| 168 | rtems_device_driver console_open( |
---|
| 169 | rtems_device_major_number major, |
---|
| 170 | rtems_device_minor_number minor, |
---|
| 171 | void * arg |
---|
| 172 | ) |
---|
| 173 | { |
---|
| 174 | return RTEMS_SUCCESSFUL; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | /* |
---|
| 178 | * Close entry point |
---|
| 179 | */ |
---|
| 180 | |
---|
| 181 | rtems_device_driver console_close( |
---|
| 182 | rtems_device_major_number major, |
---|
| 183 | rtems_device_minor_number minor, |
---|
| 184 | void * arg |
---|
| 185 | ) |
---|
| 186 | { |
---|
| 187 | return RTEMS_SUCCESSFUL; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | /* |
---|
| 191 | * read bytes from the serial port. We only have stdin. |
---|
| 192 | */ |
---|
| 193 | |
---|
| 194 | rtems_device_driver console_read( |
---|
| 195 | rtems_device_major_number major, |
---|
| 196 | rtems_device_minor_number minor, |
---|
| 197 | void * arg |
---|
| 198 | ) |
---|
| 199 | { |
---|
| 200 | rtems_libio_rw_args_t *rw_args; |
---|
| 201 | unsigned8 *buffer; |
---|
| 202 | unsigned32 maximum; |
---|
| 203 | unsigned32 count = 0; |
---|
| 204 | |
---|
| 205 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 206 | |
---|
| 207 | buffer = rw_args->buffer; |
---|
| 208 | maximum = rw_args->count; |
---|
| 209 | |
---|
| 210 | for (count = 0; count < maximum; count++) { |
---|
| 211 | buffer[ count ] = inbyte(minor); |
---|
| 212 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 213 | buffer[ count++ ] = '\n'; |
---|
| 214 | outbyte( minor, '\n' ); /* newline */ |
---|
| 215 | break; |
---|
| 216 | } |
---|
| 217 | else if (buffer[ count ] == '\b' && count > 0 ) |
---|
| 218 | { |
---|
| 219 | outbyte( minor, '\b' ); /* move back one space */ |
---|
| 220 | outbyte( minor, ' ' ); /* erase the character */ |
---|
| 221 | outbyte( minor, '\b' ); /* move back one space */ |
---|
| 222 | count-=2; |
---|
| 223 | } |
---|
| 224 | else |
---|
| 225 | outbyte( minor, buffer[ count ] ); /* echo the character */ |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | rw_args->bytes_moved = count; |
---|
| 229 | return (count > 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /* |
---|
| 233 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
| 234 | */ |
---|
| 235 | |
---|
| 236 | rtems_device_driver console_write( |
---|
| 237 | rtems_device_major_number major, |
---|
| 238 | rtems_device_minor_number minor, |
---|
| 239 | void * arg |
---|
| 240 | ) |
---|
| 241 | { |
---|
| 242 | int count; |
---|
| 243 | int maximum; |
---|
| 244 | rtems_libio_rw_args_t *rw_args; |
---|
| 245 | unsigned8 *buffer; |
---|
| 246 | |
---|
| 247 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 248 | |
---|
| 249 | buffer = rw_args->buffer; |
---|
| 250 | maximum = rw_args->count; |
---|
| 251 | |
---|
| 252 | #ifdef HIF_OUTPUT |
---|
| 253 | _write( 0, buffer, maximum ); |
---|
| 254 | #endif |
---|
| 255 | #ifdef SERIAL_OUTPUT |
---|
| 256 | for (count = 0; count < maximum; count++) { |
---|
| 257 | if ( buffer[ count ] == '\n') { |
---|
| 258 | outbyte(minor,'\r'); |
---|
| 259 | } |
---|
| 260 | outbyte( minor,buffer[ count ] ); |
---|
| 261 | } |
---|
| 262 | #endif |
---|
| 263 | |
---|
| 264 | rw_args->bytes_moved = maximum; |
---|
| 265 | return 0; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | /* |
---|
| 269 | * IO Control entry point |
---|
| 270 | */ |
---|
| 271 | |
---|
| 272 | rtems_device_driver console_control( |
---|
| 273 | rtems_device_major_number major, |
---|
| 274 | rtems_device_minor_number minor, |
---|
| 275 | void * arg |
---|
| 276 | ) |
---|
| 277 | { |
---|
| 278 | if (!arg) |
---|
| 279 | return RTEMS_INVALID_ADDRESS; |
---|
| 280 | |
---|
| 281 | switch( ((console_ioctl_request_t *)arg)->ioctl_type ) |
---|
| 282 | { |
---|
| 283 | case CON_KBHIT: |
---|
| 284 | /* check if keyboard was hit */ |
---|
| 285 | ((console_ioctl_request_t *)arg)->param = console_sps_kbhit(minor); |
---|
| 286 | break; |
---|
| 287 | |
---|
| 288 | case CON_GET_RAW_BYTE: |
---|
| 289 | ((console_ioctl_request_t *)arg)->param = inbyte(minor); |
---|
| 290 | break; |
---|
| 291 | |
---|
| 292 | case CON_SEND_RAW_BYTE: |
---|
| 293 | outbyte(minor, ((console_ioctl_request_t *)arg)->param); |
---|
| 294 | break; |
---|
| 295 | |
---|
| 296 | default: |
---|
| 297 | break; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | return RTEMS_SUCCESSFUL; |
---|
| 301 | } |
---|