source: rtems/c/src/lib/libbsp/m68k/mrm332/console/sci.c @ b8490b9

4.104.114.84.95
Last change on this file since b8490b9 was b8490b9, checked in by Joel Sherrill <joel.sherrill@…>, on 01/07/04 at 21:13:50

2004-01-07 Joel Sherrill <joel@…>

  • times, console/sci.c: Remove efi68k and efi332 references as they are no longer in the tree.
  • Property mode set to 100644
File size: 52.5 KB
Line 
1/*****************************************************************************
2* File:     sci.c
3*
4* Desc:     This file contains the console IO routines for the SCI port.
5*           There are two interfaces in this module. One is for the rtems
6*           termios/console code and the other is a device driver interface.
7*           This module works together with the termio module which is
8*           sometimes referred to as the "line disciplines" which implements
9*           terminal i/o processing like tabs, backspaces, and newlines.
10*           The rtems printf uses interrupt io and the rtems printk routine
11*           uses polled io which is better for debugging.
12*
13* Index:    Documentation
14*           Section A  - Include Files
15*           Section B  - Manifest Constants
16*           Section C  - External Data
17*           Section D  - External Functions
18*           Section E  - Local Functions
19*           Section F  - Local Variables
20*           Section G  - A circular data buffer for rcv chars
21*           Section H  - RTEMS termios callbacks for the interrupt api
22*           Section I  - RTEMS termios callbacks for the polled api
23
24*           Section 0  - Miscellaneous routines
25*           Section 1  - Routines to manipulate the circular buffer
26*           Section 2  - Interrupt based entry points for the termios module
27*           Section 3  - Polling based entry points for the termios module
28*           Section 4  - Device driver public api entry points
29*           Section 5  - Hardware level routines
30*           Section 6  - Testing and debugging code
31*
32* Refer:    Motorola QSM Reference Manual - Chapter 5 - SCI sub-module
33*
34* Note:     See bsp.h,confdefs.h,system.h for installing drivers into RTEMS.
35*
36* $Id$
37*
38* $Log$
39* Revision 1.3  2003/01/20 20:33:17  joel
40* 2003-01-20    Duane Gustavus <duane@unt.edu>
41*
42*       * console/sci.c, include/mrm332.h, startup/linkcmds,
43*       startup/linkcmds_ROM: Various updates to make this run properly
44*       from ROM.
45*
46* Revision 1.2  2002/11/04 14:26:47  joel
47* 2002-11-04    Joel Sherrill <joel@OARcorp.com>
48*
49*       * console/sci.c, spurious/spinit.c: Removed warnings.
50*
51* Revision 1.1  2002/02/28 23:10:39  joel
52* 2002-02-28    Mike Panetta <ahuitzot@mindspring.com>
53*
54*       * console/sci.c, console/sci.h,
55*       console/console.c: Added new SCI driver.
56*       * start/start.c: Removed file.
57*       * start/start.S: New file, the asm portion of the updated start code.
58*       * start/configure.am: Added start.S, removed start.c
59*       * startup/start_c.c: New file, the C portion of the updated start code.         Contains most of the code that was in the old start.c.
60*       * startup/configure.am: Added start_c.c to C_FILES.
61*       * include/bsp.h: Added include <rtems/bspIo.h>
62*
63*****************************************************************************/
64
65
66/*****************************************************************************
67  Compiler Options for the incurably curious
68*****************************************************************************/
69
70/*
71/opt/rtems/bin/m68k-rtems-gcc
72    --pipe                                      # use pipes, not tmp files
73    -B../../../../../../../../opti/lib/         # where the library is
74    -specs bsp_specs                            # ???
75    -qrtems                                     # ???
76    -g                                          # add debugging info
77    -Wall                                       # issue all warnings
78    -fasm                                       # allow inline asm???
79    -DCONSOLE_SCI                               # for opti-r box/rev b proto
80    -mcpu32                                     # machine = motorola cpu 32
81    -c                                          # compile, don't link
82    -O4                                         # max optimization
83    -fomit-frame-pointer                        # stack frames are optional
84    -o o-optimize/sci.o                         # the object file
85    ../../../../../../../../../rtems/c/src/lib/libbsp/m68k/opti/console/sci.c
86*/
87
88
89/*****************************************************************************
90  Overview of serial port console terminal input/output
91*****************************************************************************/
92
93/*
94   +-----------+                               +---------+
95   |    app    |                               |   app   |
96   +-----------+                               +---------+
97         |                                          |
98         | (printf,scanf,etc.)                      |
99         v                                          |
100   +-----------+                                    |
101   |    libc   |                                    |
102   +-----------+                                    |
103         |                                          |
104         |                                          |
105         |     (open,close,read,write,ioctl)        |
106   ======|==========================================|========================
107         | /dev/console                             | /dev/sci
108         | (stdin,stdout,stderr)                    |
109   ======|==========================================|========================
110         |                                          |
111         |                                          |
112         v                                          v
113   +-----------+         +-----------+         +---------+
114   |  console  |  <--->  |  termios  |  <--->  |   sci   |
115   |  driver   |         |  module   |         |  driver |
116   +-----------+         +-----------+         +---------+
117                                                    |
118                                                    |
119                                                    v
120                                               +---------+
121                                               |         |
122                                               |  uart   |
123                                               |         |
124                                               +---------+
125*/
126
127
128/*****************************************************************************
129  Section A - Include Files
130*****************************************************************************/
131
132#include <rtems.h>
133#include <bsp.h>
134#include <rtems/bspIo.h>
135#include <stdio.h>
136#include <rtems/libio.h>
137#include <libchip/serial.h>
138#include <libchip/sersupp.h>
139#include "sci.h"
140//#include "../misc/include/cpu332.h"
141
142
143/*****************************************************************************
144  Section B - Manifest Constants
145*****************************************************************************/
146
147#define SCI_MINOR       0                   // minor device number
148
149
150// IMPORTANT - if the device driver api is opened, it means the sci is being
151// used for direct hardware access, so other users (like termios) get ignored
152
153#define DRIVER_CLOSED   0                   // the device driver api is closed
154#define DRIVER_OPENED   1                   // the device driver api is opened
155
156
157// system clock definitions, i dont have documentation on this...
158
159#if 0 // Not needed, this is provided in mrm332.h
160#define XTAL            32768.0                 // crystal frequency in Hz
161#define NUMB_W          0                               // system clock parameters
162#define NUMB_X          1
163//efine NUMB_Y          0x38                    // for 14.942 Mhz
164#define NUMB_Y          0x3F                        // for 16.777 Mhz
165
166#define SYS_CLOCK       (XTAL * 4.0 * (NUMB_Y+1) * (1 << (2 * NUMB_W + NUMB_X)))
167
168#endif
169
170
171/*****************************************************************************
172  Section C - External Data
173*****************************************************************************/
174
175
176
177
178/*****************************************************************************
179  Section D - External Functions
180*****************************************************************************/
181
182
183
184/*****************************************************************************
185  Section E - Local Functions
186*****************************************************************************/
187
188void SCI_output_char(char c);
189
190rtems_isr SciIsr( rtems_vector_number vector );         // interrupt handler
191
192const rtems_termios_callbacks * SciGetTermiosHandlers( signed32 polled );
193
194rtems_device_driver SciInitialize ();                   // device driver api
195rtems_device_driver SciOpen ();                         // device driver api
196rtems_device_driver SciClose ();                        // device driver api
197rtems_device_driver SciRead ();                         // device driver api
198rtems_device_driver SciWrite ();                        // device driver api
199rtems_device_driver SciControl ();                      // device driver api
200
201signed32 SciInterruptOpen();                            // termios api
202signed32 SciInterruptClose();                           // termios api
203signed32 SciInterruptWrite();                           // termios api
204
205signed32 SciSetAttributes();                            // termios api
206
207signed32 SciPolledOpen();                               // termios api
208signed32 SciPolledClose();                              // termios api
209signed32 SciPolledRead();                               // termios api
210signed32 SciPolledWrite();                              // termios api
211
212static void SciSetBaud(unsigned32 rate);                // hardware routine
213static void SciSetDataBits(unsigned16 bits);            // hardware routine
214static void SciSetParity(unsigned16 parity);            // hardware routine
215
216static void inline SciDisableAllInterrupts( void );     // hardware routine
217static void inline SciDisableTransmitInterrupts( void );// hardware routine
218static void inline SciDisableReceiveInterrupts( void ); // hardware routine
219
220static void inline SciEnableTransmitInterrupts( void ); // hardware routine
221static void inline SciEnableReceiveInterrupts( void );  // hardware routine
222
223static void inline SciDisableReceiver( void );          // hardware routine
224static void inline SciDisableTransmitter( void );       // hardware routine
225
226static void inline SciEnableReceiver( void );           // hardware routine
227static void inline SciEnableTransmitter( void );        // hardware routine
228
229void SciWriteCharWait  ( unsigned8 );                   // hardware routine
230void SciWriteCharNoWait( unsigned8 );                   // hardware routine
231
232unsigned8 inline SciCharAvailable( void );              // hardware routine
233
234unsigned8 inline SciReadCharWait( void );               // hardware routine
235unsigned8 inline SciReadCharNoWait( void );             // hardware routine
236
237void SciSendBreak( void );                              // test routine
238
239static signed8 SciRcvBufGetChar();                      // circular rcv buf
240static void    SciRcvBufPutChar( unsigned8 );           // circular rcv buf
241//atic void    SciRcvBufFlush( void );                  // circular rcv buf
242
243void SciUnitTest();                                     // test routine
244void SciPrintStats();                                   // test routine
245
246
247/*****************************************************************************
248  Section F - Local Variables
249*****************************************************************************/
250
251static struct rtems_termios_tty *SciTermioTty;
252
253
254static unsigned8 SciInited = 0;             // has the driver been inited
255
256static unsigned8 SciOpened;                 // has the driver been opened
257
258static unsigned8 SciMajor;                  // major device number
259
260static unsigned16 SciBaud;                  // current value in baud register
261
262static unsigned32 SciBytesIn  = 0;          // bytes received
263static unsigned32 SciBytesOut = 0;          // bytes transmitted
264
265static unsigned32 SciErrorsParity  = 0;     // error counter
266static unsigned32 SciErrorsNoise   = 0;     // error counter
267static unsigned32 SciErrorsFraming = 0;     // error counter
268static unsigned32 SciErrorsOverrun = 0;     // error counter
269
270#if defined(CONSOLE_SCI)
271
272// this is what rtems printk uses to do polling based output
273
274BSP_output_char_function_type      BSP_output_char = SCI_output_char;
275BSP_polling_getchar_function_type  BSP_poll_char   = NULL;
276
277#endif
278
279
280// cvs id string so you can use the unix ident command on the object
281
282#ifdef ID_STRINGS
283static const char SciIdent[]="$Id$";
284#endif
285
286
287/*****************************************************************************
288  Section G - A circular buffer for rcv chars when the driver interface is used.
289*****************************************************************************/
290
291// it is trivial to wrap your buffer pointers when size is a power of two
292
293#define SCI_RCV_BUF_SIZE        256         // must be a power of 2 !!!
294
295// if someone opens the sci device using the device driver interface,
296// then the receive data interrupt handler will put characters in this buffer
297// instead of sending them up to the termios module for the console
298
299static unsigned8 SciRcvBuffer[SCI_RCV_BUF_SIZE];
300
301static unsigned8 SciRcvBufPutIndex = 0;     // array index to put in next char
302
303static unsigned8 SciRcvBufGetIndex = 0;     // array index to take out next char
304
305static unsigned8 SciRcvBufCount = 0;        // how many bytes are in the buffer
306
307
308
309/*****************************************************************************
310  Section H - RTEMS termios callbacks for the interrupt version of the driver
311*****************************************************************************/
312
313static const rtems_termios_callbacks SciInterruptCallbacks =
314{
315    SciInterruptOpen,                       // first open
316    SciInterruptClose,                      // last close
317    NULL,                                   // polled read (not required)
318    SciInterruptWrite,                      // write
319    SciSetAttributes,                       // set attributes
320    NULL,                                   // stop remote xmit
321    NULL,                                   // start remote xmit
322    TRUE                                    // output uses interrupts
323};
324
325
326/*****************************************************************************
327  Section I - RTEMS termios callbacks for the polled version of the driver
328*****************************************************************************/
329
330static const rtems_termios_callbacks SciPolledCallbacks =
331{
332    SciPolledOpen,                          // first open
333    SciPolledClose,                         // last close
334    SciPolledRead,                          // polled read
335    SciPolledWrite,                         // write
336    SciSetAttributes,                       // set attributes
337    NULL,                                   // stop remote xmit
338    NULL,                                   // start remote xmit
339    FALSE                                   // output uses interrupts
340};
341
342
343/////////////////////////////////////////////////////////////////////////////
344//
345//                              SECTION 0
346//                        MISCELLANEOUS ROUTINES
347//
348/////////////////////////////////////////////////////////////////////////////
349
350
351/****************************************************************************
352* Func:     SCI_output_char
353* Desc:     used by rtems printk function to send a char to the uart
354* Inputs:   the character to transmit
355* Outputs:  none
356* Errors:   none
357* Scope:    public
358****************************************************************************/
359
360void SCI_output_char(char c)
361{
362//  ( minor device number, pointer to the character, length )
363
364    SciPolledWrite( SCI_MINOR, &c, 1);
365
366    return;
367}
368
369
370/****************************************************************************
371* Func:     SciGetTermiosHandlers
372* Desc:     returns a pointer to the table of serial io functions
373*           this is called from console_open with polled set to false
374* Inputs:   flag indicating whether we want polled or interrupt driven io
375* Outputs:  pointer to function table
376* Errors:   none
377* Scope:    public
378****************************************************************************/
379
380const rtems_termios_callbacks * SciGetTermiosHandlers( signed32 polled )
381{
382    if ( polled )
383    {
384        return &SciPolledCallbacks;             // polling based
385    }
386    else
387    {
388        return &SciInterruptCallbacks;          // interrupt driven
389    }
390}
391
392
393/****************************************************************************
394* Func:     SciIsr
395* Desc:     interrupt handler for serial communications interface
396* Inputs:   vector number - unused
397* Outputs:  none
398* Errors:   none
399* Scope:    public API
400****************************************************************************/
401
402rtems_isr SciIsr( rtems_vector_number vector )
403{
404    unsigned8 ch;
405
406
407    if ( (*SCSR) & SCI_ERROR_PARITY  )   SciErrorsParity  ++;
408    if ( (*SCSR) & SCI_ERROR_FRAMING )   SciErrorsFraming ++;
409    if ( (*SCSR) & SCI_ERROR_NOISE   )   SciErrorsNoise   ++;
410    if ( (*SCSR) & SCI_ERROR_OVERRUN )   SciErrorsOverrun ++;
411
412
413    // see if it was a transmit interrupt
414
415    if ( (*SCSR) & SCI_XMTR_AVAILABLE )         // data reg empty, xmt complete
416    {
417        SciDisableTransmitInterrupts();
418
419        // tell termios module that the charcter was sent
420        // he will call us later to transmit more if there are any
421
422        if (rtems_termios_dequeue_characters( SciTermioTty, 1 ))
423        {
424            // there are more bytes to transmit so enable TX interrupt
425
426            SciEnableTransmitInterrupts();
427        }
428    }
429
430    // see if it was a receive interrupt
431    // on the sci uart we just get one character per interrupt
432
433    while (  SciCharAvailable() )               // char in data register?
434    {
435        ch = SciReadCharNoWait();               // get the char from the uart
436
437        // IMPORTANT!!!
438        // either send it to the termios module or keep it locally
439
440        if ( SciOpened == DRIVER_OPENED )       // the driver is open
441        {
442            SciRcvBufPutChar(ch);               // keep it locally
443        }
444        else                                    // put in termios buffer
445        {
446            rtems_termios_enqueue_raw_characters( SciTermioTty, &ch, 1 );
447        }
448
449        *SCSR &= SCI_CLEAR_RX_INT;              // clear the interrupt
450    }
451}
452
453
454/////////////////////////////////////////////////////////////////////////////
455//
456//                              SECTION 1
457//                ROUTINES TO MANIPULATE THE CIRCULAR BUFFER
458//
459/////////////////////////////////////////////////////////////////////////////
460
461
462/****************************************************************************
463* Func:     SciRcvBufGetChar
464* Desc:     read a character from the circular buffer
465*           make sure there is data before you call this!
466* Inputs:   none
467* Outputs:  the character or -1
468* Errors:   none
469* Scope:    private
470****************************************************************************/
471
472static signed8 SciRcvBufGetChar()
473{
474    rtems_interrupt_level level;
475    unsigned8 ch;
476   
477    if ( SciRcvBufCount == 0 )
478    {
479        rtems_fatal_error_occurred(0xDEAD);     // check the count first!
480    }
481
482    rtems_interrupt_disable( level );           // disable interrupts
483
484    ch = SciRcvBuffer[SciRcvBufGetIndex];       // get next byte
485
486    SciRcvBufGetIndex++;                        // bump the index
487
488    SciRcvBufGetIndex &= SCI_RCV_BUF_SIZE - 1;  // and wrap it
489
490    SciRcvBufCount--;                           // decrement counter
491
492    rtems_interrupt_enable( level );            // restore interrupts
493
494    return ch;                                  // return the char
495}
496
497
498
499/****************************************************************************
500* Func:     SciRcvBufPutChar
501* Desc:     put a character into the rcv data circular buffer
502* Inputs:   the character
503* Outputs:  none
504* Errors:   none
505* Scope:    private
506****************************************************************************/
507
508static void SciRcvBufPutChar( unsigned8 ch )
509{
510    rtems_interrupt_level level;
511   
512    if ( SciRcvBufCount == SCI_RCV_BUF_SIZE )   // is there room?
513    {
514        return;                                 // no, throw it away
515    }
516
517    rtems_interrupt_disable( level );           // disable interrupts
518
519    SciRcvBuffer[SciRcvBufPutIndex] = ch;       // put it in the buf
520
521    SciRcvBufPutIndex++;                        // bump the index
522
523    SciRcvBufPutIndex &= SCI_RCV_BUF_SIZE - 1;  // and wrap it
524
525    SciRcvBufCount++;                           // increment counter
526
527    rtems_interrupt_enable( level );            // restore interrupts
528
529    return;                                     // return
530}
531
532
533/****************************************************************************
534* Func:     SciRcvBufFlush
535* Desc:     completely reset and clear the rcv buffer
536* Inputs:   none
537* Outputs:  none
538* Errors:   none
539* Scope:    private
540****************************************************************************/
541
542#if 0                                           // prevents compiler warning
543static void SciRcvBufFlush( void )
544{
545    rtems_interrupt_level level;
546   
547    rtems_interrupt_disable( level );           // disable interrupts
548
549    memset( SciRcvBuffer, 0, sizeof(SciRcvBuffer) );
550
551    SciRcvBufPutIndex = 0;                      // clear
552
553    SciRcvBufGetIndex = 0;                      // clear
554
555    SciRcvBufCount = 0;                         // clear
556
557    rtems_interrupt_enable( level );            // restore interrupts
558
559    return;                                     // return
560}
561#endif
562
563
564/////////////////////////////////////////////////////////////////////////////
565//
566//                              SECTION 2
567//            INTERRUPT BASED ENTRY POINTS FOR THE TERMIOS MODULE
568//
569/////////////////////////////////////////////////////////////////////////////
570
571
572/****************************************************************************
573* Func:     SciInterruptOpen
574* Desc:     open routine for the interrupt based device driver
575*           Default state is 9600 baud, 8 bits, No parity, and 1 stop bit. ??
576**CHANGED** Default baud rate is now 19200, 8N1
577*           called from rtems_termios_open which is called from console_open
578* Inputs:   major - device number
579*           minor - device number
580*           args - points to terminal info
581* Outputs:  success/fail
582* Errors:   none
583* Scope:    public API
584****************************************************************************/
585
586signed32 SciInterruptOpen(
587    signed32  major,
588    signed32  minor,
589    void     *arg
590)
591{
592    rtems_libio_open_close_args_t * args = arg;
593    rtems_isr_entry old_vector;
594
595    if ( minor != SCI_MINOR )                   // check minor device num
596    {
597        return -1;
598    }
599
600    if ( !args )                                // must have args
601    {
602        return -1;
603    }
604
605    SciTermioTty = args->iop->data1;            // save address of struct
606
607    SciDisableAllInterrupts();                  // turn off sci interrupts
608
609    // THIS IS ACTUALLY A BAD THING - SETTING LINE PARAMETERS HERE
610    // IT SHOULD BE DONE THROUGH TCSETATTR() WHEN THE CONSOLE IS OPENED!!!
611
612//  SciSetBaud(115200);                         // set the baud rate
613//  SciSetBaud( 57600);                         // set the baud rate
614//  SciSetBaud( 38400);                         // set the baud rate
615SciSetBaud( 19200);                         // set the baud rate
616//    SciSetBaud(  9600);                         // set the baud rate
617
618    SciSetParity(SCI_PARITY_NONE);              // set parity to none
619
620    SciSetDataBits(SCI_8_DATA_BITS);            // set data bits to 8
621
622
623    // Install our interrupt handler into RTEMS, where does 66 come from?
624
625    rtems_interrupt_catch( SciIsr, 66, &old_vector );
626
627    *QIVR  = 66;
628    *QIVR &= 0xf8;
629    *QILR |= 0x06 & 0x07;
630
631    SciEnableTransmitter();                     // enable the transmitter
632
633    SciEnableReceiver();                        // enable the receiver
634
635    SciEnableReceiveInterrupts();               // enable rcv interrupts
636
637    return RTEMS_SUCCESSFUL;
638}
639
640
641/****************************************************************************
642* Func:     SciInterruptClose
643* Desc:     close routine called by the termios module
644* Inputs:   major - device number
645*           minor - device number
646*           args - unused
647* Outputs:  success/fail
648* Errors:   none
649* Scope:    public - termio entry point
650****************************************************************************/
651
652signed32 SciInterruptClose(
653    signed32  major,
654    signed32  minor,
655    void     *arg
656)
657{
658    SciDisableAllInterrupts();
659
660    return RTEMS_SUCCESSFUL;
661}
662
663
664/****************************************************************************
665* Func:     SciInterruptWrite
666* Desc:     writes data to the uart using transmit interrupts
667* Inputs:   minor - device number
668*           buf - points to the data
669*           len - number of bytes to send
670* Outputs:  success/fail
671* Errors:   none
672* Scope:    public API
673****************************************************************************/
674
675signed32 SciInterruptWrite(
676    signed32    minor,
677    const char *buf,
678    signed32    len
679)
680{
681    // We are using interrupt driven output so termios only sends us
682    // one character at a time. The sci does not have a fifo.
683
684    if ( !len )                                 // no data?
685    {
686        return 0;                               // return error
687    }
688
689    if ( minor != SCI_MINOR )                   // check the minor dev num
690    {
691        return 0;                               // return error
692    }
693
694    if ( SciOpened == DRIVER_OPENED )           // is the driver api open?
695    {
696        return 1;                               // yep, throw this away
697    }
698
699    SciWriteCharNoWait(*buf);                   // try to send a char
700
701    *SCSR &= SCI_CLEAR_TDRE;                    // clear tx data reg empty flag
702
703    SciEnableTransmitInterrupts();              // enable the tx interrupt
704
705    return 1;                                   // return success
706}
707
708
709/****************************************************************************
710* Func:     SciSetAttributes
711* Desc:     setup the uart based on the termios modules requests
712* Inputs:   minor - device number
713*           t - pointer to the termios info struct
714* Outputs:  none
715* Errors:   none
716* Scope:    public API
717****************************************************************************/
718
719signed32 SciSetAttributes(
720    signed32 minor,
721    const struct termios *t
722)
723{
724    unsigned32  baud_requested;
725    unsigned32  sci_rate = 0;
726    unsigned16  sci_parity = 0;
727    unsigned16  sci_databits = 0;
728
729    if ( minor != SCI_MINOR )                   // check the minor dev num
730    {     
731        return -1;                              // return error
732    }
733
734    // if you look closely you will see this is the only thing we use
735    // set the baud rate
736
737    baud_requested = t->c_cflag & CBAUD;        // baud rate
738
739    if (!baud_requested)
740    {
741//        baud_requested = B9600;                 // default to 9600 baud
742        baud_requested = B19200;                 // default to 19200 baud
743    }
744   
745    sci_rate = termios_baud_to_number( baud_requested );
746
747    // parity error detection
748
749    if (t->c_cflag & PARENB)                    // enable parity detection?
750    {
751        if (t->c_cflag & PARODD)
752        {
753            sci_parity = SCI_PARITY_ODD;        // select odd parity
754        }
755        else
756        {
757            sci_parity = SCI_PARITY_EVEN;       // select even parity
758        }
759    }
760    else
761    {
762        sci_parity = SCI_PARITY_NONE;           // no parity, most common
763    }
764
765
766    //  set the number of data bits, 8 is most common
767
768    if (t->c_cflag & CSIZE)                     // was it specified?
769    {
770        switch (t->c_cflag & CSIZE)
771        {
772            case CS8:   sci_databits = SCI_8_DATA_BITS;   break;
773            default :   sci_databits = SCI_9_DATA_BITS;   break;
774        }
775    }
776    else
777    {
778        sci_databits = SCI_8_DATA_BITS;         // default to 8 data bits
779    }
780
781
782    //  the number of stop bits; always 1 for SCI
783
784    if (t->c_cflag & CSTOPB)
785    {
786        // do nothing
787    }
788
789
790    // setup the hardware with these serial port parameters
791
792    SciSetBaud(sci_rate);                       // set the baud rate
793
794    SciSetParity(sci_parity);                   // set the parity type
795
796    SciSetDataBits(sci_databits);               // set the data bits
797
798
799    return RTEMS_SUCCESSFUL;
800}
801
802
803/////////////////////////////////////////////////////////////////////////////
804//
805//                              SECTION 3
806//            POLLING BASED ENTRY POINTS FOR THE TERMIOS MODULE
807//
808/////////////////////////////////////////////////////////////////////////////
809
810/****************************************************************************
811* Func:     SciPolledOpen
812* Desc:     open routine for the polled i/o version of the driver
813*           called from rtems_termios_open which is called from console_open
814* Inputs:   major - device number
815*           minor - device number
816*           args - points to terminal info struct
817* Outputs:  success/fail
818* Errors:   none
819* Scope:    public - termios entry point
820****************************************************************************/
821
822signed32 SciPolledOpen(
823    signed32 major,
824    signed32 minor,
825    void    *arg
826)
827{
828    rtems_libio_open_close_args_t * args = arg;
829
830    if ( minor != SCI_MINOR )                   // check minor device num
831    {
832        return -1;
833    }
834
835    if ( !args )                                // must have args
836    {
837        return -1;
838    }
839
840    SciTermioTty = args->iop->data1;            // Store tty pointer
841
842    SciDisableAllInterrupts();                  // don't generate interrupts
843
844    // THIS IS ACTUALLY A BAD THING - SETTING LINE PARAMETERS HERE
845    // IT SHOULD BE DONE THROUGH TCSETATTR() WHEN THE CONSOLE IS OPENED!!!
846
847//  SciSetBaud(115200);                         // set the baud rate
848//  SciSetBaud( 57600);                         // set the baud rate
849//  SciSetBaud( 38400);                         // set the baud rate
850  SciSetBaud( 19200);                         // set the baud rate
851//  SciSetBaud(  9600);                         // set the baud rate
852
853    SciSetParity(SCI_PARITY_NONE);              // set no parity
854
855    SciSetDataBits(SCI_8_DATA_BITS);            // set 8 data bits
856
857    SciEnableTransmitter();                     // enable the xmitter
858
859    SciEnableReceiver();                        // enable the rcvr
860
861    return RTEMS_SUCCESSFUL;
862}
863
864
865/****************************************************************************
866* Func:     SciPolledClose
867* Desc:     close routine for the device driver, same for both
868* Inputs:   major - device number
869*           minor - device number
870*           args - unused
871* Outputs:  success/fail
872* Errors:   none
873* Scope:    public termios API
874****************************************************************************/
875
876signed32 SciPolledClose(
877    signed32  major,
878    signed32  minor,
879    void     *arg
880)
881{
882    SciDisableAllInterrupts();
883
884    return RTEMS_SUCCESSFUL;
885}
886
887
888/****************************************************************************
889* Func:     SciPolledRead
890* Desc:     polling based read routine for the uart
891* Inputs:   minor - device number
892* Outputs:  error or the character read
893* Errors:   none
894* Scope:    public API
895****************************************************************************/
896
897signed32 SciPolledRead(
898    signed32 minor
899)
900{
901    if ( minor != SCI_MINOR )               // check the minor dev num
902    {
903        return -1;                          // return error
904    }
905
906    if ( SciCharAvailable() )               // if a char is available
907    {
908        return SciReadCharNoWait();         // read the rx data register
909    }
910
911    return -1;                              // return error
912}
913
914
915/****************************************************************************
916* Func:     SciPolledWrite
917* Desc:     writes out characters in polled mode, waiting for the uart
918*           check in console_open, but we only seem to use interrupt mode
919* Inputs:   minor - device number
920*           buf - points to the data
921*           len - how many bytes
922* Outputs:  error or number of bytes written
923* Errors:   none
924* Scope:    public termios API
925****************************************************************************/
926
927signed32 SciPolledWrite(
928    signed32      minor,
929    const char   *buf,
930    signed32      len
931)
932{
933    signed32 written = 0;
934
935    if ( minor != SCI_MINOR )                   // check minor device num
936    {
937        return -1;
938    }
939
940    if ( SciOpened == DRIVER_OPENED )           // is the driver api open?
941    {
942        return -1;                              // toss the data
943    }
944
945    // send each byte in the string out the port
946
947    while ( written < len )
948    {
949        SciWriteCharWait(*buf++);               // send a byte
950
951        written++;                              // increment counter
952    }
953
954    return written;                             // return count
955}
956
957
958/////////////////////////////////////////////////////////////////////////////
959//
960//                              SECTION 4
961//                 DEVICE DRIVER PUBLIC API ENTRY POINTS
962//
963/////////////////////////////////////////////////////////////////////////////
964
965
966/****************************************************************************
967* Func:     SciInit
968* Desc:     Initialize the lasers device driver and hardware
969* Inputs:   major - the major device number which is assigned by rtems
970*           minor - the minor device number which is undefined at this point
971*           arg - ?????
972* Outputs:  RTEMS_SUCCESSFUL
973* Errors:   None.
974* Scope:    public API
975****************************************************************************/
976
977rtems_device_driver SciInitialize (
978    rtems_device_major_number major,
979    rtems_device_minor_number minor,
980    void * arg
981)
982{
983//     rtems_status_code status;
984
985//printk("%s\r\n", __FUNCTION__);
986
987
988    // register the SCI device name for termios console i/o
989    // this is done over in console.c which doesn't seem exactly right
990    // but there were problems doing it here...
991
992//  status = rtems_io_register_name( "/dev/sci", major, 0 );
993
994//  if (status != RTEMS_SUCCESSFUL)
995//      rtems_fatal_error_occurred(status);
996
997
998    SciMajor = major;                           // save the rtems major number
999
1000    SciOpened = DRIVER_CLOSED;                  // initial state is closed
1001
1002
1003    // if you have an interrupt handler, install it here
1004
1005
1006    SciInited = 1;                              // set the inited flag
1007
1008    return RTEMS_SUCCESSFUL;
1009}
1010
1011
1012/****************************************************************************
1013* Func:     SciOpen
1014* Desc:     device driver open routine
1015*           you must open a device before you can anything else
1016*           only one process can have the device opened at a time
1017*           you could look at the task id to restrict access if you want
1018* Inputs:   major - the major device number assigned by rtems
1019*           minor - the minor device number assigned by us
1020*           arg - ?????
1021* Outputs:  see below
1022* Errors:   none
1023* Scope:    public API
1024****************************************************************************/
1025
1026rtems_device_driver SciOpen (
1027    rtems_device_major_number major,
1028    rtems_device_minor_number minor,
1029    void * arg
1030)
1031{
1032//printk("%s major=%d minor=%d\r\n", __FUNCTION__,major,minor);
1033
1034    if (SciInited == 0)                         // must be initialized first!
1035    {
1036        return RTEMS_NOT_CONFIGURED;
1037    }
1038
1039    if (minor != SCI_MINOR)
1040    {
1041        return RTEMS_INVALID_NAME;              // verify minor number
1042    }
1043
1044    if (SciOpened == DRIVER_OPENED)
1045    {
1046        return RTEMS_RESOURCE_IN_USE;           // already opened!
1047    }
1048
1049    SciOpened = DRIVER_OPENED;                  // set the opened flag
1050
1051    return RTEMS_SUCCESSFUL;
1052}
1053
1054
1055/****************************************************************************
1056* Func:     SciClose
1057* Desc:     device driver close routine
1058*           the device must be opened before you can close it
1059*           the device must be closed before someone (else) can open it
1060* Inputs:   major - the major device number
1061*           minor - the minor device number
1062*           arg - ?????
1063* Outputs:  see below
1064* Errors:   none
1065* Scope:    public API
1066****************************************************************************/
1067
1068rtems_device_driver SciClose (
1069    rtems_device_major_number major,
1070    rtems_device_minor_number minor,
1071    void * arg
1072)
1073{
1074//printk("%s major=%d minor=%d\r\n", __FUNCTION__,major,minor);
1075
1076    if (minor != SCI_MINOR)
1077    {
1078        return RTEMS_INVALID_NAME;              // check the minor number
1079    }
1080
1081    if (SciOpened != DRIVER_OPENED)
1082    {
1083        return RTEMS_INCORRECT_STATE;           // must be opened first
1084    }
1085
1086    SciOpened = DRIVER_CLOSED;                  // set the flag
1087
1088    return RTEMS_SUCCESSFUL;
1089}
1090
1091
1092/****************************************************************************
1093* Func:     SciRead
1094* Desc:     device driver read routine
1095*           this function is not meaningful for the laser devices
1096* Inputs:   major - the major device number
1097*           minor - the minor device number
1098*           arg - read/write arguments
1099* Outputs:  see below
1100* Errors:   none
1101* Scope:    public API
1102****************************************************************************/
1103
1104rtems_device_driver SciRead (
1105    rtems_device_major_number major,
1106    rtems_device_minor_number minor,
1107    void *arg
1108)
1109{
1110    rtems_libio_rw_args_t *rw_args;             // ptr to argument struct
1111    unsigned8 *buffer;
1112    unsigned16 length;
1113 
1114    rw_args = (rtems_libio_rw_args_t *) arg;    // arguments to read()
1115
1116
1117    if (minor != SCI_MINOR)
1118    {
1119        return RTEMS_INVALID_NAME;              // check the minor number
1120    }
1121
1122    if (SciOpened == DRIVER_CLOSED)
1123    {
1124        return RTEMS_INCORRECT_STATE;           // must be opened first
1125    }
1126
1127    buffer = rw_args->buffer;                   // points to user's buffer
1128
1129    length = rw_args->count;                    // how many bytes they want
1130
1131//  *buffer = SciReadCharWait();                // wait for a character
1132
1133    // if there isn't a character available, wait until one shows up
1134    // or the timeout period expires, which ever happens first
1135
1136    if ( SciRcvBufCount == 0 )                  // no chars
1137    {
1138        // wait for someone to wake me up...
1139        //rtems_task_wake_after(SciReadTimeout);
1140    }
1141
1142    if ( SciRcvBufCount )                       // any characters locally?
1143    {
1144        *buffer = SciRcvBufGetChar();           // get the character
1145
1146        rw_args->bytes_moved = 1;               // how many we actually read
1147    }
1148
1149    return RTEMS_SUCCESSFUL;
1150}
1151
1152
1153/****************************************************************************
1154* Func:     SciWrite
1155* Desc:     device driver write routine
1156*           this function is not meaningful for the laser devices
1157* Inputs:   major - the major device number
1158*           minor - the minor device number
1159*           arg - read/write arguments
1160* Outputs:  see below
1161* Errors:   non3
1162* Scope:    public API
1163****************************************************************************/
1164
1165rtems_device_driver SciWrite (
1166    rtems_device_major_number major,
1167    rtems_device_minor_number minor,
1168    void * arg
1169)
1170{
1171    rtems_libio_rw_args_t *rw_args;             // ptr to argument struct
1172    unsigned8 *buffer;
1173    unsigned16 length;
1174 
1175    rw_args = (rtems_libio_rw_args_t *) arg;
1176
1177    if (minor != SCI_MINOR)
1178    {
1179        return RTEMS_INVALID_NAME;              // check the minor number
1180    }
1181
1182    if (SciOpened == DRIVER_CLOSED)
1183    {
1184        return RTEMS_INCORRECT_STATE;           // must be opened first
1185    }
1186
1187    buffer = (unsigned8*)rw_args->buffer;       // points to data
1188
1189    length = rw_args->count;                    // how many bytes
1190
1191    while (length--)
1192    {
1193        SciWriteCharWait(*buffer++);            // send the bytes out
1194    }
1195
1196    rw_args->bytes_moved = rw_args->count;      // how many we wrote
1197
1198    return RTEMS_SUCCESSFUL;
1199}
1200
1201
1202/****************************************************************************
1203* Func:     SciControl
1204* Desc:     device driver control routine
1205*           see below for an example of how to use the ioctl interface
1206* Inputs:   major - the major device number
1207*           minor - the minor device number
1208*           arg - io control args
1209* Outputs:  see below
1210* Errors:   none
1211* Scope:    public API
1212****************************************************************************/
1213
1214rtems_device_driver SciControl (
1215    rtems_device_major_number major,
1216    rtems_device_minor_number minor,
1217    void * arg
1218)
1219{
1220    rtems_libio_ioctl_args_t *args = arg;       // rtems arg struct
1221    unsigned16 command;                         // the cmd to execute
1222    unsigned16 unused;                          // maybe later
1223    unsigned16 *ptr;                            // ptr to user data
1224 
1225//printk("%s major=%d minor=%d\r\n", __FUNCTION__,major,minor);
1226
1227    // do some sanity checking
1228
1229    if (minor != SCI_MINOR)
1230    {
1231        return RTEMS_INVALID_NAME;              // check the minor number
1232    }
1233
1234    if (SciOpened == DRIVER_CLOSED)
1235    {
1236        return RTEMS_INCORRECT_STATE;           // must be open first
1237    }
1238
1239    if (args == 0)
1240    {
1241        return RTEMS_INVALID_ADDRESS;           // must have args
1242    }
1243
1244    args->ioctl_return = -1;                    // assume an error
1245
1246    command = args->command;                    // get the command
1247    ptr     = args->buffer;                     // this is an address
1248    unused  = *ptr;                             // brightness
1249
1250    if (command == SCI_SEND_BREAK)              // process the command
1251    {
1252        SciSendBreak();                         // send break char
1253    }
1254
1255    args->ioctl_return = 0;                     // return status
1256
1257    return RTEMS_SUCCESSFUL;
1258}
1259
1260
1261/////////////////////////////////////////////////////////////////////////////
1262//
1263//                              SECTION 5
1264//                       HARDWARE LEVEL ROUTINES
1265//
1266/////////////////////////////////////////////////////////////////////////////
1267
1268
1269/****************************************************************************
1270* Func:     SciSetBaud
1271* Desc:     setup the uart based on the termios modules requests
1272* Inputs:   baud rate
1273* Outputs:  none
1274* Errors:   none
1275* Scope:    private
1276****************************************************************************/
1277
1278static void SciSetBaud(unsigned32 rate)
1279{
1280    unsigned16 value;
1281    unsigned16 save_sccr1;
1282
1283// when you open the console you need to set the termio struct baud rate
1284// it has a default value of 9600, when someone calls tcsetattr it reverts!
1285
1286
1287    SciBaud = rate;                             // save the rate
1288
1289    // calculate the register value as a float and convert to an int
1290    // set baud rate - you must define the system clock constant
1291    // see mrm332.h for an example
1292
1293    value = ( (unsigned16) ( SYS_CLOCK / rate / 32.0 + 0.5 ) & 0x1fff );
1294
1295    save_sccr1 = *SCCR1;                        // save register
1296
1297    // also turns off the xmtr and rcvr
1298
1299    *SCCR1 &= SCI_DISABLE_INT_ALL;              // disable interrupts
1300
1301    *SCCR0 = value;                             // write the register
1302
1303    *SCCR1 = save_sccr1;                        // restore register
1304
1305    return;
1306}
1307
1308
1309/****************************************************************************
1310* Func:     SciSetParity
1311* Desc:     setup the uart based on the termios modules requests
1312* Inputs:   parity
1313* Outputs:  none
1314* Errors:   none
1315* Scope:    private
1316****************************************************************************/
1317
1318static void SciSetParity(unsigned16 parity)
1319{
1320    unsigned16 value;
1321
1322    value = *SCCR1;                             // get the register
1323
1324    if (parity == SCI_PARITY_ODD)
1325    {
1326        value |= SCI_PARITY_ENABLE;             // parity enabled
1327        value |= SCI_PARITY_ODD;                // parity odd
1328    }
1329
1330    else if (parity == SCI_PARITY_EVEN)
1331    {
1332        value |= SCI_PARITY_ENABLE;             // parity enabled
1333        value &= ~SCI_PARITY_ODD;               // parity even
1334    }
1335
1336    else if (parity == SCI_PARITY_NONE)
1337    {
1338        value &= ~SCI_PARITY_ENABLE;            // disabled, most common
1339    }
1340
1341    /* else no changes */
1342
1343    *SCCR1 = value;                             // write the register
1344
1345    return;
1346}
1347
1348
1349/****************************************************************************
1350* Func:     SciSetDataBits
1351* Desc:     setup the uart based on the termios modules requests
1352* Inputs:   data bits
1353* Outputs:  none
1354* Errors:   none
1355* Scope:    private
1356****************************************************************************/
1357
1358static void SciSetDataBits(unsigned16 bits)
1359{
1360    unsigned16 value;
1361
1362    value = *SCCR1;                             // get the register
1363
1364    /* note - the parity setting affects the number of data bits */
1365
1366    if (bits == SCI_9_DATA_BITS)
1367    {
1368        value |= SCI_9_DATA_BITS;               // 9 data bits
1369    }
1370
1371    else if (bits == SCI_8_DATA_BITS)
1372    {
1373        value &= SCI_8_DATA_BITS;               // 8 data bits
1374    }
1375
1376    /* else no changes */
1377
1378    *SCCR1 = value;                             // write the register
1379
1380    return;
1381}
1382
1383
1384/****************************************************************************
1385* Func:     SciDisableAllInterrupts
1386* Func:     SciEnableTransmitInterrupts
1387* Func:     SciEnableReceiveInterrupts
1388* Desc:     handles generation of interrupts by the sci module
1389* Inputs:   none
1390* Outputs:  none
1391* Errors:   none
1392* Scope:    private
1393****************************************************************************/
1394
1395static void inline SciDisableAllInterrupts( void )
1396{
1397    // this also turns off the xmtr and rcvr
1398
1399    *SCCR1 &= SCI_DISABLE_INT_ALL;
1400}
1401
1402static void inline SciEnableReceiveInterrupts( void )
1403{
1404    *SCCR1 |= SCI_ENABLE_INT_RX;
1405}
1406
1407static void inline SciDisableReceiveInterrupts( void )
1408{
1409    *SCCR1 &= SCI_DISABLE_INT_RX;
1410}
1411
1412static void inline SciEnableTransmitInterrupts( void )
1413{
1414    *SCCR1 |= SCI_ENABLE_INT_TX;
1415}
1416
1417static void inline SciDisableTransmitInterrupts( void )
1418{
1419    *SCCR1 &= SCI_DISABLE_INT_TX;
1420}
1421
1422
1423/****************************************************************************
1424* Func:     SciEnableTransmitter, SciDisableTransmitter
1425* Func:     SciEnableReceiver,    SciDisableReceiver
1426* Desc:     turns the transmitter and receiver on and off
1427* Inputs:   none
1428* Outputs:  none
1429* Errors:   none
1430* Scope:    private
1431****************************************************************************/
1432
1433static void inline SciEnableTransmitter( void )
1434{
1435    *SCCR1 |= SCI_ENABLE_XMTR;
1436}
1437
1438static void inline SciDisableTransmitter( void )
1439{
1440    *SCCR1 &= SCI_DISABLE_XMTR;
1441}
1442
1443static void inline SciEnableReceiver( void )
1444{
1445    *SCCR1 |= SCI_ENABLE_RCVR;
1446}
1447
1448static void inline SciDisableReceiver( void )
1449{
1450    *SCCR1 &= SCI_DISABLE_RCVR;
1451}
1452
1453
1454/****************************************************************************
1455* Func:     SciWriteCharWait
1456* Desc:     wait for room in the fifo and then put a char in
1457* Inputs:   a byte to send
1458* Outputs:  none
1459* Errors:   none
1460* Scope:    public
1461****************************************************************************/
1462
1463void SciWriteCharWait(unsigned8 c)
1464{
1465    // poll the fifo, waiting for room for another character
1466
1467    while ( ( *SCSR & SCI_XMTR_AVAILABLE ) == 0 )
1468    {
1469        /* Either we are writing to the fifo faster than
1470         * the uart can clock bytes out onto the cable,
1471         * or we are in flow control (actually no, we
1472         * are ignoring flow control from the other end).
1473         * In the first case, higher baud rates will help.
1474         */
1475      /* relinquish processor while waiting */
1476      rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
1477    }
1478
1479    *SCDR = c;                                  // send the charcter
1480
1481    SciBytesOut++;                              // increment the counter
1482
1483    return;
1484}
1485
1486
1487/****************************************************************************
1488* Func:     SciWriteCharNoWait
1489* Desc:     if no room in the fifo throw the char on the floor
1490* Inputs:   a byte to send
1491* Outputs:  none
1492* Errors:   none
1493* Scope:    public
1494****************************************************************************/
1495
1496void SciWriteCharNoWait(unsigned8 c)
1497{
1498    if ( ( *SCSR & SCI_XMTR_AVAILABLE ) == 0 )
1499    {
1500        return;                                 // no room, throw it away
1501    }
1502
1503    *SCDR = c;                                  // put the char in the fifo
1504
1505    SciBytesOut++;                              // increment the counter
1506
1507    return;
1508}
1509
1510
1511/****************************************************************************
1512* Func:     SciReadCharWait
1513* Desc:     read a character, waiting for one to show up, if need be
1514* Inputs:   none
1515* Outputs:  a character
1516* Errors:   none
1517* Scope:    public
1518****************************************************************************/
1519
1520unsigned8 inline SciReadCharWait( void )
1521{
1522    unsigned8 ch;
1523
1524    while ( SciCharAvailable() == 0 )           // anything there?
1525    {
1526      /* relinquish processor while waiting */
1527      rtems_task_wake_after(RTEMS_YIELD_PROCESSOR);
1528    }
1529
1530    // if you have rcv ints enabled, then the isr will probably
1531    // get the character before you will unless you turn off ints
1532    // ie polling and ints don't mix that well
1533
1534    ch = *SCDR;                                 // get the charcter
1535
1536    SciBytesIn++;                               // increment the counter
1537
1538    return ch;                                  // return the char
1539}
1540
1541
1542/****************************************************************************
1543* Func:     SciReadCharNoWait
1544* Desc:     try to get a char but dont wait for one
1545* Inputs:   none
1546* Outputs:  a character or -1 if none
1547* Errors:   none
1548* Scope:    public
1549****************************************************************************/
1550
1551unsigned8 inline SciReadCharNoWait( void )
1552{
1553    unsigned8 ch;
1554
1555    if ( SciCharAvailable() == 0 )              // anything there?
1556        return -1;
1557
1558    ch = *SCDR;                                 // get the character
1559
1560    SciBytesIn++;                               // increment the count
1561
1562    return ch;                                  // return the char
1563}
1564
1565
1566
1567/****************************************************************************
1568* Func:     SciCharAvailable
1569* Desc:     is there a receive character in the data register
1570* Inputs:   none
1571* Outputs:  false if no char available, else true
1572* Errors:   none
1573* Scope:    public
1574****************************************************************************/
1575
1576unsigned8 inline SciCharAvailable( void )
1577{
1578    return ( *SCSR & SCI_RCVR_READY );          // char in data register?
1579}
1580
1581
1582/****************************************************************************
1583* Func:     SciSendBreak
1584* Desc:     send 1 or tow breaks (all zero bits)
1585* Inputs:   none
1586* Outputs:  none
1587* Errors:   none
1588* Scope:    public
1589****************************************************************************/
1590
1591void SciSendBreak( void )
1592{
1593    // From the Motorola QSM reference manual -
1594
1595    // "if SBK is toggled by writing it first to a one and then immediately
1596    // to a zero (in less than one serial frame interval), the transmitter
1597    // sends only one or two break frames before reverting to mark (idle)
1598    // or before commencing to send more data"
1599
1600    *SCCR1 |=  SCI_SEND_BREAK;                  // set the bit
1601
1602    *SCCR1 &= ~SCI_SEND_BREAK;                  // clear the bit
1603
1604    return;
1605}
1606
1607
1608/////////////////////////////////////////////////////////////////////////////
1609//
1610//                             SECTION 6
1611//                             TEST CODE
1612//
1613/////////////////////////////////////////////////////////////////////////////
1614
1615
1616/****************************************************************************
1617* Func:     SciUnitTest
1618* Desc:     test the device driver
1619* Inputs:   nothing
1620* Outputs:  nothing
1621* Scope:    public
1622****************************************************************************/
1623
1624#if 0
1625#define O_RDWR LIBIO_FLAGS_READ_WRITE           // dont like this but...
1626
1627void SciUnitTest()
1628{
1629    unsigned8 byte;                             // a character
1630    unsigned16 fd;                              // file descriptor for device
1631    unsigned16 result;                          // result of ioctl
1632
1633
1634    fd = open("/dev/sci",O_RDWR);               // open the device
1635
1636printk("SCI open fd=%d\r\n",fd);
1637
1638
1639    result = write(fd, "abcd\r\n", 6);          // send a string
1640
1641printk("SCI write result=%d\r\n",result);
1642
1643
1644    result = read(fd, &byte, 1);                // read a byte
1645
1646printk("SCI read result=%d,byte=%x\r\n",result,byte);
1647
1648    return;
1649}
1650#endif
1651
1652
1653/****************************************************************************
1654* Func:     SciPrintStats
1655* Desc:     print out some driver information
1656* Inputs:   nothing
1657* Outputs:  nothing
1658* Scope:    public
1659****************************************************************************/
1660
1661void SciPrintStats ( void )
1662{
1663    printk("\r\n");
1664
1665    printk( "SYS_CLOCK is %2.6f Mhz\r\n\n", SYS_CLOCK / 1000000.0 );
1666
1667    printk( "Current baud rate is %d bps or %d cps\r\n\n", SciBaud, SciBaud / 10 );
1668
1669    printk( "SCI Uart chars in       %8d\r\n", SciBytesIn       );
1670    printk( "SCI Uart chars out      %8d\r\n", SciBytesOut      );
1671    printk( "SCI Uart framing errors %8d\r\n", SciErrorsFraming );
1672    printk( "SCI Uart parity  errors %8d\r\n", SciErrorsParity  );
1673    printk( "SCI Uart overrun errors %8d\r\n", SciErrorsOverrun );
1674    printk( "SCI Uart noise   errors %8d\r\n", SciErrorsNoise   );
1675
1676    return;
1677}
1678
1679
1680
Note: See TracBrowser for help on using the repository browser.