1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic MPC83xx BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | This file has been adapted from the ep1a BSP to MPC83xx by | |
---|
5 | | Thomas Doerfler <Thomas.Doerfler@embedded-brains.de> | |
---|
6 | | Copyright (c) 2007 | |
---|
7 | | Embedded Brains GmbH | |
---|
8 | | Obere Lagerstr. 30 | |
---|
9 | | D-82178 Puchheim | |
---|
10 | | Germany | |
---|
11 | | rtems@embedded-brains.de | |
---|
12 | | | |
---|
13 | | See the other copyright notice below for the original parts. | |
---|
14 | +-----------------------------------------------------------------+ |
---|
15 | | The license and distribution terms for this file may be | |
---|
16 | | found in the file LICENSE in this distribution or at | |
---|
17 | | | |
---|
18 | | http://www.rtems.com/license/LICENSE. | |
---|
19 | | | |
---|
20 | +-----------------------------------------------------------------+ |
---|
21 | | this file contains the console driver | |
---|
22 | \*===============================================================*/ |
---|
23 | /* derived from: */ |
---|
24 | /* |
---|
25 | * This file contains the TTY driver for the ep1a |
---|
26 | * |
---|
27 | * This driver uses the termios pseudo driver. |
---|
28 | * |
---|
29 | * COPYRIGHT (c) 1989-1999. |
---|
30 | * On-Line Applications Research Corporation (OAR). |
---|
31 | * |
---|
32 | * The license and distribution terms for this file may be |
---|
33 | * found in the file LICENSE in this distribution or at |
---|
34 | * http://www.rtems.com/license/LICENSE. |
---|
35 | * |
---|
36 | * $Id$ |
---|
37 | */ |
---|
38 | |
---|
39 | #include <bsp.h> |
---|
40 | #include <rtems/libio.h> |
---|
41 | #include <stdlib.h> |
---|
42 | #include <assert.h> |
---|
43 | #include <termios.h> |
---|
44 | |
---|
45 | #include "console.h" |
---|
46 | #include <rtems/bspIo.h> |
---|
47 | |
---|
48 | /* |
---|
49 | * Load configuration table |
---|
50 | */ |
---|
51 | #include "config.c" |
---|
52 | |
---|
53 | #define NUM_CONSOLE_PORTS (sizeof(Console_Port_Tbl)/sizeof(console_tbl)) |
---|
54 | |
---|
55 | console_data Console_Port_Data[NUM_CONSOLE_PORTS]; |
---|
56 | unsigned long Console_Port_Count; |
---|
57 | rtems_device_minor_number Console_Port_Minor; |
---|
58 | rtems_boolean Console_Is_Initialized = FALSE; |
---|
59 | /* PAGE |
---|
60 | * |
---|
61 | * console_open |
---|
62 | * |
---|
63 | * open a port as a termios console. |
---|
64 | * |
---|
65 | */ |
---|
66 | rtems_device_driver console_open( |
---|
67 | rtems_device_major_number major, |
---|
68 | rtems_device_minor_number minor, |
---|
69 | void * arg |
---|
70 | ) |
---|
71 | { |
---|
72 | rtems_status_code status; |
---|
73 | rtems_libio_open_close_args_t *args = arg; |
---|
74 | rtems_termios_callbacks Callbacks; |
---|
75 | console_fns *c; |
---|
76 | |
---|
77 | /* |
---|
78 | * Verify the port number is valid. |
---|
79 | */ |
---|
80 | if(minor>Console_Port_Count) |
---|
81 | { |
---|
82 | return RTEMS_INVALID_NUMBER; |
---|
83 | } |
---|
84 | |
---|
85 | /* |
---|
86 | * open the port as a termios console driver. |
---|
87 | */ |
---|
88 | c = Console_Port_Tbl[minor].pDeviceFns; |
---|
89 | Callbacks.firstOpen = c->deviceFirstOpen; |
---|
90 | Callbacks.lastClose = c->deviceLastClose; |
---|
91 | Callbacks.pollRead = c->deviceRead; |
---|
92 | Callbacks.write = c->deviceWrite; |
---|
93 | Callbacks.setAttributes = c->deviceSetAttributes; |
---|
94 | Callbacks.stopRemoteTx = |
---|
95 | Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx; |
---|
96 | Callbacks.startRemoteTx = |
---|
97 | Console_Port_Tbl[minor].pDeviceFlow->deviceStartRemoteTx; |
---|
98 | Callbacks.outputUsesInterrupts = c->deviceOutputUsesInterrupts; |
---|
99 | status = rtems_termios_open ( major, minor, arg, &Callbacks); |
---|
100 | Console_Port_Data[minor].termios_data = args->iop->data1; |
---|
101 | |
---|
102 | return status; |
---|
103 | } |
---|
104 | |
---|
105 | rtems_device_driver console_close( |
---|
106 | rtems_device_major_number major, |
---|
107 | rtems_device_minor_number minor, |
---|
108 | void * arg |
---|
109 | ) |
---|
110 | { |
---|
111 | rtems_libio_open_close_args_t *args = arg; |
---|
112 | |
---|
113 | if((args->iop->flags&LIBIO_FLAGS_READ) && |
---|
114 | Console_Port_Tbl[minor].pDeviceFlow && |
---|
115 | Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx) |
---|
116 | { |
---|
117 | Console_Port_Tbl[minor].pDeviceFlow->deviceStopRemoteTx(minor); |
---|
118 | } |
---|
119 | |
---|
120 | return rtems_termios_close (arg); |
---|
121 | } |
---|
122 | |
---|
123 | rtems_device_driver console_read( |
---|
124 | rtems_device_major_number major, |
---|
125 | rtems_device_minor_number minor, |
---|
126 | void * arg |
---|
127 | ) |
---|
128 | { |
---|
129 | return rtems_termios_read (arg); |
---|
130 | } |
---|
131 | |
---|
132 | rtems_device_driver console_write( |
---|
133 | rtems_device_major_number major, |
---|
134 | rtems_device_minor_number minor, |
---|
135 | void * arg |
---|
136 | ) |
---|
137 | { |
---|
138 | return rtems_termios_write (arg); |
---|
139 | } |
---|
140 | |
---|
141 | rtems_device_driver console_control( |
---|
142 | rtems_device_major_number major, |
---|
143 | rtems_device_minor_number minor, |
---|
144 | void * arg |
---|
145 | ) |
---|
146 | { |
---|
147 | return rtems_termios_ioctl (arg); |
---|
148 | } |
---|
149 | |
---|
150 | /* PAGE |
---|
151 | * |
---|
152 | * console_initialize |
---|
153 | * |
---|
154 | * Routine called to initialize the console device driver. |
---|
155 | */ |
---|
156 | rtems_device_driver console_initialize( |
---|
157 | rtems_device_major_number major, |
---|
158 | rtems_device_minor_number minor, |
---|
159 | void *arg |
---|
160 | ) |
---|
161 | { |
---|
162 | rtems_status_code status; |
---|
163 | |
---|
164 | /* |
---|
165 | * initialize the termio interface. |
---|
166 | */ |
---|
167 | rtems_termios_initialize(); |
---|
168 | |
---|
169 | Console_Port_Count=NUM_CONSOLE_PORTS; |
---|
170 | |
---|
171 | for(minor=0; |
---|
172 | minor<Console_Port_Count; |
---|
173 | minor++) |
---|
174 | { |
---|
175 | /* |
---|
176 | * First perform the configuration dependant probe, then the |
---|
177 | * device dependant probe |
---|
178 | */ |
---|
179 | if((!Console_Port_Tbl[minor].deviceProbe || |
---|
180 | Console_Port_Tbl[minor].deviceProbe(minor)) && |
---|
181 | Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) |
---|
182 | { |
---|
183 | /* |
---|
184 | * Use this device for the console |
---|
185 | */ |
---|
186 | break; |
---|
187 | } |
---|
188 | } |
---|
189 | if(minor==Console_Port_Count) |
---|
190 | { |
---|
191 | /* |
---|
192 | * Failed to find a working device |
---|
193 | */ |
---|
194 | rtems_fatal_error_occurred(RTEMS_IO_ERROR); |
---|
195 | } |
---|
196 | |
---|
197 | Console_Port_Minor=minor; |
---|
198 | |
---|
199 | /* |
---|
200 | * Register Device Names |
---|
201 | */ |
---|
202 | |
---|
203 | status = rtems_io_register_name("/dev/console", |
---|
204 | major, |
---|
205 | Console_Port_Minor ); |
---|
206 | if (status != RTEMS_SUCCESSFUL) |
---|
207 | { |
---|
208 | rtems_fatal_error_occurred(status); |
---|
209 | } |
---|
210 | if ( Console_Port_Tbl[Console_Port_Minor].pDeviceFns->deviceInitialize ) { |
---|
211 | Console_Port_Tbl[Console_Port_Minor] |
---|
212 | .pDeviceFns->deviceInitialize(Console_Port_Minor); |
---|
213 | Console_Is_Initialized = TRUE; |
---|
214 | } |
---|
215 | |
---|
216 | for(minor++;minor<Console_Port_Count;minor++) |
---|
217 | { |
---|
218 | /* |
---|
219 | * First perform the configuration dependant probe, then the |
---|
220 | * device dependant probe |
---|
221 | */ |
---|
222 | if((!Console_Port_Tbl[minor].deviceProbe || |
---|
223 | Console_Port_Tbl[minor].deviceProbe(minor)) && |
---|
224 | Console_Port_Tbl[minor].pDeviceFns->deviceProbe(minor)) |
---|
225 | { |
---|
226 | status = rtems_io_register_name( |
---|
227 | Console_Port_Tbl[minor].sDeviceName, |
---|
228 | major, |
---|
229 | minor ); |
---|
230 | if (status != RTEMS_SUCCESSFUL) |
---|
231 | { |
---|
232 | rtems_fatal_error_occurred(status); |
---|
233 | } |
---|
234 | |
---|
235 | /* |
---|
236 | * Initialize the hardware device. |
---|
237 | */ |
---|
238 | if ( Console_Port_Tbl[minor].pDeviceFns->deviceInitialize ) |
---|
239 | Console_Port_Tbl[minor].pDeviceFns->deviceInitialize( minor); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | return RTEMS_SUCCESSFUL; |
---|
244 | } |
---|
245 | |
---|
246 | /* PAGE |
---|
247 | * |
---|
248 | * DEBUG_puts |
---|
249 | * |
---|
250 | * This should be safe in the event of an error. It attempts to ensure |
---|
251 | * that no TX empty interrupts occur while it is doing polled IO. Then |
---|
252 | * it restores the state of that external interrupt. |
---|
253 | * |
---|
254 | * Input parameters: |
---|
255 | * string - pointer to debug output string |
---|
256 | * |
---|
257 | * Output parameters: NONE |
---|
258 | * |
---|
259 | * Return values: NONE |
---|
260 | */ |
---|
261 | |
---|
262 | void DEBUG_puts( |
---|
263 | char *string |
---|
264 | ) |
---|
265 | { |
---|
266 | char *s; |
---|
267 | uint32_t Irql; |
---|
268 | |
---|
269 | rtems_interrupt_disable(Irql); |
---|
270 | |
---|
271 | for ( s = string ; *s ; s++ ) |
---|
272 | { |
---|
273 | Console_Port_Tbl[Console_Port_Minor].pDeviceFns-> |
---|
274 | deviceWritePolled(Console_Port_Minor, *s); |
---|
275 | } |
---|
276 | |
---|
277 | rtems_interrupt_enable(Irql); |
---|
278 | } |
---|
279 | |
---|
280 | /* PAGE |
---|
281 | * |
---|
282 | * DEBUG_puth |
---|
283 | * |
---|
284 | * This should be safe in the event of an error. It attempts to ensure |
---|
285 | * that no TX empty interrupts occur while it is doing polled IO. Then |
---|
286 | * it restores the state of that external interrupt. |
---|
287 | * |
---|
288 | * Input parameters: |
---|
289 | * ulHexNum - value to display |
---|
290 | * |
---|
291 | * Output parameters: NONE |
---|
292 | * |
---|
293 | * Return values: NONE |
---|
294 | */ |
---|
295 | void |
---|
296 | DEBUG_puth( |
---|
297 | uint32_t ulHexNum |
---|
298 | ) |
---|
299 | { |
---|
300 | unsigned long i,d; |
---|
301 | uint32_t Irql; |
---|
302 | |
---|
303 | rtems_interrupt_disable(Irql); |
---|
304 | |
---|
305 | Console_Port_Tbl[Console_Port_Minor].pDeviceFns-> |
---|
306 | deviceWritePolled(Console_Port_Minor, '0'); |
---|
307 | Console_Port_Tbl[Console_Port_Minor].pDeviceFns-> |
---|
308 | deviceWritePolled(Console_Port_Minor, 'x'); |
---|
309 | |
---|
310 | for(i=32;i;) |
---|
311 | { |
---|
312 | i-=4; |
---|
313 | d=(ulHexNum>>i)&0xf; |
---|
314 | Console_Port_Tbl[Console_Port_Minor].pDeviceFns-> |
---|
315 | deviceWritePolled(Console_Port_Minor, |
---|
316 | (d<=9) ? d+'0' : d+'a'-0xa); |
---|
317 | } |
---|
318 | |
---|
319 | rtems_interrupt_enable(Irql); |
---|
320 | } |
---|
321 | |
---|
322 | |
---|
323 | /* const char arg to be compatible with BSP_output_char decl. */ |
---|
324 | void |
---|
325 | debug_putc_onlcr(const char c) |
---|
326 | { |
---|
327 | uint32_t Irql; |
---|
328 | if (Console_Is_Initialized) { |
---|
329 | rtems_interrupt_disable(Irql); |
---|
330 | |
---|
331 | Console_Port_Tbl[Console_Port_Minor].pDeviceFns-> |
---|
332 | deviceWritePolled(Console_Port_Minor,c); |
---|
333 | |
---|
334 | rtems_interrupt_enable(Irql); |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | BSP_output_char_function_type BSP_output_char = debug_putc_onlcr; |
---|
339 | /* const char arg to be compatible with BSP_output_char decl. */ |
---|
340 | |
---|