1 | /* |
---|
2 | * This file contains the Force CPU386 console IO package. |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1997. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * Copyright assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #define F386_INIT |
---|
16 | |
---|
17 | #include <bsp.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | |
---|
20 | #include <stdlib.h> |
---|
21 | |
---|
22 | /* console_cleanup |
---|
23 | * |
---|
24 | * This routine is called at exit to clean up the console hardware. |
---|
25 | * |
---|
26 | * Input parameters: NONE |
---|
27 | * |
---|
28 | * Output parameters: NONE |
---|
29 | * |
---|
30 | * Return values: |
---|
31 | */ |
---|
32 | |
---|
33 | void console_cleanup( void ) |
---|
34 | { |
---|
35 | register rtems_unsigned8 ignored; |
---|
36 | /* |
---|
37 | * FORCE technical support mentioned that it may be necessary to |
---|
38 | * read the DUSCC RX_BUFFER port four times to remove all junk. |
---|
39 | * This code is a little more paranoid. |
---|
40 | */ |
---|
41 | |
---|
42 | inport_byte( RX_BUFFER, ignored ); |
---|
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 | } |
---|
48 | |
---|
49 | /* console_initialize |
---|
50 | * |
---|
51 | * This routine initializes the console IO driver. |
---|
52 | * |
---|
53 | * Input parameters: NONE |
---|
54 | * |
---|
55 | * Output parameters: NONE |
---|
56 | * |
---|
57 | * Return values: |
---|
58 | */ |
---|
59 | |
---|
60 | rtems_device_driver console_initialize( |
---|
61 | rtems_device_major_number major, |
---|
62 | rtems_device_minor_number minor, |
---|
63 | void *arg |
---|
64 | ) |
---|
65 | { |
---|
66 | rtems_status_code status; |
---|
67 | |
---|
68 | /* |
---|
69 | * flush the console now and at exit. Just in case. |
---|
70 | */ |
---|
71 | |
---|
72 | console_cleanup(); |
---|
73 | |
---|
74 | status = rtems_io_register_name( |
---|
75 | "/dev/console", |
---|
76 | major, |
---|
77 | (rtems_device_minor_number) 0 |
---|
78 | ); |
---|
79 | |
---|
80 | if (status != RTEMS_SUCCESSFUL) |
---|
81 | rtems_fatal_error_occurred(status); |
---|
82 | |
---|
83 | atexit( console_cleanup ); |
---|
84 | |
---|
85 | return RTEMS_SUCCESSFUL; |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /* is_character_ready |
---|
90 | * |
---|
91 | * This routine returns TRUE if a character is available. |
---|
92 | * |
---|
93 | * Input parameters: NONE |
---|
94 | * |
---|
95 | * Output parameters: NONE |
---|
96 | * |
---|
97 | * Return values: |
---|
98 | */ |
---|
99 | |
---|
100 | rtems_boolean is_character_ready( |
---|
101 | char *ch |
---|
102 | ) |
---|
103 | { |
---|
104 | register rtems_unsigned8 status; |
---|
105 | |
---|
106 | inport_byte( RX_STATUS, status ); |
---|
107 | |
---|
108 | if ( Is_rx_ready( status ) ) { |
---|
109 | inport_byte( RX_BUFFER, status ); |
---|
110 | *ch = status; |
---|
111 | return TRUE; |
---|
112 | } |
---|
113 | return FALSE; |
---|
114 | } |
---|
115 | |
---|
116 | /* inbyte |
---|
117 | * |
---|
118 | * This routine reads a character from the UART. |
---|
119 | * |
---|
120 | * Input parameters: NONE |
---|
121 | * |
---|
122 | * Output parameters: NONE |
---|
123 | * |
---|
124 | * Return values: |
---|
125 | * character read from UART |
---|
126 | */ |
---|
127 | |
---|
128 | char inbyte( void ) |
---|
129 | { |
---|
130 | register rtems_unsigned8 status; |
---|
131 | char ch; |
---|
132 | |
---|
133 | do { |
---|
134 | inport_byte( RX_STATUS, status ); |
---|
135 | } while ( !Is_rx_ready( status ) ); |
---|
136 | |
---|
137 | #if ( PORTB == 1 ) |
---|
138 | /* |
---|
139 | * Force example code resets the Channel B Receiver here. |
---|
140 | * It appears to cause XON's to be lost. |
---|
141 | */ |
---|
142 | |
---|
143 | /* outport_byte( RX_STATUS, 0x10 ); */ |
---|
144 | #endif |
---|
145 | |
---|
146 | inport_byte( RX_BUFFER, ch ); |
---|
147 | |
---|
148 | return ch; |
---|
149 | } |
---|
150 | |
---|
151 | /* outbyte |
---|
152 | * |
---|
153 | * This routine transmits a character out the port. It supports |
---|
154 | * XON/XOFF flow control. |
---|
155 | * |
---|
156 | * Input parameters: |
---|
157 | * ch - character to be transmitted |
---|
158 | * |
---|
159 | * Output parameters: NONE |
---|
160 | */ |
---|
161 | |
---|
162 | void outbyte( |
---|
163 | char ch |
---|
164 | ) |
---|
165 | { |
---|
166 | rtems_unsigned8 status; |
---|
167 | |
---|
168 | do { |
---|
169 | inport_byte( TX_STATUS, status ); |
---|
170 | } while ( !Is_tx_ready( status ) ); |
---|
171 | |
---|
172 | #if 0 |
---|
173 | while ( is_character_ready( &status ) == TRUE ) { /* must be an XOFF */ |
---|
174 | if ( status == XOFF ) |
---|
175 | do { |
---|
176 | while ( is_character_ready( &status ) == FALSE ) ; |
---|
177 | } while ( status != XON ); |
---|
178 | } |
---|
179 | #endif |
---|
180 | |
---|
181 | outport_byte( TX_BUFFER, ch ); |
---|
182 | } |
---|
183 | |
---|
184 | /* |
---|
185 | * Open entry point |
---|
186 | */ |
---|
187 | |
---|
188 | rtems_device_driver console_open( |
---|
189 | rtems_device_major_number major, |
---|
190 | rtems_device_minor_number minor, |
---|
191 | void * arg |
---|
192 | ) |
---|
193 | { |
---|
194 | return RTEMS_SUCCESSFUL; |
---|
195 | } |
---|
196 | |
---|
197 | /* |
---|
198 | * Close entry point |
---|
199 | */ |
---|
200 | |
---|
201 | rtems_device_driver console_close( |
---|
202 | rtems_device_major_number major, |
---|
203 | rtems_device_minor_number minor, |
---|
204 | void * arg |
---|
205 | ) |
---|
206 | { |
---|
207 | return RTEMS_SUCCESSFUL; |
---|
208 | } |
---|
209 | |
---|
210 | /* |
---|
211 | * read bytes from the serial port. We only have stdin. |
---|
212 | */ |
---|
213 | |
---|
214 | rtems_device_driver console_read( |
---|
215 | rtems_device_major_number major, |
---|
216 | rtems_device_minor_number minor, |
---|
217 | void * arg |
---|
218 | ) |
---|
219 | { |
---|
220 | rtems_libio_rw_args_t *rw_args; |
---|
221 | char *buffer; |
---|
222 | int maximum; |
---|
223 | int count = 0; |
---|
224 | |
---|
225 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
226 | |
---|
227 | buffer = rw_args->buffer; |
---|
228 | maximum = rw_args->count; |
---|
229 | |
---|
230 | for (count = 0; count < maximum; count++) { |
---|
231 | buffer[ count ] = inbyte(); |
---|
232 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
233 | buffer[ count++ ] = '\n'; |
---|
234 | break; |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | rw_args->bytes_moved = count; |
---|
239 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
240 | } |
---|
241 | |
---|
242 | /* |
---|
243 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
244 | */ |
---|
245 | |
---|
246 | rtems_device_driver console_write( |
---|
247 | rtems_device_major_number major, |
---|
248 | rtems_device_minor_number minor, |
---|
249 | void * arg |
---|
250 | ) |
---|
251 | { |
---|
252 | int count; |
---|
253 | int maximum; |
---|
254 | rtems_libio_rw_args_t *rw_args; |
---|
255 | char *buffer; |
---|
256 | |
---|
257 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
258 | |
---|
259 | buffer = rw_args->buffer; |
---|
260 | maximum = rw_args->count; |
---|
261 | |
---|
262 | for (count = 0; count < maximum; count++) { |
---|
263 | if ( buffer[ count ] == '\n') { |
---|
264 | outbyte('\r'); |
---|
265 | } |
---|
266 | outbyte( buffer[ count ] ); |
---|
267 | } |
---|
268 | |
---|
269 | rw_args->bytes_moved = maximum; |
---|
270 | return 0; |
---|
271 | } |
---|
272 | |
---|
273 | /* |
---|
274 | * IO Control entry point |
---|
275 | */ |
---|
276 | |
---|
277 | rtems_device_driver console_control( |
---|
278 | rtems_device_major_number major, |
---|
279 | rtems_device_minor_number minor, |
---|
280 | void * arg |
---|
281 | ) |
---|
282 | { |
---|
283 | return RTEMS_SUCCESSFUL; |
---|
284 | } |
---|
285 | |
---|