diff options
Diffstat (limited to 'firmware/target/arm/olympus/mrobe-500/uart-mr500.c')
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/uart-mr500.c | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/firmware/target/arm/olympus/mrobe-500/uart-mr500.c b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c new file mode 100644 index 0000000000..f8208f8717 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-500/uart-mr500.c | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | * (C) Copyright 2007 Catalin Patulea <cat@vv.carleton.ca> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of | ||
7 | * the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
17 | * MA 02111-1307 USA | ||
18 | * | ||
19 | */ | ||
20 | #include "config.h" | ||
21 | #include "cpu.h" | ||
22 | #include "system.h" | ||
23 | |||
24 | /* UART 0/1 */ | ||
25 | #define IO_UART0_DTRR 0x0300 | ||
26 | #define IO_UART0_BRSR 0x0302 | ||
27 | #define IO_UART0_MSR 0x0304 | ||
28 | #define IO_UART0_RFCR 0x0306 | ||
29 | #define IO_UART0_TFCR 0x0308 | ||
30 | #define IO_UART0_LCR 0x030A | ||
31 | #define IO_UART0_SR 0x030C | ||
32 | |||
33 | #define IO_UART1_DTRR 0x0380 | ||
34 | #define IO_UART1_BRSR 0x0382 | ||
35 | #define IO_UART1_MSR 0x0384 | ||
36 | #define IO_UART1_RFCR 0x0386 | ||
37 | #define IO_UART1_TFCR 0x0388 | ||
38 | #define IO_UART1_LCR 0x038A | ||
39 | #define IO_UART1_SR 0x038C | ||
40 | #define CONFIG_UART_BRSR 87 | ||
41 | |||
42 | void do_checksums(char *data, int len, char *xor, char *add) | ||
43 | { | ||
44 | int i; | ||
45 | *xor = data[0]; | ||
46 | *add = data[0]; | ||
47 | for(i=1;i<len;i++) | ||
48 | { | ||
49 | *xor ^= data[i]; | ||
50 | *add += data[i]; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | void uartSetup(void) { | ||
55 | // 8-N-1 | ||
56 | outw(0x8000, IO_UART1_MSR); | ||
57 | outw(CONFIG_UART_BRSR, IO_UART1_BRSR); | ||
58 | } | ||
59 | |||
60 | void uartPutc(char ch) { | ||
61 | // Wait for room in FIFO | ||
62 | while ((inw(IO_UART1_TFCR) & 0x3f) >= 0x20); | ||
63 | |||
64 | // Write character | ||
65 | outw(ch, IO_UART1_DTRR); | ||
66 | } | ||
67 | |||
68 | // Unsigned integer to ASCII hexadecimal conversion | ||
69 | void uartPutHex(unsigned int n) { | ||
70 | unsigned int i; | ||
71 | |||
72 | for (i = 8; i != 0; i--) { | ||
73 | unsigned int digit = n >> 28; | ||
74 | uartPutc(digit >= 10 ? digit - 10 + 'A' : digit + '0'); | ||
75 | n <<= 4; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | void uartPuts(const char *str) { | ||
80 | char ch; | ||
81 | while ((ch = *str++) != '\0') { | ||
82 | uartPutc(ch); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | void uartGets(char *str, unsigned int size) { | ||
87 | for (;;) { | ||
88 | char ch; | ||
89 | |||
90 | // Wait for FIFO to contain something | ||
91 | while ((inw(IO_UART1_RFCR) & 0x3f) == 0); | ||
92 | |||
93 | // Read character | ||
94 | ch = (char)inw(IO_UART1_DTRR); | ||
95 | |||
96 | // Echo character back | ||
97 | outw(ch, IO_UART1_DTRR); | ||
98 | |||
99 | // If CR, also echo LF, null-terminate, and return | ||
100 | if (ch == '\r') { | ||
101 | outw('\n', IO_UART1_DTRR); | ||
102 | if (size) { | ||
103 | *str++ = '\0'; | ||
104 | } | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | // Append to buffer | ||
109 | if (size) { | ||
110 | *str++ = ch; | ||
111 | --size; | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | |||
116 | int uartPollch(unsigned int ticks) { | ||
117 | while (ticks--) { | ||
118 | if (inw(IO_UART1_RFCR) & 0x3f) { | ||
119 | return inw(IO_UART1_DTRR) & 0xff; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | return -1; | ||
124 | } | ||
125 | |||
126 | bool uartAvailable(void) | ||
127 | { | ||
128 | return (inw(IO_UART1_RFCR) & 0x3f)?true:false; | ||
129 | } | ||
130 | |||
131 | void uartHeartbeat(void) | ||
132 | { | ||
133 | char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; | ||
134 | uartPuts(data); | ||
135 | } | ||
136 | |||
137 | void uartSendData(char* data, int len) | ||
138 | { | ||
139 | int i; | ||
140 | for(i=0;i<len;i++) | ||
141 | uartPutc(data[i]); | ||
142 | } | ||