From 3f709eada2d67418971ec1c5d907a06ba9161200 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sat, 29 Jan 2011 00:44:59 +0000 Subject: Convert AMS target USB detection to event-based (no more polling in a tick). Seems well on my Clip v1 and Fuze v2. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29156 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/config.h | 14 +++--- firmware/target/arm/as3525/usb-as3525.c | 79 +++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 29 deletions(-) diff --git a/firmware/export/config.h b/firmware/export/config.h index f5ee003308..d59b259fb9 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -721,15 +721,19 @@ Lyre prototype 1 */ #define HAVE_SEMAPHORE_OBJECTS -#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_ARC +#ifdef HAVE_USBSTACK +#if CONFIG_USBOTG == USBOTG_ARC #define USB_STATUS_BY_EVENT #define USB_DETECT_BY_DRV #define INCLUDE_TIMEOUT_API -#endif /* HAVE_USBSTACK && USBOTG_ARC */ - -#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_AS3525 +#elif CONFIG_USBOTG == USBOTG_AS3525 +#define USB_STATUS_BY_EVENT #define USB_DETECT_BY_DRV -#endif /* HAVE_USBSTACK && USBOTG_AS3525 */ +#elif CONFIG_USBOTG == USBOTG_AS3525v2 +#define USB_STATUS_BY_EVENT +#define USB_DETECT_BY_CORE +#endif /* CONFIG_USB == */ +#endif /* HAVE_USBSTACK */ #endif /* BOOTLOADER */ diff --git a/firmware/target/arm/as3525/usb-as3525.c b/firmware/target/arm/as3525/usb-as3525.c index 5664eb2096..a6d5d3a245 100644 --- a/firmware/target/arm/as3525/usb-as3525.c +++ b/firmware/target/arm/as3525/usb-as3525.c @@ -18,9 +18,8 @@ * KIND, either express or implied. * ****************************************************************************/ - -#include #include "config.h" +#include "system.h" #include "usb.h" #ifdef HAVE_USBSTACK #include "usb_core.h" @@ -29,8 +28,40 @@ #include "power.h" #include "as3525.h" -static bool bus_activity = 0; -static bool connected = 0; +static int usb_status = USB_EXTRACTED; + +#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB) +/* Rebooting on USB plug can crash these players in a state where + * hardware power off (pressing the power button) doesn't work anymore + * TODO: Implement USB in rockbox for these players */ +#define USB_INSERT_INT_STATUS USB_EXTRACTED +#undef USB_DETECT_BY_DRV +#undef USB_DETECT_BY_CORE +#undef USB_STATUS_BY_EVENT + +#else /* !AS3525v2 */ + +#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE) + +#ifdef USB_STATUS_BY_EVENT +#define USB_INSERT_INT_STATUS USB_INSERTED +#define USB_INSERT_INT_EVENT USB_POWERED +#define USB_REMOVE_INT_EVENT USB_UNPOWERED +#else +#define USB_INSERT_INT_STATUS USB_POWERED +#endif /* USB_STATUS_BY_EVENT */ + +#else /* !USB_DETECT_BY_* */ + +#define USB_INSERT_INT_STATUS USB_INSERTED +#ifdef USB_STATUS_BY_EVENT +#define USB_INSERT_INT_EVENT USB_INSERTED +#define USB_REMOVE_INT_EVENT USB_EXTRACTED +#endif /* USB_STATUS_BY_EVENT */ + +#endif /* USB_DETECT_BY_* */ + +#endif /* AS3525v2 */ void usb_enable(bool on) { @@ -46,36 +77,36 @@ void usb_enable(bool on) void usb_insert_int(void) { - connected = 1; + usb_status = USB_INSERT_INT_STATUS; +#ifdef USB_STATUS_BY_EVENT + usb_status_event(USB_INSERT_INT_EVENT); +#endif } void usb_remove_int(void) { - connected = 0; - bus_activity = 0; + usb_status = USB_EXTRACTED; +#ifdef USB_STATUS_BY_EVENT + usb_status_event(USB_REMOVE_INT_EVENT); +#endif } void usb_drv_usb_detect_event(void) { - /* Bus activity seen */ - bus_activity = 1; +#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE) + int oldstatus = disable_irq_save(); /* May come via USB thread */ + if (usb_status == USB_INSERT_INT_STATUS) + { + usb_status = USB_INSERTED; +#ifdef USB_STATUS_BY_EVENT + usb_status_event(USB_INSERTED); +#endif + } + restore_irq(oldstatus); +#endif /* USB_DETECT_BY_* */ } int usb_detect(void) { -#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB) - /* Rebooting on USB plug can crash these players in a state where - * hardware power off (pressing the power button) doesn't work anymore - * TODO: Implement USB in rockbox for these players */ - return USB_EXTRACTED; -#elif defined(USB_DETECT_BY_DRV) - if(bus_activity && connected) - return USB_INSERTED; - else if(connected) - return USB_POWERED; - else - return USB_UNPOWERED; -#else - return connected?USB_INSERTED:USB_EXTRACTED; -#endif + return usb_status; } -- cgit v1.2.3