[ac7d5ef0] | 1 | /* |
---|
| 2 | * This file contains the MVME136 console IO package. |
---|
| 3 | * |
---|
[08311cc3] | 4 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
[98e4ebf5] | 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 9 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #define M136_INIT |
---|
| 15 | |
---|
[3a4ae6c] | 16 | #include <bsp.h> |
---|
| 17 | #include <rtems/libio.h> |
---|
[ac7d5ef0] | 18 | |
---|
| 19 | /* console_initialize |
---|
| 20 | * |
---|
| 21 | * This routine initializes the console IO driver. |
---|
| 22 | * |
---|
| 23 | * Input parameters: NONE |
---|
| 24 | * |
---|
| 25 | * Output parameters: NONE |
---|
| 26 | * |
---|
| 27 | * Return values: |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | rtems_device_driver console_initialize( |
---|
| 31 | rtems_device_major_number major, |
---|
| 32 | rtems_device_minor_number minor, |
---|
[3a4ae6c] | 33 | void *arg |
---|
[ac7d5ef0] | 34 | ) |
---|
| 35 | { |
---|
[3a4ae6c] | 36 | rtems_status_code status; |
---|
| 37 | |
---|
[ac7d5ef0] | 38 | _Write_m681 = ( struct w_m681_info * ) M681ADDR; |
---|
| 39 | _Read_m681 = ( struct r_m681_info * ) M681ADDR; |
---|
[3a4ae6c] | 40 | |
---|
| 41 | status = rtems_io_register_name( |
---|
| 42 | "/dev/console", |
---|
| 43 | major, |
---|
| 44 | (rtems_device_minor_number) 0 |
---|
| 45 | ); |
---|
| 46 | |
---|
| 47 | if (status != RTEMS_SUCCESSFUL) |
---|
| 48 | rtems_fatal_error_occurred(status); |
---|
| 49 | |
---|
| 50 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | /* is_character_ready |
---|
| 55 | * |
---|
| 56 | * This routine returns TRUE if a character is available. |
---|
| 57 | * |
---|
| 58 | * Input parameters: NONE |
---|
| 59 | * |
---|
| 60 | * Output parameters: NONE |
---|
| 61 | * |
---|
| 62 | * Return values: |
---|
| 63 | */ |
---|
| 64 | |
---|
| 65 | rtems_boolean is_character_ready( |
---|
| 66 | char *ch |
---|
| 67 | ) |
---|
| 68 | { |
---|
| 69 | if ( !(_Read_m681->srb & RXRDYB) ) |
---|
| 70 | return(FALSE); |
---|
| 71 | |
---|
| 72 | *ch = _Read_m681->rbb; |
---|
| 73 | return(TRUE); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | /* inbyte |
---|
| 77 | * |
---|
| 78 | * This routine reads a character from the UART. |
---|
| 79 | * |
---|
| 80 | * Input parameters: NONE |
---|
| 81 | * |
---|
| 82 | * Output parameters: NONE |
---|
| 83 | * |
---|
| 84 | * Return values: |
---|
| 85 | * character read from UART |
---|
| 86 | */ |
---|
| 87 | |
---|
| 88 | char inbyte( void ) |
---|
| 89 | { |
---|
| 90 | while ( !(_Read_m681->srb & RXRDYB) ); |
---|
| 91 | return _Read_m681->rbb; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | /* outbyte |
---|
| 96 | * |
---|
| 97 | * This routine transmits a character out the M68681. It supports |
---|
| 98 | * XON/XOFF flow control. |
---|
| 99 | * |
---|
| 100 | * Input parameters: |
---|
| 101 | * ch - character to be transmitted |
---|
| 102 | * |
---|
| 103 | * Output parameters: NONE |
---|
| 104 | */ |
---|
| 105 | |
---|
| 106 | void outbyte( |
---|
| 107 | char ch |
---|
| 108 | ) |
---|
| 109 | { |
---|
| 110 | while ( ! (_Read_m681->srb & TXRDYB) ) ; |
---|
| 111 | while ( _Read_m681->srb & RXRDYB ) /* must be an XOFF */ |
---|
| 112 | if ( _Read_m681->rbb == XOFF ) |
---|
| 113 | do { |
---|
| 114 | while ( ! (_Read_m681->srb & RXRDYB) ) ; |
---|
| 115 | } while ( _Read_m681->rbb != XON ); |
---|
| 116 | |
---|
| 117 | _Write_m681->tbb = ch; |
---|
| 118 | if ( ch == '\n' ) |
---|
| 119 | outbyte( CR ); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /* |
---|
[3a4ae6c] | 123 | * Open entry point |
---|
[ac7d5ef0] | 124 | */ |
---|
| 125 | |
---|
[3a4ae6c] | 126 | rtems_device_driver console_open( |
---|
| 127 | rtems_device_major_number major, |
---|
| 128 | rtems_device_minor_number minor, |
---|
| 129 | void * arg |
---|
[ac7d5ef0] | 130 | ) |
---|
| 131 | { |
---|
[3a4ae6c] | 132 | return RTEMS_SUCCESSFUL; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | /* |
---|
| 136 | * Close entry point |
---|
| 137 | */ |
---|
| 138 | |
---|
| 139 | rtems_device_driver console_close( |
---|
| 140 | rtems_device_major_number major, |
---|
| 141 | rtems_device_minor_number minor, |
---|
| 142 | void * arg |
---|
| 143 | ) |
---|
| 144 | { |
---|
| 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'; |
---|
[ac7d5ef0] | 172 | break; |
---|
| 173 | } |
---|
| 174 | } |
---|
[3a4ae6c] | 175 | |
---|
| 176 | rw_args->bytes_moved = count; |
---|
| 177 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
[ac7d5ef0] | 178 | } |
---|
| 179 | |
---|
| 180 | /* |
---|
[3a4ae6c] | 181 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
[ac7d5ef0] | 182 | */ |
---|
| 183 | |
---|
[3a4ae6c] | 184 | rtems_device_driver console_write( |
---|
| 185 | rtems_device_major_number major, |
---|
| 186 | rtems_device_minor_number minor, |
---|
| 187 | void * arg |
---|
[ac7d5ef0] | 188 | ) |
---|
| 189 | { |
---|
[3a4ae6c] | 190 | int count; |
---|
| 191 | int maximum; |
---|
| 192 | rtems_libio_rw_args_t *rw_args; |
---|
| 193 | char *buffer; |
---|
[ac7d5ef0] | 194 | |
---|
[3a4ae6c] | 195 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 196 | |
---|
| 197 | buffer = rw_args->buffer; |
---|
| 198 | maximum = rw_args->count; |
---|
| 199 | |
---|
| 200 | for (count = 0; count < maximum; count++) { |
---|
| 201 | if ( buffer[ count ] == '\n') { |
---|
| 202 | outbyte('\r'); |
---|
[ac7d5ef0] | 203 | } |
---|
[3a4ae6c] | 204 | outbyte( buffer[ count ] ); |
---|
[ac7d5ef0] | 205 | } |
---|
[3652ad35] | 206 | |
---|
| 207 | rw_args->bytes_moved = maximum; |
---|
| 208 | return 0; |
---|
[3a4ae6c] | 209 | } |
---|
| 210 | |
---|
| 211 | /* |
---|
| 212 | * IO Control entry point |
---|
| 213 | */ |
---|
| 214 | |
---|
| 215 | rtems_device_driver console_control( |
---|
| 216 | rtems_device_major_number major, |
---|
| 217 | rtems_device_minor_number minor, |
---|
| 218 | void * arg |
---|
| 219 | ) |
---|
| 220 | { |
---|
| 221 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 222 | } |
---|