1 | /* |
---|
2 | * Initialize the MC68302 SCC2 for console IO board support 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.OARcorp.com/rtems/license.html. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #define GEN68302_INIT |
---|
15 | |
---|
16 | #include <debugport.h> |
---|
17 | #include <bsp.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | |
---|
20 | /* console_initialize |
---|
21 | * |
---|
22 | * This routine initializes the console IO driver. |
---|
23 | * |
---|
24 | * Input parameters: NONE |
---|
25 | * |
---|
26 | * Output parameters: NONE |
---|
27 | * |
---|
28 | * Return values: |
---|
29 | */ |
---|
30 | |
---|
31 | rtems_device_driver console_initialize( |
---|
32 | rtems_device_major_number major, |
---|
33 | rtems_device_minor_number minor, |
---|
34 | void *arg |
---|
35 | ) |
---|
36 | { |
---|
37 | rtems_status_code status; |
---|
38 | |
---|
39 | /* debug_port_initialise(); */ |
---|
40 | |
---|
41 | status = rtems_io_register_name( |
---|
42 | "/dev/console", |
---|
43 | major, |
---|
44 | (rtems_device_minor_number) 0 |
---|
45 | ); |
---|
46 | |
---|
47 | if (status != RTEMS_SUCCESSFUL) |
---|
48 | rtems_fatal_error_occurred(status); |
---|
49 | |
---|
50 | return RTEMS_SUCCESSFUL; |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | /* is_character_ready |
---|
55 | * |
---|
56 | * Check to see if a character is available on the MC68302's SCC2. If so, |
---|
57 | * then return a TRUE (along with the character). Otherwise return FALSE. |
---|
58 | * |
---|
59 | * Input parameters: pointer to location in which to return character |
---|
60 | * |
---|
61 | * Output parameters: character (if available) |
---|
62 | * |
---|
63 | * Return values: TRUE - character available |
---|
64 | * FALSE - no character available |
---|
65 | */ |
---|
66 | |
---|
67 | rtems_boolean is_character_ready( |
---|
68 | char *ch /* -> character */ |
---|
69 | ) |
---|
70 | { |
---|
71 | if (debug_port_status(0)) |
---|
72 | { |
---|
73 | *ch = debug_port_in(); |
---|
74 | return TRUE; |
---|
75 | } |
---|
76 | return FALSE; |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | /* inbyte |
---|
81 | * |
---|
82 | * Receive a character from the MC68302's SCC2. |
---|
83 | * |
---|
84 | * Input parameters: NONE |
---|
85 | * |
---|
86 | * Output parameters: NONE |
---|
87 | * |
---|
88 | * Return values: character read |
---|
89 | */ |
---|
90 | |
---|
91 | char inbyte( void ) |
---|
92 | { |
---|
93 | char ch; |
---|
94 | |
---|
95 | while (!is_character_ready(&ch)); |
---|
96 | |
---|
97 | return ch; |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | /* outbyte |
---|
102 | * |
---|
103 | * Transmit a character out on the MC68302's SCC2. |
---|
104 | * It may support XON/XOFF flow control. |
---|
105 | * |
---|
106 | * Input parameters: |
---|
107 | * ch - character to be transmitted |
---|
108 | * |
---|
109 | * Output parameters: NONE |
---|
110 | */ |
---|
111 | |
---|
112 | void outbyte( |
---|
113 | char ch |
---|
114 | ) |
---|
115 | { |
---|
116 | debug_port_out(ch); |
---|
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 | } |
---|