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.OARcorp.com/rtems/license.html. */ |
---|
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 | uint8_t psc_minor_to_irqname[NUM_PORTS] = |
---|
120 | {BSP_SIU_IRQ_PSC1, |
---|
121 | BSP_SIU_IRQ_PSC2, |
---|
122 | BSP_SIU_IRQ_PSC3, |
---|
123 | BSP_SIU_IRQ_PSC4, |
---|
124 | BSP_SIU_IRQ_PSC5, |
---|
125 | BSP_SIU_IRQ_PSC6}; |
---|
126 | static int mpc5200_psc_irqname_to_minor(int name) |
---|
127 | { |
---|
128 | int minor; |
---|
129 | uint8_t *chrptr; |
---|
130 | |
---|
131 | chrptr = memchr(psc_minor_to_irqname, |
---|
132 | name, |
---|
133 | sizeof(psc_minor_to_irqname)); |
---|
134 | if (chrptr != NULL) { |
---|
135 | minor = chrptr - psc_minor_to_irqname; |
---|
136 | } |
---|
137 | else { |
---|
138 | minor = -1; |
---|
139 | } |
---|
140 | return minor; |
---|
141 | } |
---|
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 | */ |
---|
216 | baud = IPB_CLOCK / (baud * 32); |
---|
217 | |
---|
218 | } |
---|
219 | |
---|
220 | /* Number of data bits */ |
---|
221 | switch ( t->c_cflag & CSIZE ) |
---|
222 | { |
---|
223 | case CS5: csize = 0x00; break; |
---|
224 | case CS6: csize = 0x01; break; |
---|
225 | case CS7: csize = 0x02; break; |
---|
226 | case CS8: csize = 0x03; break; |
---|
227 | } |
---|
228 | |
---|
229 | /* Stop bits */ |
---|
230 | if(csize == 0) |
---|
231 | { |
---|
232 | |
---|
233 | if(t->c_cflag & CSTOPB) |
---|
234 | cstopb = 0x0F; /* Two stop bits */ |
---|
235 | else |
---|
236 | cstopb = 0x00; /* One stop bit */ |
---|
237 | |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | |
---|
242 | if(t->c_cflag & CSTOPB) |
---|
243 | cstopb = 0x0F; /* Two stop bits */ |
---|
244 | else |
---|
245 | cstopb = 0x07; /* One stop bit */ |
---|
246 | |
---|
247 | } |
---|
248 | |
---|
249 | /* Parity */ |
---|
250 | if (t->c_cflag & PARENB) |
---|
251 | parenb = 0x00; /* Parity enabled on Tx and Rx */ |
---|
252 | else |
---|
253 | parenb = 0x10; /* No parity on Tx and Rx */ |
---|
254 | |
---|
255 | if (t->c_cflag & PARODD) |
---|
256 | parodd = 0x04; /* Odd parity */ |
---|
257 | else |
---|
258 | parodd = 0x00; |
---|
259 | |
---|
260 | /* |
---|
261 | * Set upper timer counter |
---|
262 | */ |
---|
263 | psc->ctur = (uint16_t)(baud >> 16); |
---|
264 | |
---|
265 | /* |
---|
266 | * Set lower timer counter |
---|
267 | */ |
---|
268 | psc->ctlr = (uint16_t)(baud & 0x0000FFFF); |
---|
269 | |
---|
270 | /* |
---|
271 | * Reset mode pointer |
---|
272 | */ |
---|
273 | psc->cr = ((1 << 4) << 8); |
---|
274 | |
---|
275 | /* |
---|
276 | * Set mode1 register |
---|
277 | */ |
---|
278 | channel_info[minor].shadow_mode1 &= ~(0x1F); |
---|
279 | psc->mr = channel_info[minor].shadow_mode1 | (csize | parenb | parodd); |
---|
280 | |
---|
281 | /* |
---|
282 | * Set mode2 register |
---|
283 | */ |
---|
284 | channel_info[minor].shadow_mode2 &= ~(0x0F); |
---|
285 | psc->mr = channel_info[minor].shadow_mode2 | cstopb; |
---|
286 | |
---|
287 | return 0; |
---|
288 | |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | int mpc5200_uart_setAttributes(int minor, const struct termios *t) |
---|
293 | { |
---|
294 | |
---|
295 | |
---|
296 | /* |
---|
297 | * Check that port number is valid |
---|
298 | */ |
---|
299 | if( (minor < PSC1_MINOR) || (minor > NUM_PORTS-1) ) |
---|
300 | return 0; |
---|
301 | |
---|
302 | return mpc5200_psc_setAttributes(minor, t); |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | |
---|
307 | #ifdef UARTS_USE_TERMIOS_INT |
---|
308 | /* |
---|
309 | * Interrupt handlers |
---|
310 | */ |
---|
311 | static void mpc5200_psc_interrupt_handler(rtems_irq_hdl_param handle) |
---|
312 | { |
---|
313 | unsigned char c; |
---|
314 | uint16_t isr; |
---|
315 | int nb_overflow; |
---|
316 | int minor = (int)handle; |
---|
317 | struct mpc5200_psc *psc = |
---|
318 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
319 | |
---|
320 | /* |
---|
321 | * get content of psc interrupt status |
---|
322 | */ |
---|
323 | isr = psc->isr_imr; |
---|
324 | |
---|
325 | /* |
---|
326 | * Character received? |
---|
327 | */ |
---|
328 | if(isr & ISR_RX_RDY_FULL) |
---|
329 | { |
---|
330 | |
---|
331 | channel_info[minor].rx_interrupts++; |
---|
332 | |
---|
333 | |
---|
334 | #ifndef SINGLE_CHAR_MODE |
---|
335 | while(psc->rfnum) |
---|
336 | { |
---|
337 | #endif |
---|
338 | |
---|
339 | /* |
---|
340 | * get the character |
---|
341 | */ |
---|
342 | c = (psc->rb_tb >> 24); |
---|
343 | |
---|
344 | nb_overflow = rtems_termios_enqueue_raw_characters((void *)ttyp[minor], (char *)&c, (int)1); |
---|
345 | |
---|
346 | channel_info[minor].rx_characters++; |
---|
347 | |
---|
348 | #ifndef SINGLE_CHAR_MODE |
---|
349 | } |
---|
350 | #endif |
---|
351 | |
---|
352 | } |
---|
353 | |
---|
354 | /* |
---|
355 | * Character transmitted ? |
---|
356 | */ |
---|
357 | if(isr & ISR_TX_RDY & channel_info[minor].shadow_imr) |
---|
358 | { |
---|
359 | |
---|
360 | channel_info[minor].tx_interrupts++; |
---|
361 | |
---|
362 | /* |
---|
363 | * mask interrupt |
---|
364 | */ |
---|
365 | psc->isr_imr = channel_info[minor].shadow_imr &= ~(IMR_TX_RDY); |
---|
366 | |
---|
367 | #ifndef SINGLE_CHAR_MODE |
---|
368 | rtems_termios_dequeue_characters((void *)ttyp[minor], channel_info[minor].cur_tx_len); |
---|
369 | |
---|
370 | channel_info[minor].tx_characters += channel_info[minor].cur_tx_len; |
---|
371 | #else |
---|
372 | rtems_termios_dequeue_characters((void *)ttyp[minor], (int)1); |
---|
373 | |
---|
374 | channel_info[minor].tx_characters++; |
---|
375 | #endif |
---|
376 | |
---|
377 | } |
---|
378 | |
---|
379 | if(isr & ISR_ERROR) |
---|
380 | { |
---|
381 | |
---|
382 | if(isr & ISR_RB) |
---|
383 | channel_info[minor].breaks_detected++; |
---|
384 | |
---|
385 | if(isr & ISR_FE) |
---|
386 | channel_info[minor].framing_errors++; |
---|
387 | |
---|
388 | if(isr & ISR_PE) |
---|
389 | channel_info[minor].parity_errors++; |
---|
390 | |
---|
391 | if(isr & ISR_PE) |
---|
392 | channel_info[minor].overrun_errors++; |
---|
393 | |
---|
394 | /* |
---|
395 | * Reset error status |
---|
396 | */ |
---|
397 | psc->cr = ((4 << 4) << 8); |
---|
398 | |
---|
399 | } |
---|
400 | |
---|
401 | } |
---|
402 | |
---|
403 | void mpc5200_psc_enable(const rtems_irq_connect_data* ptr) { |
---|
404 | struct mpc5200_psc *psc; |
---|
405 | int minor = mpc5200_psc_irqname_to_minor(ptr->name); |
---|
406 | |
---|
407 | if (minor >= 0) { |
---|
408 | psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
409 | psc->isr_imr = channel_info[minor].shadow_imr |= |
---|
410 | (IMR_RX_RDY_FULL | IMR_TX_RDY); |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | |
---|
415 | void mpc5200_psc_disable(const rtems_irq_connect_data* ptr) { |
---|
416 | struct mpc5200_psc *psc; |
---|
417 | int minor = mpc5200_psc_irqname_to_minor(ptr->name); |
---|
418 | |
---|
419 | if (minor >= 0) { |
---|
420 | psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
421 | psc->isr_imr = channel_info[minor].shadow_imr &= |
---|
422 | ~(IMR_RX_RDY_FULL | IMR_TX_RDY); |
---|
423 | } |
---|
424 | } |
---|
425 | |
---|
426 | |
---|
427 | int mpc5200_psc_isOn(const rtems_irq_connect_data* ptr) { |
---|
428 | struct mpc5200_psc *psc; |
---|
429 | int minor = mpc5200_psc_irqname_to_minor(ptr->name); |
---|
430 | |
---|
431 | if (minor >= 0) { |
---|
432 | psc = (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
433 | return ((psc->isr_imr & IMR_RX_RDY_FULL) & (psc->isr_imr & IMR_TX_RDY)); |
---|
434 | } |
---|
435 | else { |
---|
436 | return FALSE; |
---|
437 | } |
---|
438 | } |
---|
439 | |
---|
440 | |
---|
441 | static rtems_irq_connect_data consoleIrqData; |
---|
442 | #endif |
---|
443 | |
---|
444 | void mpc5200_uart_psc_initialize(int minor) { |
---|
445 | uint32_t baud_divider; |
---|
446 | struct mpc5200_psc *psc = |
---|
447 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
448 | |
---|
449 | /* |
---|
450 | * Check that minor number is valid |
---|
451 | */ |
---|
452 | if((minor < PSC1_MINOR) || (minor >= (PSC1_MINOR + NUM_PORTS))) |
---|
453 | return; |
---|
454 | |
---|
455 | /* |
---|
456 | * Clear per channel info |
---|
457 | */ |
---|
458 | memset((void *)&channel_info[minor], 0, sizeof(struct per_channel_info)); |
---|
459 | |
---|
460 | |
---|
461 | /* |
---|
462 | * Reset receiver and transmitter |
---|
463 | */ |
---|
464 | psc->cr = ((2 << 4) << 8); |
---|
465 | psc->cr = ((3 << 4) << 8); |
---|
466 | |
---|
467 | /* |
---|
468 | * Reset mode pointer |
---|
469 | */ |
---|
470 | psc->cr = ((1 << 4) << 8); |
---|
471 | |
---|
472 | /* |
---|
473 | * Set clock select register |
---|
474 | */ |
---|
475 | psc->sr_csr = 0; |
---|
476 | |
---|
477 | /* |
---|
478 | * Set mode1 register |
---|
479 | */ |
---|
480 | psc->mr = channel_info[minor].shadow_mode1 = 0x33; /* 8Bit / no parity */ |
---|
481 | |
---|
482 | /* |
---|
483 | * Set mode2 register |
---|
484 | */ |
---|
485 | psc->mr = channel_info[minor].shadow_mode2 = 7; /* 1 stop bit */ |
---|
486 | |
---|
487 | /* |
---|
488 | * Set rx FIFO alarm |
---|
489 | */ |
---|
490 | psc->rfalarm = RX_FIFO_SIZE - 1; |
---|
491 | |
---|
492 | /* |
---|
493 | * Set tx FIFO alarm |
---|
494 | */ |
---|
495 | psc->tfalarm = 1; |
---|
496 | |
---|
497 | baud_divider = IPB_CLOCK / (9600 * 32); |
---|
498 | /* |
---|
499 | * Set upper timer counter |
---|
500 | */ |
---|
501 | psc->ctur = baud_divider >> 16; |
---|
502 | |
---|
503 | |
---|
504 | /* |
---|
505 | * Set lower timer counter |
---|
506 | */ |
---|
507 | |
---|
508 | psc->ctlr = baud_divider & 0x0000ffff; |
---|
509 | |
---|
510 | /* |
---|
511 | * Disable Frame mode / set granularity 0 |
---|
512 | */ |
---|
513 | psc->tfcntl = 0; |
---|
514 | |
---|
515 | #ifdef UARTS_USE_TERMIOS_INT |
---|
516 | /* |
---|
517 | * Tie interrupt dependent routines |
---|
518 | */ |
---|
519 | consoleIrqData.on = mpc5200_psc_enable; |
---|
520 | consoleIrqData.off = mpc5200_psc_disable; |
---|
521 | consoleIrqData.isOn = mpc5200_psc_isOn; |
---|
522 | consoleIrqData.handle = (rtems_irq_hdl_param)minor; |
---|
523 | consoleIrqData.hdl = (rtems_irq_hdl)mpc5200_psc_interrupt_handler; |
---|
524 | |
---|
525 | /* |
---|
526 | * Tie interrupt handler |
---|
527 | */ |
---|
528 | consoleIrqData.name = psc_minor_to_irqname[minor]; |
---|
529 | |
---|
530 | /* |
---|
531 | * Install rtems irq handler |
---|
532 | */ |
---|
533 | if(!BSP_install_rtems_irq_handler (&consoleIrqData)) |
---|
534 | { |
---|
535 | |
---|
536 | printk("Unable to connect PSC Irq handler\n"); |
---|
537 | rtems_fatal_error_occurred(1); |
---|
538 | |
---|
539 | } |
---|
540 | #endif |
---|
541 | |
---|
542 | /* |
---|
543 | * Reset rx fifo errors Error/UF/OF |
---|
544 | */ |
---|
545 | psc->rfstat |= 0x70; |
---|
546 | |
---|
547 | /* |
---|
548 | * Reset tx fifo errors Error/UF/OF |
---|
549 | */ |
---|
550 | psc->tfstat |= 0x70; |
---|
551 | |
---|
552 | #ifdef UARTS_USE_TERMIOS_INT |
---|
553 | /* |
---|
554 | * Unmask receive interrupt |
---|
555 | */ |
---|
556 | psc->isr_imr = channel_info[minor].shadow_imr = IMR_RX_RDY_FULL; |
---|
557 | #endif |
---|
558 | |
---|
559 | /* |
---|
560 | * Enable receiver |
---|
561 | */ |
---|
562 | psc->cr = ((1 << 0) << 8); |
---|
563 | |
---|
564 | /* |
---|
565 | * Enable transmitter |
---|
566 | */ |
---|
567 | psc->cr = ((1 << 2) << 8); |
---|
568 | |
---|
569 | } |
---|
570 | |
---|
571 | |
---|
572 | int mpc5200_uart_pollRead(int minor) |
---|
573 | { |
---|
574 | unsigned char c; |
---|
575 | struct mpc5200_psc *psc = |
---|
576 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
577 | |
---|
578 | if(psc->sr_csr & (1 << 8)) |
---|
579 | c = (psc->rb_tb >> 24); |
---|
580 | else |
---|
581 | return -1; |
---|
582 | |
---|
583 | return c; |
---|
584 | |
---|
585 | } |
---|
586 | |
---|
587 | |
---|
588 | int mpc5200_uart_pollWrite(int minor, const char *buf, int len) |
---|
589 | { |
---|
590 | const char *tmp_buf = buf; |
---|
591 | struct mpc5200_psc *psc = |
---|
592 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
593 | |
---|
594 | while(len--) |
---|
595 | { |
---|
596 | |
---|
597 | while(!(psc->sr_csr & (1 << 11))) |
---|
598 | continue; |
---|
599 | |
---|
600 | /*rtems_cache_flush_multiple_data_lines( (void *)buf, 1);*/ |
---|
601 | |
---|
602 | psc->rb_tb = (*tmp_buf << 24); |
---|
603 | |
---|
604 | tmp_buf++; |
---|
605 | |
---|
606 | } |
---|
607 | |
---|
608 | return 0; |
---|
609 | |
---|
610 | } |
---|
611 | |
---|
612 | |
---|
613 | int mpc5200_uart_write(int minor, const char *buf, int len) |
---|
614 | { |
---|
615 | int frame_len = len; |
---|
616 | const char *frame_buf = buf; |
---|
617 | struct mpc5200_psc *psc = |
---|
618 | (struct mpc5200_psc *)(&mpc5200.psc[psc_minor_to_regset[minor]]); |
---|
619 | |
---|
620 | /* |
---|
621 | * Check tx fifo space |
---|
622 | */ |
---|
623 | if(len > (TX_FIFO_SIZE - psc->tfnum)) |
---|
624 | frame_len = TX_FIFO_SIZE - psc->tfnum; |
---|
625 | |
---|
626 | #ifndef SINGLE_CHAR_MODE |
---|
627 | channel_info[minor].cur_tx_len = frame_len; |
---|
628 | #else |
---|
629 | frame_len = 1; |
---|
630 | #endif |
---|
631 | |
---|
632 | /*rtems_cache_flush_multiple_data_lines( (void *)frame_buf, frame_len);*/ |
---|
633 | |
---|
634 | while(frame_len--) |
---|
635 | /* perform byte write to avoid extra NUL characters */ |
---|
636 | (* (volatile char *)&(psc->rb_tb)) = *frame_buf++; |
---|
637 | |
---|
638 | /* |
---|
639 | * unmask interrupt |
---|
640 | */ |
---|
641 | psc->isr_imr = channel_info[minor].shadow_imr |= IMR_TX_RDY; |
---|
642 | |
---|
643 | return 0; |
---|
644 | |
---|
645 | } |
---|
646 | |
---|
647 | /* |
---|
648 | * Print functions prototyped in bspIo.h |
---|
649 | */ |
---|
650 | static void A_BSP_output_char( char c ) |
---|
651 | { |
---|
652 | char cr = '\r'; |
---|
653 | |
---|
654 | |
---|
655 | if(console_initialized == TRUE) |
---|
656 | { |
---|
657 | |
---|
658 | #define PRINTK_WRITE mpc5200_uart_pollWrite |
---|
659 | |
---|
660 | PRINTK_WRITE(PRINTK_MINOR, &c, 1 ); |
---|
661 | |
---|
662 | if( c == '\n' ) |
---|
663 | PRINTK_WRITE( PRINTK_MINOR, &cr, 1 ); |
---|
664 | |
---|
665 | } |
---|
666 | |
---|
667 | } |
---|
668 | |
---|
669 | /* |
---|
670 | *************** |
---|
671 | * BOILERPLATE * |
---|
672 | *************** |
---|
673 | * |
---|
674 | * All these functions are prototyped in rtems/c/src/lib/include/console.h. |
---|
675 | */ |
---|
676 | |
---|
677 | |
---|
678 | /* |
---|
679 | * Initialize and register the device |
---|
680 | */ |
---|
681 | rtems_device_driver console_initialize(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
682 | { |
---|
683 | |
---|
684 | rtems_status_code status; |
---|
685 | rtems_device_minor_number console_minor; |
---|
686 | char dev_name[] = "/dev/ttyx"; |
---|
687 | /* |
---|
688 | * Always use and set up TERMIOS |
---|
689 | */ |
---|
690 | console_minor = PSC1_MINOR; |
---|
691 | rtems_termios_initialize(); |
---|
692 | |
---|
693 | for (console_minor = PSC1_MINOR; |
---|
694 | console_minor < PSC1_MINOR + NUM_PORTS; |
---|
695 | console_minor++) { |
---|
696 | /* |
---|
697 | * check, whether UART is available for this board |
---|
698 | */ |
---|
699 | if (0 != ((1 << console_minor) & (mpc5200_uart_avail_mask))) { |
---|
700 | /* |
---|
701 | * Do device-specific initialization and registration for Motorola IceCube |
---|
702 | */ |
---|
703 | mpc5200_uart_psc_initialize(console_minor); /* /dev/tty0 */ |
---|
704 | dev_name[8] = '0' + console_minor - PSC1_MINOR; |
---|
705 | status = rtems_io_register_name (dev_name, major, console_minor); |
---|
706 | |
---|
707 | if(status != RTEMS_SUCCESSFUL) |
---|
708 | rtems_fatal_error_occurred(status); |
---|
709 | } |
---|
710 | } |
---|
711 | /* Now register the RTEMS console */ |
---|
712 | status = rtems_io_register_name ("/dev/console", major, PSC1_MINOR); |
---|
713 | |
---|
714 | if(status != RTEMS_SUCCESSFUL) |
---|
715 | rtems_fatal_error_occurred (status); |
---|
716 | |
---|
717 | console_initialized = TRUE; |
---|
718 | return RTEMS_SUCCESSFUL; |
---|
719 | |
---|
720 | } |
---|
721 | |
---|
722 | |
---|
723 | /* |
---|
724 | * Open the device |
---|
725 | */ |
---|
726 | rtems_device_driver console_open(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
727 | { |
---|
728 | #ifdef UARTS_USE_TERMIOS_INT |
---|
729 | rtems_libio_open_close_args_t *args = arg; |
---|
730 | #endif |
---|
731 | rtems_status_code sc; |
---|
732 | |
---|
733 | #ifdef UARTS_USE_TERMIOS_INT |
---|
734 | static const rtems_termios_callbacks intrCallbacks = |
---|
735 | { |
---|
736 | NULL, /* firstOpen */ |
---|
737 | NULL, /* lastClose */ |
---|
738 | NULL, /* pollRead */ |
---|
739 | mpc5200_uart_write, /* write */ |
---|
740 | mpc5200_uart_setAttributes, /* setAttributes */ |
---|
741 | NULL, |
---|
742 | NULL, |
---|
743 | 1 /* outputUsesInterrupts */ |
---|
744 | }; |
---|
745 | #else |
---|
746 | static const rtems_termios_callbacks pollCallbacks = |
---|
747 | { |
---|
748 | NULL, /* firstOpen */ |
---|
749 | NULL, /* lastClose */ |
---|
750 | mpc5200_uart_pollRead, /* pollRead */ |
---|
751 | mpc5200_uart_pollWrite, /* write */ |
---|
752 | mpc5200_uart_setAttributes, /* setAttributes */ |
---|
753 | NULL, |
---|
754 | NULL, |
---|
755 | 0 /* output don't use Interrupts */ |
---|
756 | }; |
---|
757 | #endif |
---|
758 | |
---|
759 | if(minor > NUM_PORTS - 1) |
---|
760 | return RTEMS_INVALID_NUMBER; |
---|
761 | |
---|
762 | #ifdef UARTS_USE_TERMIOS_INT |
---|
763 | sc = rtems_termios_open( major, minor, arg, &intrCallbacks ); |
---|
764 | ttyp[minor] = args->iop->data1; /* Keep cookie returned by termios_open */ |
---|
765 | #else /* RTEMS polled I/O with termios */ |
---|
766 | sc = rtems_termios_open( major, minor, arg, &pollCallbacks ); |
---|
767 | #endif |
---|
768 | |
---|
769 | return sc; |
---|
770 | |
---|
771 | } |
---|
772 | |
---|
773 | |
---|
774 | /* |
---|
775 | * Close the device |
---|
776 | */ |
---|
777 | rtems_device_driver console_close(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
778 | { |
---|
779 | |
---|
780 | if ( minor > NUM_PORTS-1 ) |
---|
781 | return RTEMS_INVALID_NUMBER; |
---|
782 | |
---|
783 | return rtems_termios_close( arg ); |
---|
784 | |
---|
785 | return 0; |
---|
786 | |
---|
787 | } |
---|
788 | |
---|
789 | |
---|
790 | /* |
---|
791 | * Read from the device |
---|
792 | */ |
---|
793 | rtems_device_driver console_read(rtems_device_major_number major, rtems_device_minor_number minor, void *arg) |
---|
794 | { |
---|
795 | |
---|
796 | if(minor > NUM_PORTS-1) |
---|
797 | return RTEMS_INVALID_NUMBER; |
---|
798 | |
---|
799 | return rtems_termios_read(arg); |
---|
800 | |
---|
801 | return 0; |
---|
802 | |
---|
803 | } |
---|
804 | |
---|
805 | |
---|
806 | /* |
---|
807 | * Write to the device |
---|
808 | */ |
---|
809 | rtems_device_driver console_write(rtems_device_major_number major,rtems_device_minor_number minor,void *arg) |
---|
810 | { |
---|
811 | |
---|
812 | if( minor > NUM_PORTS-1 ) |
---|
813 | return RTEMS_INVALID_NUMBER; |
---|
814 | |
---|
815 | return rtems_termios_write(arg); |
---|
816 | |
---|
817 | return 0; |
---|
818 | } |
---|
819 | |
---|
820 | |
---|
821 | /* |
---|
822 | * Handle ioctl request. |
---|
823 | */ |
---|
824 | rtems_device_driver console_control(rtems_device_major_number major,rtems_device_minor_number minor,void *arg) |
---|
825 | { |
---|
826 | |
---|
827 | if ( minor > NUM_PORTS-1 ) |
---|
828 | return RTEMS_INVALID_NUMBER; |
---|
829 | |
---|
830 | return rtems_termios_ioctl(arg); |
---|
831 | |
---|
832 | return 0; |
---|
833 | |
---|
834 | } |
---|