1 | /* |
---|
2 | * This file contains the IDT 4650 console IO package. |
---|
3 | * |
---|
4 | * Author: Craig Lebakken <craigl@transition.com> |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1996 by Transition Networks Inc. |
---|
7 | * |
---|
8 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
9 | * without any express or implied warranty: |
---|
10 | * permission to use, copy, modify, and distribute this file |
---|
11 | * for any purpose is hereby granted without fee, provided that |
---|
12 | * the above copyright notice and this notice appears in all |
---|
13 | * copies, and that the name of Transition Networks not be used in |
---|
14 | * advertising or publicity pertaining to distribution of the |
---|
15 | * software without specific, written prior permission. |
---|
16 | * Transition Networks makes no representations about the suitability |
---|
17 | * of this software for any purpose. |
---|
18 | * |
---|
19 | * Derived from c/src/lib/libbsp/no_cpu/no_bsp/console/console.c: |
---|
20 | * |
---|
21 | * COPYRIGHT (c) 1989-1997. |
---|
22 | * On-Line Applications Research Corporation (OAR). |
---|
23 | * Copyright assigned to U.S. Government, 1994. |
---|
24 | * |
---|
25 | * The license and distribution terms for this file may be |
---|
26 | * found in the file LICENSE in this distribution or at |
---|
27 | * http://www.OARcorp.com/rtems/license.html. |
---|
28 | * |
---|
29 | * $Id$ |
---|
30 | */ |
---|
31 | |
---|
32 | |
---|
33 | /* |
---|
34 | * Rather than deleting this, it is commented out to (hopefully) help |
---|
35 | * the submitter send updates. |
---|
36 | * |
---|
37 | * static char _sccsid[] = "@(#)console.c 08/20/96 1.6\n"; |
---|
38 | */ |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | #include <bsp.h> |
---|
43 | #include <rtems/libio.h> |
---|
44 | #include <ctype.h> |
---|
45 | |
---|
46 | char idtsim_getchar( void ); |
---|
47 | void idtsim_putchar( char c ); |
---|
48 | void mips_leddisplay( char a, char b, char c, char d ); |
---|
49 | |
---|
50 | |
---|
51 | /* console_initialize |
---|
52 | * |
---|
53 | * This routine initializes the console IO driver. |
---|
54 | * |
---|
55 | * Input parameters: NONE |
---|
56 | * |
---|
57 | * Output parameters: NONE |
---|
58 | * |
---|
59 | * Return values: |
---|
60 | */ |
---|
61 | |
---|
62 | rtems_device_driver console_initialize( |
---|
63 | rtems_device_major_number major, |
---|
64 | rtems_device_minor_number minor, |
---|
65 | void *arg |
---|
66 | ) |
---|
67 | { |
---|
68 | rtems_status_code status; |
---|
69 | |
---|
70 | status = rtems_io_register_name( |
---|
71 | "/dev/console", |
---|
72 | major, |
---|
73 | (rtems_device_minor_number) 0 |
---|
74 | ); |
---|
75 | |
---|
76 | if (status != RTEMS_SUCCESSFUL) |
---|
77 | rtems_fatal_error_occurred(status); |
---|
78 | |
---|
79 | return RTEMS_SUCCESSFUL; |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | /* is_character_ready |
---|
84 | * |
---|
85 | * This routine returns TRUE if a character is available. |
---|
86 | * |
---|
87 | * Input parameters: NONE |
---|
88 | * |
---|
89 | * Output parameters: NONE |
---|
90 | * |
---|
91 | * Return values: |
---|
92 | */ |
---|
93 | |
---|
94 | rtems_boolean is_character_ready( |
---|
95 | char *ch |
---|
96 | ) |
---|
97 | { |
---|
98 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
99 | return(TRUE); |
---|
100 | } |
---|
101 | |
---|
102 | /* inbyte |
---|
103 | * |
---|
104 | * This routine reads a character from the SOURCE. |
---|
105 | * |
---|
106 | * Input parameters: NONE |
---|
107 | * |
---|
108 | * Output parameters: NONE |
---|
109 | * |
---|
110 | * Return values: |
---|
111 | * character read from SOURCE |
---|
112 | */ |
---|
113 | |
---|
114 | char inbyte( void ) |
---|
115 | { |
---|
116 | /* |
---|
117 | * If polling, wait until a character is available. |
---|
118 | */ |
---|
119 | |
---|
120 | return idtsim_getchar(); |
---|
121 | } |
---|
122 | |
---|
123 | /* outbyte |
---|
124 | * |
---|
125 | * This routine transmits a character out the SOURCE. It may support |
---|
126 | * XON/XOFF flow control. |
---|
127 | * |
---|
128 | * Input parameters: |
---|
129 | * ch - character to be transmitted |
---|
130 | * |
---|
131 | * Output parameters: NONE |
---|
132 | */ |
---|
133 | |
---|
134 | void outbyte( |
---|
135 | char ch |
---|
136 | ) |
---|
137 | { |
---|
138 | #define NUM_LEDS 4 |
---|
139 | static unsigned int cur_led = 0; |
---|
140 | static unsigned char led_chars[NUM_LEDS]; |
---|
141 | |
---|
142 | /* |
---|
143 | * If polling, wait for the transmitter to be ready. |
---|
144 | * Check for flow control requests and process. |
---|
145 | * Then output the character. |
---|
146 | */ |
---|
147 | |
---|
148 | idtsim_putchar( ch ); |
---|
149 | |
---|
150 | /* print out first four alpha numeric characters in a line */ |
---|
151 | if ( ch == '\n' ) |
---|
152 | { |
---|
153 | mips_leddisplay( led_chars[0], led_chars[1], led_chars[2], led_chars[3] ); |
---|
154 | cur_led = 0; |
---|
155 | } |
---|
156 | else if ( isalnum( (unsigned char) ch ) && cur_led < NUM_LEDS ) |
---|
157 | { |
---|
158 | led_chars[cur_led++] = ch; |
---|
159 | } |
---|
160 | |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | #if 0 |
---|
165 | static int console_fd = -1; |
---|
166 | #endif |
---|
167 | |
---|
168 | /* |
---|
169 | * Open entry point |
---|
170 | */ |
---|
171 | |
---|
172 | rtems_device_driver console_open( |
---|
173 | rtems_device_major_number major, |
---|
174 | rtems_device_minor_number minor, |
---|
175 | void * arg |
---|
176 | ) |
---|
177 | { |
---|
178 | #if 0 |
---|
179 | int console_fd = open("tty0", 2); /* open for read/write */ |
---|
180 | #endif |
---|
181 | return RTEMS_SUCCESSFUL; |
---|
182 | } |
---|
183 | |
---|
184 | /* |
---|
185 | * Close entry point |
---|
186 | */ |
---|
187 | |
---|
188 | rtems_device_driver console_close( |
---|
189 | rtems_device_major_number major, |
---|
190 | rtems_device_minor_number minor, |
---|
191 | void * arg |
---|
192 | ) |
---|
193 | { |
---|
194 | #if 0 |
---|
195 | if ( console_fd ) |
---|
196 | close( console_fd ); |
---|
197 | #endif |
---|
198 | return RTEMS_SUCCESSFUL; |
---|
199 | } |
---|
200 | |
---|
201 | /* |
---|
202 | * read bytes from the serial port. We only have stdin. |
---|
203 | */ |
---|
204 | |
---|
205 | rtems_device_driver console_read( |
---|
206 | rtems_device_major_number major, |
---|
207 | rtems_device_minor_number minor, |
---|
208 | void * arg |
---|
209 | ) |
---|
210 | { |
---|
211 | rtems_libio_rw_args_t *rw_args; |
---|
212 | char *buffer; |
---|
213 | int maximum; |
---|
214 | int count = 0; |
---|
215 | |
---|
216 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
217 | |
---|
218 | buffer = rw_args->buffer; |
---|
219 | maximum = rw_args->count; |
---|
220 | |
---|
221 | for (count = 0; count < maximum; count++) { |
---|
222 | buffer[ count ] = inbyte(); |
---|
223 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
224 | buffer[ count++ ] = '\n'; |
---|
225 | break; |
---|
226 | } |
---|
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 | char *buffer; |
---|
247 | |
---|
248 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
249 | |
---|
250 | buffer = rw_args->buffer; |
---|
251 | maximum = rw_args->count; |
---|
252 | |
---|
253 | for (count = 0; count < maximum; count++) { |
---|
254 | if ( buffer[ count ] == '\n') { |
---|
255 | outbyte('\r'); |
---|
256 | } |
---|
257 | outbyte( buffer[ count ] ); |
---|
258 | } |
---|
259 | |
---|
260 | rw_args->bytes_moved = maximum; |
---|
261 | return 0; |
---|
262 | } |
---|
263 | |
---|
264 | /* |
---|
265 | * IO Control entry point |
---|
266 | */ |
---|
267 | |
---|
268 | rtems_device_driver console_control( |
---|
269 | rtems_device_major_number major, |
---|
270 | rtems_device_minor_number minor, |
---|
271 | void * arg |
---|
272 | ) |
---|
273 | { |
---|
274 | return RTEMS_SUCCESSFUL; |
---|
275 | } |
---|