From b763c3f33e8596afe2dd21746890fa9641362c5e Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Sat, 5 Mar 2011 11:34:04 +0000 Subject: [PATCH] Porting updates for the UC3B architecture - get UC3B partially enumerating using a modified mouse demo on the EVK1101. Implement a software FIFO for the endpoint banks; datasheet hints that this can be done through hardware as on the AVR8 architecture, but the correct method to do this not discovered yet. --- LUFA/Common/Attributes.h | 9 ++ LUFA/Common/Common.h | 41 ++++- .../USB/Core/AVR8/USBController_AVR8.c | 2 - .../Drivers/USB/Core/AVR8/USBInterrupt_AVR8.h | 5 - LUFA/Drivers/USB/Core/DeviceStandardReq.c | 9 +- LUFA/Drivers/USB/Core/StdDescriptors.h | 4 +- LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.c | 16 +- LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.h | 151 ++++++++---------- LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.c | 10 +- LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.h | 64 ++++---- .../USB/Core/UC3B/USBController_UC3B.c | 6 +- .../Drivers/USB/Core/UC3B/USBInterrupt_UC3B.c | 1 + .../Drivers/USB/Core/UC3B/USBInterrupt_UC3B.h | 5 - 13 files changed, 169 insertions(+), 154 deletions(-) diff --git a/LUFA/Common/Attributes.h b/LUFA/Common/Attributes.h index 8c40069901..62ce9f29e4 100644 --- a/LUFA/Common/Attributes.h +++ b/LUFA/Common/Attributes.h @@ -133,6 +133,15 @@ * \param[in] Func Name of the function which the given function name should alias. */ #define ATTR_ALIAS(Func) __attribute__ ((alias( #Func ))) + + /** Marks a variable or struct element for packing into the smallest space available. */ + #define ATTR_PACKED __attribute__ ((packed)) + + /** Indicates the minimum alignment in bytes for a variable or struct element. + * + * \param[in] Bytes Minimum number of bytes the item should be aligned to. + */ + #define ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes))) #endif /** @} */ diff --git a/LUFA/Common/Common.h b/LUFA/Common/Common.h index 76e1be1e2a..147ae8ebc9 100644 --- a/LUFA/Common/Common.h +++ b/LUFA/Common/Common.h @@ -87,15 +87,50 @@ #include typedef uint8_t uint_reg_t; + + #define le16_to_cpu(x) x + #define le32_to_cpu(x) x + #define be16_to_cpu(x) SwapEndian_16(x) + #define be32_to_cpu(x) SwapEndian_32(x) + #define cpu_to_le16(x) x + #define cpu_to_le32(x) x + #define cpu_to_be16(x) SwapEndian_16(x) + #define cpu_to_be32(x) SwapEndian_32(x) + #define LE16_TO_CPU(x) x + #define LE32_TO_CPU(x) x + #define BE16_TO_CPU(x) SWAPENDIAN_16(x) + #define BE32_TO_CPU(x) SWAPENDIAN_32(x) + #define CPU_TO_LE16(x) x + #define CPU_TO_LE32(x) x + #define CPU_TO_BE16(x) SWAPENDIAN_16(x) + #define CPU_TO_BE32(x) SWAPENDIAN_32(x) + #elif (ARCH == ARCH_UC3B) #include typedef uint32_t uint_reg_t; // TODO + #define le16_to_cpu(x) SwapEndian_16(x) + #define le32_to_cpu(x) SwapEndian_32(x) + #define be16_to_cpu(x) x + #define be32_to_cpu(x) x + #define cpu_to_le16(x) SwapEndian_16(x) + #define cpu_to_le32(x) SwapEndian_32(x) + #define cpu_to_be16(x) x + #define cpu_to_be32(x) x + #define LE16_TO_CPU(x) SWAPENDIAN_16(x) + #define LE32_TO_CPU(x) SWAPENDIAN_32(x) + #define BE16_TO_CPU(x) x + #define BE32_TO_CPU(x) x + #define CPU_TO_LE16(x) SWAPENDIAN_16(x) + #define CPU_TO_LE32(x) SWAPENDIAN_32(x) + #define CPU_TO_BE16(x) x + #define CPU_TO_BE32(x) x + + #define ISR(Name) void Name (void) __attribute__((__interrupt__)); void Name (void) #define EEMEM #define PROGMEM const - #define ISR(Name) void Name (void) __attribute__((__interrupt__)); void Name (void) #define ATOMIC_BLOCK(x) if (1) #define ATOMIC_RESTORESTATE #define pgm_read_byte(x) *x @@ -105,10 +140,6 @@ #define _delay_ms(x) #define memcmp_P(...) memcmp(__VA_ARGS__) #define memcpy_P(...) memcpy(__VA_ARGS__) - #define cpu_irq_enable() do { asm volatile("" ::: "memory"); __builtin_csrf(AVR32_SR_GM_OFFSET); } while (0) - #define cpu_irq_disable() do { __builtin_ssrf(AVR32_SR_GM_OFFSET); asm volatile("" ::: "memory"); } while (0) - - #warning The UC3B architecture support is currently experimental and incomplete! #endif /* Public Interface - May be used in end-application: */ diff --git a/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c b/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c index ceb0ebdb70..18fa48a236 100644 --- a/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c +++ b/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c @@ -59,8 +59,6 @@ void USB_Init( #if !defined(USE_STATIC_OPTIONS) USB_Options = Options; #endif - - USB_INT_RegisterHandlers(); if (!(USB_Options & USB_OPT_REG_DISABLED)) USB_REG_On(); diff --git a/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.h b/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.h index 14e5c518e2..6115ec6e3c 100644 --- a/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.h @@ -84,11 +84,6 @@ }; /* Inline Functions: */ - static inline void USB_INT_RegisterHandlers(void) - { - // Not required for AVR8 - } - static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE; static inline void USB_INT_Enable(const uint8_t Interrupt) { diff --git a/LUFA/Drivers/USB/Core/DeviceStandardReq.c b/LUFA/Drivers/USB/Core/DeviceStandardReq.c index f0c336eda4..e43543dfec 100644 --- a/LUFA/Drivers/USB/Core/DeviceStandardReq.c +++ b/LUFA/Drivers/USB/Core/DeviceStandardReq.c @@ -48,10 +48,11 @@ bool USB_RemoteWakeupEnabled; void USB_Device_ProcessControlRequest(void) { - uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest; - - for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++) - *(RequestHeader++) = Endpoint_Read_Byte(); + USB_ControlRequest.bmRequestType = Endpoint_Read_Byte(); + USB_ControlRequest.bRequest = Endpoint_Read_Byte(); + USB_ControlRequest.wValue = le16_to_cpu(Endpoint_Read_Word_LE()); + USB_ControlRequest.wIndex = le16_to_cpu(Endpoint_Read_Word_LE()); + USB_ControlRequest.wLength = le16_to_cpu(Endpoint_Read_Word_LE()); EVENT_USB_Device_ControlRequest(); diff --git a/LUFA/Drivers/USB/Core/StdDescriptors.h b/LUFA/Drivers/USB/Core/StdDescriptors.h index 8599f47aa1..6f12207161 100644 --- a/LUFA/Drivers/USB/Core/StdDescriptors.h +++ b/LUFA/Drivers/USB/Core/StdDescriptors.h @@ -88,13 +88,13 @@ * Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the * standard device descriptor. */ - #define VERSION_BCD(x) ((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | \ + #define VERSION_BCD(x) CPU_TO_LE16((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | \ ((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x))) /** String language ID for the English language. Should be used in \ref USB_Descriptor_String_t descriptors * to indicate that the English language is supported by the device in its string descriptors. */ - #define LANGUAGE_ID_ENG 0x0409 + #define LANGUAGE_ID_ENG CPU_TO_LE16(0x0409) /** \name Endpoint Address Direction Masks */ //@{ diff --git a/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.c b/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.c index 1f5004d7e2..ee9d35f0a6 100644 --- a/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.c +++ b/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.c @@ -39,17 +39,18 @@ uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; #endif -uint8_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP; - +volatile uint8_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP; +volatile void* USB_EndpointFIFOPos[ENDPOINT_TOTAL_ENDPOINTS]; bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, - const uint32_t UECFGXData) + const uint32_t UECFG0Data) { Endpoint_SelectEndpoint(Number); Endpoint_EnableEndpoint(); - ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0; - ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = UECFGXData; + (&AVR32_USBB.uecfg0)[Number] = 0; + (&AVR32_USBB.uecfg0)[Number] = UECFG0Data; + USB_EndpointFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000]; return Endpoint_IsConfigured(); } @@ -59,8 +60,9 @@ void Endpoint_ClearEndpoints(void) for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) { Endpoint_SelectEndpoint(EPNum); - ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0; - ((uint32_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint] = 0xFFFFFFFF; + (&AVR32_USBB.uecfg0)[EPNum] = 0; + (&AVR32_USBB.uecon0clr)[EPNum] = 0xFFFFFFFF; + USB_EndpointFIFOPos[EPNum] = &AVR32_USBB_SLAVE[EPNum * 0x10000]; Endpoint_DisableEndpoint(); } } diff --git a/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.h b/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.h index 556ac84b15..4860d26654 100644 --- a/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.h +++ b/LUFA/Drivers/USB/Core/UC3B/Endpoint_UC3B.h @@ -131,7 +131,8 @@ const uint32_t UECFGXData); /* External Variables: */ - extern uint8_t USB_SelectedEndpoint; + extern volatile uint8_t USB_SelectedEndpoint; + extern volatile void* USB_EndpointFIFOPos[]; #endif /* Public Interface - May be used in end-application: */ @@ -296,7 +297,7 @@ static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint16_t Endpoint_BytesInEndpoint(void) { - return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].byct; + return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].byct; } /** Get the endpoint address of the currently selected endpoint. This is typically used to save @@ -336,6 +337,7 @@ { AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_MASK << EndpointNumber); AVR32_USBB.uerst &= ~(AVR32_USBB_EPRST0_MASK << EndpointNumber); + USB_EndpointFIFOPos[EndpointNumber] = &AVR32_USBB_SLAVE[EndpointNumber * 0x10000]; } /** Enables the currently selected endpoint so that data can be sent and received through it to @@ -378,7 +380,7 @@ */ static inline uint8_t Endpoint_GetBusyBanks(void) { - return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].nbusybk; + return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].nbusybk; } /** Aborts all pending IN transactions on the currently selected endpoint, once the bank @@ -392,9 +394,11 @@ { while (Endpoint_GetBusyBanks() != 0) { - ((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].killbk = true; - while (((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0)[USB_SelectedEndpoint].killbk); + (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].killbks = true; + while ((&AVR32_USBB.UECON0)[USB_SelectedEndpoint].killbk); } + + USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000]; } /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint @@ -411,7 +415,7 @@ static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsReadWriteAllowed(void) { - return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].rwall; + return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rwall; } /** Determines if the currently selected endpoint is configured. @@ -421,7 +425,7 @@ static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsConfigured(void) { - return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].cfgok; + return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].cfgok; } /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their @@ -461,7 +465,7 @@ static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsINReady(void) { - return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].txini; + return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].txini; } /** Determines if the selected OUT endpoint has received new packet from the host. @@ -473,7 +477,7 @@ static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsOUTReceived(void) { - return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].rxouti; + return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rxouti; } /** Determines if the current CONTROL type endpoint has received a SETUP packet. @@ -485,7 +489,7 @@ static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsSETUPReceived(void) { - return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].rxstpi; + return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rxstpi; } /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the @@ -498,7 +502,8 @@ static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearSETUP(void) { - ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxstpic = true; + (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxstpic = true; + USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000]; } /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the @@ -509,8 +514,9 @@ static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearIN(void) { - ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].txinic = true; - ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = true; + (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].txinic = true; + (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].fifoconc = true; + USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000]; } /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint @@ -521,8 +527,9 @@ static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearOUT(void) { - ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true; - ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = true; + (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true; + (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].fifoconc = true; + USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000]; } /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the @@ -539,7 +546,7 @@ static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_StallTransaction(void) { - ((avr32_usbb_uecon0set_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].stallrqs = true; + (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].stallrqs = true; } /** Clears the STALL condition on the currently selected endpoint. @@ -549,7 +556,7 @@ static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearStall(void) { - ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].stallrqc = true; + (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].stallrqc = true; } /** Determines if the currently selected endpoint is stalled, false otherwise. @@ -561,24 +568,24 @@ static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsStalled(void) { - return ((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0)[USB_SelectedEndpoint].stallrq; + return (&AVR32_USBB.UECON0)[USB_SelectedEndpoint].stallrq; } /** Resets the data toggle of the currently selected endpoint. */ static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ResetDataToggle(void) { - ((avr32_usbb_uecon0set_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].rstdts = true; + (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].rstdts = true; } /** Determines the currently selected endpoint's direction. * * \return The currently selected endpoint's direction, as a \c ENDPOINT_DIR_* mask. */ - static inline uint8_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; - static inline uint8_t Endpoint_GetEndpointDirection(void) + static inline uint32_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; + static inline uint32_t Endpoint_GetEndpointDirection(void) { - return (((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] & AVR32_USBB_UECFG0_EPDIR_MASK); + return ((&AVR32_USBB.uecfg0)[USB_SelectedEndpoint] & AVR32_USBB_UECFG0_EPDIR_MASK); } /** Sets the direction of the currently selected endpoint. @@ -588,7 +595,7 @@ static inline void Endpoint_SetEndpointDirection(const uint32_t DirectionMask) ATTR_ALWAYS_INLINE; static inline void Endpoint_SetEndpointDirection(const uint32_t DirectionMask) { - ((avr32_usbb_uecfg0_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint].epdir = (DirectionMask == ENDPOINT_DIR_IN); + (&AVR32_USBB.UECFG0)[USB_SelectedEndpoint].epdir = (DirectionMask == ENDPOINT_DIR_IN); } /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints. @@ -600,7 +607,7 @@ static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint8_t Endpoint_Read_Byte(void) { - return *((uint8_t*)AVR32_USBB_EP_DATA); + return *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); } /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints. @@ -612,7 +619,7 @@ static inline void Endpoint_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE; static inline void Endpoint_Write_Byte(const uint8_t Byte) { - *((uint8_t*)AVR32_USBB_EP_DATA) = Byte; + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = Byte; } /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints. @@ -624,7 +631,7 @@ { uint8_t Dummy; - Dummy = *((uint8_t*)AVR32_USBB_EP_DATA); + Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); } /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT @@ -637,16 +644,10 @@ static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint16_t Endpoint_Read_Word_LE(void) { - union - { - uint16_t Word; - uint8_t Bytes[2]; - } Data; - - Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA); + uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); - return Data.Word; + return ((Byte1 << 8) | Byte0); } /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT @@ -659,16 +660,10 @@ static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint16_t Endpoint_Read_Word_BE(void) { - union - { - uint16_t Word; - uint8_t Bytes[2]; - } Data; - - Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA); + uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); - return Data.Word; + return ((Byte1 << 8) | Byte0); } /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN @@ -681,8 +676,8 @@ static inline void Endpoint_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE; static inline void Endpoint_Write_Word_LE(const uint16_t Word) { - *((uint8_t*)AVR32_USBB_EP_DATA) = (Word & 0xFF); - *((uint8_t*)AVR32_USBB_EP_DATA) = (Word >> 8); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word & 0xFF); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word >> 8); } /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN @@ -695,8 +690,8 @@ static inline void Endpoint_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE; static inline void Endpoint_Write_Word_BE(const uint16_t Word) { - *((uint8_t*)AVR32_USBB_EP_DATA) = (Word >> 8); - *((uint8_t*)AVR32_USBB_EP_DATA) = (Word & 0xFF); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word >> 8); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word & 0xFF); } /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints. @@ -708,8 +703,8 @@ { uint8_t Dummy; - Dummy = *((uint8_t*)AVR32_USBB_EP_DATA); - Dummy = *((uint8_t*)AVR32_USBB_EP_DATA); + Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); } /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT @@ -722,18 +717,12 @@ static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint32_t Endpoint_Read_DWord_LE(void) { - union - { - uint32_t DWord; - uint8_t Bytes[4]; - } Data; - - Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[2] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[3] = *((uint8_t*)AVR32_USBB_EP_DATA); + uint32_t Byte3 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint32_t Byte2 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint32_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint32_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); - return Data.DWord; + return ((Byte3 << 24) | (Byte2 << 16) | (Byte1 << 8) | Byte0); } /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT @@ -746,18 +735,12 @@ static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint32_t Endpoint_Read_DWord_BE(void) { - union - { - uint32_t DWord; - uint8_t Bytes[4]; - } Data; - - Data.Bytes[3] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[2] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA); - Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA); + uint32_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint32_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint32_t Byte2 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + uint32_t Byte3 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); - return Data.DWord; + return ((Byte3 << 24) | (Byte2 << 16) | (Byte1 << 8) | Byte0); } /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN @@ -770,10 +753,10 @@ static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE; static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) { - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord & 0xFF); - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 8); - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 16); - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 24); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord & 0xFF); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 8); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 16); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 24); } /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN @@ -786,10 +769,10 @@ static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE; static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) { - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 24); - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 16); - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 8); - *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord & 0xFF); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 24); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 16); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 8); + *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord & 0xFF); } /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. @@ -801,10 +784,10 @@ { uint8_t Dummy; - Dummy = *((uint8_t*)AVR32_USBB_EP_DATA); - Dummy = *((uint8_t*)AVR32_USBB_EP_DATA); - Dummy = *((uint8_t*)AVR32_USBB_EP_DATA); - Dummy = *((uint8_t*)AVR32_USBB_EP_DATA); + Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); + Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++); } /* External Variables: */ diff --git a/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.c b/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.c index 9d9c600947..eb411434db 100644 --- a/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.c +++ b/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.c @@ -36,7 +36,7 @@ #include "../Pipe.h" uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; -uint8_t USB_SelectedPipe = PIPE_CONTROLPIPE; +volatile uint8_t USB_SelectedPipe = PIPE_CONTROLPIPE; bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, @@ -48,8 +48,8 @@ bool Pipe_ConfigurePipe(const uint8_t Number, Pipe_SelectPipe(Number); Pipe_EnablePipe(); - ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0; - ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = (AVR32_USBB_ALLOC_MASK | + (&AVR32_USBB.upcfg0)[Number] = 0; + (&AVR32_USBB.upcfg0)[Number] = (AVR32_USBB_ALLOC_MASK | ((uint32_t)Type << AVR32_USBB_PTYPE_OFFSET) | ((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) | ((uint32_t)Banks << AVR32_USBB_PBK_OFFSET) | @@ -65,8 +65,8 @@ void Pipe_ClearPipes(void) for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++) { Pipe_SelectPipe(PNum); - ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0; - ((uint32_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe] = 0xFFFFFFFF; + (&AVR32_USBB.upcfg0)[PNum] = 0; + (&AVR32_USBB.upcon0clr)[PNum] = 0xFFFFFFFF; Pipe_DisablePipe(); } } diff --git a/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.h b/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.h index 484e48ac15..033dd0153a 100644 --- a/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.h +++ b/LUFA/Drivers/USB/Core/UC3B/Pipe_UC3B.h @@ -99,7 +99,7 @@ /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* External Variables: */ - extern uint8_t USB_SelectedPipe; + extern volatile uint8_t USB_SelectedPipe; #endif /* Public Interface - May be used in end-application: */ @@ -212,7 +212,7 @@ static inline uint16_t Pipe_BytesInPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint16_t Pipe_BytesInPipe(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].pbyct; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].pbyct; } /** Returns the pipe address of the currently selected pipe. This is typically used to save the @@ -285,7 +285,7 @@ static inline uint8_t Pipe_GetPipeToken(void) ATTR_ALWAYS_INLINE; static inline uint8_t Pipe_GetPipeToken(void) { - return ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].ptoken; + return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken; } /** Sets the token for the currently selected pipe to one of the tokens specified by the \c PIPE_TOKEN_* @@ -298,14 +298,14 @@ static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_ALWAYS_INLINE; static inline void Pipe_SetPipeToken(const uint8_t Token) { - ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].ptoken = Token; + (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken = Token; } /** Configures the currently selected pipe to allow for an unlimited number of IN requests. */ static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE; static inline void Pipe_SetInfiniteINRequests(void) { - ((avr32_usbb_upinrq0_t*)AVR32_USBB_UPINRQ0)[USB_SelectedPipe].inmode = true; + (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = true; } /** Configures the currently selected pipe to only allow the specified number of IN requests to be @@ -316,8 +316,8 @@ static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_ALWAYS_INLINE; static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) { - ((avr32_usbb_upinrq0_t*)AVR32_USBB_UPINRQ0)[USB_SelectedPipe].inmode = false; - ((avr32_usbb_upinrq0_t*)AVR32_USBB_UPINRQ0)[USB_SelectedPipe].inrq = TotalINRequests; + (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = false; + (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inrq = TotalINRequests; } /** Determines if the currently selected pipe is configured. @@ -327,7 +327,7 @@ static inline bool Pipe_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsConfigured(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].cfgok; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].cfgok; } /** Retrieves the endpoint number of the endpoint within the attached device that the currently selected @@ -338,7 +338,7 @@ static inline uint8_t Pipe_BoundEndpointNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint8_t Pipe_BoundEndpointNumber(void) { - return ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].pepnum; + return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].pepnum; } /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds. @@ -348,7 +348,7 @@ static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE; static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) { - ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].intfrq = Milliseconds; + (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].intfrq = Milliseconds; } /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should @@ -382,14 +382,14 @@ static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE; static inline void Pipe_Unfreeze(void) { - ((avr32_usbb_upcon0clr_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe].pfreezec = true; + (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].pfreezec = true; } /** Freezes the selected pipe, preventing it from communicating with an attached device. */ static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE; static inline void Pipe_Freeze(void) { - ((avr32_usbb_upcon0set_t*)AVR32_USBB_UPCON0SET)[USB_SelectedPipe].pfreezes = true; + (&AVR32_USBB.UPCON0SET)[USB_SelectedPipe].pfreezes = true; } /** Determines if the currently selected pipe is frozen, and not able to accept data. @@ -399,15 +399,15 @@ static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsFrozen(void) { - return ((((avr32_usbb_upcon0_t*)AVR32_USBB_UPCON0)[USB_SelectedPipe].pfreeze) ? true : false); + return (((&AVR32_USBB.UPCON0)[USB_SelectedPipe].pfreeze) ? true : false); } /** Clears the error flags for the currently selected pipe. */ static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearError(void) { - ((uint32_t*)AVR32_USBB_UPERR0)[USB_SelectedPipe] = 0; - ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].overfic = true; + (&AVR32_USBB.uperr0)[USB_SelectedPipe] = 0; + (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].overfic = true; } /** Determines if the master pipe error flag is set for the currently selected pipe, indicating that @@ -420,7 +420,7 @@ static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsError(void) { - return ((((uint32_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe] & + return (((&AVR32_USBB.upsta0)[USB_SelectedPipe] & (AVR32_USBB_PERRI_MASK | AVR32_USBB_OVERFI_MASK)) ? true : false); } @@ -433,11 +433,11 @@ static inline uint8_t Pipe_GetErrorFlags(void) { - return ((((uint32_t*)AVR32_USBB_UPERR0)[USB_SelectedPipe] & + return (((&AVR32_USBB.uperr0)[USB_SelectedPipe] & (PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT | PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID | PIPE_ERRORFLAG_DATATGL)) | - ((((uint32_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe] << 8) & + (((&AVR32_USBB.upsta0)[USB_SelectedPipe] << 8) & PIPE_ERRORFLAG_OVERFLOW)); } @@ -451,7 +451,7 @@ */ static inline uint8_t Pipe_GetBusyBanks(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].nbusybk; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nbusybk; } /** Determines if the currently selected pipe may be read from (if data is waiting in the pipe @@ -470,7 +470,7 @@ static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsReadWriteAllowed(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].rwall; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rwall; } /** Determines if a packet has been received on the currently selected IN pipe from the attached device. @@ -482,7 +482,7 @@ static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsINReceived(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].rxini; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxini; } /** Determines if the currently selected OUT pipe is ready to send an OUT packet to the attached device. @@ -494,7 +494,7 @@ static inline bool Pipe_IsOUTReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsOUTReady(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].txouti; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txouti; } /** Determines if no SETUP request is currently being sent to the attached device on the selected @@ -507,7 +507,7 @@ static inline bool Pipe_IsSETUPSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsSETUPSent(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].txstpi; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txstpi; } /** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet. @@ -517,7 +517,7 @@ static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearSETUP(void) { - ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].txstpic = true; + (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txstpic = true; } /** Acknowledges the reception of a setup IN request from the attached device on the currently selected @@ -528,8 +528,8 @@ static inline void Pipe_ClearIN(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearIN(void) { - ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].rxinic = true; - ((avr32_usbb_upcon0clr_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe].fifoconc = true; + (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxinic = true; + (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true; } /** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing @@ -540,8 +540,8 @@ static inline void Pipe_ClearOUT(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearOUT(void) { - ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].txoutic = true; - ((avr32_usbb_upcon0clr_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe].fifoconc = true; + (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txoutic = true; + (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true; } /** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on @@ -557,7 +557,7 @@ static inline bool Pipe_IsNAKReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsNAKReceived(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].nakedi; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nakedi; } /** Clears the NAK condition on the currently selected pipe. @@ -569,7 +569,7 @@ static inline void Pipe_ClearNAKReceived(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearNAKReceived(void) { - ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].nakedic = true; + (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].nakedic = true; } /** Determines if the currently selected pipe has had the STALL condition set by the attached device. @@ -581,7 +581,7 @@ static inline bool Pipe_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Pipe_IsStalled(void) { - return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].rxstalldi; + return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxstalldi; } /** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the @@ -592,7 +592,7 @@ static inline void Pipe_ClearStall(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearStall(void) { - ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].rxstalldic = true; + (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxstalldic = true; } /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes. diff --git a/LUFA/Drivers/USB/Core/UC3B/USBController_UC3B.c b/LUFA/Drivers/USB/Core/UC3B/USBController_UC3B.c index 191e084960..8241e0b052 100644 --- a/LUFA/Drivers/USB/Core/UC3B/USBController_UC3B.c +++ b/LUFA/Drivers/USB/Core/UC3B/USBController_UC3B.c @@ -60,8 +60,6 @@ void USB_Init( USB_Options = Options; #endif - USB_INT_RegisterHandlers(); - #if defined(USB_CAN_BE_BOTH) if (Mode == USB_MODE_UID) { @@ -71,6 +69,7 @@ void USB_Init( } else { + AVR32_USBB.USBCON.uide = false; USB_CurrentMode = Mode; } #endif @@ -108,7 +107,7 @@ void USB_ResetInterface(void) AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].pllsel = !(USB_Options & USB_OPT_GCLK_SRC_OSC); AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].oscsel = !(USB_Options & USB_OPT_GCLK_CHANNEL_0); AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].diven = (F_CLOCK != 48000000UL); - AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].div = ((F_CLOCK / 2) / 48000000UL); + AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].div = (F_CLOCK == 48000000UL) ? 0 : (uint32_t)(((F_CLOCK / 48000000UL) - 1) / 2); AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].cen = true; USB_INT_DisableAllInterrupts(); @@ -181,6 +180,7 @@ static void USB_Init_Device(void) USB_INT_Enable(USB_INT_EORSTI); USB_Attach(); + USB_Device_SetDeviceAddress(0); } #endif diff --git a/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.c b/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.c index 77dbc9f99f..aee8940e33 100644 --- a/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.c +++ b/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.c @@ -118,6 +118,7 @@ ISR(USB_GEN_vect) USB_INT_Disable(USB_INT_SUSPI); USB_INT_Enable(USB_INT_WAKEUPI); + USB_Device_SetDeviceAddress(0); Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, ENDPOINT_DIR_OUT, USB_ControlEndpointSize, ENDPOINT_BANK_SINGLE); diff --git a/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.h b/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.h index ca60e7f0fa..6bc836b772 100644 --- a/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.h +++ b/LUFA/Drivers/USB/Core/UC3B/USBInterrupt_UC3B.h @@ -83,11 +83,6 @@ ISR(USB_GEN_vect); /* Inline Functions: */ - static inline void USB_INT_RegisterHandlers(void) - { - AVR32_INTC.IPR[AVR32_USBB_IRQ % 32].autovector = (uintptr_t)&USB_GEN_vect; - } - static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE; static inline void USB_INT_Enable(const uint8_t Interrupt) {