1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * 68340/68349 console serial I/O. |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * Author: |
---|
9 | * Geoffroy Montel |
---|
10 | * France Telecom - CNET/DSM/TAM/CAT |
---|
11 | * 4, rue du Clos Courtel |
---|
12 | * 35512 CESSON-SEVIGNE |
---|
13 | * FRANCE |
---|
14 | * |
---|
15 | * e-mail: g_montel@yahoo.com |
---|
16 | * |
---|
17 | * COPYRIGHT (c) 1989-1999. |
---|
18 | * On-Line Applications Research Corporation (OAR). |
---|
19 | * |
---|
20 | * Redistribution and use in source and binary forms, with or without |
---|
21 | * modification, are permitted provided that the following conditions |
---|
22 | * are met: |
---|
23 | * 1. Redistributions of source code must retain the above copyright |
---|
24 | * notice, this list of conditions and the following disclaimer. |
---|
25 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
26 | * notice, this list of conditions and the following disclaimer in the |
---|
27 | * documentation and/or other materials provided with the distribution. |
---|
28 | * |
---|
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
30 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
33 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
36 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
37 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
39 | * POSSIBILITY OF SUCH DAMAGE. |
---|
40 | */ |
---|
41 | |
---|
42 | #include <termios.h> |
---|
43 | |
---|
44 | #include <stdarg.h> |
---|
45 | #include <stdio.h> |
---|
46 | #include <stdlib.h> |
---|
47 | |
---|
48 | #include <bsp.h> |
---|
49 | #include <rtems/libio.h> |
---|
50 | #include <rtems/termiostypes.h> |
---|
51 | #include <rtems/console.h> |
---|
52 | #include <m68340.h> |
---|
53 | #include <m340uart.h> |
---|
54 | #include <m340timer.h> |
---|
55 | |
---|
56 | #define CONSOLE_VECTOR 121 |
---|
57 | #define CONSOLE_IRQ_LEVEL 3 |
---|
58 | #define CONSOLE_INTERRUPT_ARBITRATION 2 |
---|
59 | |
---|
60 | static void *ttypA; /* to remember which tty has been opened on channel A |
---|
61 | used when interrupts are enabled */ |
---|
62 | |
---|
63 | static void *ttypB; /* to remember which tty has been opened on channel B |
---|
64 | used when interrupts are enabled */ |
---|
65 | |
---|
66 | unsigned char DUIER_mirror = 0 ; /* reflects the state of IER register, which is Write Only */ |
---|
67 | unsigned char Error_Status_A = 0; /* error status on Channel A */ |
---|
68 | unsigned char Error_Status_B = 0; /* error status on Channel A */ |
---|
69 | |
---|
70 | /* |
---|
71 | * Device-specific routines |
---|
72 | */ |
---|
73 | |
---|
74 | #define USE_INTERRUPTS_A (m340_uart_config[UART_CHANNEL_A].mode==UART_INTERRUPTS) |
---|
75 | #define USE_INTERRUPTS_B (m340_uart_config[UART_CHANNEL_B].mode==UART_INTERRUPTS) |
---|
76 | #define CHANNEL_ENABLED_A m340_uart_config[UART_CHANNEL_A].enable |
---|
77 | #define CHANNEL_ENABLED_B m340_uart_config[UART_CHANNEL_B].enable |
---|
78 | |
---|
79 | #define set_DUIER(a) DUIER_mirror |= (a); DUIER = DUIER_mirror |
---|
80 | #define unset_DUIER(a) DUIER_mirror &= ~(a); DUIER = DUIER_mirror |
---|
81 | |
---|
82 | #define Enable_Interrupts_Tx_A if (USE_INTERRUPTS_A) set_DUIER(m340_TxRDYA) |
---|
83 | #define Disable_Interrupts_Tx_A if (USE_INTERRUPTS_A) unset_DUIER(m340_TxRDYA) |
---|
84 | |
---|
85 | #define Enable_Interrupts_Tx_B if (USE_INTERRUPTS_B) set_DUIER(m340_TxRDYB) |
---|
86 | #define Disable_Interrupts_Tx_B if (USE_INTERRUPTS_B) unset_DUIER(m340_TxRDYB) |
---|
87 | |
---|
88 | /****************************************************** |
---|
89 | Name: InterruptHandler |
---|
90 | Input parameters: vector number |
---|
91 | Output parameters: - |
---|
92 | Description: UART ISR Routine, called by _RTEMS_ISR |
---|
93 | *****************************************************/ |
---|
94 | rtems_isr |
---|
95 | InterruptHandler (rtems_vector_number v) |
---|
96 | { |
---|
97 | char ch; |
---|
98 | |
---|
99 | /***************************************************************************** |
---|
100 | ** CHANNEL A ** |
---|
101 | *****************************************************************************/ |
---|
102 | |
---|
103 | /* check Received Break*/ |
---|
104 | if (DUSRA & m340_RB) { |
---|
105 | Error_Status_A |= m340_RB; |
---|
106 | /* reset error status */ |
---|
107 | DUCRA = m340_Reset_Error_Status; |
---|
108 | } |
---|
109 | |
---|
110 | /* buffer received ? */ |
---|
111 | if (DUSRA & m340_Rx_RDY) { |
---|
112 | do { |
---|
113 | /* error encountered? */ |
---|
114 | if (DUSRA & (m340_OE | m340_PE | m340_FE | m340_RB)) { |
---|
115 | Error_Status_A |= DUSRA; |
---|
116 | /* reset error status */ |
---|
117 | DUCRA = m340_Reset_Error_Status; |
---|
118 | /* all the characters in the queue may not be good */ |
---|
119 | while (DUSRA & m340_Rx_RDY) |
---|
120 | /* push them in a trash */ |
---|
121 | ch = DURBA; |
---|
122 | } |
---|
123 | else { |
---|
124 | /* this is necessary, otherwise it blocks when FIFO is full */ |
---|
125 | ch = DURBA; |
---|
126 | rtems_termios_enqueue_raw_characters(ttypA,&ch,1); |
---|
127 | } |
---|
128 | } while (DUSRA & m340_Rx_RDY); |
---|
129 | Restart_Fifo_Full_A_Timer(); /* only if necessary (pointer to a fake function if |
---|
130 | not in FIFO full mode) */ |
---|
131 | } |
---|
132 | |
---|
133 | else /* if no character has been received */ |
---|
134 | Restart_Check_A_Timer(); /* same remark */ |
---|
135 | |
---|
136 | /* ready to accept a character ? */ |
---|
137 | if (DUISR & DUIER_mirror & m340_TxRDYA) { |
---|
138 | Disable_Interrupts_Tx_A; |
---|
139 | /* one character has been transmitted */ |
---|
140 | rtems_termios_dequeue_characters(ttypA,1); |
---|
141 | } |
---|
142 | |
---|
143 | /***************************************************************************** |
---|
144 | ** CHANNEL B ** |
---|
145 | *****************************************************************************/ |
---|
146 | |
---|
147 | /* check Received Break*/ |
---|
148 | if (DUSRB & m340_RB) { |
---|
149 | Error_Status_B |= m340_RB; |
---|
150 | /* reset error status */ |
---|
151 | DUCRB = m340_Reset_Error_Status; |
---|
152 | } |
---|
153 | |
---|
154 | /* buffer received ? */ |
---|
155 | if (DUSRB & m340_Rx_RDY) { |
---|
156 | do { |
---|
157 | if (DUSRB & (m340_OE | m340_PE | m340_FE | m340_RB)) { |
---|
158 | Error_Status_B |= DUSRB; |
---|
159 | /* reset error status */ |
---|
160 | DUCRB = m340_Reset_Error_Status; |
---|
161 | /* all the characters in the queue may not be good */ |
---|
162 | while (DUSRB & m340_Rx_RDY) |
---|
163 | /* push them in a trash */ |
---|
164 | ch = DURBB; |
---|
165 | } |
---|
166 | else { |
---|
167 | ch = DURBB; |
---|
168 | rtems_termios_enqueue_raw_characters(ttypB,&ch,1); |
---|
169 | } |
---|
170 | |
---|
171 | } while (DUSRB & m340_Rx_RDY); |
---|
172 | Restart_Fifo_Full_B_Timer(); |
---|
173 | } |
---|
174 | else /* if no character has been received */ |
---|
175 | Restart_Check_B_Timer(); |
---|
176 | |
---|
177 | /* ready to accept a character ? */ |
---|
178 | if (DUISR & DUIER_mirror & m340_TxRDYB) { |
---|
179 | Disable_Interrupts_Tx_B; |
---|
180 | /* one character has been transmitted */ |
---|
181 | rtems_termios_dequeue_characters(ttypB,1); |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | /****************************************************** |
---|
186 | Name: InterruptWrite |
---|
187 | Input parameters: minor = channel, pointer to buffer, |
---|
188 | and length of buffer to transmit |
---|
189 | Output parameters: - |
---|
190 | Description: write the first character of buf only |
---|
191 | may be called by either console_write |
---|
192 | or rtems_termios_enqueue_raw_characters |
---|
193 | *****************************************************/ |
---|
194 | static ssize_t |
---|
195 | InterruptWrite (int minor, const char *buf, size_t len) |
---|
196 | { |
---|
197 | if (minor==UART_CHANNEL_A) { |
---|
198 | if (len>0) { |
---|
199 | DUTBA=*buf; |
---|
200 | Enable_Interrupts_Tx_A; |
---|
201 | } |
---|
202 | } |
---|
203 | else if (minor==UART_CHANNEL_B) { |
---|
204 | if (len>0) { |
---|
205 | DUTBB=*buf; |
---|
206 | Enable_Interrupts_Tx_B; |
---|
207 | } |
---|
208 | } |
---|
209 | return 0; |
---|
210 | } |
---|
211 | |
---|
212 | /****************************************************** |
---|
213 | Name: dbug_out_char |
---|
214 | Input parameters: channel, character to emit |
---|
215 | Output parameters: - |
---|
216 | Description: wait for the UART to be ready to emit |
---|
217 | a character and send it |
---|
218 | *****************************************************/ |
---|
219 | void dbug_out_char( int minor, int ch ) |
---|
220 | { |
---|
221 | if (minor==UART_CHANNEL_A) { |
---|
222 | while (!(DUSRA & m340_Tx_RDY)) continue; |
---|
223 | DUTBA=ch; |
---|
224 | } |
---|
225 | else if (minor==UART_CHANNEL_B) { |
---|
226 | while (!(DUSRB & m340_Tx_RDY)) continue; |
---|
227 | DUTBB=ch; |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | /****************************************************** |
---|
232 | Name: dbug_in_char |
---|
233 | Input parameters: - |
---|
234 | Output parameters: received character |
---|
235 | Description: return the character in the UART |
---|
236 | *****************************************************/ |
---|
237 | int dbug_in_char( int minor ) |
---|
238 | { |
---|
239 | if (minor==UART_CHANNEL_A) { |
---|
240 | return DURBA; |
---|
241 | } |
---|
242 | else if (minor==UART_CHANNEL_B) { |
---|
243 | return DURBB; |
---|
244 | } |
---|
245 | return 0; |
---|
246 | } |
---|
247 | |
---|
248 | /****************************************************** |
---|
249 | Name: dbug_char_present |
---|
250 | Input parameters: channel # |
---|
251 | Output parameters: TRUE or FALSE |
---|
252 | Description: return whether there's a character |
---|
253 | in the receive buffer |
---|
254 | *****************************************************/ |
---|
255 | int dbug_char_present( int minor ) |
---|
256 | { |
---|
257 | if (minor==UART_CHANNEL_A) { |
---|
258 | return (DUSRA & m340_Rx_RDY); |
---|
259 | } |
---|
260 | else if (minor==UART_CHANNEL_B) { |
---|
261 | return (DUSRB & m340_Rx_RDY); |
---|
262 | } |
---|
263 | return 0; |
---|
264 | } |
---|
265 | |
---|
266 | /****************************************************** |
---|
267 | Name: dbugInitialise |
---|
268 | Input parameters: - |
---|
269 | Output parameters: - |
---|
270 | Description: Init the UART |
---|
271 | *****************************************************/ |
---|
272 | static void |
---|
273 | dbugInitialise (void) |
---|
274 | { |
---|
275 | t_baud_speed_table uart_config; /* configuration of UARTS */ |
---|
276 | |
---|
277 | /* |
---|
278 | * Reset Receiver |
---|
279 | */ |
---|
280 | DUCRA = m340_Reset_Receiver; |
---|
281 | DUCRB = m340_Reset_Receiver; |
---|
282 | |
---|
283 | /* |
---|
284 | * Reset Transmitter |
---|
285 | */ |
---|
286 | DUCRA = m340_Reset_Transmitter; |
---|
287 | DUCRB = m340_Reset_Transmitter; |
---|
288 | |
---|
289 | /* |
---|
290 | * Enable serial module for normal operation, ignore FREEZE, select the crystal clock, |
---|
291 | * supervisor/user serial registers unrestricted |
---|
292 | * interrupt arbitration at priority CONSOLE_INTERRUPT_ARBITRATION |
---|
293 | * WARNING : 8 bits access only on this UART! |
---|
294 | */ |
---|
295 | DUMCRH = 0x00; |
---|
296 | DUMCRL = CONSOLE_INTERRUPT_ARBITRATION; |
---|
297 | |
---|
298 | /* |
---|
299 | * Interrupt level register |
---|
300 | */ |
---|
301 | DUILR = CONSOLE_IRQ_LEVEL; |
---|
302 | |
---|
303 | /* sets the IVR */ |
---|
304 | DUIVR = CONSOLE_VECTOR; |
---|
305 | |
---|
306 | /* search for a correct m340 uart configuration */ |
---|
307 | uart_config = Find_Right_m340_UART_Config(m340_uart_config[UART_CHANNEL_A].rx_baudrate, |
---|
308 | m340_uart_config[UART_CHANNEL_A].tx_baudrate, |
---|
309 | CHANNEL_ENABLED_A, |
---|
310 | m340_uart_config[UART_CHANNEL_B].rx_baudrate, |
---|
311 | m340_uart_config[UART_CHANNEL_B].tx_baudrate, |
---|
312 | CHANNEL_ENABLED_B); |
---|
313 | |
---|
314 | /***************************************************************************** |
---|
315 | ** CHANNEL A ** |
---|
316 | *****************************************************************************/ |
---|
317 | if (CHANNEL_ENABLED_A) { |
---|
318 | |
---|
319 | if (USE_INTERRUPTS_A) { |
---|
320 | rtems_isr_entry old_handler; |
---|
321 | |
---|
322 | (void) rtems_interrupt_catch (InterruptHandler, |
---|
323 | CONSOLE_VECTOR, |
---|
324 | &old_handler); |
---|
325 | |
---|
326 | /* uncomment this if you want to pass control to your own ISR handler |
---|
327 | it may be usefull to do so to check for performances with an oscilloscope */ |
---|
328 | /* |
---|
329 | { |
---|
330 | CPU_ISR_raw_handler ignored; |
---|
331 | _CPU_ISR_install_raw_handler( CONSOLE_VECTOR, _Debug_ISR_Handler_Console, &ignored ); |
---|
332 | } |
---|
333 | */ |
---|
334 | |
---|
335 | /* |
---|
336 | * Interrupt Enable Register |
---|
337 | * Enable Interrupts on Channel A Receiver Ready |
---|
338 | */ |
---|
339 | set_DUIER(m340_RxRDYA); |
---|
340 | } |
---|
341 | else { |
---|
342 | /* |
---|
343 | * Disable Interrupts on channel A |
---|
344 | */ |
---|
345 | unset_DUIER(m340_RxRDYA&m340_TxRDYA); |
---|
346 | } |
---|
347 | |
---|
348 | /* |
---|
349 | * Change set of baud speeds |
---|
350 | * disable input control |
---|
351 | */ |
---|
352 | /* no good uart configuration ? */ |
---|
353 | if (uart_config.nb<1) rtems_fatal_error_occurred (-1); |
---|
354 | |
---|
355 | if (uart_config.baud_speed_table[UART_CHANNEL_A].set==1) |
---|
356 | DUACR = m340_BRG_Set1; |
---|
357 | else |
---|
358 | DUACR = m340_BRG_Set2; |
---|
359 | |
---|
360 | /* |
---|
361 | * make OPCR an auxiliary function serving the communication channels |
---|
362 | */ |
---|
363 | DUOPCR = m340_OPCR_Aux; |
---|
364 | |
---|
365 | /* poll the XTAL_RDY bit until it is cleared to ensure that an unstable crystal |
---|
366 | input is not applied to the baud rate generator */ |
---|
367 | while (DUISR & m340_XTAL_RDY) continue; |
---|
368 | |
---|
369 | /* |
---|
370 | * Serial Channel Baud Speed |
---|
371 | */ |
---|
372 | DUCSRA = (uart_config.baud_speed_table[UART_CHANNEL_A].rcs << 4) |
---|
373 | | (uart_config.baud_speed_table[UART_CHANNEL_A].tcs); |
---|
374 | |
---|
375 | /* |
---|
376 | * Serial Channel Configuration |
---|
377 | */ |
---|
378 | DUMR1A = m340_uart_config[UART_CHANNEL_A].parity_mode |
---|
379 | | m340_uart_config[UART_CHANNEL_A].bits_per_char |
---|
380 | | m340_RxRTS; |
---|
381 | |
---|
382 | if (m340_uart_config[UART_CHANNEL_A].rx_mode==UART_FIFO_FULL) DUMR1A |= m340_R_F | m340_ERR; |
---|
383 | |
---|
384 | /* |
---|
385 | * Serial Channel Configuration 2 |
---|
386 | */ |
---|
387 | DUMR2A |= m340_normal; |
---|
388 | |
---|
389 | /* |
---|
390 | * Enable Channel A: transmitter and receiver |
---|
391 | */ |
---|
392 | DUCRA = m340_Transmitter_Enable | m340_Receiver_Enable; |
---|
393 | } /* channel A enabled */ |
---|
394 | |
---|
395 | /***************************************************************************** |
---|
396 | ** CHANNEL B ** |
---|
397 | *****************************************************************************/ |
---|
398 | if (CHANNEL_ENABLED_B) { |
---|
399 | |
---|
400 | /* we mustn't set the console vector twice! */ |
---|
401 | if ((USE_INTERRUPTS_B && !(CHANNEL_ENABLED_A)) |
---|
402 | || (USE_INTERRUPTS_B && CHANNEL_ENABLED_A && !USE_INTERRUPTS_A)) { |
---|
403 | rtems_isr_entry old_handler; |
---|
404 | |
---|
405 | (void) rtems_interrupt_catch (InterruptHandler, |
---|
406 | CONSOLE_VECTOR, |
---|
407 | &old_handler); |
---|
408 | |
---|
409 | /* uncomment this if you want to pass control to your own ISR handler |
---|
410 | it may be usefull to do so to check for performances with an oscilloscope */ |
---|
411 | /* |
---|
412 | { |
---|
413 | CPU_ISR_raw_handler ignored; |
---|
414 | _CPU_ISR_install_raw_handler( CONSOLE_VECTOR, _Debug_ISR_Handler_Console, &ignored ); |
---|
415 | } |
---|
416 | */ |
---|
417 | |
---|
418 | /* |
---|
419 | * Interrupt Enable Register |
---|
420 | * Enable Interrupts on Channel A Receiver Ready |
---|
421 | */ |
---|
422 | set_DUIER(m340_RxRDYB); |
---|
423 | } |
---|
424 | else { |
---|
425 | /* |
---|
426 | * Disable Interrupts on channel B |
---|
427 | */ |
---|
428 | unset_DUIER(m340_RxRDYB&m340_TxRDYB); |
---|
429 | } |
---|
430 | |
---|
431 | /* |
---|
432 | * Change set of baud speeds |
---|
433 | * disable input control |
---|
434 | */ |
---|
435 | |
---|
436 | /* no good uart configuration ? */ |
---|
437 | if (uart_config.nb<2) rtems_fatal_error_occurred (-1); |
---|
438 | |
---|
439 | /* don't set DUACR twice! */ |
---|
440 | if (!CHANNEL_ENABLED_A) { |
---|
441 | if (uart_config.baud_speed_table[UART_CHANNEL_B].set==1) |
---|
442 | DUACR = m340_BRG_Set1; |
---|
443 | else |
---|
444 | DUACR = m340_BRG_Set2; |
---|
445 | } |
---|
446 | |
---|
447 | /* |
---|
448 | * make OPCR an auxiliary function serving the communication channels |
---|
449 | */ |
---|
450 | if (!CHANNEL_ENABLED_A) DUOPCR = m340_OPCR_Aux; |
---|
451 | |
---|
452 | /* poll the XTAL_RDY bit until it is cleared to ensure that an unstable crystal |
---|
453 | input is not applied to the baud rate generator */ |
---|
454 | while (DUISR & m340_XTAL_RDY) continue; |
---|
455 | |
---|
456 | /* |
---|
457 | * Serial Channel Baud Speed |
---|
458 | */ |
---|
459 | DUCSRB = (uart_config.baud_speed_table[UART_CHANNEL_B].rcs << 4) |
---|
460 | | (uart_config.baud_speed_table[UART_CHANNEL_B].tcs); |
---|
461 | |
---|
462 | /* |
---|
463 | * Serial Channel Configuration |
---|
464 | */ |
---|
465 | DUMR1B = m340_uart_config[UART_CHANNEL_B].parity_mode |
---|
466 | | m340_uart_config[UART_CHANNEL_B].bits_per_char |
---|
467 | | m340_RxRTS; |
---|
468 | |
---|
469 | if (m340_uart_config[UART_CHANNEL_B].rx_mode==UART_FIFO_FULL) DUMR1B |= m340_R_F | m340_ERR; |
---|
470 | |
---|
471 | /* |
---|
472 | * Serial Channel Configuration 2 |
---|
473 | */ |
---|
474 | DUMR2B |= m340_normal; |
---|
475 | |
---|
476 | /* |
---|
477 | * Enable Channel A: transmitter and receiver |
---|
478 | */ |
---|
479 | DUCRB = m340_Transmitter_Enable | m340_Receiver_Enable; |
---|
480 | } /* channel B enabled */ |
---|
481 | } |
---|
482 | |
---|
483 | /****************************************************** |
---|
484 | Name: SetAttributes |
---|
485 | Input parameters: termios structure, channel |
---|
486 | Output parameters: - |
---|
487 | Description: return whether there's a character |
---|
488 | in the receive buffer |
---|
489 | TO DO: add the channel # to check for!! |
---|
490 | *****************************************************/ |
---|
491 | static int |
---|
492 | SetAttributes (int minor, const struct termios *t) |
---|
493 | { |
---|
494 | rtems_interrupt_level level; |
---|
495 | float ispeed, ospeed; |
---|
496 | |
---|
497 | /* convert it */ |
---|
498 | ispeed = rtems_termios_baud_to_number(t->c_ispeed); |
---|
499 | ospeed = rtems_termios_baud_to_number(t->c_ospeed); |
---|
500 | |
---|
501 | if (ispeed || ospeed) { |
---|
502 | /* update config table */ |
---|
503 | m340_uart_config[UART_CHANNEL_A].rx_baudrate = ((minor==UART_CHANNEL_A)&&(ispeed!=0)) ? ispeed : m340_uart_config[UART_CHANNEL_A].rx_baudrate; |
---|
504 | m340_uart_config[UART_CHANNEL_A].tx_baudrate = ((minor==UART_CHANNEL_A)&&(ospeed!=0)) ? ospeed : m340_uart_config[UART_CHANNEL_A].tx_baudrate; |
---|
505 | m340_uart_config[UART_CHANNEL_B].rx_baudrate = ((minor==UART_CHANNEL_B)&&(ispeed!=0)) ? ispeed : m340_uart_config[UART_CHANNEL_B].rx_baudrate; |
---|
506 | m340_uart_config[UART_CHANNEL_B].tx_baudrate = ((minor==UART_CHANNEL_B)&&(ospeed!=0)) ? ospeed : m340_uart_config[UART_CHANNEL_B].tx_baudrate; |
---|
507 | } |
---|
508 | |
---|
509 | /* change parity */ |
---|
510 | if (t->c_cflag & PARENB) { |
---|
511 | if (t->c_cflag & PARODD) m340_uart_config[minor].parity_mode = m340_Odd_Parity; |
---|
512 | else m340_uart_config[minor].parity_mode = m340_Even_Parity; |
---|
513 | } |
---|
514 | |
---|
515 | /* change bits per character */ |
---|
516 | if (t->c_cflag & CSIZE) { |
---|
517 | switch (t->c_cflag & CSIZE) { |
---|
518 | default: break; |
---|
519 | case CS5: m340_uart_config[minor].bits_per_char = m340_5bpc; break; |
---|
520 | case CS6: m340_uart_config[minor].bits_per_char = m340_6bpc; break; |
---|
521 | case CS7: m340_uart_config[minor].bits_per_char = m340_7bpc; break; |
---|
522 | case CS8: m340_uart_config[minor].bits_per_char = m340_8bpc; break; |
---|
523 | } |
---|
524 | } |
---|
525 | |
---|
526 | /* if serial module configuration has been changed */ |
---|
527 | if (t->c_cflag & (CSIZE | PARENB)) { |
---|
528 | rtems_interrupt_disable(level); |
---|
529 | /* reinit the UART */ |
---|
530 | dbugInitialise(); |
---|
531 | rtems_interrupt_enable (level); |
---|
532 | } |
---|
533 | |
---|
534 | return 0; |
---|
535 | } |
---|
536 | |
---|
537 | /****************************************************** |
---|
538 | Name: console_initialize |
---|
539 | Input parameters: MAJOR # of console_driver, |
---|
540 | minor is always 0, |
---|
541 | args are always NULL |
---|
542 | Output parameters: - |
---|
543 | Description: Reserve resources consumed by this driver |
---|
544 | TODO: We should pass m340_uart_config table in arg |
---|
545 | *****************************************************/ |
---|
546 | rtems_device_driver console_initialize( |
---|
547 | rtems_device_major_number major, |
---|
548 | rtems_device_minor_number minor, |
---|
549 | void *arg |
---|
550 | ) |
---|
551 | { |
---|
552 | rtems_status_code status; |
---|
553 | int i; |
---|
554 | |
---|
555 | /* |
---|
556 | * Set up TERMIOS |
---|
557 | */ |
---|
558 | rtems_termios_initialize (); |
---|
559 | |
---|
560 | /* |
---|
561 | * Do device-specific initialization |
---|
562 | */ |
---|
563 | Init_UART_Table(); |
---|
564 | dbugInitialise (); |
---|
565 | Fifo_Full_benchmark_timer_initialize(); |
---|
566 | |
---|
567 | /* |
---|
568 | * Register the devices |
---|
569 | */ |
---|
570 | for (i=0; i<UART_NUMBER_OF_CHANNELS; i++) { |
---|
571 | if (m340_uart_config[i].enable) { |
---|
572 | status = rtems_io_register_name (m340_uart_config[i].name, major, i); |
---|
573 | if (status != RTEMS_SUCCESSFUL) |
---|
574 | rtems_fatal_error_occurred (status); |
---|
575 | } |
---|
576 | } |
---|
577 | |
---|
578 | return RTEMS_SUCCESSFUL; |
---|
579 | } |
---|
580 | |
---|
581 | /****************************************************** |
---|
582 | Name: console_open |
---|
583 | Input parameters: channel #, arg |
---|
584 | Output parameters: - |
---|
585 | Description: open the device |
---|
586 | *****************************************************/ |
---|
587 | rtems_device_driver console_open( |
---|
588 | rtems_device_major_number major, |
---|
589 | rtems_device_minor_number minor, |
---|
590 | void * arg |
---|
591 | ) |
---|
592 | { |
---|
593 | rtems_status_code sc = 0; |
---|
594 | |
---|
595 | static const rtems_termios_callbacks intrCallbacks = { |
---|
596 | NULL, /* firstOpen */ |
---|
597 | NULL, /* lastClose */ |
---|
598 | NULL, /* pollRead */ |
---|
599 | InterruptWrite, /* write */ |
---|
600 | SetAttributes, /* setAttributes */ |
---|
601 | NULL, /* stopRemoteTx */ |
---|
602 | NULL, /* startRemoteTx */ |
---|
603 | TERMIOS_IRQ_DRIVEN /* outputUsesInterrupts */ |
---|
604 | }; |
---|
605 | |
---|
606 | static const rtems_termios_callbacks pollCallbacks = { |
---|
607 | NULL, /* firstOpen */ |
---|
608 | NULL, /* lastClose */ |
---|
609 | dbugRead, /* pollRead */ |
---|
610 | dbugWrite, /* write */ |
---|
611 | SetAttributes, /* setAttributes */ |
---|
612 | NULL, /* stopRemoteTx */ |
---|
613 | NULL, /* startRemoteTx */ |
---|
614 | TERMIOS_POLLED /* outputUsesInterrupts */ |
---|
615 | }; |
---|
616 | |
---|
617 | if (minor==UART_CHANNEL_A) { |
---|
618 | if (USE_INTERRUPTS_A) { |
---|
619 | rtems_libio_open_close_args_t *args = arg; |
---|
620 | |
---|
621 | sc |= rtems_termios_open (major, minor, arg, &intrCallbacks); |
---|
622 | ttypA = args->iop->data1; |
---|
623 | } |
---|
624 | else { |
---|
625 | sc |= rtems_termios_open (major, minor, arg, &pollCallbacks); |
---|
626 | } |
---|
627 | } |
---|
628 | |
---|
629 | else if (minor==UART_CHANNEL_B) { |
---|
630 | if (USE_INTERRUPTS_B) { |
---|
631 | rtems_libio_open_close_args_t *args = arg; |
---|
632 | |
---|
633 | sc |= rtems_termios_open (major, minor, arg, &intrCallbacks); |
---|
634 | ttypB = args->iop->data1; |
---|
635 | } |
---|
636 | else { |
---|
637 | sc |= rtems_termios_open (major, minor, arg, &pollCallbacks); |
---|
638 | } |
---|
639 | } |
---|
640 | |
---|
641 | else return RTEMS_INVALID_NUMBER; |
---|
642 | |
---|
643 | return sc; |
---|
644 | } |
---|
645 | |
---|
646 | /****************************************************** |
---|
647 | Name: console_close |
---|
648 | Input parameters: channel #, termios args |
---|
649 | Output parameters: - |
---|
650 | Description: close the device |
---|
651 | *****************************************************/ |
---|
652 | rtems_device_driver console_close( |
---|
653 | rtems_device_major_number major, |
---|
654 | rtems_device_minor_number minor, |
---|
655 | void * arg |
---|
656 | ) |
---|
657 | { |
---|
658 | return rtems_termios_close (arg); |
---|
659 | } |
---|
660 | |
---|
661 | /****************************************************** |
---|
662 | Name: console_read |
---|
663 | Input parameters: channel #, termios args |
---|
664 | Output parameters: - |
---|
665 | Description: read the device |
---|
666 | *****************************************************/ |
---|
667 | rtems_device_driver console_read( |
---|
668 | rtems_device_major_number major, |
---|
669 | rtems_device_minor_number minor, |
---|
670 | void * arg |
---|
671 | ) |
---|
672 | { |
---|
673 | return rtems_termios_read (arg); |
---|
674 | } |
---|
675 | |
---|
676 | /****************************************************** |
---|
677 | Name: console_write |
---|
678 | Input parameters: channel #, termios args |
---|
679 | Output parameters: - |
---|
680 | Description: write to the device |
---|
681 | *****************************************************/ |
---|
682 | rtems_device_driver console_write( |
---|
683 | rtems_device_major_number major, |
---|
684 | rtems_device_minor_number minor, |
---|
685 | void * arg |
---|
686 | ) |
---|
687 | { |
---|
688 | return rtems_termios_write (arg); |
---|
689 | } |
---|
690 | |
---|
691 | /****************************************************** |
---|
692 | Name: console_control |
---|
693 | Input parameters: channel #, termios args |
---|
694 | Output parameters: - |
---|
695 | Description: Handle ioctl request |
---|
696 | *****************************************************/ |
---|
697 | rtems_device_driver console_control( |
---|
698 | rtems_device_major_number major, |
---|
699 | rtems_device_minor_number minor, |
---|
700 | void * arg |
---|
701 | ) |
---|
702 | { |
---|
703 | rtems_libio_ioctl_args_t *args = arg; |
---|
704 | |
---|
705 | if (args->command == TIOCSETA) |
---|
706 | SetAttributes (minor, (struct termios *)args->buffer); |
---|
707 | |
---|
708 | return rtems_termios_ioctl (arg); |
---|
709 | } |
---|