]> hackdaworld.org Git - my-code/arm.git/blob - betty/uart.c
the interrupt routines
[my-code/arm.git] / betty / uart.c
1 /*
2  * uart.c - uart0/1 api
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 #include "uart.h"
9
10 /*
11  * functions
12  */
13
14 void uart0_init(void) {
15
16         /* configure uart 0 */
17         UART0_FCR=0x07;                 // enable fifo
18         UART0_LCR=0x83;                 // set dlab + word length
19         UART0_DLL=0x04;                 // br: 115200
20         UART0_DLM=0x00; 
21         UART0_LCR=0x03;                 // unset dlab
22 }
23
24 void uart0_send_string(char *txbuf) {
25
26         int i;
27
28         i=0;
29
30         while(txbuf[i]) {
31                 UART0_THR=txbuf[i++];
32                 /* flush if tx buffer maximum reached */
33                 if(!(i%16))
34                         while(!(UART0_LSR&(1<<6)))
35                                 continue;
36         }
37         
38         /* flush uart0 anyways */
39         while(!(UART0_LSR&(1<<6)))
40                 continue;
41 }
42
43 void uart0_send_buf16(u16 *buf,int len) {
44
45         int i;
46
47         i=0;
48
49         for(i=0;i<len/2;i++) {
50                 if(!(i%8))
51                         while(!(UART0_LSR&(1<<6)))
52                                 continue;
53                 UART0_THR=buf[i]&0xff;
54                 UART0_THR=(buf[i]>>8)&0xff;
55         }
56 }
57
58 void uart0_send_buf32(u32 *buf,int len) {
59
60         int i;
61
62         i=0;
63
64         for(i=0;i<len/4;i++) {
65                 if(!(i%4))
66                         while(!(UART0_LSR&(1<<6)))
67                                 continue;
68                 UART0_THR=buf[i]&0xff;
69                 UART0_THR=(buf[i]>>8)&0xff;
70                 UART0_THR=(buf[i]>>16)&0xff;
71                 UART0_THR=(buf[i]>>24)&0xff;
72         }
73 }
74
75 void uart0_send_byte(u8 send) {
76
77         while(!(UART0_LSR&(1<<5)))
78                 continue;
79
80         UART0_THR=send;
81 }
82
83 u8 uart0_get_byte(void) {
84
85         u8 rx;
86
87         while(!(UART0_LSR&(1<<0)))
88                 continue;
89
90         rx=UART0_RBR;
91
92         return rx;
93 }
94