[ac7d5ef0] | 1 | /* |
---|
| 2 | * This file contains the MVME136 console IO package. |
---|
| 3 | * |
---|
[03f2154e] | 4 | * COPYRIGHT (c) 1989-1997. |
---|
[ac7d5ef0] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
[03f2154e] | 6 | * Copyright assigned to U.S. Government, 1994. |
---|
[ac7d5ef0] | 7 | * |
---|
[98e4ebf5] | 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #define M136_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 | |
---|
[ac7d5ef0] | 39 | _Write_m681 = ( struct w_m681_info * ) M681ADDR; |
---|
| 40 | _Read_m681 = ( struct r_m681_info * ) M681ADDR; |
---|
[3a4ae6c] | 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; |
---|
[ac7d5ef0] | 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /* is_character_ready |
---|
| 56 | * |
---|
| 57 | * This routine returns TRUE if a character is available. |
---|
| 58 | * |
---|
| 59 | * Input parameters: NONE |
---|
| 60 | * |
---|
| 61 | * Output parameters: NONE |
---|
| 62 | * |
---|
| 63 | * Return values: |
---|
| 64 | */ |
---|
| 65 | |
---|
| 66 | rtems_boolean is_character_ready( |
---|
| 67 | char *ch |
---|
| 68 | ) |
---|
| 69 | { |
---|
| 70 | if ( !(_Read_m681->srb & RXRDYB) ) |
---|
| 71 | return(FALSE); |
---|
| 72 | |
---|
| 73 | *ch = _Read_m681->rbb; |
---|
| 74 | return(TRUE); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | /* inbyte |
---|
| 78 | * |
---|
| 79 | * This routine reads a character from the UART. |
---|
| 80 | * |
---|
| 81 | * Input parameters: NONE |
---|
| 82 | * |
---|
| 83 | * Output parameters: NONE |
---|
| 84 | * |
---|
| 85 | * Return values: |
---|
| 86 | * character read from UART |
---|
| 87 | */ |
---|
| 88 | |
---|
| 89 | char inbyte( void ) |
---|
| 90 | { |
---|
| 91 | while ( !(_Read_m681->srb & RXRDYB) ); |
---|
| 92 | return _Read_m681->rbb; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /* outbyte |
---|
| 97 | * |
---|
| 98 | * This routine transmits a character out the M68681. It supports |
---|
| 99 | * XON/XOFF flow control. |
---|
| 100 | * |
---|
| 101 | * Input parameters: |
---|
| 102 | * ch - character to be transmitted |
---|
| 103 | * |
---|
| 104 | * Output parameters: NONE |
---|
| 105 | */ |
---|
| 106 | |
---|
| 107 | void outbyte( |
---|
| 108 | char ch |
---|
| 109 | ) |
---|
| 110 | { |
---|
| 111 | while ( ! (_Read_m681->srb & TXRDYB) ) ; |
---|
| 112 | while ( _Read_m681->srb & RXRDYB ) /* must be an XOFF */ |
---|
| 113 | if ( _Read_m681->rbb == XOFF ) |
---|
| 114 | do { |
---|
| 115 | while ( ! (_Read_m681->srb & RXRDYB) ) ; |
---|
| 116 | } while ( _Read_m681->rbb != XON ); |
---|
| 117 | |
---|
| 118 | _Write_m681->tbb = ch; |
---|
| 119 | if ( ch == '\n' ) |
---|
| 120 | outbyte( CR ); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | /* |
---|
[3a4ae6c] | 124 | * Open entry point |
---|
[ac7d5ef0] | 125 | */ |
---|
| 126 | |
---|
[3a4ae6c] | 127 | rtems_device_driver console_open( |
---|
| 128 | rtems_device_major_number major, |
---|
| 129 | rtems_device_minor_number minor, |
---|
| 130 | void * arg |
---|
[ac7d5ef0] | 131 | ) |
---|
| 132 | { |
---|
[3a4ae6c] | 133 | return RTEMS_SUCCESSFUL; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | /* |
---|
| 137 | * Close entry point |
---|
| 138 | */ |
---|
| 139 | |
---|
| 140 | rtems_device_driver console_close( |
---|
| 141 | rtems_device_major_number major, |
---|
| 142 | rtems_device_minor_number minor, |
---|
| 143 | void * arg |
---|
| 144 | ) |
---|
| 145 | { |
---|
| 146 | return RTEMS_SUCCESSFUL; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | /* |
---|
| 150 | * read bytes from the serial port. We only have stdin. |
---|
| 151 | */ |
---|
[ac7d5ef0] | 152 | |
---|
[3a4ae6c] | 153 | rtems_device_driver console_read( |
---|
| 154 | rtems_device_major_number major, |
---|
| 155 | rtems_device_minor_number minor, |
---|
| 156 | void * arg |
---|
| 157 | ) |
---|
| 158 | { |
---|
| 159 | rtems_libio_rw_args_t *rw_args; |
---|
| 160 | char *buffer; |
---|
| 161 | int maximum; |
---|
| 162 | int count = 0; |
---|
| 163 | |
---|
| 164 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 165 | |
---|
| 166 | buffer = rw_args->buffer; |
---|
| 167 | maximum = rw_args->count; |
---|
| 168 | |
---|
| 169 | for (count = 0; count < maximum; count++) { |
---|
| 170 | buffer[ count ] = inbyte(); |
---|
| 171 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
| 172 | buffer[ count++ ] = '\n'; |
---|
[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; |
---|
[ac7d5ef0] | 195 | |
---|
[3a4ae6c] | 196 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
| 197 | |
---|
| 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 | } |
---|
[3652ad35] | 207 | |
---|
| 208 | rw_args->bytes_moved = maximum; |
---|
| 209 | return 0; |
---|
[3a4ae6c] | 210 | } |
---|
| 211 | |
---|
| 212 | /* |
---|
| 213 | * IO Control entry point |
---|
| 214 | */ |
---|
| 215 | |
---|
| 216 | rtems_device_driver console_control( |
---|
| 217 | rtems_device_major_number major, |
---|
| 218 | rtems_device_minor_number minor, |
---|
| 219 | void * arg |
---|
| 220 | ) |
---|
| 221 | { |
---|
| 222 | return RTEMS_SUCCESSFUL; |
---|
[ac7d5ef0] | 223 | } |
---|