[0074691a] | 1 | /* |
---|
| 2 | * Initialize the MC68302 SCC2 for console IO board support package. |
---|
| 3 | * |
---|
| 4 | * COPYRIGHT (c) 1989-1997. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * Copyright assigned to U.S. Government, 1994. |
---|
| 7 | * |
---|
[98e4ebf5] | 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
[0074691a] | 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define GEN68302_INIT |
---|
| 16 | |
---|
| 17 | #include <debugport.h> |
---|
| 18 | #include <bsp.h> |
---|
| 19 | #include <rtems/libio.h> |
---|
| 20 | |
---|
| 21 | /* console_initialize |
---|
| 22 | * |
---|
| 23 | * This routine initializes the console IO driver. |
---|
| 24 | * |
---|
| 25 | * Input parameters: NONE |
---|
| 26 | * |
---|
| 27 | * Output parameters: NONE |
---|
| 28 | * |
---|
| 29 | * Return values: |
---|
| 30 | */ |
---|
| 31 | |
---|
| 32 | rtems_device_driver console_initialize( |
---|
| 33 | rtems_device_major_number major, |
---|
| 34 | rtems_device_minor_number minor, |
---|
| 35 | void *arg |
---|
| 36 | ) |
---|
| 37 | { |
---|
| 38 | rtems_status_code status; |
---|
| 39 | |
---|
| 40 | /* debug_port_initialise(); */ |
---|
| 41 | |
---|
| 42 | status = rtems_io_register_name( |
---|
| 43 | "/dev/console", |
---|
| 44 | major, |
---|
| 45 | (rtems_device_minor_number) 0 |
---|
| 46 | ); |
---|
| 47 | |
---|
| 48 | if (status != RTEMS_SUCCESSFUL) |
---|
| 49 | rtems_fatal_error_occurred(status); |
---|
| 50 | |
---|
| 51 | return RTEMS_SUCCESSFUL; |
---|
| 52 | |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | /* is_character_ready |
---|
| 56 | * |
---|
| 57 | * Check to see if a character is available on the MC68302's SCC2. If so, |
---|
| 58 | * then return a TRUE (along with the character). Otherwise return FALSE. |
---|
| 59 | * |
---|
| 60 | * Input parameters: pointer to location in which to return character |
---|
| 61 | * |
---|
| 62 | * Output parameters: character (if available) |
---|
| 63 | * |
---|
| 64 | * Return values: TRUE - character available |
---|
| 65 | * FALSE - no character available |
---|
| 66 | */ |
---|
| 67 | |
---|
| 68 | rtems_boolean is_character_ready( |
---|
| 69 | char *ch /* -> character */ |
---|
| 70 | ) |
---|
| 71 | { |
---|
| 72 | if (debug_port_status(0)) |
---|
| 73 | { |
---|
[53cea31] | 74 | *ch = debug_port_in(); |
---|
[0074691a] | 75 | return TRUE; |
---|
| 76 | } |
---|
| 77 | return FALSE; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | /* inbyte |
---|
| 82 | * |
---|
| 83 | * Receive a character from the MC68302's SCC2. |
---|
| 84 | * |
---|
| 85 | * Input parameters: NONE |
---|
| 86 | * |
---|
| 87 | * Output parameters: NONE |
---|
| 88 | * |
---|
| 89 | * Return values: character read |
---|
| 90 | */ |
---|
| 91 | |
---|
| 92 | char inbyte( void ) |
---|
| 93 | { |
---|
| 94 | char ch; |
---|
| 95 | |
---|
| 96 | while (!is_character_ready(&ch)); |
---|
| 97 | |
---|
| 98 | return ch; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | /* outbyte |
---|
| 103 | * |
---|
| 104 | * Transmit a character out on the MC68302's SCC2. |
---|
| 105 | * It may support XON/XOFF flow control. |
---|
| 106 | * |
---|
| 107 | * Input parameters: |
---|
| 108 | * ch - character to be transmitted |
---|
| 109 | * |
---|
| 110 | * Output parameters: NONE |
---|
| 111 | */ |
---|
| 112 | |
---|
| 113 | void outbyte( |
---|
| 114 | char ch |
---|
| 115 | ) |
---|
| 116 | { |
---|
| 117 | debug_port_out(ch); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | * Open entry point |
---|
| 122 | */ |
---|
| 123 | |
---|
| 124 | rtems_device_driver console_open( |
---|
| 125 | rtems_device_major_number major, |
---|
| 126 | rtems_device_minor_number minor, |
---|
| 127 | void * arg |
---|
| 128 | ) |
---|
| 129 | { |
---|
| 130 | return RTEMS_SUCCESSFUL; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | /* |
---|
| 134 | * Close entry point |
---|
| 135 | */ |
---|
| 136 | |
---|
| 137 | rtems_device_driver console_close( |
---|
| 138 | rtems_device_major_number major, |
---|
| 139 | rtems_device_minor_number minor, |
---|
| 140 | void * arg |
---|
| 141 | ) |
---|
| 142 | { |
---|
| 143 | return RTEMS_SUCCESSFUL; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | /* |
---|
| 147 | * read bytes from the serial port. We only have stdin. |
---|
| 148 | */ |
---|
| 149 | |
---|
| 150 | rtems_device_driver console_read( |
---|
| 151 | rtems_device_major_number major, |
---|
| 152 | rtems_device_minor_number minor, |
---|
| 153 | void * arg |
---|
| 154 | ) |
---|
| 155 | { |
---|
| 156 | rtems_libio_rw_args_t *rw_args; |
---|
| 157 | char *buffer; |
---|
| 158 | int maximum; |
---|
| 159 | int count = 0; |
---|
| 160 | |
---|
| 161 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 162 | |
---|
| 163 | buffer = rw_args->buffer; |
---|
| 164 | maximum = rw_args->count; |
---|
| 165 | |
---|
| 166 | for (count = 0; count < maximum; count++) { |
---|
| 167 | buffer[ count ] = inbyte(); |
---|
| 168 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 169 | buffer[ count++ ] = '\n'; |
---|
| 170 | break; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | rw_args->bytes_moved = count; |
---|
| 175 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | /* |
---|
| 179 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
| 180 | */ |
---|
| 181 | |
---|
| 182 | rtems_device_driver console_write( |
---|
| 183 | rtems_device_major_number major, |
---|
| 184 | rtems_device_minor_number minor, |
---|
| 185 | void * arg |
---|
| 186 | ) |
---|
| 187 | { |
---|
| 188 | int count; |
---|
| 189 | int maximum; |
---|
| 190 | rtems_libio_rw_args_t *rw_args; |
---|
| 191 | char *buffer; |
---|
| 192 | |
---|
| 193 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 194 | |
---|
| 195 | buffer = rw_args->buffer; |
---|
| 196 | maximum = rw_args->count; |
---|
| 197 | |
---|
| 198 | for (count = 0; count < maximum; count++) { |
---|
| 199 | if ( buffer[ count ] == '\n') { |
---|
| 200 | outbyte('\r'); |
---|
| 201 | } |
---|
| 202 | outbyte( buffer[ count ] ); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | rw_args->bytes_moved = maximum; |
---|
| 206 | return 0; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | /* |
---|
| 210 | * IO Control entry point |
---|
| 211 | */ |
---|
| 212 | |
---|
| 213 | rtems_device_driver console_control( |
---|
| 214 | rtems_device_major_number major, |
---|
| 215 | rtems_device_minor_number minor, |
---|
| 216 | void * arg |
---|
| 217 | ) |
---|
| 218 | { |
---|
| 219 | return RTEMS_SUCCESSFUL; |
---|
| 220 | } |
---|