From 32f0f605efa293430a47d60bb857695ff6937d21 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Thu, 14 May 2009 10:07:08 +0000 Subject: Removed all user pipe/endpoint interrupt APIs, added internal library support for interrupt driven control endpoints when in device mode by defining INTERRUPT_CONTROL_ENDPOINT token and passing it to the compiler via the -D switch. --- LUFA/ChangeLog.txt | 1 + LUFA/CompileTimeTokens.txt | 5 +++ LUFA/Drivers/USB/HighLevel/USBInterrupt.c | 17 ++++++++++ LUFA/Drivers/USB/HighLevel/USBInterrupt.h | 50 ++++----------------------- LUFA/Drivers/USB/HighLevel/USBTask.h | 3 ++ LUFA/Drivers/USB/LowLevel/Endpoint.h | 13 ------- LUFA/Drivers/USB/LowLevel/Pipe.h | 56 ------------------------------- LUFA/MigrationInformation.txt | 3 +- 8 files changed, 35 insertions(+), 113 deletions(-) (limited to 'LUFA') diff --git a/LUFA/ChangeLog.txt b/LUFA/ChangeLog.txt index d86805578..be15e73f8 100644 --- a/LUFA/ChangeLog.txt +++ b/LUFA/ChangeLog.txt @@ -14,6 +14,7 @@ * - Fixed Mouse and Keyboard device demos not acting in accordance with the HID specification for idle periods (thanks to Brian Dickman) * - Removed support for endpoint/pipe non-control interrupts; these did not act in the way users expected, and had many subtle issues * - Fixed Device Mode not handling Set Feature and Clear Feature Chapter 9 requests that are addressed to the device (thanks to Brian Dickman) + * - Moved control endpoint interrupt handling into the library itself, enable via the new INTERRUPT_CONTROL_ENDPOINT token * * * \section Sec_ChangeLog090510 Version 090510 diff --git a/LUFA/CompileTimeTokens.txt b/LUFA/CompileTimeTokens.txt index e3afc59bd..bb235e172 100644 --- a/LUFA/CompileTimeTokens.txt +++ b/LUFA/CompileTimeTokens.txt @@ -158,4 +158,9 @@ * required, the VBUS line of the USB connector should be routed to an AVR pin to detect its level, so that the USB_IsConnected global * can be accurately set and the USB_Connect and USB_Disconnect events manually raised by the RAISE_EVENT macro. When defined, this token disables * the library's auto-detection of the connection state by the aforementioned suspension and wake up events. + * + * INTERRUPT_CONTROL_ENDPOINT - ( \ref Group_USBManagement ) \n + * Some applications prefer to not call the USB_USBTask() management task reguarly while in device mode, as it can complicate code significantly. + * Instead, when device mode is used this token can be passed to the library via the -D switch to allow the library to manage the USB control + * endpoint entirely via interrupts asynchronously to the user application. */ diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c index 93bd6d084..14d277c9a 100644 --- a/LUFA/Drivers/USB/HighLevel/USBInterrupt.c +++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.c @@ -174,6 +174,10 @@ ISR(USB_GEN_vect, ISR_BLOCK) ENDPOINT_DIR_OUT, USB_ControlEndpointSize, ENDPOINT_BANK_SINGLE); + #if defined(INTERRUPT_CONTROL_ENDPOINT) + USB_INT_Enable(USB_INT_ENDPOINT_SETUP); + #endif + RAISE_EVENT(USB_Reset); } #endif @@ -249,3 +253,16 @@ ISR(USB_GEN_vect, ISR_BLOCK) } #endif } + +#if defined(INTERRUPT_CONTROL_ENDPOINT) +ISR(USB_COM_vect, ISR_BLOCK) +{ + uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint(); + + USB_USBTask(); + + USB_INT_Clear(USB_INT_ENDPOINT_SETUP); + + Endpoint_SelectEndpoint(PrevSelectedEndpoint); +} +#endif diff --git a/LUFA/Drivers/USB/HighLevel/USBInterrupt.h b/LUFA/Drivers/USB/HighLevel/USBInterrupt.h index 9a1604703..7fbb33efc 100644 --- a/LUFA/Drivers/USB/HighLevel/USBInterrupt.h +++ b/LUFA/Drivers/USB/HighLevel/USBInterrupt.h @@ -28,16 +28,6 @@ this software. */ -/** \ingroup Group_USB - * @defgroup Group_USBInterrupt Endpoint and Pipe Interrupts - * - * This module manages the main USB interrupt vector, for handling such events as VBUS interrupts - * (on supported USB AVR models), device connections and disconnections, etc. as well as providing - * easy to use macros for the management of the unified Endpoint/Pipe interrupt vector. - * - * @{ - */ - #ifndef __USBINTERRUPT_H__ #define __USBINTERRUPT_H__ @@ -56,37 +46,6 @@ #endif /* Public Interface - May be used in end-application: */ - /* Macros: */ - /** Vector name for the common endpoint and pipe vector. This can be used to write an ISR handler - * for the endpoint and pipe events, to make certain USB functions interrupt rather than poll - * driven. - */ - #define ENDPOINT_PIPE_vect USB_COM_vect - - /** Enables the given USB interrupt vector (such as the ENDPOINT_INT_* and PIPE_INT_* vectors in - * Endpoint.h and Pipe.h). - */ - #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE - - /** Disables the given USB interrupt vector. - * - * \see \ref USB_INT_Enable() - */ - #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE - - /** Resets the given USB interrupt flag, so that the interrupt is re-primed for the next firing. */ - #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE - - /** Returns boolean false if the given USB interrupt is disabled, or true if the interrupt is currently - * enabled. - */ - #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false) - - /** Returns boolean true if the given interrupt flag is set (i.e. the condition for the interrupt has occurred, - * but the interrupt vector is not necessarily enabled), otherwise returns false. - */ - #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false) - /* Throwable Events: */ /** This module raises the USB Connected interrupt when the AVR is attached to a host while in device * USB mode. @@ -196,6 +155,12 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ + #define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE + #define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE + #define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE + #define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false) + #define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false) + #define USB_INT_GET_EN_REG(a, b, c, d) a #define USB_INT_GET_EN_MASK(a, b, c, d) b #define USB_INT_GET_INT_REG(a, b, c, d) c @@ -214,6 +179,7 @@ #define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI) #define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI) #define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI) + #define USB_INT_ENDPOINT_SETUP UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI) /* Function Prototypes: */ void USB_INT_ClearAllInterrupts(void); @@ -226,5 +192,3 @@ #endif #endif - -/** @} */ diff --git a/LUFA/Drivers/USB/HighLevel/USBTask.h b/LUFA/Drivers/USB/HighLevel/USBTask.h index 1718ed691..9cb4e6059 100644 --- a/LUFA/Drivers/USB/HighLevel/USBTask.h +++ b/LUFA/Drivers/USB/HighLevel/USBTask.h @@ -183,6 +183,9 @@ * - In host mode, it may be disabled at start-up, enabled on the firing of the \ref USB_DeviceAttached * event and disabled again on the firing of the \ref USB_DeviceUnattached event. * + * If in device mode (only), the control endpoint can instead be managed via interrupts entirely by the library + * by defining the INTERRUPT_CONTROL_ENDPOINT token and passing it to the compiler via the -D switch. + * * \see \ref Group_Events for more information on the USB events. * * \ingroup Group_USBManagement diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h index 4882acc3b..9a553d33f 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.h +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -140,19 +140,6 @@ #else #define ENDPOINT_TOTAL_ENDPOINTS 1 #endif - - /** Interrupt definition for the endpoint SETUP interrupt (for CONTROL type endpoints). Should be - * used with the USB_INT_* macros located in USBInterrupt.h. - * - * This interrupt will fire if enabled on a CONTROL type endpoint if a new control packet is - * received from the host. - * - * \note This interrupt must be enabled and cleared on *each* endpoint which requires it (after the - * endpoint is selected), and will fire the common endpoint interrupt vector. - * - * \see \ref ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. - */ - #define ENDPOINT_INT_SETUP UEIENX, (1 << RXSTPE), UEINTX, (1 << RXSTPI) /* Pseudo-Function Macros: */ #if defined(__DOXYGEN__) diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h index d5c209492..796b4c5a2 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.h +++ b/LUFA/Drivers/USB/LowLevel/Pipe.h @@ -158,62 +158,6 @@ */ #define PIPE_EPSIZE_MASK 0x7FF - /** Interrupt definition for the pipe SETUP bank ready interrupt (for CONTROL type pipes). Should be - * used with the USB_INT_* macros located in USBInterrupt.h. - * - * This interrupt will fire if enabled on an CONTROL type pipe when the pipe is ready for a new - * control request. - * - * \note This interrupt must be enabled and cleared on *each* pipe which requires it (after the pipe - * is selected), and will fire the common pipe interrupt vector. - * - * \see \ref ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. - */ - #define PIPE_INT_SETUP UPIENX, (1 << TXSTPE) , UPINTX, (1 << TXSTPI) - - /** Interrupt definition for the pipe error interrupt. Should be used with the USB_INT_* macros - * located in USBInterrupt.h. - * - * This interrupt will fire if enabled on a particular pipe if an error occurs on that pipe, such - * as a CRC mismatch error. - * - * \note This interrupt must be enabled and cleared on *each* pipe which requires it (after the pipe - * is selected), and will fire the common pipe interrupt vector. - * - * \see \ref ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. - * - * \see \ref Pipe_GetErrorFlags() for more information on the pipe errors. - */ - #define PIPE_INT_ERROR UPIENX, (1 << PERRE), UPINTX, (1 << PERRI) - - /** Interrupt definition for the pipe NAK received interrupt. Should be used with the USB_INT_* macros - * located in USBInterrupt.h. - * - * This interrupt will fire if enabled on a particular pipe if an attached device returns a NAK in - * response to a sent packet. - * - * \note This interrupt must be enabled and cleared on *each* pipe which requires it (after the pipe - * is selected), and will fire the common pipe interrupt vector. - * - * \see \ref ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. - * - * \see \ref Pipe_IsNAKReceived() for more information on pipe NAKs. - */ - #define PIPE_INT_NAK UPIENX, (1 << NAKEDE), UPINTX, (1 << NAKEDI) - - /** Interrupt definition for the pipe STALL received interrupt. Should be used with the USB_INT_* macros - * located in USBInterrupt.h. - * - * This interrupt will fire if enabled on a particular pipe if an attached device returns a STALL on the - * currently selected pipe. This will also fire if the pipe is an isochronous pipe and a CRC error occurs. - * - * \note This interrupt must be enabled and cleared on *each* pipe which requires it (after the pipe - * is selected), and will fire the common pipe interrupt vector. - * - * \see \ref ENDPOINT_PIPE_vect for more information on the common pipe and endpoint interrupt vector. - */ - #define PIPE_INT_STALL UPIENX, (1 << RXSTALLE), UPINTX, (1 << RXSTALLI) - /* Pseudo-Function Macros: */ #if defined(__DOXYGEN__) /** Indicates the number of bytes currently stored in the current pipes's selected bank. diff --git a/LUFA/MigrationInformation.txt b/LUFA/MigrationInformation.txt index d7eb2dfcc..c1a2e3c43 100644 --- a/LUFA/MigrationInformation.txt +++ b/LUFA/MigrationInformation.txt @@ -14,7 +14,8 @@ * * Device Mode * - Support for non-control data endpoint interrupts has been dropped due to many issues in the implementation. All existing - * projects using interrupts on non-control endpoints should switch to polling. + * projects using interrupts on non-control endpoints should switch to polling. For control interrupts, the library can + * manage the control endpoint via interrupts automatically by compiling with the INTERRUPT_CONTROL_ENDPOINT token defined. * - The Endpoint_ClearEndpointInterrupt() macro has been deleted and references to it should be removed. * * Device Mode -- cgit v1.2.3