diff options
author | andypotter <liveboxandy@gmail.com> | 2013-04-15 20:09:39 +0100 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2013-04-25 21:02:09 +0200 |
commit | ecaa40166000e3d6b49542d42804127c0a6079e2 (patch) | |
tree | 35ce073fb6d63f90fa3be39aa7433907327b8998 /firmware/drivers | |
parent | 354c9894062886443e1c53cc4dc5669a1d72a5f4 (diff) | |
download | rockbox-ecaa40166000e3d6b49542d42804127c0a6079e2.tar.gz rockbox-ecaa40166000e3d6b49542d42804127c0a6079e2.zip |
Add Serial Port 1 support for iPod Photo/Color/4G/Mini2G
Based on FS#9920 by Ryan Press with changes to selection logic so
that it works on my iPod Photo. Should also work on iPod Color/4G
and Mini2G. Moved all target specific code from
firmware/drivers/serial.c into new file
firmware/target/arm/pp/uart-pp.c in the same manner as other
target specific uart code.
Update to fix build error on ipodmini2g by adding defines in config file.
Removed unwanted whitespace
Tested on iPod Photo.
Change-Id: Ia5539563966198e06372d70b5adf2ef78882f863
Reviewed-on: http://gerrit.rockbox.org/455
Reviewed-by: andypotter <liveboxandy@gmail.com>
Tested-by: andypotter <liveboxandy@gmail.com>
Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/serial.c | 172 |
1 files changed, 0 insertions, 172 deletions
diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c index a46342389d..0fab570fdc 100644 --- a/firmware/drivers/serial.c +++ b/firmware/drivers/serial.c | |||
@@ -21,179 +21,7 @@ | |||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <stdarg.h> | 23 | #include <stdarg.h> |
24 | #include "button.h" | ||
25 | #include "config.h" | ||
26 | #include "cpu.h" | ||
27 | #include "system.h" | ||
28 | #include "kernel.h" | ||
29 | #include "lcd.h" | ||
30 | #include "serial.h" | 24 | #include "serial.h" |
31 | #include "iap.h" | ||
32 | |||
33 | #if defined(IPOD_ACCESSORY_PROTOCOL) | ||
34 | static int autobaud = 0; | ||
35 | |||
36 | static void set_bitrate(unsigned int rate) | ||
37 | { | ||
38 | unsigned int divisor; | ||
39 | |||
40 | divisor = 24000000L / rate / 16; | ||
41 | SER0_LCR = 0x80; /* Divisor latch enable */ | ||
42 | SER0_DLL = (divisor >> 0) & 0xFF; | ||
43 | SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */ | ||
44 | } | ||
45 | |||
46 | void serial_setup (void) | ||
47 | { | ||
48 | int tmp; | ||
49 | |||
50 | #if defined(IPOD_COLOR) || defined(IPOD_4G) | ||
51 | /* Route the Tx/Rx pins. 4G Ipod??? */ | ||
52 | outl(0x70000018, inl(0x70000018) & ~0xc00); | ||
53 | #elif defined(IPOD_NANO) || defined(IPOD_VIDEO) | ||
54 | /* Route the Tx/Rx pins. 5G Ipod */ | ||
55 | (*(volatile unsigned long *)(0x7000008C)) &= ~0x0C; | ||
56 | GPO32_ENABLE &= ~0x0C; | ||
57 | #endif | ||
58 | |||
59 | DEV_EN = DEV_EN | DEV_SER0; | ||
60 | CPU_HI_INT_DIS = SER0_MASK; | ||
61 | |||
62 | DEV_RS |= DEV_SER0; | ||
63 | sleep(1); | ||
64 | DEV_RS &= ~DEV_SER0; | ||
65 | |||
66 | SER0_LCR = 0x80; /* Divisor latch enable */ | ||
67 | SER0_DLM = 0x00; | ||
68 | SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */ | ||
69 | SER0_IER = 0x01; | ||
70 | |||
71 | SER0_FCR = 0x07; /* Tx+Rx FIFO reset and FIFO enable */ | ||
72 | |||
73 | CPU_INT_EN |= HI_MASK; | ||
74 | CPU_HI_INT_EN |= SER0_MASK; | ||
75 | tmp = SER0_RBR; | ||
76 | |||
77 | serial_bitrate(0); | ||
78 | } | ||
79 | |||
80 | void serial_bitrate(int rate) | ||
81 | { | ||
82 | if(rate == 0) | ||
83 | { | ||
84 | autobaud = 2; | ||
85 | set_bitrate(115200); | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | autobaud = 0; | ||
90 | set_bitrate(rate); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | int tx_rdy(void) | ||
95 | { | ||
96 | if((SER0_LSR & 0x20)) | ||
97 | return 1; | ||
98 | else | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | static int rx_rdy(void) | ||
103 | { | ||
104 | if((SER0_LSR & 0x1)) | ||
105 | return 1; | ||
106 | else | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | void tx_writec(unsigned char c) | ||
111 | { | ||
112 | SER0_THR =(int) c; | ||
113 | } | ||
114 | |||
115 | static unsigned char rx_readc(void) | ||
116 | { | ||
117 | return (SER0_RBR & 0xFF); | ||
118 | } | ||
119 | |||
120 | void SERIAL0(void) | ||
121 | { | ||
122 | static int badbaud = 0; | ||
123 | static bool newpkt = true; | ||
124 | char temp; | ||
125 | |||
126 | while(rx_rdy()) | ||
127 | { | ||
128 | temp = rx_readc(); | ||
129 | if (newpkt && autobaud > 0) | ||
130 | { | ||
131 | if (autobaud == 1) | ||
132 | { | ||
133 | switch (temp) | ||
134 | { | ||
135 | case 0xFF: | ||
136 | case 0x55: | ||
137 | break; | ||
138 | case 0xFC: | ||
139 | set_bitrate(19200); | ||
140 | temp = 0xFF; | ||
141 | break; | ||
142 | case 0xE0: | ||
143 | set_bitrate(9600); | ||
144 | temp = 0xFF; | ||
145 | break; | ||
146 | default: | ||
147 | badbaud++; | ||
148 | if (badbaud >= 6) /* Switch baud detection mode */ | ||
149 | { | ||
150 | autobaud = 2; | ||
151 | set_bitrate(115200); | ||
152 | badbaud = 0; | ||
153 | } else { | ||
154 | set_bitrate(57600); | ||
155 | } | ||
156 | continue; | ||
157 | } | ||
158 | } else { | ||
159 | switch (temp) | ||
160 | { | ||
161 | case 0xFF: | ||
162 | case 0x55: | ||
163 | break; | ||
164 | case 0xFE: | ||
165 | set_bitrate(57600); | ||
166 | temp = 0xFF; | ||
167 | break; | ||
168 | case 0xFC: | ||
169 | set_bitrate(38400); | ||
170 | temp = 0xFF; | ||
171 | break; | ||
172 | case 0xE0: | ||
173 | set_bitrate(19200); | ||
174 | temp = 0xFF; | ||
175 | break; | ||
176 | default: | ||
177 | badbaud++; | ||
178 | if (badbaud >= 6) /* Switch baud detection */ | ||
179 | { | ||
180 | autobaud = 1; | ||
181 | set_bitrate(57600); | ||
182 | badbaud = 0; | ||
183 | } else { | ||
184 | set_bitrate(115200); | ||
185 | } | ||
186 | continue; | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | bool pkt = iap_getc(temp); | ||
191 | if(newpkt && !pkt) | ||
192 | autobaud = 0; /* Found good baud */ | ||
193 | newpkt = pkt; | ||
194 | } | ||
195 | } | ||
196 | #endif | ||
197 | 25 | ||
198 | void dprintf(const char * str, ... ) | 26 | void dprintf(const char * str, ... ) |
199 | { | 27 | { |