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

4.104.115
Last change on this file since 39a9f8e was 39a9f8e, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 12/17/09 at 08:42:17

adapted to new prototype for *_write function

  • 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 ssize_t IntUartPollWrite(int minor, const char *buf, size_t len);
36static ssize_t IntUartInterruptWrite (int minor, const char *buf, size_t 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 ssize_t
410IntUartInterruptWrite (int minor, const char *buf, size_t 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 =
451                  (MCF5282_GPIO_PASPAR
452                   & ~(MCF5282_GPIO_PASPAR_PASPA3(3)|MCF5282_GPIO_PASPAR_PASPA2(3)))
453                  |  (MCF5282_GPIO_PASPAR_PASPA3(2)|MCF5282_GPIO_PASPAR_PASPA2(2));
454                break;
455        }
456        rtems_interrupt_enable(level);
457        /* enable the uart */
458        MCF5282_UART_UCR(minor) = (MCF5282_UART_UCR_TX_ENABLED | MCF5282_UART_UCR_RX_ENABLED);
459
460        /* check to see if interrupts need to be enabled */
461        if ( info->iomode != TERMIOS_POLLED )
462        {
463                /* enable rx interrupts */
464                info->uimr |= MCF5282_UART_UIMR_FFULL;
465                MCF5282_UART_UIMR(minor) = info->uimr;
466        }
467
468        /* check to see if doing hardware flow control */
469        if ( info->hwflow )
470        {
471                /* assert the RTS line */
472                MCF5282_UART_UOP1(minor) = 1;
473        }
474
475        return( 0 );
476}
477
478
479
480/***************************************************************************
481   Function : IntUartInterruptClose
482
483   Description : This disables interrupts when the tty is closed.
484 ***************************************************************************/
485static int
486IntUartInterruptClose(int major, int minor, void *arg)
487{
488        struct IntUartInfoStruct   *info = &IntUartInfo[minor];
489
490        /* disable the interrupts and the uart */
491        MCF5282_UART_UIMR(minor) = 0;
492        MCF5282_UART_UCR(minor) = (MCF5282_UART_UCR_TX_DISABLED | MCF5282_UART_UCR_RX_DISABLED);
493
494        /* reset values */
495        info->ttyp     = NULL;
496        info->uimr       = 0;
497        info->rx_in    = 0;
498        info->rx_out   = 0;
499
500        return( 0 );
501}
502
503/***************************************************************************
504   Function : IntUartTaskRead
505
506   Description : This reads all available characters from the internal uart
507   and places them into the termios buffer.  The rx interrupts will be
508   re-enabled after all data has been read.
509 ***************************************************************************/
510static int
511IntUartTaskRead(int minor)
512{
513        char                        buffer[RX_BUFFER_SIZE];
514        int                         count;
515        int                         rx_in;
516        int                         index = 0;
517        struct IntUartInfoStruct   *info  = &IntUartInfo[minor];
518
519        /* determine number of values to copy out */
520        rx_in = info->rx_in;
521        if ( info->rx_out <= rx_in )
522        {
523                count = rx_in - info->rx_out;
524        }
525        else
526        {
527                count = (RX_BUFFER_SIZE - info->rx_out) + rx_in;
528        }
529
530        /* copy data into local buffer from rx buffer */
531        while ( ( index < count ) && ( index < RX_BUFFER_SIZE ) )
532        {
533                /* copy data byte */
534                buffer[index] = info->rx_buffer[info->rx_out];
535                index++;
536
537                /* increment rx buffer values */
538                info->rx_out++;
539                if ( info->rx_out >= RX_BUFFER_SIZE )
540                {
541                        info->rx_out = 0;
542                }
543        }
544
545        /* check to see if buffer is not empty */
546        if ( count > 0 )
547        {
548                /* set characters into termios buffer  */
549                rtems_termios_enqueue_raw_characters(info->ttyp, buffer, count);
550        }
551
552        return( EOF );
553}
554
555
556
557/***************************************************************************
558   Function : IntUartPollRead
559
560   Description : This reads a character from the internal uart. It returns
561   to the caller without blocking if not character is waiting.
562 ***************************************************************************/
563static int
564IntUartPollRead (int minor)
565{
566        if ( (MCF5282_UART_USR(minor) & MCF5282_UART_USR_RXRDY) == 0 )
567                return(-1);
568
569        return(MCF5282_UART_URB(minor));
570}
571
572
573/***************************************************************************
574   Function : IntUartPollWrite
575
576   Description : This writes out each character in the buffer to the
577   appropriate internal uart channel waiting till each one is sucessfully
578   transmitted.
579 ***************************************************************************/
580static ssize_t
581IntUartPollWrite (int minor, const char *buf, size_t len)
582{
583        size_t retval = len;
584        /* loop over buffer */
585        while ( len-- )
586        {
587                /* block until we can transmit */
588                while ( (MCF5282_UART_USR(minor) & MCF5282_UART_USR_TXRDY) == 0 )
589                        continue;
590                /* transmit data byte */
591                MCF5282_UART_UTB(minor) = *buf++;
592        }
593        return retval;
594}
595
596/***************************************************************************
597   Function : console_initialize
598
599   Description : This initialises termios, all uart hardware before
600   registering /dev/tty devices for each channel and the system /dev/console.
601 ***************************************************************************/
602rtems_device_driver console_initialize(
603        rtems_device_major_number  major,
604        rtems_device_minor_number  minor,
605        void  *arg )
606{
607        rtems_status_code status;
608        int chan;
609
610        /* Set up TERMIOS */
611        rtems_termios_initialize ();
612
613        /* set io modes for the different channels and initialize device */
614        for ( chan = 0; chan < MAX_UART_INFO; chan++ )
615                IntUartInfo[chan].iomode = TERMIOS_IRQ_DRIVEN;
616        IntUartInitialize();
617
618        /* Register the console port */
619        status = rtems_io_register_name ("/dev/console", major, CONSOLE_PORT);
620        if ( status != RTEMS_SUCCESSFUL )
621        {
622                rtems_fatal_error_occurred (status);
623        }
624
625        /* Register the other ports */
626        if ( CONSOLE_PORT != 0 )
627        {
628                status = rtems_io_register_name ("/dev/tty00", major, 0);
629                if ( status != RTEMS_SUCCESSFUL )
630                {
631                        rtems_fatal_error_occurred (status);
632                }
633        }
634        if ( CONSOLE_PORT != 1 )
635        {
636                status = rtems_io_register_name ("/dev/tty01", major, 1);
637                if ( status != RTEMS_SUCCESSFUL )
638                {
639                        rtems_fatal_error_occurred (status);
640                }
641        }
642    status = rtems_io_register_name ("/dev/tty02", major, 2);
643    if ( status != RTEMS_SUCCESSFUL )
644    {
645        rtems_fatal_error_occurred (status);
646    }
647
648        return(RTEMS_SUCCESSFUL);
649}
650
651/***************************************************************************
652   Function : console_open
653
654   Description : This actually opens the device depending on the minor
655   number set during initialisation. The device specific access routines are
656   passed to termios when the devices is opened depending on whether it is
657   polled or not.
658 ***************************************************************************/
659rtems_device_driver console_open(
660        rtems_device_major_number major,
661        rtems_device_minor_number minor,
662        void  * arg)
663{
664        rtems_status_code                status = RTEMS_INVALID_NUMBER;
665        rtems_libio_open_close_args_t   *args   = (rtems_libio_open_close_args_t *)arg;
666        struct IntUartInfoStruct        *info;
667
668        static const rtems_termios_callbacks IntUartPollCallbacks = {
669                NULL,                             /* firstOpen */
670                NULL,                             /* lastClose */
671                IntUartPollRead,          /* pollRead */
672                IntUartPollWrite,         /* write */
673                IntUartSetAttributes, /* setAttributes */
674                NULL,                             /* stopRemoteTx */
675                NULL,                             /* startRemoteTx */
676                TERMIOS_POLLED            /* mode */
677        };
678        static const rtems_termios_callbacks IntUartIntrCallbacks = {
679                IntUartInterruptOpen,  /* firstOpen */
680                IntUartInterruptClose, /* lastClose */
681                NULL,                              /* pollRead */
682                IntUartInterruptWrite, /* write */
683                IntUartSetAttributes,  /* setAttributes */
684                NULL,                              /* stopRemoteTx */
685                NULL,                              /* startRemoteTx */
686                TERMIOS_IRQ_DRIVEN         /* mode */
687        };
688
689        static const rtems_termios_callbacks IntUartTaskCallbacks = {
690                IntUartInterruptOpen,  /* firstOpen */
691                IntUartInterruptClose, /* lastClose */
692                IntUartTaskRead,           /* pollRead */
693                IntUartInterruptWrite, /* write */
694                IntUartSetAttributes,  /* setAttributes */
695                NULL,                              /* stopRemoteTx */
696                NULL,                              /* startRemoteTx */
697                TERMIOS_TASK_DRIVEN        /* mode */
698        };
699
700        /* open the port depending on the minor device number */
701        if ( ( minor >= 0 ) && ( minor < MAX_UART_INFO ) )
702        {
703                info = &IntUartInfo[minor];
704                switch ( info->iomode )
705                {
706                        case TERMIOS_POLLED:
707                                status = rtems_termios_open(major, minor, arg, &IntUartPollCallbacks);
708                                break;
709                        case TERMIOS_IRQ_DRIVEN:
710                                status = rtems_termios_open(major, minor, arg, &IntUartIntrCallbacks);
711                                info->ttyp = args->iop->data1;
712                                break;
713                        case TERMIOS_TASK_DRIVEN:
714                                status = rtems_termios_open(major, minor, arg, &IntUartTaskCallbacks);
715                                info->ttyp = args->iop->data1;
716                                break;
717                }
718        }
719
720        return( status );
721}
722
723/***************************************************************************
724   Function : console_close
725
726   Description : This closes the device via termios
727 ***************************************************************************/
728rtems_device_driver console_close(
729        rtems_device_major_number major,
730        rtems_device_minor_number minor,
731        void   * arg)
732{
733    return(rtems_termios_close (arg));
734}
735
736/******************
737*********************************************************
738   Function : console_read
739
740   Description : Read from the device via termios
741 ***************************************************************************/
742rtems_device_driver console_read(
743        rtems_device_major_number major,
744        rtems_device_minor_number minor,
745        void  * arg)
746{
747    return(rtems_termios_read (arg));
748}
749
750/***************************************************************************
751   Function : console_write
752
753   Description : Write to the device via termios
754 ***************************************************************************/
755rtems_device_driver console_write(
756        rtems_device_major_number major,
757        rtems_device_minor_number minor,
758        void  * arg)
759{
760    return(rtems_termios_write (arg));
761}
762
763/***************************************************************************
764   Function : console_ioctl
765
766   Description : Pass the IOCtl call to termios
767 ***************************************************************************/
768rtems_device_driver console_control(
769        rtems_device_major_number major,
770        rtems_device_minor_number minor,
771        void  * arg)
772{
773    return( rtems_termios_ioctl (arg) );
774}
775int DEBUG_OUTCHAR(int c)
776{
777    if(c == '\n')
778        DEBUG_OUTCHAR('\r');
779    _BSP_null_char(c);
780    return c;
781}
782void DEBUG_OUTSTR(const char *msg)
783{
784    while (*msg)
785        DEBUG_OUTCHAR(*msg++);
786}
787void DEBUG_OUTNUM(int i)
788{
789    int n;
790    static const char map[] = "0123456789ABCDEF";
791    DEBUG_OUTCHAR(' ');
792    for (n = 28 ; n >= 0 ; n -= 4)
793        DEBUG_OUTCHAR(map[(i >> n) & 0xF]);
794}
795
796BSP_polling_getchar_function_type       BSP_poll_char = NULL;
797
Note: See TracBrowser for help on using the repository browser.