[ac7d5ef0] | 1 | /* |
---|
| 2 | * This file contains the DMV152 console IO package. |
---|
| 3 | * |
---|
| 4 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * All rights assigned to U.S. Government, 1994. |
---|
| 7 | * |
---|
| 8 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 9 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 10 | * notice must appear in all copies of this file and its derivatives. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define D152_INIT |
---|
| 16 | |
---|
[3a4ae6c] | 17 | #include <bsp.h> |
---|
| 18 | #include <rtems/libio.h> |
---|
| 19 | |
---|
[ac7d5ef0] | 20 | /* console_initialize |
---|
| 21 | * |
---|
| 22 | * This routine initializes the console IO driver. |
---|
| 23 | * |
---|
| 24 | * Input parameters: NONE |
---|
| 25 | * |
---|
| 26 | * Output parameters: NONE |
---|
| 27 | * |
---|
| 28 | * Return values: |
---|
| 29 | */ |
---|
[3a4ae6c] | 30 | |
---|
[ac7d5ef0] | 31 | rtems_device_driver console_initialize( |
---|
| 32 | rtems_device_major_number major, |
---|
| 33 | rtems_device_minor_number minor, |
---|
[3a4ae6c] | 34 | void *arg |
---|
[ac7d5ef0] | 35 | ) |
---|
| 36 | { |
---|
[3a4ae6c] | 37 | rtems_status_code status; |
---|
| 38 | |
---|
| 39 | status = rtems_io_register_name( |
---|
| 40 | "/dev/console", |
---|
| 41 | major, |
---|
| 42 | (rtems_device_minor_number) 0 |
---|
| 43 | ); |
---|
| 44 | |
---|
| 45 | if (status != RTEMS_SUCCESSFUL) |
---|
| 46 | rtems_fatal_error_occurred(status); |
---|
| 47 | |
---|
| 48 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 49 | } |
---|
| 50 | |
---|
| 51 | /* is_character_ready |
---|
| 52 | * |
---|
| 53 | * This routine returns TRUE if a character is available. |
---|
| 54 | * |
---|
| 55 | * Input parameters: NONE |
---|
| 56 | * |
---|
| 57 | * Output parameters: NONE |
---|
| 58 | * |
---|
| 59 | * Return values: |
---|
| 60 | */ |
---|
| 61 | |
---|
| 62 | rtems_boolean is_character_ready( |
---|
| 63 | char *ch |
---|
| 64 | ) |
---|
| 65 | { |
---|
| 66 | rtems_unsigned8 rr_0; |
---|
| 67 | |
---|
| 68 | for ( ; ; ) { |
---|
| 69 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
| 70 | if ( !(rr_0 & RR_0_RX_DATA_AVAILABLE) ) |
---|
| 71 | return( FALSE ); |
---|
| 72 | |
---|
| 73 | Z8x30_READ_DATA( CONSOLE_DATA, *ch ); |
---|
| 74 | return( TRUE ); |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /* inbyte |
---|
| 79 | * |
---|
| 80 | * This routine reads a character from the SCC. |
---|
| 81 | * |
---|
| 82 | * Input parameters: NONE |
---|
| 83 | * |
---|
| 84 | * Output parameters: NONE |
---|
| 85 | * |
---|
| 86 | * Return values: |
---|
| 87 | * character read from SCC |
---|
| 88 | */ |
---|
| 89 | |
---|
| 90 | char inbyte( void ) |
---|
| 91 | { |
---|
| 92 | rtems_unsigned8 rr_0; |
---|
| 93 | char ch; |
---|
| 94 | |
---|
| 95 | for ( ; ; ) { |
---|
| 96 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
| 97 | if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) != 0 ) |
---|
| 98 | break; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | Z8x30_READ_DATA( CONSOLE_DATA, ch ); |
---|
| 102 | return ( ch ); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | /* outbyte |
---|
| 106 | * |
---|
| 107 | * This routine transmits a character out the SCC. It supports |
---|
| 108 | * XON/XOFF flow control. |
---|
| 109 | * |
---|
| 110 | * Input parameters: |
---|
| 111 | * ch - character to be transmitted |
---|
| 112 | * |
---|
| 113 | * Output parameters: NONE |
---|
| 114 | */ |
---|
| 115 | |
---|
| 116 | void outbyte( |
---|
| 117 | char ch |
---|
| 118 | ) |
---|
| 119 | { |
---|
| 120 | rtems_unsigned8 rr_0; |
---|
| 121 | char flow_control; |
---|
| 122 | |
---|
| 123 | for ( ; ; ) { |
---|
| 124 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
| 125 | if ( (rr_0 & RR_0_TX_BUFFER_EMPTY) != 0 ) |
---|
| 126 | break; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | for ( ; ; ) { |
---|
| 130 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
| 131 | if ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 ) |
---|
| 132 | break; |
---|
| 133 | |
---|
| 134 | Z8x30_READ_DATA( CONSOLE_DATA, flow_control ); |
---|
| 135 | |
---|
| 136 | if ( flow_control == XOFF ) |
---|
| 137 | do { |
---|
| 138 | do { |
---|
| 139 | Z8x30_READ_CONTROL( CONSOLE_CONTROL, RR_0, rr_0 ); |
---|
| 140 | } while ( (rr_0 & RR_0_RX_DATA_AVAILABLE) == 0 ); |
---|
| 141 | Z8x30_READ_DATA( CONSOLE_DATA, flow_control ); |
---|
| 142 | } while ( flow_control != XON ); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | Z8x30_WRITE_DATA( CONSOLE_DATA, ch ); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | /* |
---|
[3a4ae6c] | 149 | * Open entry point |
---|
[ac7d5ef0] | 150 | */ |
---|
| 151 | |
---|
[3a4ae6c] | 152 | rtems_device_driver console_open( |
---|
| 153 | rtems_device_major_number major, |
---|
| 154 | rtems_device_minor_number minor, |
---|
| 155 | void * arg |
---|
[ac7d5ef0] | 156 | ) |
---|
| 157 | { |
---|
[3a4ae6c] | 158 | return RTEMS_SUCCESSFUL; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | /* |
---|
| 162 | * Close entry point |
---|
| 163 | */ |
---|
| 164 | |
---|
| 165 | rtems_device_driver console_close( |
---|
| 166 | rtems_device_major_number major, |
---|
| 167 | rtems_device_minor_number minor, |
---|
| 168 | void * arg |
---|
| 169 | ) |
---|
| 170 | { |
---|
| 171 | return RTEMS_SUCCESSFUL; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | /* |
---|
| 175 | * read bytes from the serial port. We only have stdin. |
---|
| 176 | */ |
---|
[ac7d5ef0] | 177 | |
---|
[3a4ae6c] | 178 | rtems_device_driver console_read( |
---|
| 179 | rtems_device_major_number major, |
---|
| 180 | rtems_device_minor_number minor, |
---|
| 181 | void * arg |
---|
| 182 | ) |
---|
| 183 | { |
---|
| 184 | rtems_libio_rw_args_t *rw_args; |
---|
| 185 | char *buffer; |
---|
| 186 | int maximum; |
---|
| 187 | int count = 0; |
---|
| 188 | |
---|
| 189 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 190 | |
---|
| 191 | buffer = rw_args->buffer; |
---|
| 192 | maximum = rw_args->count; |
---|
| 193 | |
---|
| 194 | for (count = 0; count < maximum; count++) { |
---|
| 195 | buffer[ count ] = inbyte(); |
---|
| 196 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 197 | buffer[ count++ ] = '\n'; |
---|
| 198 | buffer[ count ] = 0; |
---|
[ac7d5ef0] | 199 | break; |
---|
| 200 | } |
---|
| 201 | } |
---|
[3a4ae6c] | 202 | |
---|
| 203 | rw_args->bytes_moved = count; |
---|
| 204 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
[ac7d5ef0] | 205 | } |
---|
| 206 | |
---|
| 207 | /* |
---|
[3a4ae6c] | 208 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
[ac7d5ef0] | 209 | */ |
---|
| 210 | |
---|
[3a4ae6c] | 211 | rtems_device_driver console_write( |
---|
| 212 | rtems_device_major_number major, |
---|
| 213 | rtems_device_minor_number minor, |
---|
| 214 | void * arg |
---|
[ac7d5ef0] | 215 | ) |
---|
| 216 | { |
---|
[3a4ae6c] | 217 | int count; |
---|
| 218 | int maximum; |
---|
| 219 | rtems_libio_rw_args_t *rw_args; |
---|
| 220 | char *buffer; |
---|
[ac7d5ef0] | 221 | |
---|
[3a4ae6c] | 222 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 223 | |
---|
| 224 | buffer = rw_args->buffer; |
---|
| 225 | maximum = rw_args->count; |
---|
| 226 | |
---|
| 227 | for (count = 0; count < maximum; count++) { |
---|
| 228 | if ( buffer[ count ] == '\n') { |
---|
| 229 | outbyte('\r'); |
---|
[ac7d5ef0] | 230 | } |
---|
[3a4ae6c] | 231 | outbyte( buffer[ count ] ); |
---|
[ac7d5ef0] | 232 | } |
---|
[3652ad35] | 233 | |
---|
| 234 | rw_args->bytes_moved = maximum; |
---|
| 235 | return 0; |
---|
[3a4ae6c] | 236 | } |
---|
| 237 | |
---|
| 238 | /* |
---|
| 239 | * IO Control entry point |
---|
| 240 | */ |
---|
| 241 | |
---|
| 242 | rtems_device_driver console_control( |
---|
| 243 | rtems_device_major_number major, |
---|
| 244 | rtems_device_minor_number minor, |
---|
| 245 | void * arg |
---|
| 246 | ) |
---|
| 247 | { |
---|
| 248 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 249 | } |
---|