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

Removed Pipe_ClearErrorFlags(), pipe error flags are now automatically cleared...

Removed Pipe_ClearErrorFlags(), pipe error flags are now automatically cleared when Pipe_ClearError() is called.

More UC3B architecture porting.
parent 66c38cd9
This diff is collapsed.
...@@ -410,10 +410,11 @@ ...@@ -410,10 +410,11 @@
return ((UPCONX & (1 << PFREEZE)) ? true : false); return ((UPCONX & (1 << PFREEZE)) ? true : false);
} }
/** Clears the master pipe error flag. */ /** Clears the error flags for the currently selected pipe. */
static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE; static inline void Pipe_ClearError(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearError(void) static inline void Pipe_ClearError(void)
{ {
UPERRX = 0;
UPINTX &= ~(1 << PERRI); UPINTX &= ~(1 << PERRI);
} }
...@@ -430,15 +431,6 @@ ...@@ -430,15 +431,6 @@
return ((UPINTX & (1 << PERRI)) ? true : false); return ((UPINTX & (1 << PERRI)) ? true : false);
} }
/** Clears all the currently selected pipe's hardware error flags, but does not clear the master error
* flag for the pipe.
*/
static inline void Pipe_ClearErrorFlags(void) ATTR_ALWAYS_INLINE;
static inline void Pipe_ClearErrorFlags(void)
{
UPERRX = 0;
}
/** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This /** Gets a mask of the hardware error flags which have occurred on the currently selected pipe. This
* value can then be masked against the \c PIPE_ERRORFLAG_* masks to determine what error has occurred. * value can then be masked against the \c PIPE_ERRORFLAG_* masks to determine what error has occurred.
* *
......
...@@ -38,11 +38,11 @@ ...@@ -38,11 +38,11 @@
uint8_t USB_Host_SendControlRequest(void* const BufferPtr) uint8_t USB_Host_SendControlRequest(void* const BufferPtr)
{ {
uint8_t* HeaderStream = (uint8_t*)&USB_ControlRequest; uint8_t* HeaderStream = (uint8_t*)&USB_ControlRequest;
uint8_t* DataStream = (uint8_t*)BufferPtr; uint8_t* DataStream = (uint8_t*)BufferPtr;
bool BusSuspended = USB_Host_IsBusSuspended(); bool BusSuspended = USB_Host_IsBusSuspended();
uint8_t ReturnStatus = HOST_SENDCONTROL_Successful; uint8_t ReturnStatus = HOST_SENDCONTROL_Successful;
uint16_t DataLen = USB_ControlRequest.wLength; uint16_t DataLen = USB_ControlRequest.wLength;
USB_Host_ResumeBus(); USB_Host_ResumeBus();
...@@ -50,7 +50,7 @@ uint8_t USB_Host_SendControlRequest(void* const BufferPtr) ...@@ -50,7 +50,7 @@ uint8_t USB_Host_SendControlRequest(void* const BufferPtr)
goto End_Of_Control_Send; goto End_Of_Control_Send;
Pipe_SetPipeToken(PIPE_TOKEN_SETUP); Pipe_SetPipeToken(PIPE_TOKEN_SETUP);
Pipe_ClearErrorFlags(); Pipe_ClearError();
Pipe_Unfreeze(); Pipe_Unfreeze();
......
...@@ -55,8 +55,6 @@ ...@@ -55,8 +55,6 @@
#if (ARCH == ARCH_AVR8) #if (ARCH == ARCH_AVR8)
#include "AVR8/OTG_AVR8.h" #include "AVR8/OTG_AVR8.h"
#elif (ARCH == ARCH_UC3B)
#include "UC3B/OTG_UC3B.h"
#endif #endif
/* Preprocessor Checks: */ /* Preprocessor Checks: */
......
...@@ -119,9 +119,9 @@ ...@@ -119,9 +119,9 @@
#endif #endif
/* Inline Functions: */ /* Inline Functions: */
static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST static inline uint32_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST
ATTR_ALWAYS_INLINE; ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) static inline uint32_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes)
{ {
uint8_t MaskVal = 0; uint8_t MaskVal = 0;
uint16_t CheckBytes = 8; uint16_t CheckBytes = 8;
...@@ -151,12 +151,12 @@ ...@@ -151,12 +151,12 @@
/** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
* should be initialized in the OUT direction - i.e. data flows from host to device. * should be initialized in the OUT direction - i.e. data flows from host to device.
*/ */
#define ENDPOINT_DIR_OUT (0 << AVR32_USBB_UECFG0_EPDIR_OFFSET) #define ENDPOINT_DIR_OUT AVR32_USBB_UECFG0_EPDIR_OUT
/** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
* should be initialized in the IN direction - i.e. data flows from device to host. * should be initialized in the IN direction - i.e. data flows from device to host.
*/ */
#define ENDPOINT_DIR_IN (1 << AVR32_USBB_UECFG0_EPDIR_OFFSET) #define ENDPOINT_DIR_IN AVR32_USBB_UECFG0_EPDIR_IN
//@} //@}
/** \name Endpoint Bank Mode Masks */ /** \name Endpoint Bank Mode Masks */
...@@ -166,21 +166,21 @@ ...@@ -166,21 +166,21 @@
* in slower transfers as only one USB device (the AVR or the host) can access the endpoint's * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
* bank at the one time. * bank at the one time.
*/ */
#define ENDPOINT_BANK_SINGLE (0 << AVR32_USBB_UECFG0_EPBK0_OFFSET) #define ENDPOINT_BANK_SINGLE AVR32_USBB_UECFG0_EPBK0_SINGLE
/** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
* that the endpoint should have two banks, which requires more USB FIFO memory but results * that the endpoint should have two banks, which requires more USB FIFO memory but results
* in faster transfers as one USB device (the AVR or the host) can access one bank while the other * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
* accesses the second bank. * accesses the second bank.
*/ */
#define ENDPOINT_BANK_DOUBLE (1 << AVR32_USBB_UECFG0_EPBK0_OFFSET) #define ENDPOINT_BANK_DOUBLE AVR32_USBB_UECFG0_EPBK0_DOUBLE
/** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
* that the endpoint should have three banks, which requires more USB FIFO memory but results * that the endpoint should have three banks, which requires more USB FIFO memory but results
* in faster transfers as one USB device (the AVR or the host) can access one bank while the other * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
* accesses the remaining banks. * accesses the remaining banks.
*/ */
#define ENDPOINT_BANK_TRIPLE (2 << AVR32_USBB_UECFG0_EPBK0_OFFSET) #define ENDPOINT_BANK_TRIPLE AVR32_USBB_UECFG0_TRIPLE
//@} //@}
/** Endpoint address for the default control endpoint, which always resides in address 0. This is /** Endpoint address for the default control endpoint, which always resides in address 0. This is
...@@ -309,9 +309,10 @@ ...@@ -309,9 +309,10 @@
const uint16_t Size, const uint16_t Size,
const uint8_t Banks) const uint8_t Banks)
{ {
return Endpoint_ConfigureEndpoint_Prv(Number, ((Type << AVR32_USBB_EPTYPE_OFFSET) | AVR32_USBB_ALLOC | return Endpoint_ConfigureEndpoint_Prv(Number, (AVR32_USBB_ALLOC_MASK |
(Direction << AVR32_USBB_EPDIR_OFFSET) | ((uint32_t)Type << AVR32_USBB_EPTYPE_OFFSET) |
(Banks << AVR32_USBB_EPBK_OFFSET) | ((uint32_t)Direction << AVR32_USBB_EPDIR_OFFSET) |
((uint32_t)Banks << AVR32_USBB_EPBK_OFFSET) |
Endpoint_BytesToEPSizeMask(Size))); Endpoint_BytesToEPSizeMask(Size)));
} }
...@@ -365,8 +366,8 @@ ...@@ -365,8 +366,8 @@
static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE; static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber) ATTR_ALWAYS_INLINE;
static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber) static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber)
{ {
AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_OFFSET << EndpointNumber); AVR32_USBB.uerst |= (AVR32_USBB_EPRST0_MASK << EndpointNumber);
AVR32_USBB.uerst &= ~(AVR32_USBB_EPRST0_OFFSET << EndpointNumber); AVR32_USBB.uerst &= ~(AVR32_USBB_EPRST0_MASK << EndpointNumber);
} }
/** 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
...@@ -377,7 +378,7 @@ ...@@ -377,7 +378,7 @@
static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_EnableEndpoint(void) static inline void Endpoint_EnableEndpoint(void)
{ {
AVR32_USBB.uerst |= (AVR32_USBB_EPEN0 << USB_SelectedEndpoint); AVR32_USBB.uerst |= (AVR32_USBB_EPEN0_MASK << USB_SelectedEndpoint);
} }
/** Disables the currently selected endpoint so that data cannot be sent and received through it /** Disables the currently selected endpoint so that data cannot be sent and received through it
...@@ -386,7 +387,7 @@ ...@@ -386,7 +387,7 @@
static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_DisableEndpoint(void) static inline void Endpoint_DisableEndpoint(void)
{ {
AVR32_USBB.uerst &= ~(AVR32_USBB_EPEN0_OFFSET << USB_SelectedEndpoint); AVR32_USBB.uerst &= ~(AVR32_USBB_EPEN0_MASK << USB_SelectedEndpoint);
} }
/** Determines if the currently selected endpoint is enabled, but not necessarily configured. /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
...@@ -396,7 +397,7 @@ ...@@ -396,7 +397,7 @@
static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_IsEnabled(void) static inline bool Endpoint_IsEnabled(void)
{ {
return ((AVR32_USBB.uerst & (AVR32_USBB_EPEN0_OFFSET << USB_SelectedEndpoint)) ? true : false); return ((AVR32_USBB.uerst & (AVR32_USBB_EPEN0_MASK << USB_SelectedEndpoint)) ? true : false);
} }
/** Retrieves the number of busy banks in the currently selected endpoint, which have been queued for /** Retrieves the number of busy banks in the currently selected endpoint, which have been queued for
...@@ -464,10 +465,10 @@ ...@@ -464,10 +465,10 @@
static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_GetEndpointInterrupts(void) static inline uint8_t Endpoint_GetEndpointInterrupts(void)
{ {
return ((AVR32_USBB.udint & (AVR32_USBB_EP6INTES_MASK | AVR32_USBB_EP5INTES_MASK | return ((AVR32_USBB.udint & (AVR32_USBB_EP6INT_MASK | AVR32_USBB_EP5INT_MASK |
AVR32_USBB_EP4INTES_MASK | AVR32_USBB_EP3INTES_MASK | AVR32_USBB_EP4INT_MASK | AVR32_USBB_EP3INT_MASK |
AVR32_USBB_EP2INTES_MASK | AVR32_USBB_EP1INTES_MASK | AVR32_USBB_EP2INT_MASK | AVR32_USBB_EP1INT_MASK |
AVR32_USBB_EP0INTES_MASK)) >> AVR32_USBB_EP0INT_OFFSET); AVR32_USBB_EP0INT_MASK)) >> AVR32_USBB_EP0INT_OFFSET);
} }
/** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
...@@ -480,7 +481,7 @@ ...@@ -480,7 +481,7 @@
static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber) static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber)
{ {
return ((Endpoint_GetEndpointInterrupts() & (1 << EndpointNumber)) ? true : false); return ((Endpoint_GetEndpointInterrupts() & (AVR32_USBB_EP0INT_MASK << EndpointNumber)) ? true : false);
} }
/** Determines if the selected IN endpoint is ready for a new packet to be sent to the host. /** Determines if the selected IN endpoint is ready for a new packet to be sent to the host.
...@@ -529,7 +530,7 @@ ...@@ -529,7 +530,7 @@
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_uesta0_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxstpi = true; ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxstpic = true;
} }
/** 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
...@@ -540,8 +541,8 @@ ...@@ -540,8 +541,8 @@
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_uesta0_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].txini = true; ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].txinic = true;
((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifocon = true; ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;
} }
/** 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
...@@ -552,8 +553,8 @@ ...@@ -552,8 +553,8 @@
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_uesta0_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxouti = true; ((avr32_usbb_uesta0clr_t*)AVR32_USBB_UESTA0CLR)[USB_SelectedEndpoint].rxoutic = true;
((avr32_usbb_uecon0_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifocon = true; ((avr32_usbb_uecon0clr_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].fifoconc = true;
} }
/** 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
...@@ -570,7 +571,7 @@ ...@@ -570,7 +571,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_uecon0_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].stallrq = true; ((avr32_usbb_uecon0set_t*)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.
...@@ -580,7 +581,7 @@ ...@@ -580,7 +581,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_uecon0_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint].stallrq = true; ((avr32_usbb_uecon0clr_t*)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.
...@@ -599,7 +600,7 @@ ...@@ -599,7 +600,7 @@
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_uecon0_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].rstdt = true; ((avr32_usbb_uecon0set_t*)AVR32_USBB_UECON0SET)[USB_SelectedEndpoint].rstdts = true;
} }
/** Determines the currently selected endpoint's direction. /** Determines the currently selected endpoint's direction.
......
...@@ -245,7 +245,7 @@ ...@@ -245,7 +245,7 @@
*/ */
static inline uint16_t USB_Host_GetFrameNumber(void) static inline uint16_t USB_Host_GetFrameNumber(void)
{ {
return UHFNUM; return AVR32_USBB_UHFNUM;
} }
#if !defined(NO_SOF_EVENTS) #if !defined(NO_SOF_EVENTS)
...@@ -282,7 +282,7 @@ ...@@ -282,7 +282,7 @@
static inline void USB_Host_ResetBus(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_ResetBus(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ResetBus(void) static inline void USB_Host_ResetBus(void)
{ {
UHCON |= (1 << RESET); AVR32_USBB_UHCON.reset = true;
} }
/** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has /** Determines if a previously issued bus reset (via the \ref USB_Host_ResetBus() macro) has
...@@ -293,7 +293,7 @@ ...@@ -293,7 +293,7 @@
static inline bool USB_Host_IsBusResetComplete(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool USB_Host_IsBusResetComplete(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsBusResetComplete(void) static inline bool USB_Host_IsBusResetComplete(void)
{ {
return ((UHCON & (1 << RESET)) ? false : true); return AVR32_USBB_UHCON.reset;
} }
/** Resumes USB communications with an attached and enumerated device, by resuming the transmission /** Resumes USB communications with an attached and enumerated device, by resuming the transmission
...@@ -303,7 +303,7 @@ ...@@ -303,7 +303,7 @@
static inline void USB_Host_ResumeBus(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_ResumeBus(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ResumeBus(void) static inline void USB_Host_ResumeBus(void)
{ {
UHCON |= (1 << SOFEN); AVR32_USBB_UHCON.sofe = true;
} }
/** Suspends the USB bus, preventing any communications from occurring between the host and attached /** Suspends the USB bus, preventing any communications from occurring between the host and attached
...@@ -313,7 +313,7 @@ ...@@ -313,7 +313,7 @@
static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_SuspendBus(void) static inline void USB_Host_SuspendBus(void)
{ {
UHCON &= ~(1 << SOFEN); AVR32_USBB_UHCON.sofe = false;
} }
/** Determines if the USB bus has been suspended via the use of the \ref USB_Host_SuspendBus() macro, /** Determines if the USB bus has been suspended via the use of the \ref USB_Host_SuspendBus() macro,
...@@ -325,7 +325,7 @@ ...@@ -325,7 +325,7 @@
static inline bool USB_Host_IsBusSuspended(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool USB_Host_IsBusSuspended(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsBusSuspended(void) static inline bool USB_Host_IsBusSuspended(void)
{ {
return ((UHCON & (1 << SOFEN)) ? false : true); return AVR32_USBB_UHCON.sofe;
} }
/** Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or /** Determines if the attached device is currently enumerated in Full Speed mode (12Mb/s), or
...@@ -336,7 +336,7 @@ ...@@ -336,7 +336,7 @@
static inline bool USB_Host_IsDeviceFullSpeed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool USB_Host_IsDeviceFullSpeed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsDeviceFullSpeed(void) static inline bool USB_Host_IsDeviceFullSpeed(void)
{ {
return ((USBSTA & (1 << SPEED)) ? true : false); return (AVR32_USBB_USBSTA.speed == AVR32_USBB_SPEED_FULL);
} }
/** Determines if the attached device is currently issuing a Remote Wakeup request, requesting /** Determines if the attached device is currently issuing a Remote Wakeup request, requesting
...@@ -347,14 +347,14 @@ ...@@ -347,14 +347,14 @@
static inline bool USB_Host_IsRemoteWakeupSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool USB_Host_IsRemoteWakeupSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsRemoteWakeupSent(void) static inline bool USB_Host_IsRemoteWakeupSent(void)
{ {
return ((UHINT & (1 << RXRSMI)) ? true : false); return AVR32_USBB_UHINT.rxrsmi;
} }
/** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */ /** Clears the flag indicating that a Remote Wakeup request has been issued by an attached device. */
static inline void USB_Host_ClearRemoteWakeupSent(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_ClearRemoteWakeupSent(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ClearRemoteWakeupSent(void) static inline void USB_Host_ClearRemoteWakeupSent(void)
{ {
UHINT &= ~(1 << RXRSMI); AVR32_USBB_UHINTCLR.rxrsmic = true;
} }
/** Accepts a Remote Wakeup request from an attached device. This must be issued in response to /** Accepts a Remote Wakeup request from an attached device. This must be issued in response to
...@@ -364,7 +364,7 @@ ...@@ -364,7 +364,7 @@
static inline void USB_Host_ResumeFromWakeupRequest(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_ResumeFromWakeupRequest(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_ResumeFromWakeupRequest(void) static inline void USB_Host_ResumeFromWakeupRequest(void)
{ {
UHCON |= (1 << RESUME); AVR32_USBB_UHCON.resume = true;
} }
/** Determines if a resume from Remote Wakeup request is currently being sent to an attached /** Determines if a resume from Remote Wakeup request is currently being sent to an attached
...@@ -375,7 +375,7 @@ ...@@ -375,7 +375,7 @@
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE; static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_Host_IsResumeFromWakeupRequestSent(void) static inline bool USB_Host_IsResumeFromWakeupRequestSent(void)
{ {
return ((UHCON & (1 << RESUME)) ? false : true); return AVR32_USBB_UHCON.resume;
} }
/* Function Prototypes: */ /* Function Prototypes: */
...@@ -438,59 +438,63 @@ ...@@ -438,59 +438,63 @@
static inline void USB_Host_HostMode_On(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_HostMode_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_HostMode_On(void) static inline void USB_Host_HostMode_On(void)
{ {
USBCON |= (1 << HOST); // Not required for UC3B
} }
static inline void USB_Host_HostMode_Off(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_HostMode_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_HostMode_Off(void) static inline void USB_Host_HostMode_Off(void)
{ {
USBCON &= ~(1 << HOST); // Not required for UC3B
} }
static inline void USB_Host_VBUS_Auto_Enable(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Auto_Enable(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Auto_Enable(void) static inline void USB_Host_VBUS_Auto_Enable(void)
{ {
OTGCON &= ~(1 << VBUSHWC); AVR32_USBB_USBCON.vbushwc = false;
UHWCON |= (1 << UVCONE);
} }
static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Manual_Enable(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Manual_Enable(void) static inline void USB_Host_VBUS_Manual_Enable(void)
{ {
OTGCON |= (1 << VBUSHWC); AVR32_USBB_USBCON.vbushwc = true;
UHWCON &= ~(1 << UVCONE);
// TODO: Manual VBUS pin output setup
DDRE |= (1 << 7);
} }
static inline void USB_Host_VBUS_Auto_On(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Auto_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Auto_On(void) static inline void USB_Host_VBUS_Auto_On(void)
{ {
OTGCON |= (1 << VBUSREQ); AVR32_USBB_USBSTASET.vbusreqs = true;
} }
static inline void USB_Host_VBUS_Manual_On(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Manual_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Manual_On(void) static inline void USB_Host_VBUS_Manual_On(void)
{ {
PORTE |= (1 << 7); // TODO: Manual VBUS pin output on
} }
static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Auto_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Auto_Off(void) static inline void USB_Host_VBUS_Auto_Off(void)
{ {
OTGCON |= (1 << VBUSRQC); AVR32_USBB_USBSTACLR.vbusreqc = true;
} }
static inline void USB_Host_VBUS_Manual_Off(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_VBUS_Manual_Off(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_VBUS_Manual_Off(void) static inline void USB_Host_VBUS_Manual_Off(void)
{ {
PORTE &= ~(1 << 7); // TODO: Manual VBUS pin output off
} }
static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE; static inline void USB_Host_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
static inline void USB_Host_SetDeviceAddress(const uint8_t Address) static inline void USB_Host_SetDeviceAddress(const uint8_t Address)
{ {
UHADDR = (Address & 0x7F);