1 /* xilinx uartlite driver (polling) */
2 #include "include.h"
3
4 enum {
5 /* UART Lite register offsets */
6 Rxfifo = 0, /* receive FIFO, read only */
7 Txfifo = 4, /* transmit FIFO, write only */
8 Status = 8, /* status register, read only */
9 Ctl = 12, /* control reg, write only */
10
11 /* control register bit positions */
12 Ctlintrena = 0x10, /* enable interrupt */
13 Rxfiforst = 0x02, /* reset receive FIFO */
14 Txfiforst = 0x01, /* reset transmit FIFO */
15
16 /* status register bit positions */
17 Parerr = 0x80,
18 Framerr = 0x40,
19 Overrunerr = 0x20,
20 Stsintrena = 0x10, /* interrupt enabled */
21 Txfifofull = 0x08, /* transmit FIFO full */
22 Txfifoempty = 0x04, /* transmit FIFO empty */
23 Rxfifofull = 0x02, /* receive FIFO full */
24 Rxfifohasdata = 0x01, /* data in receive FIFO */
25
26 FIFO_SIZE = 16, /* bytes in tx or rx fifo */
27 };
28
29 #define Uartctl ((ulong *)(Uartlite + Ctl))
30 #define Uartstatus ((ulong *)(Uartlite + Status))
31 #define Uartrxfifo ((ulong *)(Uartlite + Rxfifo))
32 /* #define Uarttxfifo ((ulong *)(Uartlite + Txfifo)) /* see prototype.h */
33
34 void
vuartputc(int c)35 vuartputc(int c)
36 {
37 int i;
38
39 coherence();
40 i = 2000000; /* allow > 1.04 ms per char @ 9600 baud */
41 while(*Uartstatus & Txfifofull && i-- > 0)
42 ;
43 *Uarttxfifo = (uchar)c;
44 coherence();
45 }
46
47 int
vuartputs(char * s,int len)48 vuartputs(char *s, int len)
49 {
50 while (len-- > 0) {
51 if (*s == '\n')
52 vuartputc('\r');
53 vuartputc(*s++);
54 }
55 return len;
56 }
57
58 int
vuartgetc(void)59 vuartgetc(void)
60 {
61 while((*Uartstatus & Rxfifohasdata) == 0)
62 ;
63 return (uchar)*Uartrxfifo;
64 }
65