[ac7d5ef0] | 1 | /* |
---|
| 2 | * This file contains the template for a 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 NO_BSP_INIT |
---|
| 16 | |
---|
[3a4ae6c] | 17 | #include <bsp.h> |
---|
| 18 | #include <rtems/libio.h> |
---|
[ac7d5ef0] | 19 | |
---|
| 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 | */ |
---|
| 30 | |
---|
| 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 | |
---|
| 52 | /* is_character_ready |
---|
| 53 | * |
---|
| 54 | * This routine returns TRUE if a character is available. |
---|
| 55 | * |
---|
| 56 | * Input parameters: NONE |
---|
| 57 | * |
---|
| 58 | * Output parameters: NONE |
---|
| 59 | * |
---|
| 60 | * Return values: |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | rtems_boolean is_character_ready( |
---|
| 64 | char *ch |
---|
| 65 | ) |
---|
| 66 | { |
---|
| 67 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
| 68 | return(TRUE); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /* inbyte |
---|
| 72 | * |
---|
| 73 | * This routine reads a character from the SOURCE. |
---|
| 74 | * |
---|
| 75 | * Input parameters: NONE |
---|
| 76 | * |
---|
| 77 | * Output parameters: NONE |
---|
| 78 | * |
---|
| 79 | * Return values: |
---|
| 80 | * character read from SOURCE |
---|
| 81 | */ |
---|
| 82 | |
---|
| 83 | char inbyte( void ) |
---|
| 84 | { |
---|
| 85 | /* |
---|
| 86 | * If polling, wait until a character is available. |
---|
| 87 | */ |
---|
| 88 | |
---|
| 89 | return '\0'; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /* outbyte |
---|
| 93 | * |
---|
| 94 | * This routine transmits a character out the SOURCE. It may support |
---|
| 95 | * XON/XOFF flow control. |
---|
| 96 | * |
---|
| 97 | * Input parameters: |
---|
| 98 | * ch - character to be transmitted |
---|
| 99 | * |
---|
| 100 | * Output parameters: NONE |
---|
| 101 | */ |
---|
| 102 | |
---|
| 103 | void outbyte( |
---|
| 104 | char ch |
---|
| 105 | ) |
---|
| 106 | { |
---|
| 107 | /* |
---|
| 108 | * If polling, wait for the transmitter to be ready. |
---|
| 109 | * Check for flow control requests and process. |
---|
| 110 | * Then output the character. |
---|
| 111 | */ |
---|
| 112 | |
---|
| 113 | /* |
---|
| 114 | * Carriage Return/New line translation. |
---|
| 115 | */ |
---|
| 116 | |
---|
| 117 | if ( ch == '\n' ) |
---|
| 118 | outbyte( '\r' ); |
---|
| 119 | } |
---|
| 120 | |
---|
[3a4ae6c] | 121 | |
---|
| 122 | /* |
---|
| 123 | * Open entry point |
---|
| 124 | */ |
---|
| 125 | |
---|
| 126 | rtems_device_driver console_open( |
---|
| 127 | rtems_device_major_number major, |
---|
| 128 | rtems_device_minor_number minor, |
---|
| 129 | void * arg |
---|
| 130 | ) |
---|
| 131 | { |
---|
| 132 | return RTEMS_SUCCESSFUL; |
---|
| 133 | } |
---|
| 134 | |
---|
[ac7d5ef0] | 135 | /* |
---|
[3a4ae6c] | 136 | * Close entry point |
---|
[ac7d5ef0] | 137 | */ |
---|
| 138 | |
---|
[3a4ae6c] | 139 | rtems_device_driver console_close( |
---|
| 140 | rtems_device_major_number major, |
---|
| 141 | rtems_device_minor_number minor, |
---|
| 142 | void * arg |
---|
[ac7d5ef0] | 143 | ) |
---|
| 144 | { |
---|
[3a4ae6c] | 145 | return RTEMS_SUCCESSFUL; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | /* |
---|
| 149 | * read bytes from the serial port. We only have stdin. |
---|
| 150 | */ |
---|
[ac7d5ef0] | 151 | |
---|
[3a4ae6c] | 152 | rtems_device_driver console_read( |
---|
| 153 | rtems_device_major_number major, |
---|
| 154 | rtems_device_minor_number minor, |
---|
| 155 | void * arg |
---|
| 156 | ) |
---|
| 157 | { |
---|
| 158 | rtems_libio_rw_args_t *rw_args; |
---|
| 159 | char *buffer; |
---|
| 160 | int maximum; |
---|
| 161 | int count = 0; |
---|
| 162 | |
---|
| 163 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 164 | |
---|
| 165 | buffer = rw_args->buffer; |
---|
| 166 | maximum = rw_args->count; |
---|
| 167 | |
---|
| 168 | for (count = 0; count < maximum; count++) { |
---|
| 169 | buffer[ count ] = inbyte(); |
---|
| 170 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 171 | buffer[ count++ ] = '\n'; |
---|
| 172 | buffer[ count ] = 0; |
---|
[ac7d5ef0] | 173 | break; |
---|
| 174 | } |
---|
| 175 | } |
---|
[3a4ae6c] | 176 | |
---|
| 177 | rw_args->bytes_moved = count; |
---|
| 178 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
[ac7d5ef0] | 179 | } |
---|
| 180 | |
---|
| 181 | /* |
---|
[3a4ae6c] | 182 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
[ac7d5ef0] | 183 | */ |
---|
| 184 | |
---|
[3a4ae6c] | 185 | rtems_device_driver console_write( |
---|
| 186 | rtems_device_major_number major, |
---|
| 187 | rtems_device_minor_number minor, |
---|
| 188 | void * arg |
---|
[ac7d5ef0] | 189 | ) |
---|
| 190 | { |
---|
[3a4ae6c] | 191 | int count; |
---|
| 192 | int maximum; |
---|
| 193 | rtems_libio_rw_args_t *rw_args; |
---|
| 194 | char *buffer; |
---|
| 195 | |
---|
| 196 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
[ac7d5ef0] | 197 | |
---|
[3a4ae6c] | 198 | buffer = rw_args->buffer; |
---|
| 199 | maximum = rw_args->count; |
---|
| 200 | |
---|
| 201 | for (count = 0; count < maximum; count++) { |
---|
| 202 | if ( buffer[ count ] == '\n') { |
---|
| 203 | outbyte('\r'); |
---|
[ac7d5ef0] | 204 | } |
---|
[3a4ae6c] | 205 | outbyte( buffer[ count ] ); |
---|
[ac7d5ef0] | 206 | } |
---|
[3a4ae6c] | 207 | return maximum; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | /* |
---|
| 211 | * IO Control entry point |
---|
| 212 | */ |
---|
| 213 | |
---|
| 214 | rtems_device_driver console_control( |
---|
| 215 | rtems_device_major_number major, |
---|
| 216 | rtems_device_minor_number minor, |
---|
| 217 | void * arg |
---|
| 218 | ) |
---|
| 219 | { |
---|
| 220 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 221 | } |
---|