diff options
author | Cástor Muñoz <cmvidal@gmail.com> | 2016-05-25 23:18:33 +0200 |
---|---|---|
committer | Cástor Muñoz <cmvidal@gmail.com> | 2016-05-26 09:05:44 +0200 |
commit | f6ed4f830666b7281308cca4bf90e0000dcfaef4 (patch) | |
tree | 5cdcbf641268ec6f9ad551d6c274bd2db384dca1 /firmware/target/arm | |
parent | d8989b15b79b4732df147b35bbf0beb39be06065 (diff) | |
download | rockbox-f6ed4f830666b7281308cca4bf90e0000dcfaef4.tar.gz rockbox-f6ed4f830666b7281308cca4bf90e0000dcfaef4.zip |
iPod Classic: use PMU interrupts to detect accessories
- Speed auto detection is launched when an accessory is inserted,
so the user doesn't need to modify settings to use accessories
that operates at different speeds (or when the same accessory is
unplugged and plugged again).
- UART controller is disabled when no accessory is inserted, not
much powersave but everything counts.
Change-Id: If20c3617c2a87b6277fd7e0270031030c44fa953
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/s5l8702/debug-s5l8702.c | 38 | ||||
-rw-r--r-- | firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c | 67 |
2 files changed, 75 insertions, 30 deletions
diff --git a/firmware/target/arm/s5l8702/debug-s5l8702.c b/firmware/target/arm/s5l8702/debug-s5l8702.c index 48a20a97c2..b274b5fc0a 100644 --- a/firmware/target/arm/s5l8702/debug-s5l8702.c +++ b/firmware/target/arm/s5l8702/debug-s5l8702.c | |||
@@ -138,22 +138,26 @@ bool dbg_hw_info(void) | |||
138 | else if(state==2) | 138 | else if(state==2) |
139 | { | 139 | { |
140 | extern struct uartc_port ser_port; | 140 | extern struct uartc_port ser_port; |
141 | int tx_stat, rx_stat, tx_speed, rx_speed; | 141 | bool opened = !!ser_port.uartc->port_l[ser_port.id]; |
142 | char line_cfg[4]; | 142 | _DEBUG_PRINTF("UART %d: %s", ser_port.id, opened ? "opened":"closed"); |
143 | int abr_stat; | 143 | if (opened) |
144 | uint32_t abr_cnt; | 144 | { |
145 | char *abrstatus[] = {"Idle", "Launched", "Counting", "Abnormal"}; | 145 | int tx_stat, rx_stat, tx_speed, rx_speed; |
146 | 146 | char line_cfg[4]; | |
147 | uartc_port_get_line_info(&ser_port, | 147 | int abr_stat; |
148 | &tx_stat, &rx_stat, &tx_speed, &rx_speed, line_cfg); | 148 | uint32_t abr_cnt; |
149 | abr_stat = uartc_port_get_abr_info(&ser_port, &abr_cnt); | 149 | char *abrstatus[] = {"Idle", "Launched", "Counting", "Abnormal"}; |
150 | 150 | ||
151 | _DEBUG_PRINTF("UART %d:", ser_port.id); | 151 | uartc_port_get_line_info(&ser_port, |
152 | line++; | 152 | &tx_stat, &rx_stat, &tx_speed, &rx_speed, line_cfg); |
153 | _DEBUG_PRINTF("line: %s", line_cfg); | 153 | abr_stat = uartc_port_get_abr_info(&ser_port, &abr_cnt); |
154 | _DEBUG_PRINTF("Tx: %s, speed: %d", tx_stat ? "On":"Off", tx_speed); | 154 | |
155 | _DEBUG_PRINTF("Rx: %s, speed: %d", rx_stat ? "On":"Off", rx_speed); | 155 | line++; |
156 | _DEBUG_PRINTF("ABR: %s, cnt: %u", abrstatus[abr_stat], abr_cnt); | 156 | _DEBUG_PRINTF("line: %s", line_cfg); |
157 | _DEBUG_PRINTF("Tx: %s, speed: %d", tx_stat ? "On":"Off", tx_speed); | ||
158 | _DEBUG_PRINTF("Rx: %s, speed: %d", rx_stat ? "On":"Off", rx_speed); | ||
159 | _DEBUG_PRINTF("ABR: %s, cnt: %u", abrstatus[abr_stat], abr_cnt); | ||
160 | } | ||
157 | line++; | 161 | line++; |
158 | _DEBUG_PRINTF("n_tx_bytes: %u", ser_port.n_tx_bytes); | 162 | _DEBUG_PRINTF("n_tx_bytes: %u", ser_port.n_tx_bytes); |
159 | _DEBUG_PRINTF("n_rx_bytes: %u", ser_port.n_rx_bytes); | 163 | _DEBUG_PRINTF("n_rx_bytes: %u", ser_port.n_rx_bytes); |
@@ -162,7 +166,7 @@ bool dbg_hw_info(void) | |||
162 | _DEBUG_PRINTF("n_frame_err: %u", ser_port.n_frame_err); | 166 | _DEBUG_PRINTF("n_frame_err: %u", ser_port.n_frame_err); |
163 | _DEBUG_PRINTF("n_break_detect: %u", ser_port.n_break_detect); | 167 | _DEBUG_PRINTF("n_break_detect: %u", ser_port.n_break_detect); |
164 | _DEBUG_PRINTF("ABR n_abnormal: %u %u", | 168 | _DEBUG_PRINTF("ABR n_abnormal: %u %u", |
165 | ser_port.n_abnormal0, ser_port.n_abnormal1); | 169 | ser_port.n_abnormal0, ser_port.n_abnormal1); |
166 | } | 170 | } |
167 | #endif | 171 | #endif |
168 | else | 172 | else |
diff --git a/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c index c77b5d0c95..f1f06987bc 100644 --- a/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c +++ b/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c | |||
@@ -48,7 +48,7 @@ | |||
48 | 48 | ||
49 | extern const struct uartc s5l8702_uartc; | 49 | extern const struct uartc s5l8702_uartc; |
50 | #ifdef IPOD_ACCESSORY_PROTOCOL | 50 | #ifdef IPOD_ACCESSORY_PROTOCOL |
51 | void iap_rx_isr(int, char*, char*, uint32_t); | 51 | static void iap_rx_isr(int, char*, char*, uint32_t); |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | struct uartc_port ser_port IDATA_ATTR = | 54 | struct uartc_port ser_port IDATA_ATTR = |
@@ -75,6 +75,17 @@ struct uartc_port ser_port IDATA_ATTR = | |||
75 | /* | 75 | /* |
76 | * serial driver API | 76 | * serial driver API |
77 | */ | 77 | */ |
78 | int tx_rdy(void) | ||
79 | { | ||
80 | return uartc_port_tx_ready(&ser_port) ? 1 : 0; | ||
81 | } | ||
82 | |||
83 | void tx_writec(unsigned char c) | ||
84 | { | ||
85 | uartc_port_tx_byte(&ser_port, c); | ||
86 | } | ||
87 | |||
88 | #ifndef IPOD_ACCESSORY_PROTOCOL | ||
78 | void serial_setup(void) | 89 | void serial_setup(void) |
79 | { | 90 | { |
80 | uartc_port_open(&ser_port); | 91 | uartc_port_open(&ser_port); |
@@ -91,18 +102,10 @@ void serial_setup(void) | |||
91 | logf("[%lu] "MODEL_NAME" port %d ready!", USEC_TIMER, ser_port.id); | 102 | logf("[%lu] "MODEL_NAME" port %d ready!", USEC_TIMER, ser_port.id); |
92 | } | 103 | } |
93 | 104 | ||
94 | int tx_rdy(void) | ||
95 | { | ||
96 | return uartc_port_tx_ready(&ser_port) ? 1 : 0; | ||
97 | } | ||
98 | |||
99 | void tx_writec(unsigned char c) | ||
100 | { | ||
101 | uartc_port_tx_byte(&ser_port, c); | ||
102 | } | ||
103 | |||
104 | 105 | ||
105 | #ifdef IPOD_ACCESSORY_PROTOCOL | 106 | #else /* IPOD_ACCESSORY_PROTOCOL */ |
107 | #include "kernel.h" | ||
108 | #include "pmu-target.h" | ||
106 | #include "iap.h" | 109 | #include "iap.h" |
107 | 110 | ||
108 | static enum { | 111 | static enum { |
@@ -111,8 +114,46 @@ static enum { | |||
111 | ABR_STATUS_DONE | 114 | ABR_STATUS_DONE |
112 | } abr_status; | 115 | } abr_status; |
113 | 116 | ||
117 | static int bitrate = 0; | ||
118 | static bool acc_plugged = false; | ||
119 | |||
120 | static void serial_acc_tick(void) | ||
121 | { | ||
122 | bool plugged = pmu_accessory_present(); | ||
123 | if (acc_plugged != plugged) | ||
124 | { | ||
125 | acc_plugged = plugged; | ||
126 | if (acc_plugged) | ||
127 | { | ||
128 | uartc_open(ser_port.uartc); | ||
129 | uartc_port_open(&ser_port); | ||
130 | /* set a default configuration, Tx and Rx modes are | ||
131 | disabled when the port is initialized */ | ||
132 | uartc_port_config(&ser_port, ULCON_DATA_BITS_8, | ||
133 | ULCON_PARITY_NONE, ULCON_STOP_BITS_1); | ||
134 | uartc_port_set_tx_mode(&ser_port, UCON_MODE_INTREQ); | ||
135 | serial_bitrate(bitrate); | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | uartc_port_close(&ser_port); | ||
140 | uartc_close(ser_port.uartc); | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
145 | void serial_setup(void) | ||
146 | { | ||
147 | uartc_close(ser_port.uartc); | ||
148 | tick_add_task(serial_acc_tick); | ||
149 | } | ||
150 | |||
114 | void serial_bitrate(int rate) | 151 | void serial_bitrate(int rate) |
115 | { | 152 | { |
153 | bitrate = rate; | ||
154 | if (!acc_plugged) | ||
155 | return; | ||
156 | |||
116 | logf("[%lu] serial_bitrate(%d)", USEC_TIMER, rate); | 157 | logf("[%lu] serial_bitrate(%d)", USEC_TIMER, rate); |
117 | 158 | ||
118 | if (rate == 0) { | 159 | if (rate == 0) { |
@@ -150,7 +191,7 @@ void serial_bitrate(int rate) | |||
150 | } | 191 | } |
151 | } | 192 | } |
152 | 193 | ||
153 | void iap_rx_isr(int len, char *data, char *err, uint32_t abr_cnt) | 194 | static void iap_rx_isr(int len, char *data, char *err, uint32_t abr_cnt) |
154 | { | 195 | { |
155 | /* ignore Rx errors, upper layer will discard bad packets */ | 196 | /* ignore Rx errors, upper layer will discard bad packets */ |
156 | (void) err; | 197 | (void) err; |