diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2007-09-20 09:08:40 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2007-09-20 09:08:40 +0000 |
commit | 300f64c99a28bf76dfc23b8730f4ef2749a61140 (patch) | |
tree | a80a47fd676675e38d6073f6630c8e2ede87d85d | |
parent | 140828563645d983ce8e5148dc571e946971ff86 (diff) | |
download | rockbox-300f64c99a28bf76dfc23b8730f4ef2749a61140.tar.gz rockbox-300f64c99a28bf76dfc23b8730f4ef2749a61140.zip |
uart driver (which the buttons need) and button test code in the bootloader
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14768 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-x | bootloader/mrobe500.c | 14 | ||||
-rw-r--r-- | firmware/SOURCES | 1 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/button-mr500.c | 1 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/uart-mr500.c | 142 | ||||
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/uart-target.h | 30 |
5 files changed, 187 insertions, 1 deletions
diff --git a/bootloader/mrobe500.c b/bootloader/mrobe500.c index 02726dde5a..fd2587eda2 100755 --- a/bootloader/mrobe500.c +++ b/bootloader/mrobe500.c | |||
@@ -52,7 +52,7 @@ void main(void) | |||
52 | adc_init(); | 52 | adc_init(); |
53 | button_init(); | 53 | button_init(); |
54 | backlight_init(); | 54 | backlight_init(); |
55 | 55 | uartSetup(); | |
56 | lcd_init(); | 56 | lcd_init(); |
57 | font_init(); | 57 | font_init(); |
58 | 58 | ||
@@ -96,8 +96,20 @@ void main(void) | |||
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | printf("ATA"); | 98 | printf("ATA"); |
99 | int count = 0, i = 0, c = 0; | ||
100 | char data[64]; | ||
99 | while(true) | 101 | while(true) |
100 | { | 102 | { |
103 | i = button_read_device(); | ||
104 | c++; | ||
105 | if (i) | ||
106 | { | ||
107 | c = 0; | ||
108 | __backlight_on(); | ||
109 | printf("button: %x", i); | ||
110 | } | ||
111 | else if (c>50) | ||
112 | __backlight_off(); | ||
101 | } | 113 | } |
102 | #if 0 | 114 | #if 0 |
103 | rc = ata_init(); | 115 | rc = ata_init(); |
diff --git a/firmware/SOURCES b/firmware/SOURCES index 0f5da2fe6c..e62d9331a5 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -600,6 +600,7 @@ target/arm/olympus/mrobe-500/power-mr500.c | |||
600 | target/arm/olympus/mrobe-500/system-mr500.c | 600 | target/arm/olympus/mrobe-500/system-mr500.c |
601 | target/arm/olympus/mrobe-500/timer-mr500.c | 601 | target/arm/olympus/mrobe-500/timer-mr500.c |
602 | target/arm/olympus/mrobe-500/usb-mr500.c | 602 | target/arm/olympus/mrobe-500/usb-mr500.c |
603 | target/arm/olympus/mrobe-500/uart-mr500.c | ||
603 | #ifndef BOOTLOADER | 604 | #ifndef BOOTLOADER |
604 | 605 | ||
605 | #endif | 606 | #endif |
diff --git a/firmware/target/arm/olympus/mrobe-500/button-mr500.c b/firmware/target/arm/olympus/mrobe-500/button-mr500.c index 388dbf0689..f85eeca912 100644 --- a/firmware/target/arm/olympus/mrobe-500/button-mr500.c +++ b/firmware/target/arm/olympus/mrobe-500/button-mr500.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "adc.h" | 26 | #include "adc.h" |
27 | #include "system.h" | 27 | #include "system.h" |
28 | #include "backlight-target.h" | 28 | #include "backlight-target.h" |
29 | #include "uart-target.h" | ||
29 | 30 | ||
30 | #define BUTTON_TIMEOUT 50 | 31 | #define BUTTON_TIMEOUT 50 |
31 | void button_init_device(void) | 32 | void button_init_device(void) |
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 | } | ||
diff --git a/firmware/target/arm/olympus/mrobe-500/uart-target.h b/firmware/target/arm/olympus/mrobe-500/uart-target.h new file mode 100644 index 0000000000..3b765d3ed8 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-500/uart-target.h | |||
@@ -0,0 +1,30 @@ | |||
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 | #ifndef UART_H | ||
21 | #define UART_H | ||
22 | |||
23 | void uartPutc(char ch); | ||
24 | void uartPutHex(unsigned int n); | ||
25 | void uartSetup(void); | ||
26 | void uartPuts(const char *str); | ||
27 | void uartGets(char *str, unsigned int size); | ||
28 | int uartPollch(unsigned int ticks); | ||
29 | |||
30 | #endif | ||