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

4.104.115
Last change on this file since d4b4664b was d4b4664b, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/29/09 at 14:59:41

Whitespace removal.

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