diff options
author | Dominik Wenger <domonoky@googlemail.com> | 2009-10-26 18:16:58 +0000 |
---|---|---|
committer | Dominik Wenger <domonoky@googlemail.com> | 2009-10-26 18:16:58 +0000 |
commit | 90b576f55ea6854a70c8ed77095b42e57b744723 (patch) | |
tree | 33b5a4d1b76b435ef6ec5138e7160d9d32c955c1 /firmware/target/arm/s3c2440/uart-s3c2440.c | |
parent | 6d20102a9c468135770f820a896dad3518c2093f (diff) | |
download | rockbox-90b576f55ea6854a70c8ed77095b42e57b744723.tar.gz rockbox-90b576f55ea6854a70c8ed77095b42e57b744723.zip |
Many more drivers for mini2440. Now the main binary compiles and runs.
Flyspray: FS#10725
Author: Bob Cousins
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23362 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/s3c2440/uart-s3c2440.c')
-rw-r--r-- | firmware/target/arm/s3c2440/uart-s3c2440.c | 108 |
1 files changed, 73 insertions, 35 deletions
diff --git a/firmware/target/arm/s3c2440/uart-s3c2440.c b/firmware/target/arm/s3c2440/uart-s3c2440.c index 2a61b61a39..84282f731a 100644 --- a/firmware/target/arm/s3c2440/uart-s3c2440.c +++ b/firmware/target/arm/s3c2440/uart-s3c2440.c | |||
@@ -30,13 +30,32 @@ | |||
30 | #include "kernel.h" | 30 | #include "kernel.h" |
31 | #include "thread.h" | 31 | #include "thread.h" |
32 | 32 | ||
33 | #include "system-target.h" | ||
33 | #include "uart-s3c2440.h" | 34 | #include "uart-s3c2440.h" |
34 | 35 | ||
35 | #define FCLK 405000000 | 36 | #define MAX_PRINTF_BUF 1024 |
36 | #define HCLK (FCLK/4) /* = 101,250,000 */ | ||
37 | #define PCLK (HCLK/2) /* = 50,625,000 */ | ||
38 | 37 | ||
39 | #define MAX_TX_BUF 1024 | 38 | /**************************************************************************** |
39 | * serial driver API | ||
40 | ****************************************************************************/ | ||
41 | void serial_setup (void) | ||
42 | { | ||
43 | uart_init(); | ||
44 | uart_init_device(DEBUG_UART_PORT); | ||
45 | } | ||
46 | |||
47 | int tx_rdy(void) | ||
48 | { | ||
49 | if (uart_tx_ready (DEBUG_UART_PORT)) | ||
50 | return 1; | ||
51 | else | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | void tx_writec(unsigned char c) | ||
56 | { | ||
57 | uart_send_byte (DEBUG_UART_PORT, c); | ||
58 | } | ||
40 | 59 | ||
41 | 60 | ||
42 | /**************************************************************************** | 61 | /**************************************************************************** |
@@ -46,10 +65,12 @@ | |||
46 | void uart_printf (const char *format, ...) | 65 | void uart_printf (const char *format, ...) |
47 | { | 66 | { |
48 | static bool debug_uart_init = false; | 67 | static bool debug_uart_init = false; |
49 | static char tx_buf [MAX_TX_BUF]; | 68 | static char tx_buf [MAX_PRINTF_BUF]; |
50 | 69 | ||
51 | int len; | 70 | int len; |
52 | unsigned char *ptr; | 71 | unsigned char *ptr; |
72 | int j; | ||
73 | |||
53 | va_list ap; | 74 | va_list ap; |
54 | va_start(ap, format); | 75 | va_start(ap, format); |
55 | 76 | ||
@@ -59,11 +80,16 @@ void uart_printf (const char *format, ...) | |||
59 | 80 | ||
60 | if (!debug_uart_init) | 81 | if (!debug_uart_init) |
61 | { | 82 | { |
62 | uart_init_device(UART_DEBUG); | 83 | uart_init_device(DEBUG_UART_PORT); |
63 | debug_uart_init = true; | 84 | debug_uart_init = true; |
64 | } | 85 | } |
65 | 86 | ||
66 | uart_send (UART_DEBUG, tx_buf, len); | 87 | for (j=0; j<len; j++) |
88 | { | ||
89 | uart_send_byte (DEBUG_UART_PORT, tx_buf[j]); | ||
90 | if ( tx_buf[j] == '\n') | ||
91 | uart_send_byte (DEBUG_UART_PORT, '\r'); | ||
92 | } | ||
67 | } | 93 | } |
68 | 94 | ||
69 | /**************************************************************************** | 95 | /**************************************************************************** |
@@ -142,28 +168,49 @@ bool uart_config (unsigned dev, unsigned speed, unsigned num_bits, | |||
142 | return true; | 168 | return true; |
143 | } | 169 | } |
144 | 170 | ||
171 | /* transmit */ | ||
172 | bool uart_tx_ready (unsigned dev) | ||
173 | { | ||
174 | /* test if transmit buffer empty */ | ||
175 | switch (dev) | ||
176 | { | ||
177 | case 0: | ||
178 | if (UTRSTAT0 & 0x02) | ||
179 | return true; | ||
180 | else | ||
181 | return false; | ||
182 | break; | ||
183 | case 1: | ||
184 | if (UTRSTAT1 & 0x02) | ||
185 | return true; | ||
186 | else | ||
187 | return false; | ||
188 | break; | ||
189 | case 2: | ||
190 | if (UTRSTAT2 & 0x02) | ||
191 | return true; | ||
192 | else | ||
193 | return false; | ||
194 | break; | ||
195 | } | ||
196 | return false; | ||
197 | } | ||
198 | |||
145 | bool uart_send_byte (unsigned dev, char ch) | 199 | bool uart_send_byte (unsigned dev, char ch) |
146 | { | 200 | { |
201 | /* wait for transmit buffer empty */ | ||
202 | while (!uart_tx_ready(dev)) | ||
203 | ; | ||
204 | |||
147 | switch (dev) | 205 | switch (dev) |
148 | { | 206 | { |
149 | case 0: | 207 | case 0: |
150 | /* wait for transmit buffer empty */ | ||
151 | while ((UTRSTAT0 & 0x02) == 0) | ||
152 | ; | ||
153 | UTXH0 = ch; | 208 | UTXH0 = ch; |
154 | break; | 209 | break; |
155 | |||
156 | case 1: | 210 | case 1: |
157 | /* wait for transmit buffer empty */ | ||
158 | while ((UTRSTAT1 & 0x02) == 0) | ||
159 | ; | ||
160 | UTXH1 = ch; | 211 | UTXH1 = ch; |
161 | break; | 212 | break; |
162 | |||
163 | case 2: | 213 | case 2: |
164 | /* wait for transmit buffer empty */ | ||
165 | while ((UTRSTAT2 & 0x02) == 0) | ||
166 | ; | ||
167 | UTXH2 = ch; | 214 | UTXH2 = ch; |
168 | break; | 215 | break; |
169 | } | 216 | } |
@@ -171,26 +218,26 @@ bool uart_send_byte (unsigned dev, char ch) | |||
171 | return true; | 218 | return true; |
172 | } | 219 | } |
173 | 220 | ||
174 | char uart_rx_ready (unsigned dev) | 221 | /* Receive */ |
222 | |||
223 | bool uart_rx_ready (unsigned dev) | ||
175 | { | 224 | { |
225 | /* test receive buffer data ready */ | ||
176 | switch (dev) | 226 | switch (dev) |
177 | { | 227 | { |
178 | case 0: | 228 | case 0: |
179 | /* wait for receive buffer data ready */ | ||
180 | if (UTRSTAT0 & 0x01) | 229 | if (UTRSTAT0 & 0x01) |
181 | return true; | 230 | return true; |
182 | else | 231 | else |
183 | return false; | 232 | return false; |
184 | break; | 233 | break; |
185 | case 1: | 234 | case 1: |
186 | /* wait for receive buffer data ready */ | ||
187 | if (UTRSTAT1 & 0x01) | 235 | if (UTRSTAT1 & 0x01) |
188 | return true; | 236 | return true; |
189 | else | 237 | else |
190 | return false; | 238 | return false; |
191 | break; | 239 | break; |
192 | case 2: | 240 | case 2: |
193 | /* wait for receive buffer data ready */ | ||
194 | if (UTRSTAT2 & 0x01) | 241 | if (UTRSTAT2 & 0x01) |
195 | return true; | 242 | return true; |
196 | else | 243 | else |
@@ -202,43 +249,34 @@ char uart_rx_ready (unsigned dev) | |||
202 | 249 | ||
203 | char uart_read_byte (unsigned dev) | 250 | char uart_read_byte (unsigned dev) |
204 | { | 251 | { |
252 | while (!uart_rx_ready(dev)) | ||
253 | ; | ||
205 | switch (dev) | 254 | switch (dev) |
206 | { | 255 | { |
207 | case 0: | 256 | case 0: |
208 | while (!uart_rx_ready(dev)) | ||
209 | ; | ||
210 | return URXH0; | 257 | return URXH0; |
211 | break; | 258 | break; |
212 | case 1: | 259 | case 1: |
213 | while (!uart_rx_ready(dev)) | ||
214 | ; | ||
215 | return URXH1; | 260 | return URXH1; |
216 | break; | 261 | break; |
217 | case 2: | 262 | case 2: |
218 | while (!uart_rx_ready(dev)) | ||
219 | ; | ||
220 | return URXH2; | 263 | return URXH2; |
221 | break; | 264 | break; |
222 | } | 265 | } |
223 | 266 | ||
224 | return true; | 267 | return '\0'; |
225 | } | 268 | } |
226 | 269 | ||
227 | /**************************************************************************** | 270 | /**************************************************************************** |
228 | * General | 271 | * General |
229 | *****************************************************************************/ | 272 | *****************************************************************************/ |
230 | 273 | ||
231 | bool uart_send (unsigned dev, char *buf, unsigned len) | 274 | bool uart_send_buf (unsigned dev, char *buf, unsigned len) |
232 | { | 275 | { |
233 | unsigned index=0; | 276 | unsigned index=0; |
234 | while (index<len) | 277 | while (index<len) |
235 | { | 278 | { |
236 | uart_send_byte (dev, buf[index]); | 279 | uart_send_byte (dev, buf[index]); |
237 | |||
238 | /* hack for ASCII terminals */ | ||
239 | if (buf[index] == '\n') | ||
240 | uart_send_byte (dev, '\r'); | ||
241 | |||
242 | index++; | 280 | index++; |
243 | } | 281 | } |
244 | return true; | 282 | return true; |