diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2009-01-14 07:01:49 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2009-01-14 07:01:49 +0000 |
commit | e2a25592f8655fda9bf9260d22501017fba26390 (patch) | |
tree | 64ed029f1362c7ef4758e66eb00392af96566099 /firmware/usb.c | |
parent | 3bfb9d44ae6440b75eaf494a1100f6c1ed21a666 (diff) | |
download | rockbox-e2a25592f8655fda9bf9260d22501017fba26390.tar.gz rockbox-e2a25592f8655fda9bf9260d22501017fba26390.zip |
Gigabeat S has no need for a USB tick. Put in a simple framework that allows USB monitoring by event. Also add a couple missed usb_enable calls when the connection is not for 'slave mode'.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19768 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/usb.c')
-rw-r--r-- | firmware/usb.c | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/firmware/usb.c b/firmware/usb.c index e0f8e4c22a..387adc75ad 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -64,9 +64,6 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */ | |||
64 | 64 | ||
65 | #if !defined(SIMULATOR) && !defined(USB_NONE) | 65 | #if !defined(SIMULATOR) && !defined(USB_NONE) |
66 | 66 | ||
67 | #define NUM_POLL_READINGS (HZ/5) | ||
68 | static int countdown; | ||
69 | |||
70 | static int usb_state; | 67 | static int usb_state; |
71 | 68 | ||
72 | #if (CONFIG_STORAGE & STORAGE_MMC) && defined(USB_FULL_INIT) | 69 | #if (CONFIG_STORAGE & STORAGE_MMC) && defined(USB_FULL_INIT) |
@@ -81,8 +78,12 @@ static const char usb_thread_name[] = "usb"; | |||
81 | static unsigned int usb_thread_entry = 0; | 78 | static unsigned int usb_thread_entry = 0; |
82 | #endif /* USB_FULL_INIT */ | 79 | #endif /* USB_FULL_INIT */ |
83 | static struct event_queue usb_queue; | 80 | static struct event_queue usb_queue; |
84 | static int last_usb_status; | 81 | #ifndef USB_STATUS_BY_EVENT |
82 | #define NUM_POLL_READINGS (HZ/5) | ||
83 | static int countdown; | ||
84 | #endif /* USB_STATUS_BY_EVENT */ | ||
85 | static bool usb_monitor_enabled; | 85 | static bool usb_monitor_enabled; |
86 | static int last_usb_status; | ||
86 | #ifdef HAVE_USBSTACK | 87 | #ifdef HAVE_USBSTACK |
87 | static bool exclusive_storage_access; | 88 | static bool exclusive_storage_access; |
88 | #endif | 89 | #endif |
@@ -269,15 +270,17 @@ static void usb_thread(void) | |||
269 | * access requirements. */ | 270 | * access requirements. */ |
270 | exclusive_storage_access = usb_core_any_exclusive_storage(); | 271 | exclusive_storage_access = usb_core_any_exclusive_storage(); |
271 | 272 | ||
272 | if (exclusive_storage_access) | 273 | if(!exclusive_storage_access) |
273 | #endif /* HAVE_USBSTACK */ | ||
274 | { | 274 | { |
275 | /* Tell all threads that they have to back off the storage. | 275 | usb_enable(true); |
276 | We subtract one for our own thread. */ | 276 | break; |
277 | num_acks_to_expect = queue_broadcast(SYS_USB_CONNECTED, 0) - 1; | ||
278 | DEBUGF("USB inserted. Waiting for ack from %d threads...\n", | ||
279 | num_acks_for_connect); | ||
280 | } | 277 | } |
278 | #endif /* HAVE_USBSTACK */ | ||
279 | /* Tell all threads that they have to back off the storage. | ||
280 | We subtract one for our own thread. */ | ||
281 | num_acks_to_expect = queue_broadcast(SYS_USB_CONNECTED, 0) - 1; | ||
282 | DEBUGF("USB inserted. Waiting for ack from %d threads...\n", | ||
283 | num_acks_for_connect); | ||
281 | break; | 284 | break; |
282 | 285 | ||
283 | case SYS_USB_CONNECTED_ACK: | 286 | case SYS_USB_CONNECTED_ACK: |
@@ -322,10 +325,14 @@ static void usb_thread(void) | |||
322 | usb_state = USB_EXTRACTED; | 325 | usb_state = USB_EXTRACTED; |
323 | #ifdef HAVE_USBSTACK | 326 | #ifdef HAVE_USBSTACK |
324 | if (!exclusive_storage_access) | 327 | if (!exclusive_storage_access) |
328 | { | ||
329 | usb_enable(false); | ||
325 | break; | 330 | break; |
331 | } | ||
326 | 332 | ||
327 | exclusive_storage_access = false; | 333 | exclusive_storage_access = false; |
328 | #endif /* HAVE_USBSTACK */ | 334 | #endif /* HAVE_USBSTACK */ |
335 | |||
329 | /* Tell all threads that we are back in business */ | 336 | /* Tell all threads that we are back in business */ |
330 | num_acks_to_expect = | 337 | num_acks_to_expect = |
331 | queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; | 338 | queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; |
@@ -382,6 +389,24 @@ static void usb_thread(void) | |||
382 | } | 389 | } |
383 | } | 390 | } |
384 | 391 | ||
392 | #ifdef USB_STATUS_BY_EVENT | ||
393 | void usb_status_event(int current_status) | ||
394 | { | ||
395 | /* Status should be USB_INSERTED or USB_EXTRACTED. | ||
396 | * Caller isn't expected to filter for changes in status. */ | ||
397 | if (usb_monitor_enabled && last_usb_status != current_status) | ||
398 | { | ||
399 | last_usb_status = current_status; | ||
400 | queue_post(&usb_queue, current_status, 0); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | void usb_start_monitoring(void) | ||
405 | { | ||
406 | usb_monitor_enabled = true; | ||
407 | usb_status_event(usb_detect()); | ||
408 | } | ||
409 | #else /* !USB_STATUS_BY_EVENT */ | ||
385 | static void usb_tick(void) | 410 | static void usb_tick(void) |
386 | { | 411 | { |
387 | int current_status; | 412 | int current_status; |
@@ -441,6 +466,12 @@ static void usb_tick(void) | |||
441 | } | 466 | } |
442 | #endif | 467 | #endif |
443 | } | 468 | } |
469 | |||
470 | void usb_start_monitoring(void) | ||
471 | { | ||
472 | usb_monitor_enabled = true; | ||
473 | } | ||
474 | #endif /* USB_STATUS_BY_EVENT */ | ||
444 | #endif /* USB_FULL_INIT */ | 475 | #endif /* USB_FULL_INIT */ |
445 | 476 | ||
446 | void usb_acknowledge(long id) | 477 | void usb_acknowledge(long id) |
@@ -450,12 +481,14 @@ void usb_acknowledge(long id) | |||
450 | 481 | ||
451 | void usb_init(void) | 482 | void usb_init(void) |
452 | { | 483 | { |
484 | /* We assume that the USB cable is extracted */ | ||
453 | usb_state = USB_EXTRACTED; | 485 | usb_state = USB_EXTRACTED; |
486 | last_usb_status = USB_EXTRACTED; | ||
487 | usb_monitor_enabled = false; | ||
488 | |||
454 | #ifdef HAVE_USBSTACK | 489 | #ifdef HAVE_USBSTACK |
455 | exclusive_storage_access = false; | 490 | exclusive_storage_access = false; |
456 | #endif | 491 | #endif |
457 | usb_monitor_enabled = false; | ||
458 | countdown = -1; | ||
459 | 492 | ||
460 | #ifdef USB_FIREWIRE_HANDLING | 493 | #ifdef USB_FIREWIRE_HANDLING |
461 | firewire_countdown = -1; | 494 | firewire_countdown = -1; |
@@ -465,19 +498,17 @@ void usb_init(void) | |||
465 | usb_init_device(); | 498 | usb_init_device(); |
466 | #ifdef USB_FULL_INIT | 499 | #ifdef USB_FULL_INIT |
467 | usb_enable(false); | 500 | usb_enable(false); |
468 | #endif | ||
469 | 501 | ||
470 | /* We assume that the USB cable is extracted */ | ||
471 | last_usb_status = USB_EXTRACTED; | ||
472 | |||
473 | #ifdef USB_FULL_INIT | ||
474 | queue_init(&usb_queue, true); | 502 | queue_init(&usb_queue, true); |
475 | 503 | ||
476 | usb_thread_entry = create_thread(usb_thread, usb_stack, | 504 | usb_thread_entry = create_thread(usb_thread, usb_stack, |
477 | sizeof(usb_stack), 0, usb_thread_name | 505 | sizeof(usb_stack), 0, usb_thread_name |
478 | IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU)); | 506 | IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU)); |
479 | 507 | ||
508 | #ifndef USB_STATUS_BY_EVENT | ||
509 | countdown = -1; | ||
480 | tick_add_task(usb_tick); | 510 | tick_add_task(usb_tick); |
511 | #endif | ||
481 | #endif /* USB_FULL_INIT */ | 512 | #endif /* USB_FULL_INIT */ |
482 | } | 513 | } |
483 | 514 | ||
@@ -525,11 +556,6 @@ int usb_wait_for_disconnect_w_tmo(struct event_queue *q, int ticks) | |||
525 | #endif /* USB_FULL_INIT */ | 556 | #endif /* USB_FULL_INIT */ |
526 | } | 557 | } |
527 | 558 | ||
528 | void usb_start_monitoring(void) | ||
529 | { | ||
530 | usb_monitor_enabled = true; | ||
531 | } | ||
532 | |||
533 | #ifdef USB_DRIVER_CLOSE | 559 | #ifdef USB_DRIVER_CLOSE |
534 | void usb_close(void) | 560 | void usb_close(void) |
535 | { | 561 | { |
@@ -539,7 +565,9 @@ void usb_close(void) | |||
539 | if (thread == 0) | 565 | if (thread == 0) |
540 | return; | 566 | return; |
541 | 567 | ||
568 | #ifndef USB_STATUS_BY_EVENT | ||
542 | tick_remove_task(usb_tick); | 569 | tick_remove_task(usb_tick); |
570 | #endif | ||
543 | usb_monitor_enabled = false; | 571 | usb_monitor_enabled = false; |
544 | 572 | ||
545 | queue_post(&usb_queue, USB_QUIT, 0); | 573 | queue_post(&usb_queue, USB_QUIT, 0); |