1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS generic MPC5200 BSP | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | Partially based on the code references which are named below. | |
---|
5 | | Adaptions, modifications, enhancements and any recent parts of | |
---|
6 | | the code are: | |
---|
7 | | Copyright (c) 2005 | |
---|
8 | | Embedded Brains GmbH | |
---|
9 | | Obere Lagerstr. 30 | |
---|
10 | | D-82178 Puchheim | |
---|
11 | | Germany | |
---|
12 | | rtems@embedded-brains.de | |
---|
13 | +-----------------------------------------------------------------+ |
---|
14 | | The license and distribution terms for this file may be | |
---|
15 | | found in the file LICENSE in this distribution or at | |
---|
16 | | | |
---|
17 | | http://www.rtems.com/license/LICENSE. | |
---|
18 | | | |
---|
19 | +-----------------------------------------------------------------+ |
---|
20 | | this file contains the console driver functions | |
---|
21 | \*===============================================================*/ |
---|
22 | /***********************************************************************/ |
---|
23 | /* */ |
---|
24 | /* Module: console.c */ |
---|
25 | /* Date: 07/17/2003 */ |
---|
26 | /* Purpose: RTEMS MPC5x00 console driver */ |
---|
27 | /* */ |
---|
28 | /*---------------------------------------------------------------------*/ |
---|
29 | /* */ |
---|
30 | /* Description: */ |
---|
31 | /* */ |
---|
32 | /* The PSCs of mpc5200 are assigned as follows */ |
---|
33 | /* */ |
---|
34 | /* Channel Device Minor Note */ |
---|
35 | /* PSC1 /dev/tty0 0 */ |
---|
36 | /* PSC2 /dev/tty1 1 */ |
---|
37 | /* PSC3 /dev/tty2 2 */ |
---|
38 | /* */ |
---|
39 | /*---------------------------------------------------------------------*/ |
---|
40 | /* */ |
---|
41 | /* Code */ |
---|
42 | /* References: Serial driver for MPC8260ads */ |
---|
43 | /* Module: console-generic.c */ |
---|
44 | /* Project: RTEMS 4.6.0pre1 / MPC8260ads BSP */ |
---|
45 | /* Version 1.3 */ |
---|
46 | /* Date: 2002/11/04 */ |
---|
47 | /* */ |
---|
48 | /* Author(s) / Copyright(s): */ |
---|
49 | /* */ |
---|
50 | /* Author: Jay Monkman (jmonkman@frasca.com) */ |
---|
51 | /* Copyright (C) 1998 by Frasca International, Inc. */ |
---|
52 | /* */ |
---|
53 | /* Derived from c/src/lib/libbsp/m68k/gen360/console/console.c */ |
---|
54 | /* written by: */ |
---|
55 | /* W. Eric Norum */ |
---|
56 | /* Saskatchewan Accelerator Laboratory */ |
---|
57 | /* University of Saskatchewan */ |
---|
58 | /* Saskatoon, Saskatchewan, CANADA */ |
---|
59 | /* eric@skatter.usask.ca */ |
---|
60 | /* */ |
---|
61 | /* COPYRIGHT (c) 1989-1998. */ |
---|
62 | /* On-Line Applications Research Corporation (OAR). */ |
---|
63 | /* */ |
---|
64 | /* Modifications by Darlene Stewart <Darlene.Stewart@iit.nrc.ca> */ |
---|
65 | /* and Charles-Antoine Gauthier <charles.gauthier@iit.nrc.ca> */ |
---|
66 | /* Copyright (c) 1999, National Research Council of Canada */ |
---|
67 | /* */ |
---|
68 | /* Modifications by Andy Dachs <a.dachs@sstl.co.uk> to add MPC8260 */ |
---|
69 | /* support. */ |
---|
70 | /* Copyright (c) 2001, Surrey Satellite Technology Ltd */ |
---|
71 | /* */ |
---|
72 | /* The license and distribution terms for this file may be */ |
---|
73 | /* found in the file LICENSE in this distribution or at */ |
---|
74 | /* http://www.rtems.com/license/LICENSE. */ |
---|
75 | /* */ |
---|
76 | /*---------------------------------------------------------------------*/ |
---|
77 | /* */ |
---|
78 | /* Partially based on the code references which are named above. */ |
---|
79 | /* Adaptions, modifications, enhancements and any recent parts of */ |
---|
80 | /* the code are under the right of */ |
---|
81 | /* */ |
---|
82 | /* IPR Engineering, Dachauer StraÃe 38, D-80335 MÃŒnchen */ |
---|
83 | /* Copyright(C) 2003 */ |
---|
84 | /* */ |
---|
85 | /*---------------------------------------------------------------------*/ |
---|
86 | /* */ |
---|
87 | /* IPR Engineering makes no representation or warranties with */ |
---|
88 | /* respect to the performance of this computer program, and */ |
---|
89 | /* specifically disclaims any responsibility for any damages, */ |
---|
90 | /* special or consequential, connected with the use of this program. */ |
---|
91 | /* */ |
---|
92 | /*---------------------------------------------------------------------*/ |
---|
93 | /* */ |
---|
94 | /* Version history: 1.0 */ |
---|
95 | /* */ |
---|
96 | /***********************************************************************/ |
---|
97 | |
---|
98 | #include <rtems.h> |
---|
99 | #include "../include/mpc5200.h" |
---|
100 | #include <bsp.h> |
---|
101 | #include "../irq/irq.h" |
---|
102 | |
---|
103 | #include <rtems/bspIo.h> |
---|
104 | #include <rtems/libio.h> |
---|
105 | #include <string.h> |
---|
106 | |
---|
107 | |
---|
108 | #define NUM_PORTS MPC5200_PSC_NO |
---|
109 | |
---|
110 | #define PSC1_MINOR 0 |
---|
111 | #define PSC2_MINOR 1 |
---|
112 | #define PSC3_MINOR 2 |
---|
113 | #define PSC4_MINOR 3 |
---|
114 | #define PSC5_MINOR 4 |
---|
115 | #define PSC6_MINOR 5 |
---|
116 | |
---|
117 | uint32_t mpc5200_uart_avail_mask = GEN5200_UART_AVAIL_MASK; |
---|
118 | |
---|
119 | #if defined(UARTS_USE_TERMIOS_INT) |
---|
120 | uint8_t psc_minor_to_irqname[NUM_PORTS] = |
---|
121 | {BSP_SIU_IRQ_PSC1, |
---|
122 | BSP_SIU_IRQ_PSC2, |
---|
123 | BSP_SIU_IRQ_PSC3, |
---|
124 | BSP_SIU_IRQ_PSC4, |
---|
125 | BSP_SIU_IRQ_PSC5, |
---|
126 | BSP_SIU_IRQ_PSC6}; |
---|
127 | |
---|
128 | static int mpc5200_psc_irqname_to_minor(int name) |
---|
129 | { |
---|
130 | int minor; |
---|
131 | uint8_t *chrptr; |
---|
132 | |
---|
133 | uuchrptr = memchr(psc_minor_to_irqname, name, sizeof(psc_minor_to_irqname)); |
---|
134 | if (chrptr != NULL) { |
---|
135 | minor = chrptr - psc_minor_to_irqname; |
---|
136 | } else { |
---|
137 | minor = -1; |
---|
138 | } |
---|
139 | return minor; |
---|
140 | } |
---|
141 | #endif |
---|
142 | |
---|
143 | static void A_BSP_output_char(char c); |
---|
144 | BSP_output_char_function_type BSP_output_char = A_BSP_output_char; |
---|
145 | |
---|
146 | /* Used to handle premature outputs of printk */ |
---|
147 | uint32_t console_initialized = FALSE; |
---|
148 | |
---|
149 | /* per channel info structure */ |
---|
150 | struct per_channel_info |
---|
151 | { |
---|
152 | uint16_t shadow_imr; |
---|
153 | uint8_t shadow_mode1; |
---|
154 | uint8_t shadow_mode2; |
---|
155 | int cur_tx_len; |
---|
156 | int rx_interrupts; |
---|
157 | int tx_interrupts; |
---|
158 | int rx_characters; |
---|
159 | int tx_characters; |
---|
160 | int breaks_detected; |
---|
161 | int framing_errors; |
---|
162 | int parity_errors; |
---|
163 | int overrun_errors; |
---|
164 | }; |
---|
165 | |
---|
166 | /* Used to handle more than one channel */ |
---|
167 | struct per_channel_info channel_info[NUM_PORTS]; |
---|
168 | |
---|
169 | /* |
---|
170 | * XXX: there are only 6 PSCs, but PSC6 has an extra register gap |
---|
171 | * from PSC5, therefore we instantiate seven(!) PSC register sets |
---|
172 | */ |
---|
173 | uint8_t psc_minor_to_regset[MPC5200_PSC_NO] = {0,1,2,3,4,6}; |
---|
174 | |
---|
175 | /* Used to track termios private data for callbacks */ |
---|
176 | struct rtems_termios_tty *ttyp[NUM_PORTS]; |
---|
177 | |
---|
178 | int mpc5200_psc_setAttributes(int minor, const struct termios *t) |
---|
179 | { |
---|
180 | int baud; |
---|
181 | uint8_t csize=0, cstopb, parenb, parodd; |
---|
182 | struct mpc5200_psc *psc = |
---|
183 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
184 | |
---|
185 | /* Baud rate */ |
---|
186 | switch(t->c_cflag & CBAUD) |
---|
187 | { |
---|
188 | default: baud = -1; break; |
---|
189 | case B50: baud = 50; break; |
---|
190 | case B75: baud = 75; break; |
---|
191 | case B110: baud = 110; break; |
---|
192 | case B134: baud = 134; break; |
---|
193 | case B150: baud = 150; break; |
---|
194 | case B200: baud = 200; break; |
---|
195 | case B300: baud = 300; break; |
---|
196 | case B600: baud = 600; break; |
---|
197 | case B1200: baud = 1200; break; |
---|
198 | case B1800: baud = 1800; break; |
---|
199 | case B2400: baud = 2400; break; |
---|
200 | case B4800: baud = 4800; break; |
---|
201 | case B9600: baud = 9600; break; |
---|
202 | case B19200: baud = 19200; break; |
---|
203 | case B38400: baud = 38400; break; |
---|
204 | case B57600: baud = 57600; break; |
---|
205 | case B115200: baud = 115200; break; |
---|
206 | case B230400: baud = 230400; break; |
---|
207 | case B460800: baud = 460800; break; |
---|
208 | } |
---|
209 | |
---|
210 | if(baud > 0) |
---|
211 | { |
---|
212 | |
---|
213 | /* |
---|
214 | * Calculate baud rate |
---|
215 | * round divider to nearest! |
---|
216 | */ |
---|
217 | baud = (IPB_CLOCK + baud *16) / (baud * 32); |
---|
218 | |
---|
219 | } |
---|
220 | |
---|
221 | /* Number of data bits */ |
---|
222 | switch ( t->c_cflag & CSIZE ) |
---|
223 | { |
---|
224 | case CS5: csize = 0x00; break; |
---|
225 | case CS6: csize = 0x01; break; |
---|
226 | case CS7: csize = 0x02; break; |
---|
227 | case CS8: csize = 0x03; break; |
---|
228 | } |
---|
229 | |
---|
230 | /* Stop bits */ |
---|
231 | if(csize == 0) |
---|
232 | { |
---|
233 | |
---|
234 | if(t->c_cflag & CSTOPB) |
---|
235 | cstopb = 0x0F; /* Two stop bits */ |
---|
236 | else |
---|
237 | cstopb = 0x00; /* One stop bit */ |
---|
238 | |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | |
---|
243 | if(t->c_cflag & CSTOPB) |
---|
244 | cstopb = 0x0F; /* Two stop bits */ |
---|
245 | else |
---|
246 | cstopb = 0x07; /* One stop bit */ |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | /* Parity */ |
---|
251 | if (t->c_cflag & PARENB) |
---|
252 | parenb = 0x00; /* Parity enabled on Tx and Rx */ |
---|
253 | else |
---|
254 | parenb = 0x10; /* No parity on Tx and Rx */ |
---|
255 | |
---|
256 | if (t->c_cflag & PARODD) |
---|
257 | parodd = 0x04; /* Odd parity */ |
---|
258 | else |
---|
259 | parodd = 0x00; |
---|
260 | |
---|
261 | /* |
---|
262 | * Set upper timer counter |
---|
263 | */ |
---|
264 | psc->ctur = (uint16_t)(baud >> 16); |
---|
265 | |
---|
266 | /* |
---|
267 | * Set lower timer counter |
---|
268 | */ |
---|
269 | psc->ctlr = (uint16_t)(baud & 0x0000FFFF); |
---|
270 | |
---|
271 | /* |
---|
272 | * Reset mode pointer |
---|
273 | */ |
---|
274 | psc->cr = ((1 << 4) << 8); |
---|
275 | |
---|
276 | /* |
---|
277 | * Set mode1 register |
---|
278 | */ |
---|
279 | channel_info[minor].shadow_mode1 &= ~(0x1F); |
---|
280 | psc->mr = channel_info[minor].shadow_mode1 | (csize | parenb | parodd); |
---|
281 | |
---|
282 | /* |
---|
283 | * Set mode2 register |
---|
284 | */ |
---|
285 | channel_info[minor].shadow_mode2 &= ~(0x0F); |
---|
286 | psc->mr = channel_info[minor].shadow_mode2 | cstopb; |
---|
287 | |
---|
288 | return 0; |
---|
289 | |
---|
290 | } |
---|
291 | |
---|
292 | |
---|
293 | int mpc5200_uart_setAttributes(int minor, const struct termios *t) |
---|
294 | { |
---|
295 | |
---|
296 | |
---|
297 | /* |
---|
298 | * Check that port number is valid |
---|
299 | */ |
---|
300 | if( (minor < PSC1_MINOR) || (minor > NUM_PORTS-1) ) |
---|
301 | return 0; |
---|
302 | |
---|
303 | return mpc5200_psc_setAttributes(minor, t); |
---|
304 | |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | #ifdef UARTS_USE_TERMIOS_INT |
---|
309 | /* |
---|
310 | * Interrupt handlers |
---|
311 | */ |
---|
312 | static void mpc5200_psc_interrupt_handler(rtems_irq_hdl_param handle) |
---|
313 | { |
---|
314 | unsigned char c; |
---|
315 | uint16_t isr; |
---|
316 | int nb_overflow; |
---|
317 | int minor = (int)handle; |
---|
318 | struct mpc5200_psc *psc = |
---|
319 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
320 | |
---|
321 | /* |
---|
322 | * get content of psc interrupt status |
---|
323 | */ |
---|
324 | isr = psc->isr_imr; |
---|
325 | |
---|
326 | /* |
---|
327 | * Character received? |
---|
328 | */ |
---|
329 | if(isr & ISR_RX_RDY_FULL) |
---|
330 | { |
---|
331 | |
---|
332 | channel_info[minor].rx_interrupts++; |
---|
333 | |
---|
334 | |
---|
335 | #ifndef SINGLE_CHAR_MODE |
---|
336 | while(psc->rfnum) |
---|
337 | { |
---|
338 | #endif |
---|
339 | |
---|
340 | /* |
---|
341 | * get the character |
---|
342 | */ |
---|
343 | c = (psc->rb_tb >> 24); |
---|
344 | |
---|
345 | if (ttyp[minor] != NULL) { |
---|
346 | nb_overflow = rtems_termios_enqueue_raw_characters((void *)ttyp[minor], (char *)&c, (int)1); |
---|
347 | channel_info[minor].rx_characters++; |
---|
348 | } |
---|
349 | |
---|
350 | #ifndef SINGLE_CHAR_MODE |
---|
351 | } |
---|
352 | #endif |
---|
353 | |
---|
354 | } |
---|
355 | |
---|
356 | /* |
---|
357 | * Character transmitted ? |
---|
358 | */ |
---|
359 | if(isr & ISR_TX_RDY & channel_info[minor].shadow_imr) |
---|
360 | { |
---|
361 | |
---|
362 | channel_info[minor].tx_interrupts++; |
---|
363 | |
---|
364 | /* |
---|
365 | * mask interrupt |
---|
366 | */ |
---|
367 | psc->isr_imr = channel_info[minor].shadow_imr &= ~(IMR_TX_RDY); |
---|
368 | |
---|
369 | if (ttyp[minor] != NULL) { |
---|
370 | #ifndef SINGLE_CHAR_MODE |
---|
371 | rtems_termios_dequeue_characters((void *)ttyp[minor], channel_info[minor].cur_tx_len); |
---|
372 | |
---|
373 | channel_info[minor].tx_characters += channel_info[minor].cur_tx_len; |
---|
374 | #else |
---|
375 | rtems_termios_dequeue_characters((void *)ttyp[minor], (int)1); |
---|
376 | |
---|
377 | channel_info[minor].tx_characters++; |
---|
378 | #endif |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | if(isr & ISR_ERROR) |
---|
383 | { |
---|
384 | |
---|
385 | if(isr & ISR_RB) |
---|
386 | channel_info[minor].breaks_detected++; |
---|
387 | |
---|
388 | if(isr & ISR_FE) |
---|
389 | channel_info[minor].framing_errors++; |
---|
390 | |
---|
391 | if(isr & ISR_PE) |
---|
392 | channel_info[minor].parity_errors++; |
---|
393 | |
---|
394 | if(isr & ISR_OE) |
---|
395 | channel_info[minor].overrun_errors++; |
---|
396 | |
---|
397 | /* |
---|
398 | * Reset error status |
---|
399 | */ |
---|
400 | psc->cr = ((4 << 4) << 8); |
---|
401 | |
---|
402 | } |
---|
403 | |
---|
404 | } |
---|
405 | |
---|
406 | void mpc5200_psc_enable(const rtems_irq_connect_data* ptr) { |
---|
407 | struct mpc5200_psc *psc; |
---|
408 | int minor = mpc5200_psc_irqname_to_minor(ptr->name); |
---|
409 | |
---|
410 | if (minor >= 0) { |
---|
411 | psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
412 | psc->isr_imr = channel_info[minor].shadow_imr |= |
---|
413 | (IMR_RX_RDY_FULL | IMR_TX_RDY); |
---|
414 | } |
---|
415 | } |
---|
416 | |
---|
417 | |
---|
418 | void mpc5200_psc_disable(const rtems_irq_connect_data* ptr) { |
---|
419 | struct mpc5200_psc *psc; |
---|
420 | int minor = mpc5200_psc_irqname_to_minor(ptr->name); |
---|
421 | |
---|
422 | if (minor >= 0) { |
---|
423 | psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
424 | psc->isr_imr = channel_info[minor].shadow_imr &= |
---|
425 | ~(IMR_RX_RDY_FULL | IMR_TX_RDY); |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | |
---|
430 | int mpc5200_psc_isOn(const rtems_irq_connect_data* ptr) { |
---|
431 | struct mpc5200_psc *psc; |
---|
432 | int minor = mpc5200_psc_irqname_to_minor(ptr->name); |
---|
433 | |
---|
434 | if (minor >= 0) { |
---|
435 | psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
436 | return ((psc->isr_imr & IMR_RX_RDY_FULL) & (psc->isr_imr & IMR_TX_RDY)); |
---|
437 | } |
---|
438 | else { |
---|
439 | return FALSE; |
---|
440 | } |
---|
441 | } |
---|
442 | |
---|
443 | |
---|
444 | static rtems_irq_connect_data consoleIrqData; |
---|
445 | #endif |
---|
446 | |
---|
447 | void mpc5200_uart_psc_initialize(int minor) { |
---|
448 | uint32_t baud_divider; |
---|
449 | struct mpc5200_psc *psc = |
---|
450 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
451 | |
---|
452 | /* |
---|
453 | * Check that minor number is valid |
---|
454 | */ |
---|
455 | if((minor < PSC1_MINOR) || (minor >= (PSC1_MINOR + NUM_PORTS))) |
---|
456 | return; |
---|
457 | |
---|
458 | /* |
---|
459 | * Clear per channel info |
---|
460 | */ |
---|
461 | memset((void *)&channel_info[minor], 0, sizeof(struct per_channel_info)); |
---|
462 | |
---|
463 | |
---|
464 | /* |
---|
465 | * Reset receiver and transmitter |
---|
466 | */ |
---|
467 | psc->cr = ((2 << 4) << 8); |
---|
468 | psc->cr = ((3 << 4) << 8); |
---|
469 | |
---|
470 | /* |
---|
471 | * Reset mode pointer |
---|
472 | */ |
---|
473 | psc->cr = ((1 << 4) << 8); |
---|
474 | |
---|
475 | /* |
---|
476 | * Set clock select register |
---|
477 | */ |
---|
478 | psc->sr_csr = 0; |
---|
479 | |
---|
480 | /* |
---|
481 | * Set mode1 register |
---|
482 | */ |
---|
483 | psc->mr = channel_info[minor].shadow_mode1 = 0x33; /* 8Bit / no parity */ |
---|
484 | |
---|
485 | /* |
---|
486 | * Set mode2 register |
---|
487 | */ |
---|
488 | psc->mr = channel_info[minor].shadow_mode2 = 7; /* 1 stop bit */ |
---|
489 | |
---|
490 | /* |
---|
491 | * Set rx FIFO alarm |
---|
492 | */ |
---|
493 | psc->rfalarm = RX_FIFO_SIZE - 1; |
---|
494 | |
---|
495 | /* |
---|
496 | * Set tx FIFO alarm |
---|
497 | */ |
---|
498 | psc->tfalarm = 1; |
---|
499 | |
---|
500 | baud_divider = (IPB_CLOCK + GEN5200_CONSOLE_BAUD *16) / (GEN5200_CONSOLE_BAUD * 32); |
---|
501 | |
---|
502 | /* |
---|
503 | * Set upper timer counter |
---|
504 | */ |
---|
505 | psc->ctur = baud_divider >> 16; |
---|
506 | |
---|
507 | /* |
---|
508 | * Set lower timer counter |
---|
509 | */ |
---|
510 | |
---|
511 | psc->ctlr = baud_divider & 0x0000ffff; |
---|
512 | |
---|
513 | /* |
---|
514 | * Disable Frame mode / set granularity 0 |
---|
515 | */ |
---|
516 | psc->tfcntl = 0; |
---|
517 | |
---|
518 | #ifdef UARTS_USE_TERMIOS_INT |
---|
519 | /* |
---|
520 | * Tie interrupt dependent routines |
---|
521 | */ |
---|
522 | consoleIrqData.on = mpc5200_psc_enable; |
---|
523 | consoleIrqData.off = mpc5200_psc_disable; |
---|
524 | consoleIrqData.isOn = mpc5200_psc_isOn; |
---|
525 | consoleIrqData.handle = (rtems_irq_hdl_param)minor; |
---|
526 | consoleIrqData.hdl = (rtems_irq_hdl)mpc5200_psc_interrupt_handler; |
---|
527 | |
---|
528 | /* |
---|
529 | * Tie interrupt handler |
---|
530 | */ |
---|
531 | consoleIrqData.name = psc_minor_to_irqname[minor]; |
---|
532 | |
---|
533 | /* |
---|
534 | * Install rtems irq handler |
---|
535 | */ |
---|
536 | if(!BSP_install_rtems_irq_handler (&consoleIrqData)) |
---|
537 | { |
---|
538 | |
---|
539 | printk("Unable to connect PSC Irq handler\n"); |
---|
540 | rtems_fatal_error_occurred(1); |
---|
541 | |
---|
542 | } |
---|
543 | #endif |
---|
544 | |
---|
545 | /* |
---|
546 | * Reset rx fifo errors Error/UF/OF |
---|
547 | */ |
---|
548 | psc->rfstat |= 0x70; |
---|
549 | |
---|
550 | /* |
---|
551 | * Reset tx fifo errors Error/UF/OF |
---|
552 | */ |
---|
553 | psc->tfstat |= 0x70; |
---|
554 | |
---|
555 | #ifdef UARTS_USE_TERMIOS_INT |
---|
556 | /* |
---|
557 | * Unmask receive interrupt |
---|
558 | */ |
---|
559 | psc->isr_imr = channel_info[minor].shadow_imr = IMR_RX_RDY_FULL; |
---|
560 | #endif |
---|
561 | |
---|
562 | /* |
---|
563 | * Enable receiver |
---|
564 | */ |
---|
565 | psc->cr = ((1 << 0) << 8); |
---|
566 | |
---|
567 | /* |
---|
568 | * Enable transmitter |
---|
569 | */ |
---|
570 | psc->cr = ((1 << 2) << 8); |
---|
571 | |
---|
572 | } |
---|
573 | |
---|
574 | |
---|
575 | int mpc5200_uart_pollRead(int minor) |
---|
576 | { |
---|
577 | unsigned char c; |
---|
578 | struct mpc5200_psc *psc = |
---|
579 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
580 | |
---|
581 | if(psc->sr_csr & (1 << 8)) |
---|
582 | c = (psc->rb_tb >> 24); |
---|
583 | else |
---|
584 | return -1; |
---|
585 | |
---|
586 | return c; |
---|
587 | |
---|
588 | } |
---|
589 | |
---|
590 | |
---|
591 | int mpc5200_uart_pollWrite(int minor, const char *buf, int len) |
---|
592 | { |
---|
593 | const char *tmp_buf = buf; |
---|
594 | struct mpc5200_psc *psc = |
---|
595 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
596 | |
---|
597 | while(len--) |
---|
598 | { |
---|
599 | |
---|
600 | while(!(psc->sr_csr & (1 << 11))) |
---|
601 | continue; |
---|
602 | |
---|
603 | /*rtems_cache_flush_multiple_data_lines( (void *)buf, 1);*/ |
---|
604 | |
---|
605 | psc->rb_tb = (*tmp_buf << 24); |
---|
606 | |
---|
607 | tmp_buf++; |
---|
608 | |
---|
609 | } |
---|
610 | |
---|
611 | return 0; |
---|
612 | |
---|
613 | } |
---|
614 | |
---|
615 | |
---|
616 | int mpc5200_uart_write(int minor, const char *buf, int len) |
---|
617 | { |
---|
618 | int frame_len = len; |
---|
619 | const char *frame_buf = buf; |
---|
620 | struct mpc5200_psc *psc = |
---|
621 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
622 | |
---|
623 | /* |
---|
624 | * Check tx fifo space |
---|
625 | */ |
---|
626 | if(len > (TX_FIFO_SIZE - psc->tfnum)) |
---|
627 | frame_len = TX_FIFO_SIZE - psc->tfnum; |
---|
628 | |
---|
629 | #ifndef SINGLE_CHAR_MODE |
---|
630 | channel_info[minor].cur_tx_len = frame_len; |
---|
631 | #else |
---|
632 | frame_len = 1; |
---|
633 | #endif |
---|
634 | |
---|
635 | /*rtems_cache_flush_multiple_data_lines( (void *)frame_buf, frame_len);*/ |
---|
636 | |
---|
637 | while(frame_len--) |
---|
638 | /* perform byte write to avoid extra NUL characters */ |
---|
639 | (* (volatile char *)&(psc->rb_tb)) = *frame_buf++; |
---|
640 | |
---|
641 | /* |
---|
642 | * unmask interrupt |
---|
643 | */ |
---|
644 | psc->isr_imr = channel_info[minor].shadow_imr |= IMR_TX_RDY; |
---|
645 | |
---|
646 | return 0; |
---|
647 | |
---|
648 | } |
---|
649 | |
---|
650 | /* |
---|
651 | * Print functions prototyped in bspIo.h |
---|
652 | */ |
---|
653 | static void A_BSP_output_char( char c ) |
---|
654 | { |
---|
655 | char cr = '\r'; |
---|
656 | |
---|
657 | /* |
---|
658 | * If we are using U-Boot, then the console is already initialized |
---|
659 | * and we can just poll bytes out at any time. |
---|
660 | */ |
---|
661 | #if !defined(HAS_UBOOT) |
---|
662 | if (console_initialized == FALSE ) |
---|
663 | return |
---|
664 | #endif |
---|
665 | |
---|
666 | #define PRINTK_WRITE mpc5200_uart_pollWrite |
---|
667 | |
---|
668 | PRINTK_WRITE(PRINTK_MINOR, &c, 1 ); |
---|
669 | |
---|
670 | if( c == '\n' ) |
---|
671 | PRINTK_WRITE( PRINTK_MINOR, &cr, 1 ); |
---|
672 | } |
---|
673 | |
---|
674 | /* |
---|
675 | *************** |
---|
676 | * BOILERPLATE * |
---|
677 | *************** |
---|
678 | * |
---|
679 | * All these functions are prototyped in rtems/c/src/lib/include/console.h. |
---|
680 | */ |
---|
681 | |
---|
682 | |
---|
683 | /* |
---|
684 | * Initialize and register the device |
---|
685 | */ |
---|
686 | rtems_device_driver console_initialize(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
687 | { |
---|
688 | |
---|
689 | rtems_status_code status; |
---|
690 | rtems_device_minor_number console_minor; |
---|
691 | char dev_name[] = "/dev/ttyx"; |
---|
692 | uint32_t tty_num = 0; |
---|
693 | |
---|
694 | /* |
---|
695 | * Always use and set up TERMIOS |
---|
696 | */ |
---|
697 | console_minor = PSC1_MINOR; |
---|
698 | rtems_termios_initialize(); |
---|
699 | |
---|
700 | for (console_minor = PSC1_MINOR; |
---|
701 | console_minor < PSC1_MINOR + NUM_PORTS; |
---|
702 | console_minor++) { |
---|
703 | /* |
---|
704 | * check, whether UART is available for this board |
---|
705 | */ |
---|
706 | if (0 != ((1 << console_minor) & (mpc5200_uart_avail_mask))) { |
---|
707 | /* |
---|
708 | * Do device-specific initialization and registration for Motorola IceCube |
---|
709 | */ |
---|
710 | mpc5200_uart_psc_initialize(console_minor); /* /dev/tty0 */ |
---|
711 | dev_name[8] = '0' + tty_num; |
---|
712 | status = rtems_io_register_name (dev_name, major, console_minor); |
---|
713 | |
---|
714 | if(status != RTEMS_SUCCESSFUL) |
---|
715 | { |
---|
716 | rtems_fatal_error_occurred(status); |
---|
717 | } |
---|
718 | |
---|
719 | tty_num++; |
---|
720 | } |
---|
721 | } |
---|
722 | |
---|
723 | /* Now register the RTEMS console */ |
---|
724 | status = rtems_io_register_name ("/dev/console", major, PSC1_MINOR); |
---|
725 | |
---|
726 | if(status != RTEMS_SUCCESSFUL) |
---|
727 | rtems_fatal_error_occurred (status); |
---|
728 | |
---|
729 | console_initialized = TRUE; |
---|
730 | return RTEMS_SUCCESSFUL; |
---|
731 | |
---|
732 | } |
---|
733 | |
---|
734 | |
---|
735 | /* |
---|
736 | * Open the device |
---|
737 | */ |
---|
738 | rtems_device_driver console_open(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
739 | { |
---|
740 | #ifdef UARTS_USE_TERMIOS_INT |
---|
741 | rtems_libio_open_close_args_t *args = arg; |
---|
742 | #endif |
---|
743 | rtems_status_code sc; |
---|
744 | |
---|
745 | #ifdef UARTS_USE_TERMIOS_INT |
---|
746 | static const rtems_termios_callbacks intrCallbacks = |
---|
747 | { |
---|
748 | NULL, /* firstOpen */ |
---|
749 | NULL, /* lastClose */ |
---|
750 | NULL, /* pollRead */ |
---|
751 | mpc5200_uart_write, /* write */ |
---|
752 | mpc5200_uart_setAttributes, /* setAttributes */ |
---|
753 | NULL, |
---|
754 | NULL, |
---|
755 | 1 /* outputUsesInterrupts */ |
---|
756 | }; |
---|
757 | #else |
---|
758 | static const rtems_termios_callbacks pollCallbacks = |
---|
759 | { |
---|
760 | NULL, /* firstOpen */ |
---|
761 | NULL, /* lastClose */ |
---|
762 | mpc5200_uart_pollRead, /* pollRead */ |
---|
763 | mpc5200_uart_pollWrite, /* write */ |
---|
764 | mpc5200_uart_setAttributes, /* setAttributes */ |
---|
765 | NULL, |
---|
766 | NULL, |
---|
767 | 0 /* output don't use Interrupts */ |
---|
768 | }; |
---|
769 | #endif |
---|
770 | |
---|
771 | if(minor > NUM_PORTS - 1) |
---|
772 | return RTEMS_INVALID_NUMBER; |
---|
773 | |
---|
774 | #ifdef UARTS_USE_TERMIOS_INT |
---|
775 | sc = rtems_termios_open( major, minor, arg, &intrCallbacks ); |
---|
776 | ttyp[minor] = args->iop->data1; /* Keep cookie returned by termios_open */ |
---|
777 | #else /* RTEMS polled I/O with termios */ |
---|
778 | sc = rtems_termios_open( major, minor, arg, &pollCallbacks ); |
---|
779 | #endif |
---|
780 | |
---|
781 | return sc; |
---|
782 | |
---|
783 | } |
---|
784 | |
---|
785 | |
---|
786 | /* |
---|
787 | * Close the device |
---|
788 | */ |
---|
789 | rtems_device_driver console_close(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
790 | { |
---|
791 | |
---|
792 | if ( minor > NUM_PORTS-1 ) |
---|
793 | return RTEMS_INVALID_NUMBER; |
---|
794 | |
---|
795 | ttyp[minor] = NULL; /* mark for int handler: tty no longer open */ |
---|
796 | |
---|
797 | return rtems_termios_close( arg ); |
---|
798 | return 0; |
---|
799 | |
---|
800 | } |
---|
801 | |
---|
802 | |
---|
803 | /* |
---|
804 | * Read from the device |
---|
805 | */ |
---|
806 | rtems_device_driver console_read(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
807 | { |
---|
808 | |
---|
809 | if(minor > NUM_PORTS-1) |
---|
810 | return RTEMS_INVALID_NUMBER; |
---|
811 | |
---|
812 | return rtems_termios_read(arg); |
---|
813 | |
---|
814 | return 0; |
---|
815 | |
---|
816 | } |
---|
817 | |
---|
818 | |
---|
819 | /* |
---|
820 | * Write to the device |
---|
821 | */ |
---|
822 | rtems_device_driver console_write(rtems_device_major_number major,rtems_device_minor_number minor,void *arg) |
---|
823 | { |
---|
824 | |
---|
825 | if( minor > NUM_PORTS-1 ) |
---|
826 | return RTEMS_INVALID_NUMBER; |
---|
827 | |
---|
828 | return rtems_termios_write(arg); |
---|
829 | |
---|
830 | return 0; |
---|
831 | } |
---|
832 | |
---|
833 | |
---|
834 | /* |
---|
835 | * Handle ioctl request. |
---|
836 | */ |
---|
837 | rtems_device_driver console_control(rtems_device_major_number major,rtems_device_minor_number minor,void *arg) |
---|
838 | { |
---|
839 | |
---|
840 | if ( minor > NUM_PORTS-1 ) |
---|
841 | return RTEMS_INVALID_NUMBER; |
---|
842 | |
---|
843 | return rtems_termios_ioctl(arg); |
---|
844 | |
---|
845 | return 0; |
---|
846 | |
---|
847 | } |
---|