[ac7d5ef0] | 1 | /* |
---|
| 2 | * This file contains the Force CPU386 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 F386_INIT |
---|
| 16 | |
---|
| 17 | #include <stdlib.h> |
---|
| 18 | |
---|
| 19 | #include <rtems.h> |
---|
| 20 | #include "console.h" |
---|
| 21 | #include "bsp.h" |
---|
| 22 | |
---|
| 23 | /* console_cleanup |
---|
| 24 | * |
---|
| 25 | * This routine is called at exit to clean up the console hardware. |
---|
| 26 | * |
---|
| 27 | * Input parameters: NONE |
---|
| 28 | * |
---|
| 29 | * Output parameters: NONE |
---|
| 30 | * |
---|
| 31 | * Return values: |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | void console_cleanup( void ) |
---|
| 35 | { |
---|
| 36 | register rtems_unsigned8 ignored; |
---|
| 37 | /* |
---|
| 38 | * FORCE technical support mentioned that it may be necessary to |
---|
| 39 | * read the DUSCC RX_BUFFER port four times to remove all junk. |
---|
| 40 | * This code is a little more paranoid. |
---|
| 41 | */ |
---|
| 42 | |
---|
| 43 | inport_byte( RX_BUFFER, ignored ); |
---|
| 44 | inport_byte( RX_BUFFER, ignored ); |
---|
| 45 | inport_byte( RX_BUFFER, ignored ); |
---|
| 46 | inport_byte( RX_BUFFER, ignored ); |
---|
| 47 | inport_byte( RX_BUFFER, ignored ); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | /* console_initialize |
---|
| 51 | * |
---|
| 52 | * This routine initializes the console IO driver. |
---|
| 53 | * |
---|
| 54 | * Input parameters: NONE |
---|
| 55 | * |
---|
| 56 | * Output parameters: NONE |
---|
| 57 | * |
---|
| 58 | * Return values: |
---|
| 59 | */ |
---|
| 60 | |
---|
| 61 | rtems_device_driver console_initialize( |
---|
| 62 | rtems_device_major_number major, |
---|
| 63 | rtems_device_minor_number minor, |
---|
| 64 | void *arg, |
---|
| 65 | rtems_id self, |
---|
| 66 | rtems_unsigned32 *status |
---|
| 67 | ) |
---|
| 68 | { |
---|
| 69 | /* |
---|
| 70 | * flush the console now and at exit. Just in case. |
---|
| 71 | */ |
---|
| 72 | |
---|
| 73 | console_cleanup(); |
---|
| 74 | |
---|
| 75 | atexit( console_cleanup ); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | /* is_character_ready |
---|
| 80 | * |
---|
| 81 | * This routine returns TRUE if a character is available. |
---|
| 82 | * |
---|
| 83 | * Input parameters: NONE |
---|
| 84 | * |
---|
| 85 | * Output parameters: NONE |
---|
| 86 | * |
---|
| 87 | * Return values: |
---|
| 88 | */ |
---|
| 89 | |
---|
| 90 | rtems_boolean is_character_ready( |
---|
| 91 | char *ch |
---|
| 92 | ) |
---|
| 93 | { |
---|
| 94 | register rtems_unsigned8 status; |
---|
| 95 | |
---|
| 96 | inport_byte( RX_STATUS, status ); |
---|
| 97 | |
---|
| 98 | if ( Is_rx_ready( status ) ) { |
---|
| 99 | inport_byte( RX_BUFFER, status ); |
---|
| 100 | *ch = status; |
---|
| 101 | return TRUE; |
---|
| 102 | } |
---|
| 103 | return FALSE; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /* inbyte |
---|
| 107 | * |
---|
| 108 | * This routine reads a character from the UART. |
---|
| 109 | * |
---|
| 110 | * Input parameters: NONE |
---|
| 111 | * |
---|
| 112 | * Output parameters: NONE |
---|
| 113 | * |
---|
| 114 | * Return values: |
---|
| 115 | * character read from UART |
---|
| 116 | */ |
---|
| 117 | |
---|
| 118 | char inbyte( void ) |
---|
| 119 | { |
---|
| 120 | register rtems_unsigned8 status; |
---|
| 121 | char ch; |
---|
| 122 | |
---|
| 123 | do { |
---|
| 124 | inport_byte( RX_STATUS, status ); |
---|
| 125 | } while ( !Is_rx_ready( status ) ); |
---|
| 126 | |
---|
| 127 | #if ( PORTB == 1 ) |
---|
| 128 | /* |
---|
| 129 | * Force example code resets the Channel B Receiver here. |
---|
| 130 | * It appears to cause XON's to be lost. |
---|
| 131 | */ |
---|
| 132 | |
---|
| 133 | /* outport_byte( RX_STATUS, 0x10 ); */ |
---|
| 134 | #endif |
---|
| 135 | |
---|
| 136 | inport_byte( RX_BUFFER, ch ); |
---|
| 137 | |
---|
| 138 | return ch; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /* outbyte |
---|
| 142 | * |
---|
| 143 | * This routine transmits a character out the port. It supports |
---|
| 144 | * XON/XOFF flow control. |
---|
| 145 | * |
---|
| 146 | * Input parameters: |
---|
| 147 | * ch - character to be transmitted |
---|
| 148 | * |
---|
| 149 | * Output parameters: NONE |
---|
| 150 | */ |
---|
| 151 | |
---|
| 152 | void outbyte( |
---|
| 153 | char ch |
---|
| 154 | ) |
---|
| 155 | { |
---|
| 156 | rtems_unsigned8 status; |
---|
| 157 | |
---|
| 158 | do { |
---|
| 159 | inport_byte( TX_STATUS, status ); |
---|
| 160 | } while ( !Is_tx_ready( status ) ); |
---|
| 161 | |
---|
| 162 | #if 0 |
---|
| 163 | while ( is_character_ready( &status ) == TRUE ) { /* must be an XOFF */ |
---|
| 164 | if ( status == XOFF ) |
---|
| 165 | do { |
---|
| 166 | while ( is_character_ready( &status ) == FALSE ) ; |
---|
| 167 | } while ( status != XON ); |
---|
| 168 | } |
---|
| 169 | #endif |
---|
| 170 | |
---|
| 171 | outport_byte( TX_BUFFER, ch ); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | /* |
---|
| 175 | * __read -- read bytes from the serial port. Ignore fd, since |
---|
| 176 | * we only have stdin. |
---|
| 177 | */ |
---|
| 178 | |
---|
| 179 | int __read( |
---|
| 180 | int fd, |
---|
| 181 | char *buf, |
---|
| 182 | int nbytes |
---|
| 183 | ) |
---|
| 184 | { |
---|
| 185 | int i = 0; |
---|
| 186 | |
---|
| 187 | for (i = 0; i < nbytes; i++) { |
---|
| 188 | *(buf + i) = inbyte(); |
---|
| 189 | if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) { |
---|
| 190 | (*(buf + i++)) = '\n'; |
---|
| 191 | (*(buf + i)) = 0; |
---|
| 192 | break; |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | return (i); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /* |
---|
| 199 | * __write -- write bytes to the serial port. Ignore fd, since |
---|
| 200 | * stdout and stderr are the same. Since we have no filesystem, |
---|
| 201 | * open will only return an error. |
---|
| 202 | */ |
---|
| 203 | |
---|
| 204 | int __write( |
---|
| 205 | int fd, |
---|
| 206 | char *buf, |
---|
| 207 | int nbytes |
---|
| 208 | ) |
---|
| 209 | { |
---|
| 210 | int i; |
---|
| 211 | |
---|
| 212 | for (i = 0; i < nbytes; i++) { |
---|
| 213 | if (*(buf + i) == '\n') { |
---|
| 214 | outbyte ('\r'); |
---|
| 215 | } |
---|
| 216 | outbyte (*(buf + i)); |
---|
| 217 | } |
---|
| 218 | return (nbytes); |
---|
| 219 | } |
---|