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 @@
* \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
/** @} */
......
......@@ -87,15 +87,50 @@
#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
......@@ -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: */
......
......@@ -60,8 +60,6 @@ void USB_Init(
USB_Options = Options;
#endif
USB_INT_RegisterHandlers();
if (!(USB_Options & USB_OPT_REG_DISABLED))
USB_REG_On();
else
......
......@@ -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)
{
......
......@@ -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();
......
......@@ -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 */
//@{
......
......@@ -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();
}
}
......
......@@ -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: */
......
......@@ -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();
}
}
......
......@@ -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_*