diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/mrobe-500/uart-mr500.c')
-rw-r--r-- | firmware/target/arm/tms320dm320/mrobe-500/uart-mr500.c | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/uart-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/uart-mr500.c deleted file mode 100644 index 66e59eaaac..0000000000 --- a/firmware/target/arm/tms320dm320/mrobe-500/uart-mr500.c +++ /dev/null | |||
@@ -1,172 +0,0 @@ | |||
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 | |||
26 | #define CONFIG_UART_BRSR 87 | ||
27 | #define MAX_UART_BUFFER 32 | ||
28 | static unsigned char uart1buffer[MAX_UART_BUFFER]; | ||
29 | int uart1read = 0, uart1write = 0, uart1count = 0; | ||
30 | |||
31 | void do_checksums(char *data, int len, char *xor, char *add) | ||
32 | { | ||
33 | int i; | ||
34 | *xor = data[0]; | ||
35 | *add = data[0]; | ||
36 | for(i=1;i<len;i++) | ||
37 | { | ||
38 | *xor ^= data[i]; | ||
39 | *add += data[i]; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | void uart_init(void) | ||
44 | { | ||
45 | // 8-N-1 | ||
46 | IO_UART1_MSR=0x8000; | ||
47 | IO_UART1_BRSR=CONFIG_UART_BRSR; | ||
48 | IO_UART1_RFCR = 0x8000; | ||
49 | /* gio 27 is input, uart1 rx | ||
50 | gio 28 is output, uart1 tx */ | ||
51 | IO_GIO_DIR1 |= (1<<11); /* gio 27 */ | ||
52 | IO_GIO_DIR1 &= ~(1<<12); /* gio 28 */ | ||
53 | |||
54 | /* init the recieve buffer */ | ||
55 | uart1read = 0; | ||
56 | uart1write = 0; | ||
57 | uart1count = 0; | ||
58 | |||
59 | /* Enable the interrupt */ | ||
60 | IO_INTC_EINT0 |= (1<<IRQ_UART1); | ||
61 | } | ||
62 | |||
63 | void uartPutc(char ch) { | ||
64 | // Wait for room in FIFO | ||
65 | while ((IO_UART1_TFCR & 0x3f) >= 0x20); | ||
66 | |||
67 | // Write character | ||
68 | IO_UART1_DTRR=ch; | ||
69 | } | ||
70 | |||
71 | // Unsigned integer to ASCII hexadecimal conversion | ||
72 | void uartPutHex(unsigned int n) { | ||
73 | unsigned int i; | ||
74 | |||
75 | for (i = 8; i != 0; i--) { | ||
76 | unsigned int digit = n >> 28; | ||
77 | uartPutc(digit >= 10 ? digit - 10 + 'A' : digit + '0'); | ||
78 | n <<= 4; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | void uartPuts(const char *str) { | ||
83 | char ch; | ||
84 | while ((ch = *str++) != '\0') { | ||
85 | uartPutc(ch); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | void uartGets(char *str, unsigned int size) { | ||
90 | for (;;) { | ||
91 | char ch; | ||
92 | |||
93 | // Wait for FIFO to contain something | ||
94 | while ((IO_UART1_RFCR & 0x3f) == 0); | ||
95 | |||
96 | // Read character | ||
97 | ch = (char)IO_UART1_DTRR; | ||
98 | |||
99 | // Echo character back | ||
100 | IO_UART1_DTRR=ch; | ||
101 | |||
102 | // If CR, also echo LF, null-terminate, and return | ||
103 | if (ch == '\r') { | ||
104 | IO_UART1_DTRR='\n'; | ||
105 | if (size) { | ||
106 | *str++ = '\0'; | ||
107 | } | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | // Append to buffer | ||
112 | if (size) { | ||
113 | *str++ = ch; | ||
114 | --size; | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | |||
119 | int uartPollch(unsigned int ticks) { | ||
120 | while (ticks--) { | ||
121 | if (IO_UART1_RFCR & 0x3f) { | ||
122 | return IO_UART1_DTRR & 0xff; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | return -1; | ||
127 | } | ||
128 | |||
129 | bool uartAvailable(void) | ||
130 | { | ||
131 | return uart1count > 0; | ||
132 | } | ||
133 | |||
134 | void uart1_heartbeat(void) | ||
135 | { | ||
136 | char data[5] = {0x11, 0x30, 0x11^0x30, 0x11+0x30, '\0'}; | ||
137 | uartPuts(data); | ||
138 | } | ||
139 | |||
140 | void uartSendData(char* data, int len) | ||
141 | { | ||
142 | int i; | ||
143 | for(i=0;i<len;i++) | ||
144 | uartPutc(data[i]); | ||
145 | } | ||
146 | |||
147 | bool uart1_getch(char *c) | ||
148 | { | ||
149 | if (uart1count > 0) | ||
150 | { | ||
151 | *c = uart1buffer[uart1read]; | ||
152 | uart1read = (uart1read+1) % MAX_UART_BUFFER; | ||
153 | uart1count--; | ||
154 | return true; | ||
155 | } | ||
156 | return false; | ||
157 | } | ||
158 | |||
159 | /* UART1 receive intterupt handler */ | ||
160 | void UART1(void) | ||
161 | { | ||
162 | if (IO_UART1_RFCR & 0x3f) | ||
163 | { | ||
164 | if (uart1count >= MAX_UART_BUFFER) | ||
165 | panicf("UART1 buffer overflow"); | ||
166 | uart1buffer[uart1write] = IO_UART1_DTRR & 0xff; | ||
167 | uart1write = (uart1write+1) % MAX_UART_BUFFER; | ||
168 | uart1count++; | ||
169 | } | ||
170 | |||
171 | IO_INTC_IRQ0 = (1<<IRQ_UART1); | ||
172 | } | ||