source: svn/trunk/newcon3bcm2_21bu/dta/src/nexus_serial.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 3.9 KB
Line 
1/*************************************************************************
2**
3**     Broadcom Corp. Confidential
4**     Copyright 1999, 2000 Broadcom Corp.  All Rights Reserved.
5**
6**  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7**  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8**  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9**
10**      File:           serial.h
11**      Description:    polled uart io
12**    Created:          Jeff Fisher
13**    REVISION:
14**
15****************************************************************************/
16
17#include "serial.h"
18
19/***********************************************************************/
20/* serial_init(UartChannel *uart,unsigned int baud)*/
21/***********************************************************************/
22void serial_init(volatile UartChannel *uart, unsigned int baud)
23{
24#if (BCHP_CHIP==7550)
25        uart->sdw_lsr = 0;
26#else
27        /*---------------------------------------------------------------------*/
28        /* Dissable channel's receiver and transmitter.                        */
29        /*---------------------------------------------------------------------*/
30        uart->control = 0;
31//    uart->control &= ~(TXEN|RXEN);
32
33        /*---------------------------------------------------------------------*/
34    /* disable interrupts on this channel        .                          */
35        /*---------------------------------------------------------------------*/
36        uart->rxstat = 0;
37        uart->txstat = 0;
38
39        /*-----------------------------------------------------------------*/
40        /* set character size  and parity control bit (8,none only)        */
41        /*-----------------------------------------------------------------*/
42        uart->control = BITM8;
43        baud =  ((XTALFREQ / baud) /16);
44        uart->baudh = (unsigned char)((baud >> 8) & 0xFF);
45        uart->baudl = (unsigned char)(baud & 0xFF);
46
47        /*---------------------------------------------------------------------*/
48        /* Finally, re-enable the transmitter and receiver.                    */
49        /*---------------------------------------------------------------------*/
50        uart->control |= (TXEN|RXEN);
51#endif
52}
53
54/***********************************************************************/
55/* serial_getc(UartChannel *uart, int block)*/
56/***********************************************************************/
57#define RXRDA          0x01
58#define RXOVFERR       0x02
59#define RXPARERR       0x04
60#define RXFRAMERR      0x08
61#define RXBIERR        0x10             /* BI error */
62#define RXFIFOERR      0x80     /* Rx FIFO error */
63int serial_getc(volatile UartChannel *uart, bool block)
64{       
65#if (BCHP_CHIP==7550)
66        int blen = 1;
67        unsigned int status;
68        char tval;
69
70        while (blen > 0) 
71        {
72                status = uart->sdw_lsr;
73                if(status & (RXOVFERR | RXPARERR | RXFRAMERR | RXBIERR | RXFIFOERR)) 
74                {
75                        /* Just read the bad character to clear the bit. */
76                        tval = uart->sdw_rbr_thr_dll & 0xFF;
77                } 
78                else if(status & RXRDA) 
79                {
80                        tval = uart->sdw_rbr_thr_dll & 0xFF;
81                        blen--;
82                }
83                else {
84                        /* block if required */
85                        if (!block) {
86                                return 0;
87                        }
88                }
89        }
90        return tval;
91#else
92        if (!block)
93        {
94                if (!(uart->rxstat & RXDATARDY)) {
95                        return 0;
96                }
97        } 
98        while (!(uart->rxstat & RXDATARDY)) ;
99
100        return (unsigned char)uart->rxdata;
101#endif
102}
103
104/***********************************************************************/
105/* serial_putc(UartChannel *uart, unsigned int c)*/
106/***********************************************************************/
107static inline void serial_do_putc(volatile UartChannel *uart, int c)
108{
109#if (BCHP_CHIP==7550)
110        while (!(uart->sdw_lsr & THRE))
111                ;
112
113        uart->sdw_rbr_thr_dll = (unsigned char)c;
114#else
115        while (!(uart->txstat & TXDREGEMT))
116                ;
117
118        uart->txdata = (unsigned char)c;
119#endif
120}
121
122/***********************************************************************/
123/* serial_putc(UartChannel *uart, unsigned int c)*/
124/***********************************************************************/
125void serial_putc(volatile UartChannel *uart, int c)
126{
127        serial_do_putc(uart,c);
128}
129
Note: See TracBrowser for help on using the repository browser.