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

4.104.114.84.95
Last change on this file since 8e6835a5 was 8e6835a5, checked in by Eric Norum <WENorum@…>, on 11/08/05 at 20:11:02

Add code to set up pin assignments.

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