1 | /* |
---|
2 | * This file contains the termios TTY driver for the Motorola MC68681. |
---|
3 | * |
---|
4 | * This part is available from a number of secondary sources. |
---|
5 | * In particular, we know about the following: |
---|
6 | * |
---|
7 | * + Exar 88c681 and 68c681 |
---|
8 | * |
---|
9 | * COPYRIGHT (c) 1989-1998. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * Copyright assigned to U.S. Government, 1994. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.OARcorp.com/rtems/license.html. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #include <rtems.h> |
---|
21 | #include <rtems/libio.h> |
---|
22 | #include <stdlib.h> |
---|
23 | |
---|
24 | #include <libchip/serial.h> |
---|
25 | #include <libchip/mc68681.h> |
---|
26 | #include "sersupp.h" |
---|
27 | #include "mc68681_p.h" |
---|
28 | |
---|
29 | /* |
---|
30 | * Flow control is only supported when using interrupts |
---|
31 | */ |
---|
32 | |
---|
33 | console_fns mc68681_fns = |
---|
34 | { |
---|
35 | libchip_serial_default_probe, /* deviceProbe */ |
---|
36 | mc68681_open, /* deviceFirstOpen */ |
---|
37 | NULL, /* deviceLastClose */ |
---|
38 | NULL, /* deviceRead */ |
---|
39 | mc68681_write_support_int, /* deviceWrite */ |
---|
40 | mc68681_initialize_interrupts, /* deviceInitialize */ |
---|
41 | mc68681_write_polled, /* deviceWritePolled */ |
---|
42 | mc68681_set_attributes, /* deviceSetAttributes */ |
---|
43 | TRUE /* deviceOutputUsesInterrupts */ |
---|
44 | }; |
---|
45 | |
---|
46 | console_fns mc68681_fns_polled = |
---|
47 | { |
---|
48 | libchip_serial_default_probe, /* deviceProbe */ |
---|
49 | mc68681_open, /* deviceFirstOpen */ |
---|
50 | mc68681_close, /* deviceLastClose */ |
---|
51 | mc68681_inbyte_nonblocking_polled, /* deviceRead */ |
---|
52 | mc68681_write_support_polled, /* deviceWrite */ |
---|
53 | mc68681_init, /* deviceInitialize */ |
---|
54 | mc68681_write_polled, /* deviceWritePolled */ |
---|
55 | mc68681_set_attributes, /* deviceSetAttributes */ |
---|
56 | FALSE, /* deviceOutputUsesInterrupts */ |
---|
57 | }; |
---|
58 | |
---|
59 | extern void set_vector( rtems_isr_entry, rtems_vector_number, int ); |
---|
60 | |
---|
61 | /* |
---|
62 | * Console Device Driver Entry Points |
---|
63 | */ |
---|
64 | |
---|
65 | /* |
---|
66 | * mc68681_baud_rate |
---|
67 | * |
---|
68 | * This routine returns the proper ACR bit and baud rate field values |
---|
69 | * based on the requested baud rate. The baud rate set to be used |
---|
70 | * must be configured by the user. |
---|
71 | */ |
---|
72 | |
---|
73 | MC68681_STATIC int mc68681_baud_rate( |
---|
74 | int minor, |
---|
75 | int baud, |
---|
76 | unsigned int *baud_mask_p, |
---|
77 | unsigned int *acr_bit_p, |
---|
78 | unsigned int *command |
---|
79 | ); |
---|
80 | |
---|
81 | /* |
---|
82 | * mc68681_set_attributes |
---|
83 | * |
---|
84 | * This function sets the DUART channel to reflect the requested termios |
---|
85 | * port settings. |
---|
86 | */ |
---|
87 | |
---|
88 | MC68681_STATIC int mc68681_set_attributes( |
---|
89 | int minor, |
---|
90 | const struct termios *t |
---|
91 | ) |
---|
92 | { |
---|
93 | unsigned32 pMC68681_port; |
---|
94 | unsigned32 pMC68681; |
---|
95 | unsigned int mode1; |
---|
96 | unsigned int mode2; |
---|
97 | unsigned int baud_mask; |
---|
98 | unsigned int acr_bit; |
---|
99 | unsigned int cmd; |
---|
100 | setRegister_f setReg; |
---|
101 | rtems_interrupt_level Irql; |
---|
102 | |
---|
103 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
104 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
105 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
106 | |
---|
107 | /* |
---|
108 | * Set the baud rate |
---|
109 | */ |
---|
110 | |
---|
111 | if (mc68681_baud_rate( minor, t->c_cflag, &baud_mask, &acr_bit, &cmd ) == -1) |
---|
112 | return -1; |
---|
113 | |
---|
114 | baud_mask |= baud_mask << 4; |
---|
115 | acr_bit <<= 7; |
---|
116 | |
---|
117 | /* |
---|
118 | * Parity |
---|
119 | */ |
---|
120 | |
---|
121 | mode1 = 0; |
---|
122 | mode2 = 0; |
---|
123 | |
---|
124 | if (t->c_cflag & PARENB) { |
---|
125 | if (t->c_cflag & PARODD) |
---|
126 | mode1 |= 0x04; |
---|
127 | else |
---|
128 | mode1 |= 0x04; |
---|
129 | } else { |
---|
130 | mode1 |= 0x10; |
---|
131 | } |
---|
132 | |
---|
133 | /* |
---|
134 | * Character Size |
---|
135 | */ |
---|
136 | |
---|
137 | if (t->c_cflag & CSIZE) { |
---|
138 | switch (t->c_cflag & CSIZE) { |
---|
139 | case CS5: break; |
---|
140 | case CS6: mode1 |= 0x01; break; |
---|
141 | case CS7: mode1 |= 0x02; break; |
---|
142 | case CS8: mode1 |= 0x03; break; |
---|
143 | } |
---|
144 | } else { |
---|
145 | mode1 |= 0x03; /* default to 9600,8,N,1 */ |
---|
146 | } |
---|
147 | |
---|
148 | /* |
---|
149 | * Stop Bits |
---|
150 | */ |
---|
151 | |
---|
152 | if (t->c_cflag & CSTOPB) { |
---|
153 | mode2 |= 0x07; /* 2 stop bits */ |
---|
154 | } else { |
---|
155 | if ((t->c_cflag & CSIZE) == CS5) /* CS5 and 2 stop bits not supported */ |
---|
156 | return -1; |
---|
157 | mode2 |= 0x0F; /* 1 stop bit */ |
---|
158 | } |
---|
159 | |
---|
160 | rtems_interrupt_disable(Irql); |
---|
161 | (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr_bit ); |
---|
162 | (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud_mask ); |
---|
163 | if ( cmd ) { |
---|
164 | (*setReg)( pMC68681_port, MC68681_COMMAND, cmd ); /* RX */ |
---|
165 | (*setReg)( pMC68681_port, MC68681_COMMAND, cmd | 0x20 ); /* TX */ |
---|
166 | } |
---|
167 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR ); |
---|
168 | (*setReg)( pMC68681_port, MC68681_MODE, mode1 ); |
---|
169 | (*setReg)( pMC68681_port, MC68681_MODE, mode2 ); |
---|
170 | rtems_interrupt_enable(Irql); |
---|
171 | return 0; |
---|
172 | } |
---|
173 | |
---|
174 | /* |
---|
175 | * mc68681_initialize_context |
---|
176 | * |
---|
177 | * This function sets the default values of the per port context structure. |
---|
178 | */ |
---|
179 | |
---|
180 | MC68681_STATIC void mc68681_initialize_context( |
---|
181 | int minor, |
---|
182 | mc68681_context *pmc68681Context |
---|
183 | ) |
---|
184 | { |
---|
185 | int port; |
---|
186 | unsigned int pMC68681; |
---|
187 | unsigned int pMC68681_port; |
---|
188 | |
---|
189 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
190 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
191 | |
---|
192 | pmc68681Context->mate = -1; |
---|
193 | |
---|
194 | for (port=0 ; port<Console_Port_Count ; port++ ) { |
---|
195 | if ( Console_Port_Tbl[port].ulCtrlPort1 == pMC68681 && |
---|
196 | Console_Port_Tbl[port].ulCtrlPort2 != pMC68681_port ) { |
---|
197 | pmc68681Context->mate = port; |
---|
198 | pmc68681Context->imr = 0; |
---|
199 | break; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | } |
---|
204 | |
---|
205 | /* |
---|
206 | * mc68681_init |
---|
207 | * |
---|
208 | * This function initializes the DUART to a quiecsent state. |
---|
209 | */ |
---|
210 | |
---|
211 | MC68681_STATIC void mc68681_init(int minor) |
---|
212 | { |
---|
213 | unsigned32 pMC68681_port; |
---|
214 | unsigned32 pMC68681; |
---|
215 | mc68681_context *pmc68681Context; |
---|
216 | setRegister_f setReg; |
---|
217 | getRegister_f getReg; |
---|
218 | |
---|
219 | pmc68681Context = (mc68681_context *) malloc(sizeof(mc68681_context)); |
---|
220 | |
---|
221 | Console_Port_Data[minor].pDeviceContext = (void *)pmc68681Context; |
---|
222 | |
---|
223 | mc68681_initialize_context( minor, pmc68681Context ); |
---|
224 | |
---|
225 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
226 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
227 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
228 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
229 | |
---|
230 | /* |
---|
231 | * Reset everything and leave this port disabled. |
---|
232 | */ |
---|
233 | |
---|
234 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_RX ); |
---|
235 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_TX ); |
---|
236 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR ); |
---|
237 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_BREAK ); |
---|
238 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_STOP_BREAK ); |
---|
239 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX ); |
---|
240 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX ); |
---|
241 | |
---|
242 | |
---|
243 | (*setReg)( pMC68681_port, MC68681_MODE_REG_1A, 0x00 ); |
---|
244 | (*setReg)( pMC68681_port, MC68681_MODE_REG_2A, 0x02 ); |
---|
245 | |
---|
246 | /* |
---|
247 | * Disable interrupts on RX and TX for this port |
---|
248 | */ |
---|
249 | |
---|
250 | mc68681_enable_interrupts( minor, MC68681_IMR_DISABLE_ALL ); |
---|
251 | } |
---|
252 | |
---|
253 | /* |
---|
254 | * mc68681_open |
---|
255 | * |
---|
256 | * This function opens a port for communication. |
---|
257 | * |
---|
258 | * Default state is 9600 baud, 8 bits, No parity, and 1 stop bit. |
---|
259 | */ |
---|
260 | |
---|
261 | MC68681_STATIC int mc68681_open( |
---|
262 | int major, |
---|
263 | int minor, |
---|
264 | void *arg |
---|
265 | ) |
---|
266 | { |
---|
267 | unsigned32 pMC68681; |
---|
268 | unsigned32 pMC68681_port; |
---|
269 | unsigned int baud; |
---|
270 | unsigned int acr; |
---|
271 | unsigned int vector; |
---|
272 | unsigned int command; |
---|
273 | rtems_interrupt_level Irql; |
---|
274 | setRegister_f setReg; |
---|
275 | |
---|
276 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
277 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
278 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
279 | vector = Console_Port_Tbl[minor].ulIntVector; |
---|
280 | |
---|
281 | /* XXX default baud rate should be from configuration table */ |
---|
282 | |
---|
283 | (void) mc68681_baud_rate( minor, B9600, &baud, &acr, &command ); |
---|
284 | |
---|
285 | /* |
---|
286 | * Set the DUART channel to a default useable state |
---|
287 | */ |
---|
288 | |
---|
289 | rtems_interrupt_disable(Irql); |
---|
290 | (*setReg)( pMC68681, MC68681_AUX_CTRL_REG, acr ); |
---|
291 | (*setReg)( pMC68681_port, MC68681_CLOCK_SELECT, baud ); |
---|
292 | if ( command ) { |
---|
293 | (*setReg)( pMC68681_port, MC68681_COMMAND, command ); /* RX */ |
---|
294 | (*setReg)( pMC68681_port, MC68681_COMMAND, command | 0x20 ); /* TX */ |
---|
295 | } |
---|
296 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_MR_PTR ); |
---|
297 | (*setReg)( pMC68681_port, MC68681_MODE, 0x13 ); |
---|
298 | (*setReg)( pMC68681_port, MC68681_MODE, 0x07 ); |
---|
299 | rtems_interrupt_enable(Irql); |
---|
300 | |
---|
301 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_TX ); |
---|
302 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_ENABLE_RX ); |
---|
303 | |
---|
304 | (*setReg)( pMC68681, MC68681_INTERRUPT_VECTOR_REG, vector ); |
---|
305 | |
---|
306 | return RTEMS_SUCCESSFUL; |
---|
307 | } |
---|
308 | |
---|
309 | /* |
---|
310 | * mc68681_close |
---|
311 | * |
---|
312 | * This function shuts down the requested port. |
---|
313 | */ |
---|
314 | |
---|
315 | MC68681_STATIC int mc68681_close( |
---|
316 | int major, |
---|
317 | int minor, |
---|
318 | void *arg |
---|
319 | ) |
---|
320 | { |
---|
321 | unsigned32 pMC68681; |
---|
322 | unsigned32 pMC68681_port; |
---|
323 | setRegister_f setReg; |
---|
324 | |
---|
325 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
326 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
327 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
328 | |
---|
329 | /* |
---|
330 | * Disable interrupts from this channel and then disable it totally. |
---|
331 | */ |
---|
332 | |
---|
333 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_TX ); |
---|
334 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_DISABLE_RX ); |
---|
335 | |
---|
336 | return(RTEMS_SUCCESSFUL); |
---|
337 | } |
---|
338 | |
---|
339 | /* |
---|
340 | * mc68681_write_polled |
---|
341 | * |
---|
342 | * This routine polls out the requested character. |
---|
343 | */ |
---|
344 | |
---|
345 | MC68681_STATIC void mc68681_write_polled( |
---|
346 | int minor, |
---|
347 | char cChar |
---|
348 | ) |
---|
349 | { |
---|
350 | unsigned32 pMC68681_port; |
---|
351 | unsigned char ucLineStatus; |
---|
352 | int iTimeout; |
---|
353 | getRegister_f getReg; |
---|
354 | setRegister_f setReg; |
---|
355 | |
---|
356 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
357 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
358 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
359 | |
---|
360 | /* |
---|
361 | * wait for transmitter holding register to be empty |
---|
362 | */ |
---|
363 | iTimeout = 1000; |
---|
364 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
365 | while ((ucLineStatus & (MC68681_TX_READY|MC68681_TX_EMPTY)) == 0) { |
---|
366 | |
---|
367 | if ((ucLineStatus & 0xF0)) |
---|
368 | (*setReg)( pMC68681_port, MC68681_COMMAND, MC68681_MODE_REG_RESET_ERROR ); |
---|
369 | |
---|
370 | /* |
---|
371 | * Yield while we wait |
---|
372 | */ |
---|
373 | |
---|
374 | #if 0 |
---|
375 | if(_System_state_Is_up(_System_state_Get())) { |
---|
376 | rtems_task_wake_after(RTEMS_YIELD_PROCESSOR); |
---|
377 | } |
---|
378 | #endif |
---|
379 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
380 | if(!--iTimeout) { |
---|
381 | break; |
---|
382 | } |
---|
383 | } |
---|
384 | |
---|
385 | /* |
---|
386 | * transmit character |
---|
387 | */ |
---|
388 | |
---|
389 | (*setReg)(pMC68681_port, MC68681_TX_BUFFER, cChar); |
---|
390 | } |
---|
391 | |
---|
392 | /* |
---|
393 | * mc68681_isr |
---|
394 | * |
---|
395 | * This is the single interrupt entry point which parcels interrupts |
---|
396 | * out to the various ports. |
---|
397 | */ |
---|
398 | |
---|
399 | MC68681_STATIC rtems_isr mc68681_isr( |
---|
400 | rtems_vector_number vector |
---|
401 | ) |
---|
402 | { |
---|
403 | int minor; |
---|
404 | |
---|
405 | for(minor=0 ; minor<Console_Port_Count ; minor++) { |
---|
406 | if(Console_Port_Tbl[minor].ulIntVector == vector && |
---|
407 | Console_Port_Tbl[minor].deviceType == SERIAL_MC68681 ) { |
---|
408 | mc68681_process(minor); |
---|
409 | } |
---|
410 | } |
---|
411 | } |
---|
412 | |
---|
413 | /* |
---|
414 | * mc68681_initialize_interrupts |
---|
415 | * |
---|
416 | * This routine initializes the console's receive and transmit |
---|
417 | * ring buffers and loads the appropriate vectors to handle the interrupts. |
---|
418 | */ |
---|
419 | |
---|
420 | MC68681_STATIC void mc68681_initialize_interrupts(int minor) |
---|
421 | { |
---|
422 | mc68681_init(minor); |
---|
423 | |
---|
424 | Console_Port_Data[minor].bActive = FALSE; |
---|
425 | |
---|
426 | set_vector(mc68681_isr, Console_Port_Tbl[minor].ulIntVector, 1); |
---|
427 | |
---|
428 | mc68681_enable_interrupts(minor,MC68681_IMR_ENABLE_ALL_EXCEPT_TX); |
---|
429 | } |
---|
430 | |
---|
431 | /* |
---|
432 | * mc68681_write_support_int |
---|
433 | * |
---|
434 | * Console Termios output entry point when using interrupt driven output. |
---|
435 | */ |
---|
436 | |
---|
437 | MC68681_STATIC int mc68681_write_support_int( |
---|
438 | int minor, |
---|
439 | const char *buf, |
---|
440 | int len |
---|
441 | ) |
---|
442 | { |
---|
443 | unsigned32 Irql; |
---|
444 | unsigned32 pMC68681_port; |
---|
445 | setRegister_f setReg; |
---|
446 | |
---|
447 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
448 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
449 | |
---|
450 | /* |
---|
451 | * We are using interrupt driven output and termios only sends us |
---|
452 | * one character at a time. |
---|
453 | */ |
---|
454 | |
---|
455 | if ( !len ) |
---|
456 | return 0; |
---|
457 | |
---|
458 | /* |
---|
459 | * Put the character out and enable interrupts if necessary. |
---|
460 | */ |
---|
461 | |
---|
462 | rtems_interrupt_disable(Irql); |
---|
463 | if ( Console_Port_Data[minor].bActive == FALSE ) { |
---|
464 | Console_Port_Data[minor].bActive = TRUE; |
---|
465 | mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL); |
---|
466 | } |
---|
467 | (*setReg)(pMC68681_port, MC68681_TX_BUFFER, *buf); |
---|
468 | rtems_interrupt_enable(Irql); |
---|
469 | |
---|
470 | return 1; |
---|
471 | } |
---|
472 | |
---|
473 | /* |
---|
474 | * mc68681_write_support_polled |
---|
475 | * |
---|
476 | * Console Termios output entry point when using polled output. |
---|
477 | * |
---|
478 | */ |
---|
479 | |
---|
480 | MC68681_STATIC int mc68681_write_support_polled( |
---|
481 | int minor, |
---|
482 | const char *buf, |
---|
483 | int len |
---|
484 | ) |
---|
485 | { |
---|
486 | int nwrite = 0; |
---|
487 | |
---|
488 | /* |
---|
489 | * poll each byte in the string out of the port. |
---|
490 | */ |
---|
491 | while (nwrite < len) { |
---|
492 | /* |
---|
493 | * transmit character |
---|
494 | */ |
---|
495 | mc68681_write_polled(minor, *buf++); |
---|
496 | nwrite++; |
---|
497 | } |
---|
498 | |
---|
499 | /* |
---|
500 | * return the number of bytes written. |
---|
501 | */ |
---|
502 | return nwrite; |
---|
503 | } |
---|
504 | |
---|
505 | /* |
---|
506 | * mc68681_inbyte_nonblocking_polled |
---|
507 | * |
---|
508 | * Console Termios polling input entry point. |
---|
509 | */ |
---|
510 | |
---|
511 | MC68681_STATIC int mc68681_inbyte_nonblocking_polled( |
---|
512 | int minor |
---|
513 | ) |
---|
514 | { |
---|
515 | unsigned32 pMC68681_port; |
---|
516 | unsigned char ucLineStatus; |
---|
517 | unsigned char cChar; |
---|
518 | getRegister_f getReg; |
---|
519 | |
---|
520 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
521 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
522 | |
---|
523 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
524 | if(ucLineStatus & MC68681_RX_READY) { |
---|
525 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
526 | return (int)cChar; |
---|
527 | } else { |
---|
528 | return -1; |
---|
529 | } |
---|
530 | } |
---|
531 | |
---|
532 | /* |
---|
533 | * mc68681_baud_rate |
---|
534 | */ |
---|
535 | |
---|
536 | MC68681_STATIC int mc68681_baud_rate( |
---|
537 | int minor, |
---|
538 | int baud, |
---|
539 | unsigned int *baud_mask_p, |
---|
540 | unsigned int *acr_bit_p, |
---|
541 | unsigned int *command |
---|
542 | ) |
---|
543 | { |
---|
544 | unsigned int baud_mask; |
---|
545 | unsigned int acr_bit; |
---|
546 | int status; |
---|
547 | int is_extended; |
---|
548 | int baud_requested; |
---|
549 | mc68681_baud_table_t *baud_tbl; |
---|
550 | |
---|
551 | baud_mask = 0; |
---|
552 | acr_bit = 0; |
---|
553 | status = 0; |
---|
554 | |
---|
555 | if ( !(Console_Port_Tbl[minor].ulDataPort & MC68681_DATA_BAUD_RATE_SET_1) ) |
---|
556 | acr_bit = 1; |
---|
557 | |
---|
558 | is_extended = 0; |
---|
559 | |
---|
560 | switch (Console_Port_Tbl[minor].ulDataPort & MC68681_XBRG_MASK) { |
---|
561 | case MC68681_XBRG_IGNORED: |
---|
562 | *command = 0x00; |
---|
563 | break; |
---|
564 | case MC68681_XBRG_ENABLED: |
---|
565 | *command = 0x80; |
---|
566 | is_extended = 1; |
---|
567 | break; |
---|
568 | case MC68681_XBRG_DISABLED: |
---|
569 | *command = 0x90; |
---|
570 | break; |
---|
571 | } |
---|
572 | |
---|
573 | baud_requested = baud & CBAUD; |
---|
574 | if (!baud_requested) |
---|
575 | baud_requested = B9600; /* default to 9600 baud */ |
---|
576 | |
---|
577 | baud_requested = termios_baud_to_index( baud_requested ); |
---|
578 | |
---|
579 | baud_tbl = (mc68681_baud_table_t *) Console_Port_Tbl[minor].ulClock; |
---|
580 | if (!baud_tbl) |
---|
581 | rtems_fatal_error_occurred(RTEMS_INVALID_ADDRESS); |
---|
582 | |
---|
583 | if ( is_extended ) |
---|
584 | baud_mask = (unsigned int)baud_tbl[ acr_bit + 2 ][ baud_requested ]; |
---|
585 | else |
---|
586 | baud_mask = baud_tbl[ acr_bit ][ baud_requested ]; |
---|
587 | |
---|
588 | if ( baud_mask == MC68681_BAUD_NOT_VALID ) |
---|
589 | status = -1; |
---|
590 | |
---|
591 | /* |
---|
592 | * upper nibble is receiver and lower nibble is transmitter |
---|
593 | */ |
---|
594 | |
---|
595 | *baud_mask_p = (baud_mask << 4) | baud_mask; |
---|
596 | *acr_bit_p = acr_bit; |
---|
597 | return status; |
---|
598 | } |
---|
599 | |
---|
600 | /* |
---|
601 | * mc68681_process |
---|
602 | * |
---|
603 | * This routine is the per port console interrupt handler. |
---|
604 | */ |
---|
605 | |
---|
606 | MC68681_STATIC void mc68681_process( |
---|
607 | int minor |
---|
608 | ) |
---|
609 | { |
---|
610 | unsigned32 pMC68681; |
---|
611 | unsigned32 pMC68681_port; |
---|
612 | volatile unsigned8 ucLineStatus; |
---|
613 | unsigned char cChar; |
---|
614 | getRegister_f getReg; |
---|
615 | setRegister_f setReg; |
---|
616 | |
---|
617 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
618 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
619 | getReg = Console_Port_Tbl[minor].getRegister; |
---|
620 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
621 | |
---|
622 | /* |
---|
623 | * Deal with any received characters |
---|
624 | */ |
---|
625 | while(TRUE) { |
---|
626 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
627 | if(!(ucLineStatus & MC68681_RX_READY)) { |
---|
628 | break; |
---|
629 | } |
---|
630 | /* |
---|
631 | * If there is a RX error, then dump all the data. |
---|
632 | */ |
---|
633 | if ( ucLineStatus & MC68681_RX_ERRORS ) { |
---|
634 | do { |
---|
635 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
636 | ucLineStatus = (*getReg)(pMC68681_port, MC68681_STATUS); |
---|
637 | } while ( ucLineStatus & MC68681_RX_READY ); |
---|
638 | continue; |
---|
639 | } |
---|
640 | cChar = (*getReg)(pMC68681_port, MC68681_RX_BUFFER); |
---|
641 | rtems_termios_enqueue_raw_characters( |
---|
642 | Console_Port_Data[minor].termios_data, |
---|
643 | &cChar, |
---|
644 | 1 |
---|
645 | ); |
---|
646 | } |
---|
647 | |
---|
648 | /* |
---|
649 | * Deal with the transmitter |
---|
650 | */ |
---|
651 | |
---|
652 | ucLineStatus = (*getReg)(pMC68681, MC68681_INTERRUPT_STATUS_REG); |
---|
653 | if (pMC68681 != pMC68681_port) |
---|
654 | ucLineStatus >>= 4; |
---|
655 | |
---|
656 | if(ucLineStatus & MC68681_IR_TX_READY) { |
---|
657 | if (!rtems_termios_dequeue_characters( |
---|
658 | Console_Port_Data[minor].termios_data, 1)) { |
---|
659 | Console_Port_Data[minor].bActive = FALSE; |
---|
660 | mc68681_enable_interrupts(minor, MC68681_IMR_ENABLE_ALL_EXCEPT_TX); |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | } |
---|
665 | |
---|
666 | /* |
---|
667 | * mc68681_build_imr |
---|
668 | * |
---|
669 | * This function returns the value for the interrupt mask register for this |
---|
670 | * DUART. Since this is a shared register, we must look at the other port |
---|
671 | * on this chip to determine whether or not it is using interrupts. |
---|
672 | */ |
---|
673 | |
---|
674 | MC68681_STATIC unsigned int mc68681_build_imr( |
---|
675 | int minor, |
---|
676 | int enable_flag |
---|
677 | ) |
---|
678 | { |
---|
679 | int mate; |
---|
680 | int is_a; |
---|
681 | unsigned int mask; |
---|
682 | unsigned int mate_mask; |
---|
683 | unsigned int pMC68681; |
---|
684 | unsigned int pMC68681_port; |
---|
685 | mc68681_context *pmc68681Context; |
---|
686 | mc68681_context *mateContext; |
---|
687 | |
---|
688 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
689 | pMC68681_port = Console_Port_Tbl[minor].ulCtrlPort2; |
---|
690 | pmc68681Context = (mc68681_context *) Console_Port_Data[minor].pDeviceContext; |
---|
691 | mate = pmc68681Context->mate; |
---|
692 | |
---|
693 | mask = 0; |
---|
694 | mate_mask = 0; |
---|
695 | |
---|
696 | is_a = (pMC68681 == pMC68681_port); |
---|
697 | |
---|
698 | /* |
---|
699 | * If there is a mate for this port, get its IMR mask. |
---|
700 | */ |
---|
701 | |
---|
702 | if ( mate != -1 ) { |
---|
703 | mateContext = Console_Port_Data[mate].pDeviceContext; |
---|
704 | |
---|
705 | if (mateContext) |
---|
706 | mate_mask = mateContext->imr; |
---|
707 | } |
---|
708 | |
---|
709 | /* |
---|
710 | * Calculate this port's IMR mask and save it in the context area. |
---|
711 | */ |
---|
712 | |
---|
713 | if ( Console_Port_Tbl[minor].pDeviceFns->deviceOutputUsesInterrupts ) |
---|
714 | mask = enable_flag; |
---|
715 | |
---|
716 | pmc68681Context->imr = mask; |
---|
717 | |
---|
718 | /* |
---|
719 | * Now return the full IMR value |
---|
720 | */ |
---|
721 | |
---|
722 | if (is_a) |
---|
723 | return (mate_mask << 4) | mask; |
---|
724 | |
---|
725 | return (mask << 4) | mate_mask; |
---|
726 | } |
---|
727 | |
---|
728 | /* |
---|
729 | * mc68681_enable_interrupts |
---|
730 | * |
---|
731 | * This function initializes the hardware for this port to use interrupts. |
---|
732 | */ |
---|
733 | |
---|
734 | MC68681_STATIC void mc68681_enable_interrupts( |
---|
735 | int minor, |
---|
736 | int imr_mask |
---|
737 | ) |
---|
738 | { |
---|
739 | unsigned32 pMC68681; |
---|
740 | setRegister_f setReg; |
---|
741 | |
---|
742 | pMC68681 = Console_Port_Tbl[minor].ulCtrlPort1; |
---|
743 | setReg = Console_Port_Tbl[minor].setRegister; |
---|
744 | |
---|
745 | /* |
---|
746 | * Enable interrupts on RX and TX -- not break |
---|
747 | */ |
---|
748 | |
---|
749 | (*setReg)( |
---|
750 | pMC68681, |
---|
751 | MC68681_INTERRUPT_MASK_REG, |
---|
752 | mc68681_build_imr(minor, imr_mask) |
---|
753 | ); |
---|
754 | } |
---|
755 | |
---|