source: rtems/c/src/lib/libbsp/m68k/uC5282/console/console.c @ 33fc4f6

Last change on this file since 33fc4f6 was 33fc4f6, checked in by Eric Norum <WENorum@…>, on 02/05/07 at 15:27:26

Enable RTS/CTS flow-control pins.

  • Property mode set to 100644
File size: 23.4 KB
Line 
1/*
2 *  Multi UART console serial I/O.
3 *
4 * TO DO: Add DMA input/output
5 *
6 *  Author: W. Eric Norum <norume@aps.anl.gov>
7 *
8 *  COPYRIGHT (c) 2005.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.OARcorp.com/rtems/license.html.
14 *
15 */
16
17#include <stdio.h>
18#include <fcntl.h>
19#include <rtems/libio.h>
20#include <rtems/termiostypes.h>
21#include <termios.h>
22#include <bsp.h>
23#include <malloc.h>
24#include <rtems/mw_uid.h>
25
26#include <rtems/bspIo.h>
27
28#define UART_INTC0_IRQ_VECTOR(x) (64+13+(x))
29
30#define MCF5282_UART_USR_ERROR ( MCF5282_UART_USR_RB | \
31                                 MCF5282_UART_USR_FE | \
32                                 MCF5282_UART_USR_PE | \
33                                 MCF5282_UART_USR_OE )
34
35static int IntUartPollWrite(int minor, const char *buf, int len);
36static int IntUartInterruptWrite (int minor, const char *buf, int len);
37
38static void
39_BSP_null_char( char c )
40{
41        int level;
42
43    if (c == '\n')
44        _BSP_null_char('\r');
45        rtems_interrupt_disable(level);
46    while ( (MCF5282_UART_USR(CONSOLE_PORT) & MCF5282_UART_USR_TXRDY) == 0 )
47        continue;
48    MCF5282_UART_UTB(CONSOLE_PORT) = c;
49    while ( (MCF5282_UART_USR(CONSOLE_PORT) & MCF5282_UART_USR_TXRDY) == 0 )
50        continue;
51        rtems_interrupt_enable(level);
52}
53BSP_output_char_function_type BSP_output_char = _BSP_null_char;
54
55/*
56 * The MCF5282 has three UARTs.  Enable all them here.  I/O pin selection
57 * is assumed to have been done elsewhere.
58 */
59#define MAX_UART_INFO     3
60#define RX_BUFFER_SIZE    512
61
62struct IntUartInfoStruct
63{
64        int                    iomode;
65        volatile int           uimr;
66        int                    baud;
67        int                    databits;
68        int                    parity;
69        int                    stopbits;
70        int                    hwflow;
71        int                    rx_in;
72        int                    rx_out;
73        char                   rx_buffer[RX_BUFFER_SIZE];
74        void                  *ttyp;
75};
76
77struct IntUartInfoStruct IntUartInfo[MAX_UART_INFO];
78
79static int GetBaud( int baudHandle )
80{
81        int baud = 9600;
82        switch ( baudHandle )
83        {
84                case B0:
85                        baud = (int)0;
86                        break;
87                case B1200:
88                        baud = (int)1200;
89                        break;
90                case B2400:
91                        baud = (int)2400;
92                        break;
93                case B4800:
94                        baud = (int)4800;
95                        break;
96                case B9600:
97                        baud = (int)9600;
98                        break;
99                case B19200:
100                        baud = (int)19200;
101                        break;
102                case B38400:
103                        baud = (int)38400;
104                        break;
105                case B57600:
106                        baud = (int)57600;
107                        break;
108                case B115200:
109                        baud = (int)115200;
110                        break;
111/*              case B576000:
112                        baud = (int)576000; */
113                        break;
114        }
115        return ( baud );
116}
117
118/***************************************************************************
119   Function : IntUartSet
120
121   Description : This updates the hardware UART settings.
122 ***************************************************************************/
123static void
124IntUartSet(int minor, int baud, int databits, int parity, int stopbits, int hwflow)
125{
126        int                         divisor;
127        uint32_t                                        clock_speed;
128        uint8_t                   umr1 = 0;
129        uint8_t                   umr2 = 0;
130        struct IntUartInfoStruct   *info = &IntUartInfo[minor];
131        int                         level;
132
133        rtems_interrupt_disable(level);
134
135
136        /* disable interrupts, clear RTS line, and disable the UARTS */
137        MCF5282_UART_UIMR(minor) = 0;
138        MCF5282_UART_UOP0(minor) = 1;
139        MCF5282_UART_UCR(minor) = (MCF5282_UART_UCR_TX_DISABLED | MCF5282_UART_UCR_RX_DISABLED);
140
141        /* save the current values */
142        info->uimr     = 0;
143        info->baud     = baud;
144        info->databits = databits;
145        info->parity   = parity;
146        info->stopbits = stopbits;
147        info->hwflow   = hwflow;
148
149    clock_speed = bsp_get_CPU_clock_speed();
150    /* determine the baud divisor value */
151    divisor = (clock_speed / ( 32 * baud ));
152    if ( divisor < 2 )
153        divisor = 2;
154
155        /* check to see if doing hardware flow control */
156        if ( hwflow )
157        {
158                /* set hardware flow options */
159                umr1 |= MCF5282_UART_UMR1_RXRTS;
160                umr2 |= MCF5282_UART_UMR2_TXCTS;
161        }
162
163        /* determine the new umr values */
164        umr1 |= (parity | databits);
165        umr2 |= (stopbits);
166
167        /* reset the uart */
168        MCF5282_UART_UCR(minor) = MCF5282_UART_UCR_RESET_ERROR;
169        MCF5282_UART_UCR(minor) = MCF5282_UART_UCR_RESET_RX;
170        MCF5282_UART_UCR(minor) = MCF5282_UART_UCR_RESET_TX;
171
172        /* reset the uart mode register and update values */
173        MCF5282_UART_UCR(minor) = MCF5282_UART_UCR_RESET_MR;
174        MCF5282_UART_UMR(minor) = umr1;
175        MCF5282_UART_UMR(minor) = umr2;
176
177        /* set the baud rate values */
178        MCF5282_UART_UCSR(minor) = (MCF5282_UART_UCSR_RCS_SYS_CLK | MCF5282_UART_UCSR_TCS_SYS_CLK);
179        MCF5282_UART_UBG1(minor) = (divisor & 0xff00) >> 8;
180        MCF5282_UART_UBG2(minor) = (divisor & 0x00ff);
181
182        /* enable the uart */
183    MCF5282_UART_UCR(minor) = (MCF5282_UART_UCR_TX_ENABLED | MCF5282_UART_UCR_RX_ENABLED);
184
185        /* check to see if interrupts need to be enabled */
186        if ( info->iomode != TERMIOS_POLLED )
187        {
188                /* enable rx interrupts */
189                info->uimr |= MCF5282_UART_UIMR_FFULL;
190                MCF5282_UART_UIMR(minor) = info->uimr;
191        }
192
193    /* assert the RTS line */
194    MCF5282_UART_UOP1(minor) = 1;
195
196        rtems_interrupt_enable(level);
197
198}
199
200
201/***************************************************************************
202   Function : IntUartSetAttributes
203
204   Description : This provides the hardware-dependent portion of tcsetattr().
205   value and sets it. At the moment this just sets the baud rate.
206
207   Note: The highest baudrate is 115200 as this stays within
208   an error of +/- 5% at 25MHz processor clock
209 ***************************************************************************/
210static int
211IntUartSetAttributes(int minor, const struct termios *t)
212{
213        /* set default index values */
214        int                         baud     = (int)9600;
215        int                         databits = (int)MCF5282_UART_UMR1_BC_8;
216        int                         parity   = (int)MCF5282_UART_UMR1_PM_NONE;
217        int                         stopbits = (int)MCF5282_UART_UMR2_STOP_BITS_1;
218        int                         hwflow   = (int)0;
219        struct IntUartInfoStruct   *info     = &IntUartInfo[minor];
220
221        /* check to see if input is valid */
222        if ( t != (const struct termios *)0 )
223        {
224                /* determine baud rate index */
225                baud = GetBaud( t->c_cflag & CBAUD );
226
227                /* determine data bits */
228                switch ( t->c_cflag & CSIZE )
229                {
230                        case CS5:
231                                databits = (int)MCF5282_UART_UMR1_BC_5;
232                                break;
233                        case CS6:
234                                databits = (int)MCF5282_UART_UMR1_BC_6;
235                                break;
236                        case CS7:
237                                databits = (int)MCF5282_UART_UMR1_BC_7;
238                                break;
239                        case CS8:
240                                databits = (int)MCF5282_UART_UMR1_BC_8;
241                                break;
242                }
243
244                /* determine if parity is enabled */
245                if ( t->c_cflag & PARENB )
246                {
247                        if ( t->c_cflag & PARODD )
248                        {
249                                /* odd parity */
250                                parity = (int)MCF5282_UART_UMR1_PM_ODD;
251                        }
252                        else
253                        {
254                                /* even parity */
255                                parity = (int)MCF5282_UART_UMR1_PM_EVEN;
256                        }
257                }
258
259                /* determine stop bits */
260                if ( t->c_cflag & CSTOPB )
261                {
262                        /* two stop bits */
263                        stopbits = (int)MCF5282_UART_UMR2_STOP_BITS_2;
264                }
265
266                /* check to see if hardware flow control */
267                if ( t->c_cflag & CRTSCTS )
268                {
269                        hwflow = 1;
270                }
271        }
272
273        /* check to see if values have changed */
274        if ( ( baud     != info->baud     ) ||
275                 ( databits != info->databits ) ||
276                 ( parity   != info->parity   ) ||
277                 ( stopbits != info->stopbits ) ||
278                 ( hwflow   != info->hwflow   ) )
279        {
280
281                /* call function to set values */
282                IntUartSet(minor, baud, databits, parity, stopbits, hwflow);
283        }
284
285        return( RTEMS_SUCCESSFUL );
286
287}
288
289/***************************************************************************
290   Function : IntUartInterruptHandler
291
292   Description : This is the interrupt handler for the internal uart. It
293   determines which channel caused the interrupt before queueing any received
294   chars and dequeueing chars waiting for transmission.
295 ***************************************************************************/
296static rtems_isr
297IntUartInterruptHandler(rtems_vector_number v)
298{
299        unsigned int                chan = v - UART_INTC0_IRQ_VECTOR(0);
300        struct IntUartInfoStruct   *info = &IntUartInfo[chan];
301
302        /* check to see if received data */
303        if ( MCF5282_UART_UISR(chan) & MCF5282_UART_UISR_RXRDY )
304        {
305                /* read data and put into the receive buffer */
306                while ( MCF5282_UART_USR(chan) & MCF5282_UART_USR_RXRDY )
307                {
308
309                        if ( MCF5282_UART_USR(chan) & MCF5282_UART_USR_ERROR )
310                        {
311                                /* clear the error */
312                                MCF5282_UART_UCR(chan) = MCF5282_UART_UCR_RESET_ERROR;
313                        }
314                        /* put data in rx buffer and check for errors */
315                        info->rx_buffer[info->rx_in] = MCF5282_UART_URB(chan);
316
317                        /* update buffer values */
318                        info->rx_in++;
319
320                        if ( info->rx_in >= RX_BUFFER_SIZE )
321                        {
322                                info->rx_in = 0;
323                        }
324                }
325                /* Make sure the port has been opened */
326                if ( info->ttyp )
327                {
328
329                        /* check to see if task driven */
330                        if ( info->iomode == TERMIOS_TASK_DRIVEN )
331                        {
332                                /* notify rx task that rx buffer has data */
333                                rtems_termios_rxirq_occured(info->ttyp);
334                        }
335                        else
336                        {
337                                /* Push up the received data */
338                                rtems_termios_enqueue_raw_characters(info->ttyp, info->rx_buffer, info->rx_in);
339                                info->rx_in    = 0;
340                        }
341                }
342        }
343
344        /* check to see if data needs to be transmitted */
345        if ( ( info->uimr & MCF5282_UART_UIMR_TXRDY ) &&
346                 ( MCF5282_UART_UISR(chan) & MCF5282_UART_UISR_TXRDY ) )
347        {
348
349                /* disable tx interrupts */
350                info->uimr &= ~MCF5282_UART_UIMR_TXRDY;
351                MCF5282_UART_UIMR(chan) = info->uimr;
352
353                /* tell upper level that character has been sent */
354                if ( info->ttyp )
355                        rtems_termios_dequeue_characters(info->ttyp, 1);
356        }
357}
358
359
360
361/***************************************************************************
362   Function : IntUartInitialize
363
364   Description : This initialises the internal uart hardware for all
365   internal uarts. If the internal uart is to be interrupt driven then the
366   interrupt vectors are hooked.
367 ***************************************************************************/
368static void
369IntUartInitialize(void)
370{
371        unsigned int        chan;
372        struct IntUartInfoStruct   *info;
373        rtems_isr_entry old_handler;
374    int level;
375
376        for ( chan = 0; chan < MAX_UART_INFO; chan++ )
377        {
378                info = &IntUartInfo[chan];
379
380                info->ttyp     = NULL;
381                info->rx_in    = 0;
382                info->rx_out   = 0;
383                info->baud     = -1;
384                info->databits = -1;
385                info->parity   = -1;
386                info->stopbits = -1;
387                info->hwflow   = -1;
388
389                MCF5282_UART_UACR(chan) = 0;
390                MCF5282_UART_UIMR(chan) = 0;
391                if ( info->iomode != TERMIOS_POLLED )
392                {
393                        rtems_interrupt_catch (IntUartInterruptHandler,
394                                                                   UART_INTC0_IRQ_VECTOR(chan),
395                                                                   &old_handler);
396                }
397
398                /* set uart default values */
399                IntUartSetAttributes(chan, NULL);
400
401        /* unmask interrupt */
402                rtems_interrupt_disable(level);
403        switch(chan) {
404        case 0:
405            bsp_allocate_interrupt(UART0_IRQ_LEVEL, UART0_IRQ_PRIORITY);
406            MCF5282_INTC0_ICR13 = MCF5282_INTC_ICR_IL(UART0_IRQ_LEVEL) |
407                                  MCF5282_INTC_ICR_IP(UART0_IRQ_PRIORITY);
408            MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT13 |
409                                    MCF5282_INTC_IMRL_MASKALL);
410            break;
411
412        case 1:
413            bsp_allocate_interrupt(UART1_IRQ_LEVEL, UART1_IRQ_PRIORITY);
414            MCF5282_INTC0_ICR14 = MCF5282_INTC_ICR_IL(UART1_IRQ_LEVEL) |
415                                  MCF5282_INTC_ICR_IP(UART1_IRQ_PRIORITY);
416            MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT14 |
417                                    MCF5282_INTC_IMRL_MASKALL);
418            break;
419
420        case 2:
421            bsp_allocate_interrupt(UART2_IRQ_LEVEL, UART2_IRQ_PRIORITY);
422            MCF5282_INTC0_ICR15 = MCF5282_INTC_ICR_IL(UART2_IRQ_LEVEL) |
423                                  MCF5282_INTC_ICR_IP(UART2_IRQ_PRIORITY);
424            MCF5282_INTC0_IMRL &= ~(MCF5282_INTC_IMRL_INT15 |
425                                    MCF5282_INTC_IMRL_MASKALL);
426            break;
427        }
428                rtems_interrupt_enable(level);
429
430        } /* of chan loop */
431
432
433} /* IntUartInitialise */
434
435
436/***************************************************************************
437   Function : IntUartInterruptWrite
438
439   Description : This writes a single character to the appropriate uart
440   channel. This is either called during an interrupt or in the user's task
441   to initiate a transmit sequence. Calling this routine enables Tx
442   interrupts.
443 ***************************************************************************/
444static int
445IntUartInterruptWrite (int minor, const char *buf, int len)
446{
447        int level;
448
449        rtems_interrupt_disable(level);
450
451        /* write out character */
452        MCF5282_UART_UTB(minor) = *buf;
453
454        /* enable tx interrupt */
455        IntUartInfo[minor].uimr |= MCF5282_UART_UIMR_TXRDY;
456        MCF5282_UART_UIMR(minor) = IntUartInfo[minor].uimr;
457
458        rtems_interrupt_enable(level);
459        return( 0 );
460}
461
462/***************************************************************************
463   Function : IntUartInterruptOpen
464
465   Description : This enables interrupts when the tty is opened.
466 ***************************************************************************/
467static int
468IntUartInterruptOpen(int major, int minor, void *arg)
469{
470        struct IntUartInfoStruct   *info = &IntUartInfo[minor];
471        int level;
472
473        /*
474         * Enable serial I/O pin assignments
475         */
476        rtems_interrupt_disable(level);
477        switch(minor) {
478        case 0:
479                MCF5282_GPIO_PUAPAR |= MCF5282_GPIO_PUAPAR_PUAPA1|MCF5282_GPIO_PUAPAR_PUAPA0;
480                MCF5282_GPIO_PTCPAR = (MCF5282_GPIO_PTCPAR
481             & ~(MCF5282_GPIO_PTCPAR_PTCPA3(3)|MCF5282_GPIO_PTCPAR_PTCPA1(3)))
482             |  (MCF5282_GPIO_PTCPAR_PTCPA3(1)|MCF5282_GPIO_PTCPAR_PTCPA1(1));
483                break;
484        case 1:
485                MCF5282_GPIO_PUAPAR |= MCF5282_GPIO_PUAPAR_PUAPA3|MCF5282_GPIO_PUAPAR_PUAPA2;
486                MCF5282_GPIO_PTCPAR = (MCF5282_GPIO_PTCPAR
487             & ~(MCF5282_GPIO_PTCPAR_PTCPA2(3)|MCF5282_GPIO_PTCPAR_PTCPA0(3)))
488             |  (MCF5282_GPIO_PTCPAR_PTCPA2(2)|MCF5282_GPIO_PTCPAR_PTCPA0(2));
489                break;
490        case 2:
491                MCF5282_GPIO_PASPAR = (MCF5282_GPIO_PASPAR
492             & ~(MCF5282_GPIO_PASPAR_PASPA3(3)|MCF5282_GPIO_PASPAR_PASPA2(3)))
493             |  (MCF5282_GPIO_PASPAR_PASPA3(2)|MCF5282_GPIO_PASPAR_PASPA2(2));
494        /* UART2 flow control signals are not brought out to pins! */
495                break;
496        }
497        rtems_interrupt_enable(level);
498        /* enable the uart */
499        MCF5282_UART_UCR(minor) = (MCF5282_UART_UCR_TX_ENABLED | MCF5282_UART_UCR_RX_ENABLED);
500
501        /* check to see if interrupts need to be enabled */
502        if ( info->iomode != TERMIOS_POLLED )
503        {
504                /* enable rx interrupts */
505                info->uimr |= MCF5282_UART_UIMR_FFULL;
506                MCF5282_UART_UIMR(minor) = info->uimr;
507        }
508
509    /* assert the RTS line */
510    MCF5282_UART_UOP1(minor) = 1;
511
512        return( 0 );
513}
514
515
516
517/***************************************************************************
518   Function : IntUartInterruptClose
519
520   Description : This disables interrupts when the tty is closed.
521 ***************************************************************************/
522static int
523IntUartInterruptClose(int major, int minor, void *arg)
524{
525        struct IntUartInfoStruct   *info = &IntUartInfo[minor];
526
527        /* disable the interrupts and the uart */
528        MCF5282_UART_UIMR(minor) = 0;
529        MCF5282_UART_UCR(minor) = (MCF5282_UART_UCR_TX_DISABLED | MCF5282_UART_UCR_RX_DISABLED);
530
531        /* reset values */
532        info->ttyp     = NULL;
533        info->uimr       = 0;
534        info->rx_in    = 0;
535        info->rx_out   = 0;
536
537        return( 0 );
538}
539
540/***************************************************************************
541   Function : IntUartTaskRead
542
543   Description : This reads all available characters from the internal uart
544   and places them into the termios buffer.  The rx interrupts will be
545   re-enabled after all data has been read.
546 ***************************************************************************/
547static int
548IntUartTaskRead(int minor)
549{
550        char                        buffer[RX_BUFFER_SIZE];
551        int                         count;
552        int                         rx_in;
553        int                         index = 0;
554        struct IntUartInfoStruct   *info  = &IntUartInfo[minor];
555
556        /* determine number of values to copy out */
557        rx_in = info->rx_in;
558        if ( info->rx_out <= rx_in )
559        {
560                count = rx_in - info->rx_out;
561        }
562        else
563        {
564                count = (RX_BUFFER_SIZE - info->rx_out) + rx_in;
565        }
566
567        /* copy data into local buffer from rx buffer */
568        while ( ( index < count ) && ( index < RX_BUFFER_SIZE ) )
569        {
570                /* copy data byte */
571                buffer[index] = info->rx_buffer[info->rx_out];
572                index++;
573
574                /* increment rx buffer values */
575                info->rx_out++;
576                if ( info->rx_out >= RX_BUFFER_SIZE )
577                {
578                        info->rx_out = 0;
579                }
580        }
581
582        /* check to see if buffer is not empty */
583        if ( count > 0 )
584        {
585                /* set characters into termios buffer  */
586                rtems_termios_enqueue_raw_characters(info->ttyp, buffer, count);
587        }
588
589        return( EOF );
590}
591
592
593
594/***************************************************************************
595   Function : IntUartPollRead
596
597   Description : This reads a character from the internal uart. It returns
598   to the caller without blocking if not character is waiting.
599 ***************************************************************************/
600static int
601IntUartPollRead (int minor)
602{
603        if ( (MCF5282_UART_USR(minor) & MCF5282_UART_USR_RXRDY) == 0 )
604                return(-1);
605
606        return(MCF5282_UART_URB(minor));
607}
608
609
610/***************************************************************************
611   Function : IntUartPollWrite
612
613   Description : This writes out each character in the buffer to the
614   appropriate internal uart channel waiting till each one is sucessfully
615   transmitted.
616 ***************************************************************************/
617static int
618IntUartPollWrite (int minor, const char *buf, int len)
619{
620        /* loop over buffer */
621        while ( len-- )
622        {
623                /* block until we can transmit */
624                while ( (MCF5282_UART_USR(minor) & MCF5282_UART_USR_TXRDY) == 0 )
625                        continue;
626                /* transmit data byte */
627                MCF5282_UART_UTB(minor) = *buf++;
628        }
629        return(0);
630}
631
632/***************************************************************************
633   Function : console_reserve_resources
634
635   Description : This reserves resources consumed by this driver. It passes
636   the request on to the termios subsystem.
637 ***************************************************************************/
638void console_reserve_resources( rtems_configuration_table *configuration )
639{
640        rtems_termios_reserve_resources (configuration, 1);
641}
642
643
644/***************************************************************************
645   Function : console_initialize
646
647   Description : This initialises termios, all uart hardware before
648   registering /dev/tty devices for each channel and the system /dev/console.
649 ***************************************************************************/
650rtems_device_driver console_initialize(
651        rtems_device_major_number  major,
652        rtems_device_minor_number  minor,
653        void  *arg )
654{
655        rtems_status_code status;
656        int chan;
657
658        /* Set up TERMIOS */
659        rtems_termios_initialize ();
660
661        /* set io modes for the different channels and initialize device */
662        for ( chan = 0; chan < MAX_UART_INFO; chan++ )
663                IntUartInfo[chan].iomode = TERMIOS_IRQ_DRIVEN;
664        IntUartInitialize();
665
666        /* Register the console port */
667        status = rtems_io_register_name ("/dev/console", major, CONSOLE_PORT);
668        if ( status != RTEMS_SUCCESSFUL )
669        {
670                rtems_fatal_error_occurred (status);
671        }
672
673        /* Register the other ports */
674        if ( CONSOLE_PORT != 0 )
675        {
676                status = rtems_io_register_name ("/dev/tty00", major, 0);
677                if ( status != RTEMS_SUCCESSFUL )
678                {
679                        rtems_fatal_error_occurred (status);
680                }
681        }
682        if ( CONSOLE_PORT != 1 )
683        {
684                status = rtems_io_register_name ("/dev/tty01", major, 1);
685                if ( status != RTEMS_SUCCESSFUL )
686                {
687                        rtems_fatal_error_occurred (status);
688                }
689        }
690    status = rtems_io_register_name ("/dev/tty02", major, 2);
691    if ( status != RTEMS_SUCCESSFUL )
692    {
693        rtems_fatal_error_occurred (status);
694    }
695
696        return(RTEMS_SUCCESSFUL);
697}
698
699/***************************************************************************
700   Function : console_open
701
702   Description : This actually opens the device depending on the minor
703   number set during initialisation. The device specific access routines are
704   passed to termios when the devices is opened depending on whether it is
705   polled or not.
706 ***************************************************************************/
707rtems_device_driver console_open(
708        rtems_device_major_number major,
709        rtems_device_minor_number minor,
710        void  * arg)
711{
712        rtems_status_code                status = RTEMS_INVALID_NUMBER;
713        rtems_libio_open_close_args_t   *args   = (rtems_libio_open_close_args_t *)arg;
714        struct IntUartInfoStruct        *info;
715
716        static const rtems_termios_callbacks IntUartPollCallbacks = {
717                NULL,                             /* firstOpen */
718                NULL,                             /* lastClose */
719                IntUartPollRead,          /* pollRead */
720                IntUartPollWrite,         /* write */
721                IntUartSetAttributes, /* setAttributes */
722                NULL,                             /* stopRemoteTx */
723                NULL,                             /* startRemoteTx */
724                TERMIOS_POLLED            /* mode */
725        };
726        static const rtems_termios_callbacks IntUartIntrCallbacks = {
727                IntUartInterruptOpen,  /* firstOpen */
728                IntUartInterruptClose, /* lastClose */
729                NULL,                              /* pollRead */
730                IntUartInterruptWrite, /* write */
731                IntUartSetAttributes,  /* setAttributes */
732                NULL,                              /* stopRemoteTx */
733                NULL,                              /* startRemoteTx */
734                TERMIOS_IRQ_DRIVEN         /* mode */
735        };
736
737        static const rtems_termios_callbacks IntUartTaskCallbacks = {
738                IntUartInterruptOpen,  /* firstOpen */
739                IntUartInterruptClose, /* lastClose */
740                IntUartTaskRead,           /* pollRead */
741                IntUartInterruptWrite, /* write */
742                IntUartSetAttributes,  /* setAttributes */
743                NULL,                              /* stopRemoteTx */
744                NULL,                              /* startRemoteTx */
745                TERMIOS_TASK_DRIVEN        /* mode */
746        };
747
748        /* open the port depending on the minor device number */
749        if ( ( minor >= 0 ) && ( minor < MAX_UART_INFO ) )
750        {
751                info = &IntUartInfo[minor];
752                switch ( info->iomode )
753                {
754                        case TERMIOS_POLLED:
755                                status = rtems_termios_open(major, minor, arg, &IntUartPollCallbacks);
756                                break;
757                        case TERMIOS_IRQ_DRIVEN:
758                                status = rtems_termios_open(major, minor, arg, &IntUartIntrCallbacks);
759                                info->ttyp = args->iop->data1;
760                                break;
761                        case TERMIOS_TASK_DRIVEN:
762                                status = rtems_termios_open(major, minor, arg, &IntUartTaskCallbacks);
763                                info->ttyp = args->iop->data1;
764                                break;
765                }
766        }
767
768        return( status );
769}
770
771/***************************************************************************
772   Function : console_close
773
774   Description : This closes the device via termios
775 ***************************************************************************/
776rtems_device_driver console_close(
777        rtems_device_major_number major,
778        rtems_device_minor_number minor,
779        void   * arg)
780{
781    return(rtems_termios_close (arg));
782}
783
784/******************
785*********************************************************
786   Function : console_read
787
788   Description : Read from the device via termios
789 ***************************************************************************/
790rtems_device_driver console_read(
791        rtems_device_major_number major,
792        rtems_device_minor_number minor,
793        void  * arg)
794{
795    return(rtems_termios_read (arg));
796}
797
798/***************************************************************************
799   Function : console_write
800
801   Description : Write to the device via termios
802 ***************************************************************************/
803rtems_device_driver console_write(
804        rtems_device_major_number major,
805        rtems_device_minor_number minor,
806        void  * arg)
807{
808    return(rtems_termios_write (arg));
809}
810
811/***************************************************************************
812   Function : console_ioctl
813
814   Description : Pass the IOCtl call to termios
815 ***************************************************************************/
816rtems_device_driver console_control(
817        rtems_device_major_number major,
818        rtems_device_minor_number minor,
819        void  * arg)
820{
821    return( rtems_termios_ioctl (arg) );
822}
823int DEBUG_OUTCHAR(int c)
824{
825    if(c == '\n')
826        DEBUG_OUTCHAR('\r');
827    _BSP_null_char(c);
828    return c;
829}
830void DEBUG_OUTSTR(const char *msg)
831{
832    while (*msg)
833        DEBUG_OUTCHAR(*msg++);
834}
835void DEBUG_OUTNUM(int i)
836{
837    int n;
838    static const char map[] = "0123456789ABCDEF";
839    DEBUG_OUTCHAR(' ');
840    for (n = 28 ; n >= 0 ; n -= 4)
841        DEBUG_OUTCHAR(map[(i >> n) & 0xF]);
842}
Note: See TracBrowser for help on using the repository browser.