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-1999. |
---|
22 | * On-Line Applications Research Corporation (OAR). |
---|
23 | * |
---|
24 | * The license and distribution terms for this file may be |
---|
25 | * found in the file LICENSE in this distribution or at |
---|
26 | * http://www.rtems.org/license/LICENSE. |
---|
27 | */ |
---|
28 | |
---|
29 | #include <bsp.h> |
---|
30 | #include <rtems/libio.h> |
---|
31 | #include <ctype.h> |
---|
32 | |
---|
33 | /* PMON entry points */ |
---|
34 | int mon_read(int fd, char *buf, int cnt); /* stdin is fd=0 */ |
---|
35 | int mon_write(int fd, char *buf, int cnt); /* stdout is fd=1 */ |
---|
36 | |
---|
37 | /* console_initialize |
---|
38 | * |
---|
39 | * This routine initializes the console IO driver. |
---|
40 | * |
---|
41 | * Input parameters: NONE |
---|
42 | * |
---|
43 | * Output parameters: NONE |
---|
44 | * |
---|
45 | * Return values: |
---|
46 | */ |
---|
47 | |
---|
48 | rtems_device_driver console_initialize( |
---|
49 | rtems_device_major_number major, |
---|
50 | rtems_device_minor_number minor, |
---|
51 | void *arg |
---|
52 | ) |
---|
53 | { |
---|
54 | rtems_status_code status; |
---|
55 | |
---|
56 | status = rtems_io_register_name( |
---|
57 | "/dev/console", |
---|
58 | major, |
---|
59 | (rtems_device_minor_number) 0 |
---|
60 | ); |
---|
61 | |
---|
62 | if (status != RTEMS_SUCCESSFUL) |
---|
63 | rtems_fatal_error_occurred(status); |
---|
64 | |
---|
65 | return RTEMS_SUCCESSFUL; |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | /* is_character_ready |
---|
70 | * |
---|
71 | * This routine returns TRUE if a character is available. |
---|
72 | * |
---|
73 | * Input parameters: NONE |
---|
74 | * |
---|
75 | * Output parameters: NONE |
---|
76 | * |
---|
77 | * Return values: |
---|
78 | */ |
---|
79 | |
---|
80 | bool is_character_ready( |
---|
81 | char *ch |
---|
82 | ) |
---|
83 | { |
---|
84 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
85 | return true; |
---|
86 | } |
---|
87 | |
---|
88 | /* inbyte |
---|
89 | * |
---|
90 | * This routine reads a character from the SOURCE. |
---|
91 | * |
---|
92 | * Input parameters: NONE |
---|
93 | * |
---|
94 | * Output parameters: NONE |
---|
95 | * |
---|
96 | * Return values: |
---|
97 | * character read from SOURCE |
---|
98 | */ |
---|
99 | |
---|
100 | char inbyte( void ) |
---|
101 | { |
---|
102 | char buf[10]; |
---|
103 | /* |
---|
104 | * If polling, wait until a character is available. |
---|
105 | */ |
---|
106 | |
---|
107 | mon_read(0, buf, 1); /* stdin is fd=0, read 1 byte */ |
---|
108 | |
---|
109 | return (buf[0]); |
---|
110 | } |
---|
111 | |
---|
112 | /* outbyte |
---|
113 | * |
---|
114 | * This routine transmits a character out the SOURCE. It may support |
---|
115 | * XON/XOFF flow control. |
---|
116 | * |
---|
117 | * Input parameters: |
---|
118 | * ch - character to be transmitted |
---|
119 | * |
---|
120 | * Output parameters: NONE |
---|
121 | */ |
---|
122 | |
---|
123 | void outbyte( |
---|
124 | char ch |
---|
125 | ) |
---|
126 | { |
---|
127 | char buf[10]; |
---|
128 | /* |
---|
129 | * If polling, wait for the transmitter to be ready. |
---|
130 | * Check for flow control requests and process. |
---|
131 | * Then output the character. |
---|
132 | */ |
---|
133 | buf[0] = ch; |
---|
134 | |
---|
135 | mon_write( 1, buf, 1 ); /* stdout is fd=1, write 1 byte */ |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | #if 0 |
---|
140 | static int console_fd = -1; |
---|
141 | #endif |
---|
142 | |
---|
143 | /* |
---|
144 | * Open entry point |
---|
145 | */ |
---|
146 | |
---|
147 | rtems_device_driver console_open( |
---|
148 | rtems_device_major_number major, |
---|
149 | rtems_device_minor_number minor, |
---|
150 | void * arg |
---|
151 | ) |
---|
152 | { |
---|
153 | #if 0 |
---|
154 | int console_fd = open("tty0", 2); /* open for read/write */ |
---|
155 | #endif |
---|
156 | return RTEMS_SUCCESSFUL; |
---|
157 | } |
---|
158 | |
---|
159 | /* |
---|
160 | * Close entry point |
---|
161 | */ |
---|
162 | |
---|
163 | rtems_device_driver console_close( |
---|
164 | rtems_device_major_number major, |
---|
165 | rtems_device_minor_number minor, |
---|
166 | void * arg |
---|
167 | ) |
---|
168 | { |
---|
169 | #if 0 |
---|
170 | if ( console_fd ) |
---|
171 | close( console_fd ); |
---|
172 | #endif |
---|
173 | return RTEMS_SUCCESSFUL; |
---|
174 | } |
---|
175 | |
---|
176 | /* |
---|
177 | * read bytes from the serial port. We only have stdin. |
---|
178 | */ |
---|
179 | |
---|
180 | rtems_device_driver console_read( |
---|
181 | rtems_device_major_number major, |
---|
182 | rtems_device_minor_number minor, |
---|
183 | void * arg |
---|
184 | ) |
---|
185 | { |
---|
186 | rtems_libio_rw_args_t *rw_args; |
---|
187 | char *buffer; |
---|
188 | int maximum; |
---|
189 | int count = 0; |
---|
190 | |
---|
191 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
192 | |
---|
193 | buffer = rw_args->buffer; |
---|
194 | maximum = rw_args->count; |
---|
195 | |
---|
196 | for (count = 0; count < maximum; count++) { |
---|
197 | buffer[ count ] = inbyte(); |
---|
198 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
199 | buffer[ count++ ] = '\n'; |
---|
200 | break; |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | rw_args->bytes_moved = count; |
---|
205 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
206 | } |
---|
207 | |
---|
208 | /* |
---|
209 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
210 | */ |
---|
211 | |
---|
212 | rtems_device_driver console_write( |
---|
213 | rtems_device_major_number major, |
---|
214 | rtems_device_minor_number minor, |
---|
215 | void * arg |
---|
216 | ) |
---|
217 | { |
---|
218 | int count; |
---|
219 | int maximum; |
---|
220 | rtems_libio_rw_args_t *rw_args; |
---|
221 | char *buffer; |
---|
222 | |
---|
223 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
224 | |
---|
225 | buffer = rw_args->buffer; |
---|
226 | maximum = rw_args->count; |
---|
227 | |
---|
228 | for (count = 0; count < maximum; count++) { |
---|
229 | if ( buffer[ count ] == '\n') { |
---|
230 | outbyte('\r'); |
---|
231 | } |
---|
232 | outbyte( buffer[ count ] ); |
---|
233 | } |
---|
234 | |
---|
235 | rw_args->bytes_moved = maximum; |
---|
236 | return 0; |
---|
237 | } |
---|
238 | |
---|
239 | /* |
---|
240 | * IO Control entry point |
---|
241 | */ |
---|
242 | |
---|
243 | rtems_device_driver console_control( |
---|
244 | rtems_device_major_number major, |
---|
245 | rtems_device_minor_number minor, |
---|
246 | void * arg |
---|
247 | ) |
---|
248 | { |
---|
249 | return RTEMS_SUCCESSFUL; |
---|
250 | } |
---|
251 | |
---|
252 | #include <rtems/bspIo.h> |
---|
253 | |
---|
254 | void hurricane_output_char(char c) { outbyte( c ); } |
---|
255 | |
---|
256 | BSP_output_char_function_type BSP_output_char = hurricane_output_char; |
---|
257 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|
258 | |
---|