* \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
/** @} */
#include <util/delay.h>
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 <avr32/io.h>
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
#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: */
#if !defined(USE_STATIC_OPTIONS)
USB_Options = Options;
#endif
-
- USB_INT_RegisterHandlers();
if (!(USB_Options & USB_OPT_REG_DISABLED))
USB_REG_On();
};
/* 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)
{
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();
* 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 */
//@{
uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;\r
#endif\r
\r
-uint8_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP;\r
-\r
+volatile uint8_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP;\r
+volatile void* USB_EndpointFIFOPos[ENDPOINT_TOTAL_ENDPOINTS];\r
\r
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,\r
- const uint32_t UECFGXData)\r
+ const uint32_t UECFG0Data)\r
{\r
Endpoint_SelectEndpoint(Number);\r
Endpoint_EnableEndpoint();\r
\r
- ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0;\r
- ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = UECFGXData;\r
+ (&AVR32_USBB.uecfg0)[Number] = 0;\r
+ (&AVR32_USBB.uecfg0)[Number] = UECFG0Data;\r
+ USB_EndpointFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];\r
\r
return Endpoint_IsConfigured();\r
}\r
for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)\r
{\r
Endpoint_SelectEndpoint(EPNum);\r
- ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0;\r
- ((uint32_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint] = 0xFFFFFFFF;\r
+ (&AVR32_USBB.uecfg0)[EPNum] = 0;\r
+ (&AVR32_USBB.uecon0clr)[EPNum] = 0xFFFFFFFF;\r
+ USB_EndpointFIFOPos[EPNum] = &AVR32_USBB_SLAVE[EPNum * 0x10000];\r
Endpoint_DisableEndpoint();\r
}\r
}\r
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
#include "../Pipe.h"\r
\r
uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;\r
-uint8_t USB_SelectedPipe = PIPE_CONTROLPIPE;\r
+volatile uint8_t USB_SelectedPipe = PIPE_CONTROLPIPE;\r
\r
bool Pipe_ConfigurePipe(const uint8_t Number,\r
const uint8_t Type,\r
Pipe_SelectPipe(Number);\r
Pipe_EnablePipe();\r
\r
- ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0;\r
- ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = (AVR32_USBB_ALLOC_MASK |\r
+ (&AVR32_USBB.upcfg0)[Number] = 0;\r
+ (&AVR32_USBB.upcfg0)[Number] = (AVR32_USBB_ALLOC_MASK |\r
((uint32_t)Type << AVR32_USBB_PTYPE_OFFSET) |\r
((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) |\r
((uint32_t)Banks << AVR32_USBB_PBK_OFFSET) |\r
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)\r
{\r
Pipe_SelectPipe(PNum);\r
- ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0;\r
- ((uint32_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe] = 0xFFFFFFFF;\r
+ (&AVR32_USBB.upcfg0)[PNum] = 0;\r
+ (&AVR32_USBB.upcon0clr)[PNum] = 0xFFFFFFFF;\r
Pipe_DisablePipe();\r
}\r
}\r
/* Private Interface - For use in library only: */\r
#if !defined(__DOXYGEN__)\r
/* External Variables: */\r
- extern uint8_t USB_SelectedPipe;\r
+ extern volatile uint8_t USB_SelectedPipe;\r
#endif\r
\r
/* Public Interface - May be used in end-application: */\r
static inline uint16_t Pipe_BytesInPipe(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint16_t Pipe_BytesInPipe(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].pbyct;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].pbyct;\r
}\r
\r
/** Returns the pipe address of the currently selected pipe. This is typically used to save the\r
static inline uint8_t Pipe_GetPipeToken(void) ATTR_ALWAYS_INLINE;\r
static inline uint8_t Pipe_GetPipeToken(void)\r
{\r
- return ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].ptoken;\r
+ return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken;\r
}\r
\r
/** Sets the token for the currently selected pipe to one of the tokens specified by the \c PIPE_TOKEN_*\r
static inline void Pipe_SetPipeToken(const uint8_t Token) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_SetPipeToken(const uint8_t Token)\r
{\r
- ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].ptoken = Token;\r
+ (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].ptoken = Token;\r
}\r
\r
/** Configures the currently selected pipe to allow for an unlimited number of IN requests. */\r
static inline void Pipe_SetInfiniteINRequests(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_SetInfiniteINRequests(void)\r
{\r
- ((avr32_usbb_upinrq0_t*)AVR32_USBB_UPINRQ0)[USB_SelectedPipe].inmode = true;\r
+ (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = true;\r
}\r
\r
/** Configures the currently selected pipe to only allow the specified number of IN requests to be\r
static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_SetFiniteINRequests(const uint8_t TotalINRequests)\r
{\r
- ((avr32_usbb_upinrq0_t*)AVR32_USBB_UPINRQ0)[USB_SelectedPipe].inmode = false;\r
- ((avr32_usbb_upinrq0_t*)AVR32_USBB_UPINRQ0)[USB_SelectedPipe].inrq = TotalINRequests;\r
+ (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inmode = false;\r
+ (&AVR32_USBB.UPINRQ0)[USB_SelectedPipe].inrq = TotalINRequests;\r
}\r
\r
/** Determines if the currently selected pipe is configured.\r
static inline bool Pipe_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsConfigured(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].cfgok;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].cfgok;\r
}\r
\r
/** Retrieves the endpoint number of the endpoint within the attached device that the currently selected\r
static inline uint8_t Pipe_BoundEndpointNumber(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline uint8_t Pipe_BoundEndpointNumber(void)\r
{\r
- return ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].pepnum;\r
+ return (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].pepnum;\r
}\r
\r
/** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds.\r
static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_SetInterruptPeriod(const uint8_t Milliseconds)\r
{\r
- ((avr32_usbb_upcfg0_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe].intfrq = Milliseconds;\r
+ (&AVR32_USBB.UPCFG0)[USB_SelectedPipe].intfrq = Milliseconds;\r
}\r
\r
/** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should\r
static inline void Pipe_Unfreeze(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_Unfreeze(void)\r
{\r
- ((avr32_usbb_upcon0clr_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe].pfreezec = true;\r
+ (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].pfreezec = true;\r
}\r
\r
/** Freezes the selected pipe, preventing it from communicating with an attached device. */\r
static inline void Pipe_Freeze(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_Freeze(void)\r
{\r
- ((avr32_usbb_upcon0set_t*)AVR32_USBB_UPCON0SET)[USB_SelectedPipe].pfreezes = true;\r
+ (&AVR32_USBB.UPCON0SET)[USB_SelectedPipe].pfreezes = true;\r
}\r
\r
/** Determines if the currently selected pipe is frozen, and not able to accept data.\r
static inline bool Pipe_IsFrozen(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsFrozen(void)\r
{\r
- return ((((avr32_usbb_upcon0_t*)AVR32_USBB_UPCON0)[USB_SelectedPipe].pfreeze) ? true : false);\r
+ return (((&AVR32_USBB.UPCON0)[USB_SelectedPipe].pfreeze) ? true : false);\r
}\r
\r
/** Clears the error flags for the currently selected pipe. */\r
static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_ClearError(void)\r
{\r
- ((uint32_t*)AVR32_USBB_UPERR0)[USB_SelectedPipe] = 0;\r
- ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].overfic = true;\r
+ (&AVR32_USBB.uperr0)[USB_SelectedPipe] = 0;\r
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].overfic = true;\r
}\r
\r
/** Determines if the master pipe error flag is set for the currently selected pipe, indicating that\r
static inline bool Pipe_IsError(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsError(void)\r
{\r
- return ((((uint32_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe] &\r
+ return (((&AVR32_USBB.upsta0)[USB_SelectedPipe] &\r
(AVR32_USBB_PERRI_MASK | AVR32_USBB_OVERFI_MASK)) ? true : false);\r
}\r
\r
static inline uint8_t Pipe_GetErrorFlags(void)\r
{\r
\r
- return ((((uint32_t*)AVR32_USBB_UPERR0)[USB_SelectedPipe] &\r
+ return (((&AVR32_USBB.uperr0)[USB_SelectedPipe] &\r
(PIPE_ERRORFLAG_CRC16 | PIPE_ERRORFLAG_TIMEOUT |\r
PIPE_ERRORFLAG_PID | PIPE_ERRORFLAG_DATAPID |\r
PIPE_ERRORFLAG_DATATGL)) |\r
- ((((uint32_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe] << 8) &\r
+ (((&AVR32_USBB.upsta0)[USB_SelectedPipe] << 8) &\r
PIPE_ERRORFLAG_OVERFLOW));\r
}\r
\r
*/\r
static inline uint8_t Pipe_GetBusyBanks(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].nbusybk;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nbusybk;\r
}\r
\r
/** Determines if the currently selected pipe may be read from (if data is waiting in the pipe\r
static inline bool Pipe_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsReadWriteAllowed(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].rwall;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rwall;\r
}\r
\r
/** Determines if a packet has been received on the currently selected IN pipe from the attached device.\r
static inline bool Pipe_IsINReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsINReceived(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].rxini;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxini;\r
}\r
\r
/** Determines if the currently selected OUT pipe is ready to send an OUT packet to the attached device.\r
static inline bool Pipe_IsOUTReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsOUTReady(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].txouti;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txouti;\r
}\r
\r
/** Determines if no SETUP request is currently being sent to the attached device on the selected\r
static inline bool Pipe_IsSETUPSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsSETUPSent(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].txstpi;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].txstpi;\r
}\r
\r
/** Sends the currently selected CONTROL type pipe's contents to the device as a SETUP packet.\r
static inline void Pipe_ClearSETUP(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_ClearSETUP(void)\r
{\r
- ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].txstpic = true;\r
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txstpic = true;\r
}\r
\r
/** Acknowledges the reception of a setup IN request from the attached device on the currently selected\r
static inline void Pipe_ClearIN(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_ClearIN(void)\r
{\r
- ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].rxinic = true;\r
- ((avr32_usbb_upcon0clr_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxinic = true;\r
+ (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
}\r
\r
/** Sends the currently selected pipe's contents to the device as an OUT packet on the selected pipe, freeing\r
static inline void Pipe_ClearOUT(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_ClearOUT(void)\r
{\r
- ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].txoutic = true;\r
- ((avr32_usbb_upcon0clr_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].txoutic = true;\r
+ (&AVR32_USBB.UPCON0CLR)[USB_SelectedPipe].fifoconc = true;\r
}\r
\r
/** Determines if the device sent a NAK (Negative Acknowledge) in response to the last sent packet on\r
static inline bool Pipe_IsNAKReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsNAKReceived(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].nakedi;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].nakedi;\r
}\r
\r
/** Clears the NAK condition on the currently selected pipe.\r
static inline void Pipe_ClearNAKReceived(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_ClearNAKReceived(void)\r
{\r
- ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].nakedic = true;\r
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].nakedic = true;\r
}\r
\r
/** Determines if the currently selected pipe has had the STALL condition set by the attached device.\r
static inline bool Pipe_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;\r
static inline bool Pipe_IsStalled(void)\r
{\r
- return ((avr32_usbb_upsta0_t*)AVR32_USBB_UPSTA0)[USB_SelectedPipe].rxstalldi;\r
+ return (&AVR32_USBB.UPSTA0)[USB_SelectedPipe].rxstalldi;\r
}\r
\r
/** Clears the STALL condition detection flag on the currently selected pipe, but does not clear the\r
static inline void Pipe_ClearStall(void) ATTR_ALWAYS_INLINE;\r
static inline void Pipe_ClearStall(void)\r
{\r
- ((avr32_usbb_upsta0clr_t*)AVR32_USBB_UPSTA0CLR)[USB_SelectedPipe].rxstalldic = true;\r
+ (&AVR32_USBB.UPSTA0CLR)[USB_SelectedPipe].rxstalldic = true;\r
}\r
\r
/** Reads one byte from the currently selected pipe's bank, for OUT direction pipes.\r
USB_Options = Options;\r
#endif\r
\r
- USB_INT_RegisterHandlers();\r
-\r
#if defined(USB_CAN_BE_BOTH)\r
if (Mode == USB_MODE_UID)\r
{\r
}\r
else\r
{\r
+ AVR32_USBB.USBCON.uide = false;\r
USB_CurrentMode = Mode;\r
}\r
#endif\r
AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].pllsel = !(USB_Options & USB_OPT_GCLK_SRC_OSC);\r
AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].oscsel = !(USB_Options & USB_OPT_GCLK_CHANNEL_0);\r
AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].diven = (F_CLOCK != 48000000UL);\r
- AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].div = ((F_CLOCK / 2) / 48000000UL);\r
+ AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].div = (F_CLOCK == 48000000UL) ? 0 : (uint32_t)(((F_CLOCK / 48000000UL) - 1) / 2);\r
AVR32_PM.GCCTRL[USB_GCLK_USBB_INDEX].cen = true;\r
\r
USB_INT_DisableAllInterrupts();\r
USB_INT_Enable(USB_INT_EORSTI);\r
\r
USB_Attach();\r
+ USB_Device_SetDeviceAddress(0);\r
}\r
#endif\r
\r
USB_INT_Disable(USB_INT_SUSPI);\r
USB_INT_Enable(USB_INT_WAKEUPI);\r
\r
+ USB_Device_SetDeviceAddress(0);\r
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,\r
ENDPOINT_DIR_OUT, USB_ControlEndpointSize,\r
ENDPOINT_BANK_SINGLE);\r
ISR(USB_GEN_vect);\r
\r
/* Inline Functions: */\r
- static inline void USB_INT_RegisterHandlers(void)\r
- {\r
- AVR32_INTC.IPR[AVR32_USBB_IRQ % 32].autovector = (uintptr_t)&USB_GEN_vect; \r
- }\r
- \r
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;\r
static inline void USB_INT_Enable(const uint8_t Interrupt)\r
{ \r