From 088aaac9851d2529be2f4d2e0b301ed01b91a344 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sat, 29 Jan 2011 00:22:42 +0000 Subject: [PATCH] USB: Thread must remember that a host has been detected since the POWERED state is ambiguous when waiting for host. Storage access is not yet actually exclusive if not USB_INSERTED. usb_start_monitoring seems better posting USB_UNPOWERED only if USB_EXTRACTED, interpreting POWERED/INSERTED as POWERED. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29153 a1c6a512-1295-4272-9138-f99709370657 --- firmware/usb.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/firmware/usb.c b/firmware/usb.c index 91c620fdc0..13f66159ac 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -373,6 +373,9 @@ static void usb_thread(void) NORETURN_ATTR; #endif static void usb_thread(void) { +#ifdef USB_DELAYED_INSERT + bool host_detected = false; +#endif int num_acks_to_expect = 0; long last_broadcast_tick = current_tick; struct queue_event ev; @@ -395,6 +398,11 @@ static void usb_thread(void) #ifdef USB_DELAYED_INSERT if(usb_state != USB_POWERED) break; + + if (host_detected) + break; /* Drivers configured but we're still USB_POWERED */ + + host_detected = true; #else /* !USB_DELAYED_INSERT */ if(usb_state != USB_EXTRACTED) break; @@ -490,6 +498,9 @@ static void usb_thread(void) /* Ok to broadcast disconnect now */ usb_configure_drivers(USB_EXTRACTED); +#ifdef USB_DELAYED_INSERT + host_detected = false; +#endif break; /* USB_UNPOWERED: USB_EXTRACTED: */ @@ -566,7 +577,7 @@ void usb_start_monitoring(void) * before or during boot. */ #ifdef USB_DELAYED_INSERT /* Filter the status - USB_INSERTED may happen later */ - status = (status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED; + status = (status == USB_EXTRACTED) ? USB_UNPOWERED : USB_POWERED; #endif usb_status_event(status); @@ -749,7 +760,8 @@ bool usb_inserted(void) #ifdef HAVE_USBSTACK bool usb_exclusive_storage(void) { - return exclusive_storage_access; + /* Storage isn't actually exclusive until slave mode has been entered */ + return exclusive_storage_access && usb_state == USB_INSERTED; } #endif /* HAVE_USBSTACK */