const uint32_t UECFGXData);\r
\r
/* External Variables: */\r
- extern uint8_t USB_SelectedEndpoint;\r
+ extern volatile uint8_t USB_SelectedEndpoint;\r
+ extern volatile void* USB_EndpointFIFOPos[];\r
#endif\r
\r
/* Public Interface - May be used in end-application: */\r
static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint16_t Endpoint_BytesInEndpoint(void)\r
{\r
- return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].byct;\r
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].byct;\r
}\r
\r
/** Get the endpoint address of the currently selected endpoint. This is typically used to save\r
{\r
AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_MASK << EndpointNumber);\r
AVR32_USBB.uerst &= ~(AVR32_USBB_EPRST0_MASK << EndpointNumber);\r
+ USB_EndpointFIFOPos[EndpointNumber] = &AVR32_USBB_SLAVE[EndpointNumber * 0x10000];\r
}\r
\r
/** Enables the currently selected endpoint so that data can be sent and received through it to\r
*/\r
static inline uint8_t Endpoint_GetBusyBanks(void)\r
{\r
- return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].nbusybk;\r
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].nbusybk;\r
}\r
\r
/** Aborts all pending IN transactions on the currently selected endpoint, once the bank\r
{\r
while (Endpoint_GetBusyBanks() != 0)\r
{\r
- ((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].killbk = true;\r
- while (((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0)[USB_SelectedEndpoint].killbk);\r
+ (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].killbks = true;\r
+ while ((&AVR32_USBB.UECON0)[USB_SelectedEndpoint].killbk);\r
}\r
+\r
+ USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000];\r
}\r
\r
/** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint\r
static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Endpoint_IsReadWriteAllowed(void)\r
{\r
- return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].rwall;\r
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rwall;\r
}\r
\r
/** Determines if the currently selected endpoint is configured.\r
static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Endpoint_IsConfigured(void)\r
{\r
- return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].cfgok;\r
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].cfgok;\r
}\r
\r
/** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their\r
static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Endpoint_IsINReady(void)\r
{\r
- return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].txini;\r
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].txini;\r
}\r
\r
/** Determines if the selected OUT endpoint has received new packet from the host.\r
static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Endpoint_IsOUTReceived(void)\r
{\r
- return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].rxouti;\r
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rxouti;\r
}\r
\r
/** Determines if the current CONTROL type endpoint has received a SETUP packet.\r
static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Endpoint_IsSETUPReceived(void)\r
{\r
- return ((avr32_usbb_uesta0_t*)AVR32_USBB_UESTA0)[USB_SelectedEndpoint].rxstpi;\r
+ return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rxstpi;\r
}\r
\r
/** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the\r
static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_ClearSETUP(void)\r
{\r
- ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxstpic = true;\r
+ (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxstpic = true;\r
+ USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000];\r
}\r
\r
/** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the\r
static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_ClearIN(void)\r
{\r
- ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].txinic = true;\r
- ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;\r
+ (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].txinic = true;\r
+ (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;\r
+ USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000];\r
}\r
\r
/** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint\r
static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_ClearOUT(void)\r
{\r
- ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true;\r
- ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;\r
+ (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true;\r
+ (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;\r
+ USB_EndpointFIFOPos[USB_SelectedEndpoint] = &AVR32_USBB_SLAVE[USB_SelectedEndpoint * 0x10000];\r
}\r
\r
/** Stalls the current endpoint, indicating to the host that a logical problem occurred with the\r
static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_StallTransaction(void)\r
{\r
- ((avr32_usbb_uecon0set_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].stallrqs = true;\r
+ (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].stallrqs = true;\r
}\r
\r
/** Clears the STALL condition on the currently selected endpoint.\r
static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_ClearStall(void)\r
{\r
- ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].stallrqc = true;\r
+ (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].stallrqc = true;\r
}\r
\r
/** Determines if the currently selected endpoint is stalled, false otherwise.\r
static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Endpoint_IsStalled(void)\r
{\r
- return ((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0)[USB_SelectedEndpoint].stallrq;\r
+ return (&AVR32_USBB.UECON0)[USB_SelectedEndpoint].stallrq;\r
}\r
\r
/** Resets the data toggle of the currently selected endpoint. */\r
static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_ResetDataToggle(void)\r
{\r
- ((avr32_usbb_uecon0set_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].rstdts = true;\r
+ (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].rstdts = true;\r
}\r
\r
/** Determines the currently selected endpoint's direction.\r
*\r
* \return The currently selected endpoint's direction, as a \c ENDPOINT_DIR_* mask.\r
*/\r
- static inline uint8_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
- static inline uint8_t Endpoint_GetEndpointDirection(void)\r
+ static inline uint32_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
+ static inline uint32_t Endpoint_GetEndpointDirection(void)\r
{\r
- return (((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] & AVR32_USBB_UECFG0_EPDIR_MASK);\r
+ return ((&AVR32_USBB.uecfg0)[USB_SelectedEndpoint] & AVR32_USBB_UECFG0_EPDIR_MASK);\r
}\r
\r
/** Sets the direction of the currently selected endpoint.\r
static inline void Endpoint_SetEndpointDirection(const uint32_t DirectionMask) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_SetEndpointDirection(const uint32_t DirectionMask)\r
{\r
- ((avr32_usbb_uecfg0_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint].epdir = (DirectionMask == ENDPOINT_DIR_IN);\r
+ (&AVR32_USBB.UECFG0)[USB_SelectedEndpoint].epdir = (DirectionMask == ENDPOINT_DIR_IN);\r
}\r
\r
/** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.\r
static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint8_t Endpoint_Read_Byte(void)\r
{\r
- return *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ return *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
}\r
\r
/** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.\r
static inline void Endpoint_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_Write_Byte(const uint8_t Byte)\r
{\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = Byte;\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = Byte;\r
}\r
\r
/** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.\r
{\r
uint8_t Dummy;\r
\r
- Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
}\r
\r
/** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT\r
static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint16_t Endpoint_Read_Word_LE(void)\r
{\r
- union\r
- {\r
- uint16_t Word;\r
- uint8_t Bytes[2];\r
- } Data;\r
-\r
- Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
\r
- return Data.Word;\r
+ return ((Byte1 << 8) | Byte0);\r
}\r
\r
/** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT\r
static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint16_t Endpoint_Read_Word_BE(void)\r
{\r
- union\r
- {\r
- uint16_t Word;\r
- uint8_t Bytes[2];\r
- } Data;\r
-\r
- Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
\r
- return Data.Word;\r
+ return ((Byte1 << 8) | Byte0);\r
}\r
\r
/** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN\r
static inline void Endpoint_Write_Word_LE(const uint16_t Word) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_Write_Word_LE(const uint16_t Word)\r
{\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (Word & 0xFF);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (Word >> 8);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word & 0xFF);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word >> 8);\r
}\r
\r
/** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN\r
static inline void Endpoint_Write_Word_BE(const uint16_t Word) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_Write_Word_BE(const uint16_t Word)\r
{\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (Word >> 8);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (Word & 0xFF);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word >> 8);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word & 0xFF);\r
}\r
\r
/** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.\r
{\r
uint8_t Dummy;\r
\r
- Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
}\r
\r
/** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT\r
static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint32_t Endpoint_Read_DWord_LE(void)\r
{\r
- union\r
- {\r
- uint32_t DWord;\r
- uint8_t Bytes[4];\r
- } Data;\r
-\r
- Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[2] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[3] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ uint32_t Byte3 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint32_t Byte2 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint32_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint32_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
\r
- return Data.DWord;\r
+ return ((Byte3 << 24) | (Byte2 << 16) | (Byte1 << 8) | Byte0);\r
}\r
\r
/** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT\r
static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint32_t Endpoint_Read_DWord_BE(void)\r
{\r
- union\r
- {\r
- uint32_t DWord;\r
- uint8_t Bytes[4];\r
- } Data;\r
-\r
- Data.Bytes[3] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[2] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[1] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Data.Bytes[0] = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ uint32_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint32_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint32_t Byte2 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ uint32_t Byte3 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
\r
- return Data.DWord;\r
+ return ((Byte3 << 24) | (Byte2 << 16) | (Byte1 << 8) | Byte0);\r
}\r
\r
/** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN\r
static inline void Endpoint_Write_DWord_LE(const uint32_t DWord) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_Write_DWord_LE(const uint32_t DWord)\r
{\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord & 0xFF);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 8);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 16);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 24);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord & 0xFF);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 8);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 16);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 24);\r
}\r
\r
/** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN\r
static inline void Endpoint_Write_DWord_BE(const uint32_t DWord) ATTR_ALWAYS_INLINE;\r
static inline void Endpoint_Write_DWord_BE(const uint32_t DWord)\r
{\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 24);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 16);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord >> 8);\r
- *((uint8_t*)AVR32_USBB_EP_DATA) = (DWord & 0xFF);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 24);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 16);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord >> 8);\r
+ *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (DWord & 0xFF);\r
}\r
\r
/** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.\r
{\r
uint8_t Dummy;\r
\r
- Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
- Dummy = *((uint8_t*)AVR32_USBB_EP_DATA);\r
+ Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
+ Dummy = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);\r
}\r
\r
/* External Variables: */\r