1 | /* |
---|
2 | * This file contains the template for a console IO package. |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1999. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #define NO_BSP_INIT |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <rtems/libio.h> |
---|
18 | |
---|
19 | /* console_initialize |
---|
20 | * |
---|
21 | * This routine initializes the console IO driver. |
---|
22 | * |
---|
23 | * Input parameters: NONE |
---|
24 | * |
---|
25 | * Output parameters: NONE |
---|
26 | * |
---|
27 | * Return values: |
---|
28 | */ |
---|
29 | |
---|
30 | rtems_device_driver console_initialize( |
---|
31 | rtems_device_major_number major, |
---|
32 | rtems_device_minor_number minor, |
---|
33 | void *arg |
---|
34 | ) |
---|
35 | { |
---|
36 | rtems_status_code status; |
---|
37 | |
---|
38 | status = rtems_io_register_name( |
---|
39 | "/dev/console", |
---|
40 | major, |
---|
41 | (rtems_device_minor_number) 0 |
---|
42 | ); |
---|
43 | |
---|
44 | if (status != RTEMS_SUCCESSFUL) |
---|
45 | rtems_fatal_error_occurred(status); |
---|
46 | |
---|
47 | return RTEMS_SUCCESSFUL; |
---|
48 | } |
---|
49 | |
---|
50 | /* is_character_ready |
---|
51 | * |
---|
52 | * This routine returns TRUE if a character is available. |
---|
53 | * |
---|
54 | * Input parameters: NONE |
---|
55 | * |
---|
56 | * Output parameters: NONE |
---|
57 | * |
---|
58 | * Return values: |
---|
59 | */ |
---|
60 | |
---|
61 | bool is_character_ready( |
---|
62 | char *ch |
---|
63 | ) |
---|
64 | { |
---|
65 | *ch = '\0'; /* return NULL for no particular reason */ |
---|
66 | return true; |
---|
67 | } |
---|
68 | |
---|
69 | /* inbyte |
---|
70 | * |
---|
71 | * This routine reads a character from the SOURCE. |
---|
72 | * |
---|
73 | * Input parameters: NONE |
---|
74 | * |
---|
75 | * Output parameters: NONE |
---|
76 | * |
---|
77 | * Return values: |
---|
78 | * character read from SOURCE |
---|
79 | */ |
---|
80 | |
---|
81 | char inbyte( void ) |
---|
82 | { |
---|
83 | /* |
---|
84 | * If polling, wait until a character is available. |
---|
85 | */ |
---|
86 | |
---|
87 | return '\0'; |
---|
88 | } |
---|
89 | |
---|
90 | /* outbyte |
---|
91 | * |
---|
92 | * This routine transmits a character out the SOURCE. It may support |
---|
93 | * XON/XOFF flow control. |
---|
94 | * |
---|
95 | * Input parameters: |
---|
96 | * ch - character to be transmitted |
---|
97 | * |
---|
98 | * Output parameters: NONE |
---|
99 | */ |
---|
100 | |
---|
101 | void outbyte( |
---|
102 | char ch |
---|
103 | ) |
---|
104 | { |
---|
105 | /* |
---|
106 | * If polling, wait for the transmitter to be ready. |
---|
107 | * Check for flow control requests and process. |
---|
108 | * Then output the character. |
---|
109 | */ |
---|
110 | |
---|
111 | /* |
---|
112 | * Carriage Return/New line translation. |
---|
113 | */ |
---|
114 | |
---|
115 | if ( ch == '\n' ) |
---|
116 | outbyte( '\r' ); |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | * Open entry point |
---|
121 | */ |
---|
122 | |
---|
123 | rtems_device_driver console_open( |
---|
124 | rtems_device_major_number major, |
---|
125 | rtems_device_minor_number minor, |
---|
126 | void * arg |
---|
127 | ) |
---|
128 | { |
---|
129 | return RTEMS_SUCCESSFUL; |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | * Close entry point |
---|
134 | */ |
---|
135 | |
---|
136 | rtems_device_driver console_close( |
---|
137 | rtems_device_major_number major, |
---|
138 | rtems_device_minor_number minor, |
---|
139 | void * arg |
---|
140 | ) |
---|
141 | { |
---|
142 | return RTEMS_SUCCESSFUL; |
---|
143 | } |
---|
144 | |
---|
145 | /* |
---|
146 | * read bytes from the serial port. We only have stdin. |
---|
147 | */ |
---|
148 | |
---|
149 | rtems_device_driver console_read( |
---|
150 | rtems_device_major_number major, |
---|
151 | rtems_device_minor_number minor, |
---|
152 | void * arg |
---|
153 | ) |
---|
154 | { |
---|
155 | rtems_libio_rw_args_t *rw_args; |
---|
156 | char *buffer; |
---|
157 | int maximum; |
---|
158 | int count = 0; |
---|
159 | |
---|
160 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
161 | |
---|
162 | buffer = rw_args->buffer; |
---|
163 | maximum = rw_args->count; |
---|
164 | |
---|
165 | for (count = 0; count < maximum; count++) { |
---|
166 | buffer[ count ] = inbyte(); |
---|
167 | if (buffer[ count ] == '\n' || buffer[ count ] == '\r') { |
---|
168 | buffer[ count++ ] = '\n'; |
---|
169 | break; |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | rw_args->bytes_moved = count; |
---|
174 | return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED; |
---|
175 | } |
---|
176 | |
---|
177 | /* |
---|
178 | * write bytes to the serial port. Stdout and stderr are the same. |
---|
179 | */ |
---|
180 | |
---|
181 | rtems_device_driver console_write( |
---|
182 | rtems_device_major_number major, |
---|
183 | rtems_device_minor_number minor, |
---|
184 | void * arg |
---|
185 | ) |
---|
186 | { |
---|
187 | int count; |
---|
188 | int maximum; |
---|
189 | rtems_libio_rw_args_t *rw_args; |
---|
190 | char *buffer; |
---|
191 | |
---|
192 | rw_args = (rtems_libio_rw_args_t *) arg; |
---|
193 | |
---|
194 | buffer = rw_args->buffer; |
---|
195 | maximum = rw_args->count; |
---|
196 | |
---|
197 | for (count = 0; count < maximum; count++) { |
---|
198 | if ( buffer[ count ] == '\n') { |
---|
199 | outbyte('\r'); |
---|
200 | } |
---|
201 | outbyte( buffer[ count ] ); |
---|
202 | } |
---|
203 | |
---|
204 | rw_args->bytes_moved = maximum; |
---|
205 | return 0; |
---|
206 | } |
---|
207 | |
---|
208 | /* |
---|
209 | * IO Control entry point |
---|
210 | */ |
---|
211 | |
---|
212 | rtems_device_driver console_control( |
---|
213 | rtems_device_major_number major, |
---|
214 | rtems_device_minor_number minor, |
---|
215 | void * arg |
---|
216 | ) |
---|
217 | { |
---|
218 | return RTEMS_SUCCESSFUL; |
---|
219 | } |
---|