summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2009-01-14 07:01:49 +0000
committerMichael Sevakis <jethead71@rockbox.org>2009-01-14 07:01:49 +0000
commite2a25592f8655fda9bf9260d22501017fba26390 (patch)
tree64ed029f1362c7ef4758e66eb00392af96566099
parent3bfb9d44ae6440b75eaf494a1100f6c1ed21a666 (diff)
downloadrockbox-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
-rw-r--r--firmware/export/usb.h2
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/usb-imx31.c1
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/usb-target.h3
-rw-r--r--firmware/usb.c74
4 files changed, 57 insertions, 23 deletions
diff --git a/firmware/export/usb.h b/firmware/export/usb.h
index 49b70f659a..a6cfad5889 100644
--- a/firmware/export/usb.h
+++ b/firmware/export/usb.h
@@ -114,6 +114,8 @@ void usb_wait_for_disconnect(struct event_queue *q);
114int usb_wait_for_disconnect_w_tmo(struct event_queue *q, int ticks); 114int usb_wait_for_disconnect_w_tmo(struct event_queue *q, int ticks);
115bool usb_inserted(void); /* return the official value, what's been reported to the threads */ 115bool usb_inserted(void); /* return the official value, what's been reported to the threads */
116int usb_detect(void); /* return the raw hardware value - nothing/pc/charger */ 116int usb_detect(void); /* return the raw hardware value - nothing/pc/charger */
117/* For tick-less USB monitoring (USB_STATUS_BY_EVENT) */
118void usb_status_event(int current_status);
117#ifdef HAVE_USB_POWER 119#ifdef HAVE_USB_POWER
118bool usb_powered(void); 120bool usb_powered(void);
119#ifdef CONFIG_CHARGING 121#ifdef CONFIG_CHARGING
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c b/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c
index a7314861c3..cd8b513ecd 100644
--- a/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/usb-imx31.c
@@ -59,6 +59,7 @@ void usb_connect_event(void)
59 USB_INSERTED : USB_EXTRACTED; 59 USB_INSERTED : USB_EXTRACTED;
60 /* Notify power that USB charging is potentially available */ 60 /* Notify power that USB charging is potentially available */
61 charger_usb_detect_event(usb_status); 61 charger_usb_detect_event(usb_status);
62 usb_status_event(usb_status);
62} 63}
63 64
64int usb_detect(void) 65int usb_detect(void)
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-target.h b/firmware/target/arm/imx31/gigabeat-s/usb-target.h
index 1f96a9a7eb..31b8080b57 100644
--- a/firmware/target/arm/imx31/gigabeat-s/usb-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/usb-target.h
@@ -25,6 +25,9 @@
25#define USB_DRIVER_CLOSE 25#define USB_DRIVER_CLOSE
26#endif 26#endif
27 27
28/* Connect by events, not by tick polling */
29#define USB_STATUS_BY_EVENT
30
28void usb_connect_event(void); 31void usb_connect_event(void);
29void usb_init_device(void); 32void usb_init_device(void);
30int usb_detect(void); 33int usb_detect(void);
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)
68static int countdown;
69
70static int usb_state; 67static 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";
81static unsigned int usb_thread_entry = 0; 78static unsigned int usb_thread_entry = 0;
82#endif /* USB_FULL_INIT */ 79#endif /* USB_FULL_INIT */
83static struct event_queue usb_queue; 80static struct event_queue usb_queue;
84static int last_usb_status; 81#ifndef USB_STATUS_BY_EVENT
82#define NUM_POLL_READINGS (HZ/5)
83static int countdown;
84#endif /* USB_STATUS_BY_EVENT */
85static bool usb_monitor_enabled; 85static bool usb_monitor_enabled;
86static int last_usb_status;
86#ifdef HAVE_USBSTACK 87#ifdef HAVE_USBSTACK
87static bool exclusive_storage_access; 88static 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
393void 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
404void usb_start_monitoring(void)
405{
406 usb_monitor_enabled = true;
407 usb_status_event(usb_detect());
408}
409#else /* !USB_STATUS_BY_EVENT */
385static void usb_tick(void) 410static 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
470void 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
446void usb_acknowledge(long id) 477void usb_acknowledge(long id)
@@ -450,12 +481,14 @@ void usb_acknowledge(long id)
450 481
451void usb_init(void) 482void 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
528void usb_start_monitoring(void)
529{
530 usb_monitor_enabled = true;
531}
532
533#ifdef USB_DRIVER_CLOSE 559#ifdef USB_DRIVER_CLOSE
534void usb_close(void) 560void 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);