diff options
Diffstat (limited to 'firmware/usb.c')
-rw-r--r-- | firmware/usb.c | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/firmware/usb.c b/firmware/usb.c index 07d2c5890c..d9c13dffdf 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -73,6 +73,7 @@ static struct thread_entry *usb_thread_entry; | |||
73 | static struct event_queue usb_queue; | 73 | static struct event_queue usb_queue; |
74 | static int last_usb_status; | 74 | static int last_usb_status; |
75 | static bool usb_monitor_enabled; | 75 | static bool usb_monitor_enabled; |
76 | static bool exclusive_disk; | ||
76 | 77 | ||
77 | 78 | ||
78 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ | 79 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ |
@@ -197,6 +198,16 @@ static void usb_thread(void) | |||
197 | else | 198 | else |
198 | #endif | 199 | #endif |
199 | { | 200 | { |
201 | #ifdef HAVE_USBSTACK | ||
202 | #ifdef USE_ROCKBOX_USB | ||
203 | usb_core_enable_protocol(USB_DRIVER_MASS_STORAGE,true); | ||
204 | usb_core_enable_protocol(USB_DRIVER_SERIAL,false);/* TODO: add debug setting */ | ||
205 | usb_core_enable_protocol(USB_DRIVER_CHARGING_ONLY,false); | ||
206 | usb_enable(true); | ||
207 | #else | ||
208 | usb_request_exclusive_ata(); | ||
209 | #endif /* USE_ROCKBOX_USB */ | ||
210 | #else | ||
200 | /* Tell all threads that they have to back off the ATA. | 211 | /* Tell all threads that they have to back off the ATA. |
201 | We subtract one for our own thread. */ | 212 | We subtract one for our own thread. */ |
202 | num_acks_to_expect = | 213 | num_acks_to_expect = |
@@ -204,9 +215,23 @@ static void usb_thread(void) | |||
204 | waiting_for_ack = true; | 215 | waiting_for_ack = true; |
205 | DEBUGF("USB inserted. Waiting for ack from %d threads...\n", | 216 | DEBUGF("USB inserted. Waiting for ack from %d threads...\n", |
206 | num_acks_to_expect); | 217 | num_acks_to_expect); |
218 | #endif | ||
207 | } | 219 | } |
208 | break; | 220 | break; |
209 | 221 | #ifdef HAVE_USBSTACK | |
222 | case USB_REQUEST_DISK: | ||
223 | if(!waiting_for_ack) | ||
224 | { | ||
225 | /* Tell all threads that they have to back off the ATA. | ||
226 | We subtract one for our own thread. */ | ||
227 | num_acks_to_expect = | ||
228 | queue_broadcast(SYS_USB_CONNECTED, 0) - 1; | ||
229 | waiting_for_ack = true; | ||
230 | DEBUGF("USB inserted. Waiting for ack from %d threads...\n", | ||
231 | num_acks_to_expect); | ||
232 | } | ||
233 | break; | ||
234 | #endif | ||
210 | case SYS_USB_CONNECTED_ACK: | 235 | case SYS_USB_CONNECTED_ACK: |
211 | if(waiting_for_ack) | 236 | if(waiting_for_ack) |
212 | { | 237 | { |
@@ -215,25 +240,22 @@ static void usb_thread(void) | |||
215 | { | 240 | { |
216 | DEBUGF("All threads have acknowledged the connect.\n"); | 241 | DEBUGF("All threads have acknowledged the connect.\n"); |
217 | #ifdef HAVE_USBSTACK | 242 | #ifdef HAVE_USBSTACK |
218 | #ifdef HAVE_PRIORITY_SCHEDULING | 243 | #ifndef USE_ROCKBOX_USB |
219 | thread_set_priority(usb_thread_entry,PRIORITY_REALTIME); | ||
220 | #endif | ||
221 | #ifdef USE_ROCKBOX_USB | ||
222 | usb_core_enable_protocol(USB_DRIVER_MASS_STORAGE,true); | ||
223 | usb_core_enable_protocol(USB_DRIVER_SERIAL,false);/* TODO: add debug setting */ | ||
224 | usb_core_enable_protocol(USB_DRIVER_CHARGING_ONLY,false); | ||
225 | usb_enable(true); | ||
226 | #else /* USE_ROCKBOX_USB */ | ||
227 | /* until we have native mass-storage mode, we want to reboot on | 244 | /* until we have native mass-storage mode, we want to reboot on |
228 | usb host connect */ | 245 | usb host connect */ |
229 | try_reboot(); | 246 | try_reboot(); |
230 | #endif /* USE_ROCKBOX_USB */ | 247 | #endif /* USE_ROCKBOX_USB */ |
248 | #ifdef HAVE_PRIORITY_SCHEDULING | ||
249 | thread_set_priority(usb_thread_entry,PRIORITY_REALTIME); | ||
250 | exclusive_disk = true; | ||
251 | #endif | ||
231 | 252 | ||
232 | #else | 253 | #else |
233 | usb_slave_mode(true); | 254 | usb_slave_mode(true); |
234 | cpu_idle_mode(true); | 255 | cpu_idle_mode(true); |
235 | #endif | 256 | #endif |
236 | usb_state = USB_INSERTED; | 257 | usb_state = USB_INSERTED; |
258 | waiting_for_ack = false; | ||
237 | } | 259 | } |
238 | else | 260 | else |
239 | { | 261 | { |
@@ -246,6 +268,7 @@ static void usb_thread(void) | |||
246 | case USB_EXTRACTED: | 268 | case USB_EXTRACTED: |
247 | #ifdef HAVE_USBSTACK | 269 | #ifdef HAVE_USBSTACK |
248 | usb_enable(false); | 270 | usb_enable(false); |
271 | exclusive_disk = false; | ||
249 | #ifdef HAVE_PRIORITY_SCHEDULING | 272 | #ifdef HAVE_PRIORITY_SCHEDULING |
250 | thread_set_priority(usb_thread_entry,PRIORITY_SYSTEM); | 273 | thread_set_priority(usb_thread_entry,PRIORITY_SYSTEM); |
251 | #endif | 274 | #endif |
@@ -290,6 +313,7 @@ static void usb_thread(void) | |||
290 | { | 313 | { |
291 | DEBUGF("All threads have acknowledged. " | 314 | DEBUGF("All threads have acknowledged. " |
292 | "We're in business.\n"); | 315 | "We're in business.\n"); |
316 | waiting_for_ack = false; | ||
293 | } | 317 | } |
294 | else | 318 | else |
295 | { | 319 | { |
@@ -403,6 +427,7 @@ void usb_acknowledge(long id) | |||
403 | void usb_init(void) | 427 | void usb_init(void) |
404 | { | 428 | { |
405 | usb_state = USB_EXTRACTED; | 429 | usb_state = USB_EXTRACTED; |
430 | exclusive_disk = false; | ||
406 | usb_monitor_enabled = false; | 431 | usb_monitor_enabled = false; |
407 | countdown = -1; | 432 | countdown = -1; |
408 | 433 | ||
@@ -481,6 +506,20 @@ bool usb_inserted(void) | |||
481 | #endif | 506 | #endif |
482 | } | 507 | } |
483 | 508 | ||
509 | #ifdef HAVE_USBSTACK | ||
510 | void usb_request_exclusive_ata(void) | ||
511 | { | ||
512 | if(!exclusive_disk) { | ||
513 | queue_post(&usb_queue, USB_REQUEST_DISK, 0); | ||
514 | } | ||
515 | } | ||
516 | |||
517 | bool usb_exclusive_ata(void) | ||
518 | { | ||
519 | return exclusive_disk; | ||
520 | } | ||
521 | #endif | ||
522 | |||
484 | #ifdef HAVE_USB_POWER | 523 | #ifdef HAVE_USB_POWER |
485 | bool usb_powered(void) | 524 | bool usb_powered(void) |
486 | { | 525 | { |