1 | /* |
---|
2 | * This file contains the RBTX4938 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.com/license/LICENSE. |
---|
27 | * |
---|
28 | * $Id$ |
---|
29 | */ |
---|
30 | |
---|
31 | |
---|
32 | /* |
---|
33 | * Rather than deleting this, it is commented out to (hopefully) help |
---|
34 | * the submitter send updates. |
---|
35 | * |
---|
36 | * static char _sccsid[] = "@(#)console.c 08/20/96 1.6\n"; |
---|
37 | */ |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | #include <bsp.h> |
---|
42 | #include <rtems/libio.h> |
---|
43 | #include <ctype.h> |
---|
44 | |
---|
45 | #include "yamon_api.h" |
---|
46 | |
---|
47 | /* PMON entry points */ |
---|
48 | int mon_read(int fd, char *buf, int cnt); /* stdin is fd=0 */ |
---|
49 | int mon_write(int fd, char *buf, int cnt); /* stdout is fd=1 */ |
---|
50 | |
---|
51 | |
---|
52 | /* console_initialize |
---|
53 | * |
---|
54 | * This routine initializes the console IO driver. |
---|
55 | * |
---|
56 | * Input parameters: NONE |
---|
57 | * |
---|
58 | * Output parameters: NONE |
---|
59 | * |
---|
60 | * Return values: |
---|
61 | */ |
---|
62 | |
---|
63 | rtems_device_driver console_initialize( |
---|
64 | rtems_device_major_number major, |
---|
65 | rtems_device_minor_number minor, |
---|
66 | void *arg |
---|
67 | ) |
---|
68 | { |
---|
69 | rtems_status_code status; |
---|
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 | bool 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( void ) |
---|
116 | { |
---|
117 | char buf[10]; |
---|
118 | /* |
---|
119 | * If polling, wait until a character is available. |
---|
120 | */ |
---|
121 | |
---|
122 | while (YAMON_FUNC_GETCHAR(buf) == YAMON_FALSE); |
---|
123 | |
---|
124 | /* mon_read(0, buf, 1); */ /* stdin is fd=0, read 1 byte */ |
---|
125 | |
---|
126 | return (buf[0]); |
---|
127 | } |
---|
128 | |
---|
129 | /* outbyte |
---|
130 | * |
---|
131 | * This routine transmits a character out the SOURCE. It may support |
---|
132 | * XON/XOFF flow control. |
---|
133 | * |
---|
134 | * Input parameters: |
---|
135 | * ch - character to be transmitted |
---|
136 | * |
---|
137 | * Output parameters: NONE |
---|
138 | */ |
---|
139 | |
---|
140 | void outbyte( |
---|
141 | char ch |
---|
142 | ) |
---|
143 | { |
---|
144 | char buf[10]; |
---|
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 | buf[0] = ch; |
---|
151 | |
---|
152 | YAMON_FUNC_PRINT_COUNT(buf,1); |
---|
153 | |
---|
154 | /* mon_write( 1, buf, 1 ); */ /* stdout is fd=1, write 1 byte */ |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | #if 0 |
---|
159 | static int console_fd = -1; |
---|
160 | #endif |
---|
161 | |
---|
162 | /* |
---|
163 | * Open entry point |
---|
164 | */ |
---|
165 | |
---|
166 | rtems_device_driver console_open( |
---|
167 | rtems_device_major_number major, |
---|
168 | rtems_device_minor_number minor, |
---|
169 | void * arg |
---|
170 | ) |
---|
171 | { |
---|
172 | #if 0 |
---|
173 | int console_fd = open("tty0", 2); /* open for read/write */ |
---|
174 | #endif |
---|
175 | return RTEMS_SUCCESSFUL; |
---|
176 | } |
---|
177 | |
---|
178 | /* |
---|
179 | * Close entry point |
---|
180 | */ |
---|
181 | |
---|
182 | rtems_device_driver console_close( |
---|
183 | rtems_device_major_number major, |
---|
184 | rtems_device_minor_number minor, |
---|
185 | void * arg |
---|
186 | ) |
---|
187 | { |
---|
188 | #if 0 |
---|
189 | if ( console_fd ) |
---|
190 | close( console_fd ); |
---|
191 | #endif |
---|
192 | return RTEMS_SUCCESSFUL; |
---|
193 | } |
---|
194 | |
---|
195 | /* |
---|
196 | * read bytes from the serial port. We only have stdin. |
---|
197 | */ |
---|
198 | |
---|
199 | rtems_device_driver console_read( |
---|
200 | rtems_device_major_number major, |
---|
201 | rtems_device_minor_number minor, |
---|
202 | void * arg |
---|
203 | ) |
---|
204 | { |
---|
205 | rtems_libio_rw_args_t *rw_args; |
---|
206 | char *buffer; |
---|
207 | int maximum; |
---|
208 | int count = 0; |
---|
209 | |
---|
210 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
211 | |
---|
212 | buffer = rw_args->buffer; |
---|
213 | maximum = rw_args->count; |
---|
214 | |
---|
215 | for (count = 0; count < maximum; count++) { |
---|
216 | buffer[ count ] = inbyte(); |
---|
217 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
218 | buffer[ count++ ] = '\n'; |
---|
219 | break; |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | rw_args->bytes_moved = count; |
---|
224 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
225 | } |
---|
226 | |
---|
227 | /* |
---|
228 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
229 | */ |
---|
230 | |
---|
231 | rtems_device_driver console_write( |
---|
232 | rtems_device_major_number major, |
---|
233 | rtems_device_minor_number minor, |
---|
234 | void * arg |
---|
235 | ) |
---|
236 | { |
---|
237 | int count; |
---|
238 | int maximum; |
---|
239 | rtems_libio_rw_args_t *rw_args; |
---|
240 | char *buffer; |
---|
241 | |
---|
242 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
243 | |
---|
244 | buffer = rw_args->buffer; |
---|
245 | maximum = rw_args->count; |
---|
246 | |
---|
247 | for (count = 0; count < maximum; count++) { |
---|
248 | if ( buffer[ count ] == '\n') { |
---|
249 | outbyte('\r'); |
---|
250 | } |
---|
251 | outbyte( buffer[ count ] ); |
---|
252 | } |
---|
253 | |
---|
254 | rw_args->bytes_moved = maximum; |
---|
255 | return 0; |
---|
256 | } |
---|
257 | |
---|
258 | /* |
---|
259 | * IO Control entry point |
---|
260 | */ |
---|
261 | |
---|
262 | rtems_device_driver console_control( |
---|
263 | rtems_device_major_number major, |
---|
264 | rtems_device_minor_number minor, |
---|
265 | void * arg |
---|
266 | ) |
---|
267 | { |
---|
268 | return RTEMS_SUCCESSFUL; |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | #include <rtems/bspIo.h> |
---|
273 | |
---|
274 | void RBTX4938_output_char(char c) { outbyte( c ); } |
---|
275 | |
---|
276 | BSP_output_char_function_type BSP_output_char = RBTX4938_output_char; |
---|
277 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|
278 | |
---|