Commit b763c3f3 authored by Dean Camera's avatar Dean Camera
Browse files

Porting updates for the UC3B architecture - get UC3B partially enumerating...

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.
parent 33a81bff
...@@ -133,6 +133,15 @@ ...@@ -133,6 +133,15 @@
* \param[in] Func Name of the function which the given function name should alias. * \param[in] Func Name of the function which the given function name should alias.
*/ */
#define ATTR_ALIAS(Func) __attribute__ ((alias( #Func ))) #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 #endif
/** @} */ /** @} */
......
...@@ -87,15 +87,50 @@ ...@@ -87,15 +87,50 @@
#include <util/delay.h> #include <util/delay.h>
typedef uint8_t uint_reg_t; 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) #elif (ARCH == ARCH_UC3B)
#include <avr32/io.h> #include <avr32/io.h>
typedef uint32_t uint_reg_t; typedef uint32_t uint_reg_t;
// TODO // 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 EEMEM
#define PROGMEM const #define PROGMEM const
#define ISR(Name) void Name (void) __attribute__((__interrupt__)); void Name (void)
#define ATOMIC_BLOCK(x) if (1) #define ATOMIC_BLOCK(x) if (1)
#define ATOMIC_RESTORESTATE #define ATOMIC_RESTORESTATE
#define pgm_read_byte(x) *x #define pgm_read_byte(x) *x
...@@ -105,10 +140,6 @@ ...@@ -105,10 +140,6 @@
#define _delay_ms(x) #define _delay_ms(x)
#define memcmp_P(...) memcmp(__VA_ARGS__) #define memcmp_P(...) memcmp(__VA_ARGS__)
#define memcpy_P(...) memcpy(__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 #endif
/* Public Interface - May be used in end-application: */ /* Public Interface - May be used in end-application: */
......
...@@ -59,8 +59,6 @@ void USB_Init( ...@@ -59,8 +59,6 @@ void USB_Init(
#if !defined(USE_STATIC_OPTIONS) #if !defined(USE_STATIC_OPTIONS)
USB_Options = Options; USB_Options = Options;
#endif #endif
USB_INT_RegisterHandlers();
if (!(USB_Options & USB_OPT_REG_DISABLED)) if (!(USB_Options & USB_OPT_REG_DISABLED))
USB_REG_On(); USB_REG_On();
......
...@@ -84,11 +84,6 @@ ...@@ -84,11 +84,6 @@
}; };
/* Inline Functions: */ /* 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) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Enable(const uint8_t Interrupt) static inline void USB_INT_Enable(const uint8_t Interrupt)
{ {
......
...@@ -48,10 +48,11 @@ bool USB_RemoteWakeupEnabled; ...@@ -48,10 +48,11 @@ bool USB_RemoteWakeupEnabled;
void USB_Device_ProcessControlRequest(void) void USB_Device_ProcessControlRequest(void)
{ {
uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest; USB_ControlRequest.bmRequestType = Endpoint_Read_Byte();
USB_ControlRequest.bRequest = Endpoint_Read_Byte();
for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++) USB_ControlRequest.wValue = le16_to_cpu(Endpoint_Read_Word_LE());
*(RequestHeader++) = Endpoint_Read_Byte(); USB_ControlRequest.wIndex = le16_to_cpu(Endpoint_Read_Word_LE());
USB_ControlRequest.wLength = le16_to_cpu(Endpoint_Read_Word_LE());
EVENT_USB_Device_ControlRequest(); EVENT_USB_Device_ControlRequest();
......
...@@ -88,13 +88,13 @@ ...@@ -88,13 +88,13 @@
* Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the * Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the
* standard device descriptor. * 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))) ((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x)))
/** String language ID for the English language. Should be used in \ref USB_Descriptor_String_t descriptors /** 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. * 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 */ /** \name Endpoint Address Direction Masks */
//@{ //@{
......
...@@ -39,17 +39,18 @@ ...@@ -39,17 +39,18 @@
uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
#endif #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, bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
const uint32_t UECFGXData) const uint32_t UECFG0Data)
{ {
Endpoint_SelectEndpoint(Number); Endpoint_SelectEndpoint(Number);
Endpoint_EnableEndpoint(); Endpoint_EnableEndpoint();
((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0; (&AVR32_USBB.uecfg0)[Number] = 0;
((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = UECFGXData; (&AVR32_USBB.uecfg0)[Number] = UECFG0Data;
USB_EndpointFIFOPos[Number] = &AVR32_USBB_SLAVE[Number * 0x10000];
return Endpoint_IsConfigured(); return Endpoint_IsConfigured();
} }
...@@ -59,8 +60,9 @@ void Endpoint_ClearEndpoints(void) ...@@ -59,8 +60,9 @@ void Endpoint_ClearEndpoints(void)
for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++) for (uint8_t EPNum = 0; EPNum < ENDPOINT_TOTAL_ENDPOINTS; EPNum++)
{ {
Endpoint_SelectEndpoint(EPNum); Endpoint_SelectEndpoint(EPNum);
((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0; (&AVR32_USBB.uecfg0)[EPNum] = 0;
((uint32_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint] = 0xFFFFFFFF; (&AVR32_USBB.uecon0clr)[EPNum] = 0xFFFFFFFF;
USB_EndpointFIFOPos[EPNum] = &AVR32_USBB_SLAVE[EPNum * 0x10000];
Endpoint_DisableEndpoint(); Endpoint_DisableEndpoint();
} }
} }
......
...@@ -131,7 +131,8 @@ ...@@ -131,7 +131,8 @@
const uint32_t UECFGXData); const uint32_t UECFGXData);
/* External Variables: */ /* External Variables: */
extern uint8_t USB_SelectedEndpoint; extern volatile uint8_t USB_SelectedEndpoint;
extern volatile void* USB_EndpointFIFOPos[];
#endif #endif
/* Public Interface - May be used in end-application: */ /* Public Interface - May be used in end-application: */
...@@ -296,7 +297,7 @@ ...@@ -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) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Endpoint_BytesInEndpoint(void) 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 /** Get the endpoint address of the currently selected endpoint. This is typically used to save
...@@ -336,6 +337,7 @@ ...@@ -336,6 +337,7 @@
{ {
AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_MASK << EndpointNumber); AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_MASK << EndpointNumber);
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 /** Enables the currently selected endpoint so that data can be sent and received through it to
...@@ -378,7 +380,7 @@ ...@@ -378,7 +380,7 @@
*/ */
static inline uint8_t Endpoint_GetBusyBanks(void) 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 /** Aborts all pending IN transactions on the currently selected endpoint, once the bank
...@@ -392,9 +394,11 @@ ...@@ -392,9 +394,11 @@
{ {
while (Endpoint_GetBusyBanks() != 0) while (Endpoint_GetBusyBanks() != 0)
{ {
((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].killbk = true; (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].killbks = true;
while (((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0)[USB_SelectedEndpoint].killbk); 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 /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint
...@@ -411,7 +415,7 @@ ...@@ -411,7 +415,7 @@
static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsReadWriteAllowed(void) 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. /** Determines if the currently selected endpoint is configured.
...@@ -421,7 +425,7 @@ ...@@ -421,7 +425,7 @@
static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsConfigured(void) 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 /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
...@@ -461,7 +465,7 @@ ...@@ -461,7 +465,7 @@
static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsINReady(void) 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. /** Determines if the selected OUT endpoint has received new packet from the host.
...@@ -473,7 +477,7 @@ ...@@ -473,7 +477,7 @@
static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsOUTReceived(void) 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. /** Determines if the current CONTROL type endpoint has received a SETUP packet.
...@@ -485,7 +489,7 @@ ...@@ -485,7 +489,7 @@
static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsSETUPReceived(void) 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 /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
...@@ -498,7 +502,8 @@ ...@@ -498,7 +502,8 @@
static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearSETUP(void) 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 /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
...@@ -509,8 +514,9 @@ ...@@ -509,8 +514,9 @@
static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearIN(void) static inline void Endpoint_ClearIN(void)
{ {
((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].txinic = true; (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].txinic = true;
((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = 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 /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
...@@ -521,8 +527,9 @@ ...@@ -521,8 +527,9 @@
static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearOUT(void) static inline void Endpoint_ClearOUT(void)
{ {
((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true; (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true;
((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = 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 /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
...@@ -539,7 +546,7 @@ ...@@ -539,7 +546,7 @@
static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_StallTransaction(void) 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. /** Clears the STALL condition on the currently selected endpoint.
...@@ -549,7 +556,7 @@ ...@@ -549,7 +556,7 @@
static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ClearStall(void) 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. /** Determines if the currently selected endpoint is stalled, false otherwise.
...@@ -561,24 +568,24 @@ ...@@ -561,24 +568,24 @@
static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsStalled(void) 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. */ /** Resets the data toggle of the currently selected endpoint. */
static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ResetDataToggle(void) 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. /** Determines the currently selected endpoint's direction.
* *
* \return The currently selected endpoint's direction, as a \c ENDPOINT_DIR_* mask. * \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 uint32_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)
{ {
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. /** Sets the direction of the currently selected endpoint.
...@@ -588,7 +595,7 @@ ...@@ -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) ATTR_ALWAYS_INLINE;
static inline void Endpoint_SetEndpointDirection(const uint32_t DirectionMask) 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. /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
...@@ -600,7 +607,7 @@ ...@@ -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) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_Read_Byte(void) 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. /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
...@@ -612,7 +619,7 @@ ...@@ -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) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_Byte(const uint8_t Byte) 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. /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
...@@ -624,7 +631,7 @@ ...@@ -624,7 +631,7 @@
{ {
uint8_t Dummy; 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 /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT
...@@ -637,16 +644,10 @@ ...@@ -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) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Endpoint_Read_Word_LE(void) static inline uint16_t Endpoint_Read_Word_LE(void)
{ {
union uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);
{ uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);
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);
return Data.Word; return ((Byte1 << 8) | Byte0);
} }
/** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
...@@ -659,16 +660,10 @@ ...@@ -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) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint16_t Endpoint_Read_Word_BE(void) static inline uint16_t Endpoint_Read_Word_BE(void)
{ {
union uint16_t Byte0 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);
{ uint16_t Byte1 = *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++);
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);
return Data.Word; return ((Byte1 << 8) | Byte0);
} }
/** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
...@@ -681,8 +676,8 @@ ...@@ -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) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_Word_LE(const uint16_t Word) static inline void Endpoint_Write_Word_LE(const uint16_t Word)
{ {
*((uint8_t*)AVR32_USBB_EP_DATA) = (Word & 0xFF); *(((volatile uint8_t** volatile)USB_EndpointFIFOPos)[USB_SelectedEndpoint]++) = (Word & 0xFF);
*((uint8_t*)AVR32_USBB_EP_DATA) = (Word >> 8); *(((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 /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
...@@ -695,8 +690,8 @@ ...@@ -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) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_Word_BE(const uint16_t Word) static inline void Endpoint_Write_Word_BE(const uint16_t Word)
{ {