1 | /* |
---|
2 | * This file contains the template for a 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 NO_BSP_INIT |
---|
16 | |
---|
17 | |
---|
18 | /* only one of the following can be defined */ |
---|
19 | #define SERIAL_INPUT /* use serial input */ |
---|
20 | /* #define HIF_INPUT */ /* use HIF input */ |
---|
21 | |
---|
22 | #if defined(SERIAL_INPUT) && defined(HIF_INPUT) |
---|
23 | #error SERIAL_INPUT and HIF_INPUT cannot both be defined!!! |
---|
24 | #endif |
---|
25 | |
---|
26 | /* both of the following can be defined */ |
---|
27 | #define SERIAL_OUTPUT /* remove to disable serial port console output */ |
---|
28 | /* #define HIF_OUTPUT */ /* remove to disable HIF console output */ |
---|
29 | |
---|
30 | #include <bsp.h> |
---|
31 | #include <rtems/libio.h> |
---|
32 | #include "serial.h" |
---|
33 | #include "concntl.h" |
---|
34 | |
---|
35 | #ifndef lint |
---|
36 | static char _sccsid[] = "@(#)console.c 09/12/96 1.13\n"; |
---|
37 | #endif |
---|
38 | |
---|
39 | /* console_initialize |
---|
40 | * |
---|
41 | * This routine initializes the console IO driver. |
---|
42 | * |
---|
43 | * Input parameters: NONE |
---|
44 | * |
---|
45 | * Output parameters: NONE |
---|
46 | * |
---|
47 | * Return values: |
---|
48 | */ |
---|
49 | |
---|
50 | rtems_device_driver console_initialize( |
---|
51 | rtems_device_major_number major, |
---|
52 | rtems_device_minor_number minor, |
---|
53 | void *arg |
---|
54 | ) |
---|
55 | { |
---|
56 | rtems_status_code status; |
---|
57 | |
---|
58 | if ( arg ) |
---|
59 | { |
---|
60 | if ( console_duartinit(minor,*(unsigned32*)arg) ) |
---|
61 | return RTEMS_INVALID_NUMBER; |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | if ( console_duartinit(1,9600) || console_duartinit(0,9600) ) |
---|
66 | { |
---|
67 | return RTEMS_INVALID_NUMBER; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | status = rtems_io_register_name( |
---|
72 | "/dev/console", |
---|
73 | major, |
---|
74 | (rtems_device_minor_number) 0 |
---|
75 | ); |
---|
76 | |
---|
77 | if (status != RTEMS_SUCCESSFUL) |
---|
78 | rtems_fatal_error_occurred(status); |
---|
79 | |
---|
80 | return RTEMS_SUCCESSFUL; |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | /* is_character_ready |
---|
85 | * |
---|
86 | * This routine returns TRUE if a character is available. |
---|
87 | * |
---|
88 | * Input parameters: NONE |
---|
89 | * |
---|
90 | * Output parameters: NONE |
---|
91 | * |
---|
92 | * Return values: |
---|
93 | */ |
---|
94 | |
---|
95 | rtems_boolean is_character_ready( |
---|
96 | char *ch |
---|
97 | ) |
---|
98 | { |
---|
99 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
100 | return(TRUE); |
---|
101 | } |
---|
102 | |
---|
103 | /* inbyte |
---|
104 | * |
---|
105 | * This routine reads a character from the SOURCE. |
---|
106 | * |
---|
107 | * Input parameters: NONE |
---|
108 | * |
---|
109 | * Output parameters: NONE |
---|
110 | * |
---|
111 | * Return values: |
---|
112 | * character read from SOURCE |
---|
113 | */ |
---|
114 | |
---|
115 | char inbyte( unsigned int minor ) |
---|
116 | { |
---|
117 | /* |
---|
118 | * If polling, wait until a character is available. |
---|
119 | */ |
---|
120 | #ifdef HIF_INPUT |
---|
121 | char retch; |
---|
122 | _read( 1, &retch, 1 ); |
---|
123 | return retch; |
---|
124 | #endif |
---|
125 | #ifdef SERIAL_INPUT |
---|
126 | return console_sps_getc( minor ); |
---|
127 | #endif |
---|
128 | } |
---|
129 | |
---|
130 | /* outbyte |
---|
131 | * |
---|
132 | * This routine transmits a character out the SOURCE. It may support |
---|
133 | * XON/XOFF flow control. |
---|
134 | * |
---|
135 | * Input parameters: |
---|
136 | * ch - character to be transmitted |
---|
137 | * |
---|
138 | * Output parameters: NONE |
---|
139 | */ |
---|
140 | |
---|
141 | void outbyte( unsigned int minor, |
---|
142 | char ch |
---|
143 | ) |
---|
144 | { |
---|
145 | /* |
---|
146 | * If polling, wait for the transmitter to be ready. |
---|
147 | * Check for flow control requests and process. |
---|
148 | * Then output the character. |
---|
149 | */ |
---|
150 | |
---|
151 | #ifdef SERIAL_OUTPUT |
---|
152 | console_sps_putc( minor, ch ); |
---|
153 | #endif |
---|
154 | |
---|
155 | /* |
---|
156 | * Carriage Return/New line translation. |
---|
157 | */ |
---|
158 | |
---|
159 | if ( ch == '\n' ) |
---|
160 | outbyte( minor, '\r' ); |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | /* |
---|
165 | * Open entry point |
---|
166 | */ |
---|
167 | |
---|
168 | rtems_device_driver console_open( |
---|
169 | rtems_device_major_number major, |
---|
170 | rtems_device_minor_number minor, |
---|
171 | void * arg |
---|
172 | ) |
---|
173 | { |
---|
174 | return RTEMS_SUCCESSFUL; |
---|
175 | } |
---|
176 | |
---|
177 | /* |
---|
178 | * Close entry point |
---|
179 | */ |
---|
180 | |
---|
181 | rtems_device_driver console_close( |
---|
182 | rtems_device_major_number major, |
---|
183 | rtems_device_minor_number minor, |
---|
184 | void * arg |
---|
185 | ) |
---|
186 | { |
---|
187 | return RTEMS_SUCCESSFUL; |
---|
188 | } |
---|
189 | |
---|
190 | /* |
---|
191 | * read bytes from the serial port. We only have stdin. |
---|
192 | */ |
---|
193 | |
---|
194 | rtems_device_driver console_read( |
---|
195 | rtems_device_major_number major, |
---|
196 | rtems_device_minor_number minor, |
---|
197 | void * arg |
---|
198 | ) |
---|
199 | { |
---|
200 | rtems_libio_rw_args_t *rw_args; |
---|
201 | unsigned8 *buffer; |
---|
202 | unsigned32 maximum; |
---|
203 | unsigned32 count = 0; |
---|
204 | |
---|
205 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
206 | |
---|
207 | buffer = rw_args->buffer; |
---|
208 | maximum = rw_args->count; |
---|
209 | |
---|
210 | for (count = 0; count < maximum; count++) { |
---|
211 | buffer[ count ] = inbyte(minor); |
---|
212 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
213 | buffer[ count++ ] = '\n'; |
---|
214 | buffer[ count ] = 0; |
---|
215 | outbyte( minor, '\n' ); /* newline */ |
---|
216 | break; |
---|
217 | } |
---|
218 | else if (buffer[ count ] == '\b' && count > 0 ) |
---|
219 | { |
---|
220 | outbyte( minor, '\b' ); /* move back one space */ |
---|
221 | outbyte( minor, ' ' ); /* erase the character */ |
---|
222 | outbyte( minor, '\b' ); /* move back one space */ |
---|
223 | count-=2; |
---|
224 | } |
---|
225 | else |
---|
226 | outbyte( minor, buffer[ count ] ); /* echo the character */ |
---|
227 | } |
---|
228 | |
---|
229 | rw_args->bytes_moved = count; |
---|
230 | return (count > 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
231 | } |
---|
232 | |
---|
233 | /* |
---|
234 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
235 | */ |
---|
236 | |
---|
237 | rtems_device_driver console_write( |
---|
238 | rtems_device_major_number major, |
---|
239 | rtems_device_minor_number minor, |
---|
240 | void * arg |
---|
241 | ) |
---|
242 | { |
---|
243 | int count; |
---|
244 | int maximum; |
---|
245 | rtems_libio_rw_args_t *rw_args; |
---|
246 | unsigned8 *buffer; |
---|
247 | |
---|
248 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
249 | |
---|
250 | buffer = rw_args->buffer; |
---|
251 | maximum = rw_args->count; |
---|
252 | |
---|
253 | #ifdef HIF_OUTPUT |
---|
254 | _write( 0, buffer, maximum ); |
---|
255 | #endif |
---|
256 | #ifdef SERIAL_OUTPUT |
---|
257 | for (count = 0; count < maximum; count++) { |
---|
258 | if ( buffer[ count ] == '\n') { |
---|
259 | outbyte(minor,'\r'); |
---|
260 | } |
---|
261 | outbyte( minor,buffer[ count ] ); |
---|
262 | } |
---|
263 | #endif |
---|
264 | |
---|
265 | rw_args->bytes_moved = maximum; |
---|
266 | return 0; |
---|
267 | } |
---|
268 | |
---|
269 | /* |
---|
270 | * IO Control entry point |
---|
271 | */ |
---|
272 | |
---|
273 | rtems_device_driver console_control( |
---|
274 | rtems_device_major_number major, |
---|
275 | rtems_device_minor_number minor, |
---|
276 | void * arg |
---|
277 | ) |
---|
278 | { |
---|
279 | if (!arg) |
---|
280 | return RTEMS_INVALID_ADDRESS; |
---|
281 | |
---|
282 | switch( ((console_ioctl_request_t *)arg)->ioctl_type ) |
---|
283 | { |
---|
284 | case CON_KBHIT: |
---|
285 | /* check if keyboard was hit */ |
---|
286 | ((console_ioctl_request_t *)arg)->param = console_sps_kbhit(minor); |
---|
287 | break; |
---|
288 | |
---|
289 | case CON_GET_RAW_BYTE: |
---|
290 | ((console_ioctl_request_t *)arg)->param = inbyte(minor); |
---|
291 | break; |
---|
292 | |
---|
293 | case CON_SEND_RAW_BYTE: |
---|
294 | outbyte(minor, ((console_ioctl_request_t *)arg)->param); |
---|
295 | break; |
---|
296 | |
---|
297 | default: |
---|
298 | break; |
---|
299 | } |
---|
300 | |
---|
301 | return RTEMS_SUCCESSFUL; |
---|
302 | } |
---|