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