no automatic \r\n tx in uart0_send_string function
[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         /* select pins 0.0 and 0.1 as tx and rx */
17         PINSEL0=(PINSEL0&~(0xf))|0x05;
18
19         /* configure uart 0 */
20         UART0_FCR=0x07;                 // enable fifo
21         UART0_LCR=0x83;                 // set dlab + word length
22         UART0_DLL=0x04;                 // br: 115200
23         UART0_DLM=0x00; 
24         UART0_LCR=0x03;                 // unset dlab
25 }
26
27 void uart0_send_string(char *txbuf) {
28
29         int i;
30
31         i=0;
32
33         while(txbuf[i]) {
34                 UART0_THR=txbuf[i++];
35                 /* flush if tx buffer maximum reached */
36                 if(!(i%16))
37                         while(!(UART0_LSR&(1<<6)))
38                                 continue;
39         }
40         
41         /* flush uart0 anyways */
42         while(!(UART0_LSR&(1<<6)))
43                 continue;
44 }
45
46 void uart0_send_buf16(u16 *buf,int len) {
47
48         int i;
49
50         i=0;
51
52         for(i=0;i<len/2;i++) {
53                 if(!(i%8))
54                         while(!(UART0_LSR&(1<<6)))
55                                 continue;
56                 UART0_THR=buf[i]&0xff;
57                 UART0_THR=(buf[i]>>8)&0xff;
58         }
59 }
60
61 void uart0_send_buf32(u32 *buf,int len) {
62
63         int i;
64
65         i=0;
66
67         for(i=0;i<len/4;i++) {
68                 if(!(i%4))
69                         while(!(UART0_LSR&(1<<6)))
70                                 continue;
71                 UART0_THR=buf[i]&0xff;
72                 UART0_THR=(buf[i]>>8)&0xff;
73                 UART0_THR=(buf[i]>>16)&0xff;
74                 UART0_THR=(buf[i]>>24)&0xff;
75         }
76 }
77
78 void uart0_send_byte(u8 send) {
79
80         while(!(UART0_LSR&(1<<5)))
81                 continue;
82
83         UART0_THR=send;
84 }
85
86 u8 uart0_get_byte(void) {
87
88         u8 rx;
89
90         while(!(UART0_LSR&(1<<0)))
91                 continue;
92
93         rx=UART0_RBR;
94
95         return rx;
96 }
97