[f198c63] | 1 | /* |
---|
| 2 | * This file contains the IDT 4650 console IO package. |
---|
| 3 | * |
---|
| 4 | * Author: Craig Lebakken <craigl@transition.com> |
---|
| 5 | * |
---|
| 6 | * COPYRIGHT (c) 1996 by Transition Networks Inc. |
---|
| 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 Transition Networks not be used in |
---|
| 14 | * advertising or publicity pertaining to distribution of the |
---|
| 15 | * software without specific, written prior permission. |
---|
| 16 | * Transition Networks 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 | * |
---|
| 21 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 22 | * On-Line Applications Research Corporation (OAR). |
---|
| 23 | * All rights assigned to U.S. Government, 1994. |
---|
| 24 | * |
---|
| 25 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 26 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 27 | * notice must appear in all copies of this file and its derivatives. |
---|
| 28 | * |
---|
[5bb00a8] | 29 | * $Id$ |
---|
[f198c63] | 30 | */ |
---|
| 31 | |
---|
| 32 | |
---|
[de1d716] | 33 | /* |
---|
| 34 | * Rather than deleting this, it is commented out to (hopefully) help |
---|
| 35 | * the submitter send updates. |
---|
| 36 | * |
---|
| 37 | * static char _sccsid[] = "@(#)console.c 08/20/96 1.6\n"; |
---|
| 38 | */ |
---|
| 39 | |
---|
[f198c63] | 40 | |
---|
| 41 | |
---|
| 42 | #include <bsp.h> |
---|
| 43 | #include <rtems/libio.h> |
---|
| 44 | #include <ctype.h> |
---|
| 45 | |
---|
| 46 | char idtsim_getchar( void ); |
---|
| 47 | void idtsim_putchar( char c ); |
---|
| 48 | void mips_leddisplay( char a, char b, char c, char d ); |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | /* console_initialize |
---|
| 52 | * |
---|
| 53 | * This routine initializes the console IO driver. |
---|
| 54 | * |
---|
| 55 | * Input parameters: NONE |
---|
| 56 | * |
---|
| 57 | * Output parameters: NONE |
---|
| 58 | * |
---|
| 59 | * Return values: |
---|
| 60 | */ |
---|
| 61 | |
---|
| 62 | rtems_device_driver console_initialize( |
---|
| 63 | rtems_device_major_number major, |
---|
| 64 | rtems_device_minor_number minor, |
---|
| 65 | void *arg |
---|
| 66 | ) |
---|
| 67 | { |
---|
| 68 | rtems_status_code status; |
---|
| 69 | |
---|
| 70 | status = rtems_io_register_name( |
---|
| 71 | "/dev/console", |
---|
| 72 | major, |
---|
| 73 | (rtems_device_minor_number) 0 |
---|
| 74 | ); |
---|
| 75 | |
---|
| 76 | if (status != RTEMS_SUCCESSFUL) |
---|
| 77 | rtems_fatal_error_occurred(status); |
---|
| 78 | |
---|
| 79 | return RTEMS_SUCCESSFUL; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | /* is_character_ready |
---|
| 84 | * |
---|
| 85 | * This routine returns TRUE if a character is available. |
---|
| 86 | * |
---|
| 87 | * Input parameters: NONE |
---|
| 88 | * |
---|
| 89 | * Output parameters: NONE |
---|
| 90 | * |
---|
| 91 | * Return values: |
---|
| 92 | */ |
---|
| 93 | |
---|
| 94 | rtems_boolean is_character_ready( |
---|
| 95 | char *ch |
---|
| 96 | ) |
---|
| 97 | { |
---|
| 98 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
| 99 | return(TRUE); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | /* inbyte |
---|
| 103 | * |
---|
| 104 | * This routine reads a character from the SOURCE. |
---|
| 105 | * |
---|
| 106 | * Input parameters: NONE |
---|
| 107 | * |
---|
| 108 | * Output parameters: NONE |
---|
| 109 | * |
---|
| 110 | * Return values: |
---|
| 111 | * character read from SOURCE |
---|
| 112 | */ |
---|
| 113 | |
---|
| 114 | char inbyte( void ) |
---|
| 115 | { |
---|
| 116 | /* |
---|
| 117 | * If polling, wait until a character is available. |
---|
| 118 | */ |
---|
| 119 | |
---|
| 120 | return idtsim_getchar(); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | /* outbyte |
---|
| 124 | * |
---|
| 125 | * This routine transmits a character out the SOURCE. It may support |
---|
| 126 | * XON/XOFF flow control. |
---|
| 127 | * |
---|
| 128 | * Input parameters: |
---|
| 129 | * ch - character to be transmitted |
---|
| 130 | * |
---|
| 131 | * Output parameters: NONE |
---|
| 132 | */ |
---|
| 133 | |
---|
| 134 | void outbyte( |
---|
| 135 | char ch |
---|
| 136 | ) |
---|
| 137 | { |
---|
| 138 | #define NUM_LEDS 4 |
---|
| 139 | static unsigned int cur_led = 0; |
---|
| 140 | static unsigned char led_chars[NUM_LEDS]; |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | * If polling, wait for the transmitter to be ready. |
---|
| 144 | * Check for flow control requests and process. |
---|
| 145 | * Then output the character. |
---|
| 146 | */ |
---|
| 147 | |
---|
| 148 | idtsim_putchar( ch ); |
---|
| 149 | |
---|
| 150 | /* print out first four alpha numeric characters in a line */ |
---|
| 151 | if ( ch == '\n' ) |
---|
| 152 | { |
---|
| 153 | mips_leddisplay( led_chars[0], led_chars[1], led_chars[2], led_chars[3] ); |
---|
| 154 | cur_led = 0; |
---|
| 155 | } |
---|
[de1d716] | 156 | else if ( isalnum( (unsigned char) ch ) && cur_led < NUM_LEDS ) |
---|
[f198c63] | 157 | { |
---|
| 158 | led_chars[cur_led++] = ch; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | |
---|
[de1d716] | 164 | #if 0 |
---|
[f198c63] | 165 | static int console_fd = -1; |
---|
[de1d716] | 166 | #endif |
---|
[f198c63] | 167 | |
---|
| 168 | /* |
---|
| 169 | * Open entry point |
---|
| 170 | */ |
---|
| 171 | |
---|
| 172 | rtems_device_driver console_open( |
---|
| 173 | rtems_device_major_number major, |
---|
| 174 | rtems_device_minor_number minor, |
---|
| 175 | void * arg |
---|
| 176 | ) |
---|
| 177 | { |
---|
| 178 | #if 0 |
---|
| 179 | int console_fd = open("tty0", 2); /* open for read/write */ |
---|
| 180 | #endif |
---|
| 181 | return RTEMS_SUCCESSFUL; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /* |
---|
| 185 | * Close entry point |
---|
| 186 | */ |
---|
| 187 | |
---|
| 188 | rtems_device_driver console_close( |
---|
| 189 | rtems_device_major_number major, |
---|
| 190 | rtems_device_minor_number minor, |
---|
| 191 | void * arg |
---|
| 192 | ) |
---|
| 193 | { |
---|
| 194 | #if 0 |
---|
| 195 | if ( console_fd ) |
---|
| 196 | close( console_fd ); |
---|
| 197 | #endif |
---|
| 198 | return RTEMS_SUCCESSFUL; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | /* |
---|
| 202 | * read bytes from the serial port. We only have stdin. |
---|
| 203 | */ |
---|
| 204 | |
---|
| 205 | rtems_device_driver console_read( |
---|
| 206 | rtems_device_major_number major, |
---|
| 207 | rtems_device_minor_number minor, |
---|
| 208 | void * arg |
---|
| 209 | ) |
---|
| 210 | { |
---|
| 211 | rtems_libio_rw_args_t *rw_args; |
---|
| 212 | char *buffer; |
---|
| 213 | int maximum; |
---|
| 214 | int count = 0; |
---|
| 215 | |
---|
| 216 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 217 | |
---|
| 218 | buffer = rw_args->buffer; |
---|
| 219 | maximum = rw_args->count; |
---|
| 220 | |
---|
| 221 | for (count = 0; count < maximum; count++) { |
---|
| 222 | buffer[ count ] = inbyte(); |
---|
| 223 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 224 | buffer[ count++ ] = '\n'; |
---|
| 225 | buffer[ count ] = 0; |
---|
| 226 | break; |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | rw_args->bytes_moved = count; |
---|
| 231 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | /* |
---|
| 235 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
| 236 | */ |
---|
| 237 | |
---|
| 238 | rtems_device_driver console_write( |
---|
| 239 | rtems_device_major_number major, |
---|
| 240 | rtems_device_minor_number minor, |
---|
| 241 | void * arg |
---|
| 242 | ) |
---|
| 243 | { |
---|
| 244 | int count; |
---|
| 245 | int maximum; |
---|
| 246 | rtems_libio_rw_args_t *rw_args; |
---|
| 247 | char *buffer; |
---|
| 248 | |
---|
| 249 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 250 | |
---|
| 251 | buffer = rw_args->buffer; |
---|
| 252 | maximum = rw_args->count; |
---|
| 253 | |
---|
| 254 | for (count = 0; count < maximum; count++) { |
---|
| 255 | if ( buffer[ count ] == '\n') { |
---|
| 256 | outbyte('\r'); |
---|
| 257 | } |
---|
| 258 | outbyte( buffer[ count ] ); |
---|
| 259 | } |
---|
| 260 | |
---|
| 261 | rw_args->bytes_moved = maximum; |
---|
| 262 | return 0; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | /* |
---|
| 266 | * IO Control entry point |
---|
| 267 | */ |
---|
| 268 | |
---|
| 269 | rtems_device_driver console_control( |
---|
| 270 | rtems_device_major_number major, |
---|
| 271 | rtems_device_minor_number minor, |
---|
| 272 | void * arg |
---|
| 273 | ) |
---|
| 274 | { |
---|
| 275 | return RTEMS_SUCCESSFUL; |
---|
| 276 | } |
---|