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

4.104.114.84.95
Last change on this file since f74d9f1f was f74d9f1f, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/31/04 at 04:37:05

2004-03-31 Ralf Corsepius <ralf_corsepius@…>

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