More AVR32 UC3B architecture ports - USB device mode applications can now be sucessfully compiled, although they will be currently non-functional.

pull/1469/head
Dean Camera 14 years ago
parent cf2411435c
commit f3f481183a

File diff suppressed because one or more lines are too long

@ -92,6 +92,18 @@
typedef uint32_t uint_reg_t; typedef uint32_t uint_reg_t;
#define EEMEM
#define PROGMEM const
#define ISR(Name) void Name (void)
#define ATOMIC_BLOCK(x) if (1)
#define ATOMIC_RESTORESTATE
#define pgm_read_byte(x) *x
#define eeprom_read_byte(x) *x
#define eeprom_update_byte(x, y) *x = y
#define eeprom_write_byte(x, y) *x = y
#define memcmp_P(...) memcmp(__VA_ARGS__)
#define memcpy_P(...) memcpy(__VA_ARGS__)
#warning The UC3B architecture support is currently experimental and incomplete! #warning The UC3B architecture support is currently experimental and incomplete!
#endif #endif

@ -37,11 +37,6 @@
#define __INCLUDE_FROM_CDC_DEVICE_C #define __INCLUDE_FROM_CDC_DEVICE_C
#include "CDC.h" #include "CDC.h"
void CDC_Device_Event_Stub(void)
{
}
void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{ {
if (!(Endpoint_IsSETUPReceived())) if (!(Endpoint_IsSETUPReceived()))
@ -293,6 +288,7 @@ void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDC
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
#if defined(FDEV_SETUP_STREAM)
void CDC_Device_CreateStream(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, void CDC_Device_CreateStream(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
FILE* const Stream) FILE* const Stream)
{ {
@ -338,6 +334,12 @@ static int CDC_Device_getchar_Blocking(FILE* Stream)
return ReceivedByte; return ReceivedByte;
} }
#endif
void CDC_Device_Event_Stub(void)
{
}
#endif #endif

@ -305,6 +305,9 @@
* *
* \note The created stream can be given as stdout if desired to direct the standard output from all <stdio.h> functions * \note The created stream can be given as stdout if desired to direct the standard output from all <stdio.h> functions
* to the given CDC interface. * to the given CDC interface.
* \n\n
*
* \note This function is not available on all microcontroller architectures.
* *
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state. * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
@ -315,6 +318,8 @@
/** Identical to \ref CDC_Device_CreateStream(), except that reads are blocking until the calling stream function terminates /** Identical to \ref CDC_Device_CreateStream(), except that reads are blocking until the calling stream function terminates
* the transfer. While blocking, the USB and CDC service tasks are called repeatedly to maintain USB communications. * the transfer. While blocking, the USB and CDC service tasks are called repeatedly to maintain USB communications.
* *
* \note This function is not available on all microcontroller architectures.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state. * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
*/ */
@ -325,10 +330,12 @@
#if !defined(__DOXYGEN__) #if !defined(__DOXYGEN__)
/* Function Prototypes: */ /* Function Prototypes: */
#if defined(__INCLUDE_FROM_CDC_DEVICE_C) #if defined(__INCLUDE_FROM_CDC_DEVICE_C)
#if defined(FDEV_SETUP_STREAM)
static int CDC_Device_putchar(char c, static int CDC_Device_putchar(char c,
FILE* Stream) ATTR_NON_NULL_PTR_ARG(2); FILE* Stream) ATTR_NON_NULL_PTR_ARG(2);
static int CDC_Device_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); static int CDC_Device_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
static int CDC_Device_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); static int CDC_Device_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
#endif
void CDC_Device_Event_Stub(void) ATTR_CONST; void CDC_Device_Event_Stub(void) ATTR_CONST;
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)

@ -456,6 +456,7 @@ uint8_t CDC_Host_Flush(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo)
return PIPE_READYWAIT_NoError; return PIPE_READYWAIT_NoError;
} }
#if defined(FDEV_SETUP_STREAM)
void CDC_Host_CreateStream(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo, void CDC_Host_CreateStream(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo,
FILE* const Stream) FILE* const Stream)
{ {
@ -501,6 +502,7 @@ static int CDC_Host_getchar_Blocking(FILE* Stream)
return ReceivedByte; return ReceivedByte;
} }
#endif
void CDC_Host_Event_Stub(void) void CDC_Host_Event_Stub(void)
{ {

@ -295,6 +295,9 @@
* *
* \note The created stream can be given as stdout if desired to direct the standard output from all \c <stdio.h> functions * \note The created stream can be given as stdout if desired to direct the standard output from all \c <stdio.h> functions
* to the given CDC interface. * to the given CDC interface.
* \n\n
*
* \note This function is not available on all microcontroller architectures.
* *
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state. * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
@ -305,6 +308,8 @@
/** Identical to \ref CDC_Host_CreateStream(), except that reads are blocking until the calling stream function terminates /** Identical to \ref CDC_Host_CreateStream(), except that reads are blocking until the calling stream function terminates
* the transfer. While blocking, the USB and CDC service tasks are called repeatedly to maintain USB communications. * the transfer. While blocking, the USB and CDC service tasks are called repeatedly to maintain USB communications.
* *
* \note This function is not available on all microcontroller architectures.
*
* \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state. * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state.
* \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed. * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed.
*/ */
@ -325,10 +330,12 @@
#if !defined(__DOXYGEN__) #if !defined(__DOXYGEN__)
/* Function Prototypes: */ /* Function Prototypes: */
#if defined(__INCLUDE_FROM_CDC_HOST_C) #if defined(__INCLUDE_FROM_CDC_HOST_C)
#if defined(FDEV_SETUP_STREAM)
static int CDC_Host_putchar(char c, static int CDC_Host_putchar(char c,
FILE* Stream) ATTR_NON_NULL_PTR_ARG(2); FILE* Stream) ATTR_NON_NULL_PTR_ARG(2);
static int CDC_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); static int CDC_Host_getchar(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
static int CDC_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1); static int CDC_Host_getchar_Blocking(FILE* Stream) ATTR_NON_NULL_PTR_ARG(1);
#endif
void CDC_Host_Event_Stub(void) ATTR_CONST; void CDC_Host_Event_Stub(void) ATTR_CONST;
void EVENT_CDC_Host_ControLineStateChanged(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo) void EVENT_CDC_Host_ControLineStateChanged(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo)

@ -96,7 +96,7 @@
* a unique serial number internally, and setting the device descriptors serial number string index to this value * a unique serial number internally, and setting the device descriptors serial number string index to this value
* will cause it to use the internal serial number. * will cause it to use the internal serial number.
* *
* On unsupported devices, this will evaluate to NO_DESCRIPTOR and so will force the host to create a pseudo-serial * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
* number for the device. * number for the device.
*/ */
#define USE_INTERNAL_SERIAL 0xDC #define USE_INTERNAL_SERIAL 0xDC

@ -37,16 +37,10 @@
void USB_Device_SendRemoteWakeup(void) void USB_Device_SendRemoteWakeup(void)
{ {
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
USB_PLL_On();
while (!(USB_PLL_IsReady()));
}
USB_CLK_Unfreeze(); USB_CLK_Unfreeze();
AVR32_USBB.UDCON.rmwakeup = true; AVR32_USBB.UDCON.rmwkup = true;
while (AVR32_USBB.UDCON.rmwakeup); while (AVR32_USBB.UDCON.rmwkup);
} }
#endif #endif

@ -82,23 +82,16 @@
#define USB_DEVICE_OPT_FULLSPEED (0 << 0) #define USB_DEVICE_OPT_FULLSPEED (0 << 0)
//@} //@}
#if (!defined(NO_INTERNAL_SERIAL) && \ /** String descriptor index for the device's unique serial number string descriptor within the device.
(defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__) || \ * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || \ * number allocations) to a device regardless of the port it is plugged in to on the host. Some USB AVRs contain
defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__))) * a unique serial number internally, and setting the device descriptors serial number string index to this value
/** String descriptor index for the device's unique serial number string descriptor within the device. * will cause it to use the internal serial number.
* This unique serial number is used by the host to associate resources to the device (such as drivers or COM port *
* number allocations) to a device regardless of the port it is plugged in to on the host. Some USB AVRs contain * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
* a unique serial number internally, and setting the device descriptors serial number string index to this value * number for the device.
* will cause it to use the internal serial number. */
* #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
* On unsupported devices, this will evaluate to NO_DESCRIPTOR and so will force the host to create a pseudo-serial
* number for the device.
*/
#define USE_INTERNAL_SERIAL 0xDC
#else
#define USE_INTERNAL_SERIAL NO_DESCRIPTOR
#endif
/* Function Prototypes: */ /* Function Prototypes: */
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should /** Sends a Remote Wakeup request to the host. This signals to the host that the device should
@ -205,7 +198,7 @@
static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE; static inline void USB_Device_SetDeviceAddress(const uint8_t Address) ATTR_ALWAYS_INLINE;
static inline void USB_Device_SetDeviceAddress(const uint8_t Address) static inline void USB_Device_SetDeviceAddress(const uint8_t Address)
{ {
AVR32_USBB.udcon = (AVR32_USBB.udcon & ~AVR32_USBB_UADD_MASK) | Address; AVR32_USBB.UDCON.uadd = Address;
AVR32_USBB.UDCON.adden = true; AVR32_USBB.UDCON.adden = true;
} }

@ -48,20 +48,19 @@ bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
Endpoint_SelectEndpoint(Number); Endpoint_SelectEndpoint(Number);
Endpoint_EnableEndpoint(); Endpoint_EnableEndpoint();
*((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0; ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0;
*((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = UECFGXData; ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = UECFGXData;
return Endpoint_IsConfigured(); return Endpoint_IsConfigured();
} }
void Endpoint_ClearEndpoints(void) void Endpoint_ClearEndpoints(void)
{ {
UEINT = 0;
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; ((uint32_t*)AVR32_USBB_UECFG0)[USB_SelectedEndpoint] = 0;
((uint32_t*)AVR32_USBB_UECON0CLR)[USB_SelectedEndpoint] = 0xFFFFFFFF;
Endpoint_DisableEndpoint(); Endpoint_DisableEndpoint();
} }
} }

@ -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 AVR32_USBB_UECFG0_EPBK0_SINGLE #define ENDPOINT_BANK_SINGLE AVR32_USBB_UECFG0_EPBK_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 AVR32_USBB_UECFG0_EPBK0_DOUBLE #define ENDPOINT_BANK_DOUBLE AVR32_USBB_UECFG0_EPBK_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 AVR32_USBB_UECFG0_TRIPLE #define ENDPOINT_BANK_TRIPLE AVR32_USBB_UECFG0_EPBK_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

@ -48,12 +48,12 @@ bool Pipe_ConfigurePipe(const uint8_t Number,
Pipe_SelectPipe(Number); Pipe_SelectPipe(Number);
Pipe_EnablePipe(); Pipe_EnablePipe();
*((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0; ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0;
*((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = (AVR32_USBB_ALLOC_MASK | ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = (AVR32_USBB_ALLOC_MASK |
((uint32_t)Type << AVR32_USBB_PTYPE_OFFSET) | ((uint32_t)Type << AVR32_USBB_PTYPE_OFFSET) |
((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) | ((uint32_t)Token << AVR32_USBB_PTOKEN_OFFSET) |
((uint32_t)Banks << AVR32_USBB_PBK_OFFSET) | ((uint32_t)Banks << AVR32_USBB_PBK_OFFSET) |
((EndpointNumber & PIPE_EPNUM_MASK) << AVR32_USBB_PEPNUM_OFFSET)); ((EndpointNumber & PIPE_EPNUM_MASK) << AVR32_USBB_PEPNUM_OFFSET));
Pipe_SetInfiniteINRequests(); Pipe_SetInfiniteINRequests();
@ -62,12 +62,11 @@ bool Pipe_ConfigurePipe(const uint8_t Number,
void Pipe_ClearPipes(void) void Pipe_ClearPipes(void)
{ {
UPINT = 0;
for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++) for (uint8_t PNum = 0; PNum < PIPE_TOTAL_PIPES; PNum++)
{ {
Pipe_SelectPipe(PNum); Pipe_SelectPipe(PNum);
*((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0; ((uint32_t*)AVR32_USBB_UPCFG0)[USB_SelectedPipe] = 0;
((uint32_t*)AVR32_USBB_UPCON0CLR)[USB_SelectedPipe] = 0xFFFFFFFF;
Pipe_DisablePipe(); Pipe_DisablePipe();
} }
} }

@ -121,6 +121,18 @@
#endif #endif
/* Inline Functions: */ /* Inline Functions: */
/** Determines if the VBUS line is currently high (i.e. the USB host is supplying power).
*
* \note This function is not available on some AVR models which do not support hardware VBUS monitoring.
*
* \return Boolean \c true if the VBUS line is currently detecting power from a host, \c false otherwise.
*/
static inline bool USB_VBUS_GetStatus(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline bool USB_VBUS_GetStatus(void)
{
return AVR32_USBB.USBSTA.vbus;
}
/** Detaches the device from the USB bus. This has the effect of removing the device from any /** Detaches the device from the USB bus. This has the effect of removing the device from any
* attached host, ceasing USB communications. If no host is present, this prevents any host from * attached host, ceasing USB communications. If no host is present, this prevents any host from
* enumerating the device once attached until \ref USB_Attach() is called. * enumerating the device once attached until \ref USB_Attach() is called.
@ -278,7 +290,6 @@
#endif #endif
/* Inline Functions: */ /* Inline Functions: */
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE; static inline void USB_OTGPAD_On(void) ATTR_ALWAYS_INLINE;
static inline void USB_OTGPAD_On(void) static inline void USB_OTGPAD_On(void)
{ {
@ -290,7 +301,6 @@
{ {
AVR32_USBB.USBCON.otgpade = false; AVR32_USBB.USBCON.otgpade = false;
} }
#endif
static inline void USB_CLK_Freeze(void) ATTR_ALWAYS_INLINE; static inline void USB_CLK_Freeze(void) ATTR_ALWAYS_INLINE;
static inline void USB_CLK_Freeze(void) static inline void USB_CLK_Freeze(void)

@ -33,45 +33,23 @@
void USB_INT_DisableAllInterrupts(void) void USB_INT_DisableAllInterrupts(void)
{ {
#if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) AVR32_USBB.USBCON.vbuste = false;
USBCON &= ~((1 << VBUSTE) | (1 << IDTE)); AVR32_USBB.USBCON.idte = false;
#elif defined(USB_SERIES_4_AVR)
USBCON &= ~(1 << VBUSTE);
#endif
#if defined(USB_CAN_BE_BOTH)
OTGIEN = 0;
#endif
#if defined(USB_CAN_BE_HOST)
UHIEN = 0;
#endif
#if defined(USB_CAN_BE_DEVICE) AVR32_USBB.uhinteclr = 0xFFFFFFFF;
UDIEN = 0; AVR32_USBB.udinteclr = 0xFFFFFFFF;
#endif
} }
void USB_INT_ClearAllInterrupts(void) void USB_INT_ClearAllInterrupts(void)
{ {
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) AVR32_USBB.USBSTACLR.vbustic = true;
USBINT = 0; AVR32_USBB.USBSTACLR.idtic = true;
#endif
#if defined(USB_CAN_BE_BOTH) AVR32_USBB.uhintclr = 0xFFFFFFFF;
OTGINT = 0; AVR32_USBB.udintclr = 0xFFFFFFFF;
#endif
#if defined(USB_CAN_BE_HOST)
UHINT = 0;
#endif
#if defined(USB_CAN_BE_DEVICE)
UDINT = 0;
#endif
} }
ISR(USB_GEN_vect, ISR_BLOCK) ISR(USB_GEN_vect)
{ {
#if defined(USB_CAN_BE_DEVICE) #if defined(USB_CAN_BE_DEVICE)
#if !defined(NO_SOF_EVENTS) #if !defined(NO_SOF_EVENTS)
@ -83,7 +61,6 @@ ISR(USB_GEN_vect, ISR_BLOCK)
} }
#endif #endif
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
if (USB_INT_HasOccurred(USB_INT_VBUS) && USB_INT_IsEnabled(USB_INT_VBUS)) if (USB_INT_HasOccurred(USB_INT_VBUS) && USB_INT_IsEnabled(USB_INT_VBUS))
{ {
USB_INT_Clear(USB_INT_VBUS); USB_INT_Clear(USB_INT_VBUS);
@ -99,7 +76,6 @@ ISR(USB_GEN_vect, ISR_BLOCK)
EVENT_USB_Device_Disconnect(); EVENT_USB_Device_Disconnect();
} }
} }
#endif
if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI)) if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
{ {
@ -110,26 +86,12 @@ ISR(USB_GEN_vect, ISR_BLOCK)
USB_CLK_Freeze(); USB_CLK_Freeze();
if (!(USB_Options & USB_OPT_MANUAL_PLL))
USB_PLL_Off();
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
USB_DeviceState = DEVICE_STATE_Unattached;
EVENT_USB_Device_Disconnect();
#else
USB_DeviceState = DEVICE_STATE_Suspended; USB_DeviceState = DEVICE_STATE_Suspended;
EVENT_USB_Device_Suspend(); EVENT_USB_Device_Suspend();
#endif
} }
if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI)) if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
{ {
if (!(USB_Options & USB_OPT_MANUAL_PLL))
{
USB_PLL_On();
while (!(USB_PLL_IsReady()));
}
USB_CLK_Unfreeze(); USB_CLK_Unfreeze();
USB_INT_Clear(USB_INT_WAKEUPI); USB_INT_Clear(USB_INT_WAKEUPI);
@ -142,11 +104,7 @@ ISR(USB_GEN_vect, ISR_BLOCK)
else else
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered; USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
EVENT_USB_Device_Connect();
#else
EVENT_USB_Device_WakeUp(); EVENT_USB_Device_WakeUp();
#endif
} }
if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI)) if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))

@ -57,31 +57,243 @@
/* Private Interface - For use in library only: */ /* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__) #if !defined(__DOXYGEN__)
/* Macros: */ /* Macros: */
#define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE enum USB_Interrupts_t
#define USB_INT_Disable(int) MACROS{ USB_INT_GET_EN_REG(int) &= ~(USB_INT_GET_EN_MASK(int)); }MACROE {
#define USB_INT_Clear(int) MACROS{ USB_INT_GET_INT_REG(int) &= ~(USB_INT_GET_INT_MASK(int)); }MACROE USB_INT_VBUS = 0,
#define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false) USB_INT_IDTI = 1,
#define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false) USB_INT_WAKEUPI = 2,
USB_INT_SUSPI = 3,
#define USB_INT_GET_EN_REG(EnableReg, EnableMask, FlagReg, FlagMask) EnableReg USB_INT_EORSTI = 4,
#define USB_INT_GET_EN_MASK(EnableReg, EnableMask, FlagReg, FlagMask) EnableMask USB_INT_DCONNI = 5,
#define USB_INT_GET_INT_REG(EnableReg, EnableMask, FlagReg, FlagMask) FlagReg USB_INT_DDISCI = 6,
#define USB_INT_GET_INT_MASK(EnableReg, EnableMask, FlagReg, FlagMask) FlagMask USB_INT_BCERRI = 7,
USB_INT_VBERRI = 8,
#define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI) USB_INT_SOFI = 9,
#define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI) USB_INT_HSOFI = 10,
#define USB_INT_WAKEUPI UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI) USB_INT_RSTI = 11,
#define USB_INT_SUSPI UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI) USB_INT_SRPI = 12,
#define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI) USB_INT_RXSTPI = 13,
#define USB_INT_DCONNI UHIEN , (1 << DCONNE) , UHINT , (1 << DCONNI) };
#define USB_INT_DDISCI UHIEN , (1 << DDISCE) , UHINT , (1 << DDISCI)
#define USB_INT_BCERRI OTGIEN, (1 << BCERRE) , OTGINT, (1 << BCERRI) static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
#define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI) static inline void USB_INT_Enable(const uint8_t Interrupt)
#define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI) {
#define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI) switch (Interrupt)
#define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI) {
#define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI) case USB_INT_VBUS:
#define USB_INT_RXSTPI UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI) AVR32_USBB.USBCON.vbuste = true;
break;
case USB_INT_IDTI:
AVR32_USBB.USBCON.idte = true;
break;
case USB_INT_WAKEUPI:
AVR32_USBB.UDINTESET.wakeupes = true;
break;
case USB_INT_SUSPI:
AVR32_USBB.UDINTESET.suspes = true;
break;
case USB_INT_EORSTI:
AVR32_USBB.UDINTESET.eorstes = true;
break;
case USB_INT_DCONNI:
AVR32_USBB.UHINTESET.dconnies = true;
break;
case USB_INT_DDISCI:
AVR32_USBB.UHINTESET.ddiscies = true;
break;
case USB_INT_BCERRI:
AVR32_USBB.USBCON.bcerre = true;
break;
case USB_INT_VBERRI:
AVR32_USBB.USBCON.vberre = true;
break;
case USB_INT_SOFI:
AVR32_USBB.UDINTESET.sofes = true;
break;
case USB_INT_HSOFI:
AVR32_USBB.UHINTESET.hsofies = true;
break;
case USB_INT_RSTI:
AVR32_USBB.UHINTESET.rsties = true;
break;
case USB_INT_SRPI:
case USB_INT_RXSTPI:
// TODO
return;
}
}
static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Disable(const uint8_t Interrupt)
{
switch (Interrupt)
{
case USB_INT_VBUS:
AVR32_USBB.USBCON.vbuste = false;
break;
case USB_INT_IDTI:
AVR32_USBB.USBCON.idte = false;
break;
case USB_INT_WAKEUPI:
AVR32_USBB.UDINTECLR.wakeupec = true;
break;
case USB_INT_SUSPI:
AVR32_USBB.UDINTECLR.suspec = true;
break;
case USB_INT_EORSTI:
AVR32_USBB.UDINTECLR.eorstec = true;
break;
case USB_INT_DCONNI:
AVR32_USBB.UHINTECLR.dconniec = true;
break;
case USB_INT_DDISCI:
AVR32_USBB.UHINTECLR.ddisciec = true;
break;
case USB_INT_BCERRI:
AVR32_USBB.USBCON.bcerre = false;
break;
case USB_INT_VBERRI:
AVR32_USBB.USBCON.vberre = false;
break;
case USB_INT_SOFI:
AVR32_USBB.UDINTECLR.sofec = true;
break;
case USB_INT_HSOFI:
AVR32_USBB.UHINTECLR.hsofiec = true;
break;
case USB_INT_RSTI:
AVR32_USBB.UHINTECLR.rstiec = true;
break;
case USB_INT_SRPI:
case USB_INT_RXSTPI:
// TODO
return;
}
}
static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Clear(const uint8_t Interrupt)
{
switch (Interrupt)
{
case USB_INT_VBUS:
AVR32_USBB.USBSTACLR.vbustic = true;
break;
case USB_INT_IDTI:
AVR32_USBB.USBSTACLR.idtic = true;
break;
case USB_INT_WAKEUPI:
AVR32_USBB.UDINTCLR.wakeupc = true;
break;
case USB_INT_SUSPI:
AVR32_USBB.UDINTCLR.suspc = true;
break;
case USB_INT_EORSTI:
AVR32_USBB.UDINTCLR.eorstc = true;
break;
case USB_INT_DCONNI:
AVR32_USBB.UHINTCLR.dconnic = true;
break;
case USB_INT_DDISCI:
AVR32_USBB.UHINTCLR.ddiscic = true;
break;
case USB_INT_BCERRI:
AVR32_USBB.USBSTACLR.bcerric = true;
break;
case USB_INT_VBERRI:
AVR32_USBB.USBSTACLR.vberric = true;
break;
case USB_INT_SOFI:
AVR32_USBB.UDINTCLR.sofc = true;
break;
case USB_INT_HSOFI:
AVR32_USBB.UHINTCLR.hsofic = true;
break;
case USB_INT_RSTI:
AVR32_USBB.UHINTCLR.rstic = true;
break;
case USB_INT_SRPI:
case USB_INT_RXSTPI:
// TODO
return;
}
}
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
{
switch (Interrupt)
{
case USB_INT_VBUS:
return AVR32_USBB.USBCON.vbuste;
case USB_INT_IDTI:
return AVR32_USBB.USBCON.idte;
case USB_INT_WAKEUPI:
return AVR32_USBB.UDINTE.wakeupe;
case USB_INT_SUSPI:
return AVR32_USBB.UDINTE.suspe;
case USB_INT_EORSTI:
return AVR32_USBB.UDINTE.eorste;
case USB_INT_DCONNI:
return AVR32_USBB.UHINTE.dconnie;
case USB_INT_DDISCI:
return AVR32_USBB.UHINTE.ddiscie;
case USB_INT_BCERRI:
return AVR32_USBB.USBCON.bcerre;
case USB_INT_VBERRI:
return AVR32_USBB.USBCON.vberre;
case USB_INT_SOFI:
return AVR32_USBB.UDINTE.sofe;
case USB_INT_HSOFI:
return AVR32_USBB.UHINTE.hsofie;
case USB_INT_RSTI:
return AVR32_USBB.UHINTE.rstie;
case USB_INT_SRPI:
case USB_INT_RXSTPI:
// TODO
return false;
}
return false;
}
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
{
switch (Interrupt)
{
case USB_INT_VBUS:
return AVR32_USBB.USBSTA.vbusti;
case USB_INT_IDTI:
return AVR32_USBB.USBSTA.idti;
case USB_INT_WAKEUPI:
return AVR32_USBB.UDINT.wakeup;
case USB_INT_SUSPI:
return AVR32_USBB.UDINT.susp;
case USB_INT_EORSTI:
return AVR32_USBB.UDINT.eorst;
case USB_INT_DCONNI:
return AVR32_USBB.UHINT.dconni;
case USB_INT_DDISCI:
return AVR32_USBB.UHINT.ddisci;
case USB_INT_BCERRI:
return AVR32_USBB.USBSTA.bcerri;
case USB_INT_VBERRI:
return AVR32_USBB.USBSTA.vberri;
case USB_INT_SOFI:
return AVR32_USBB.UDINT.sof;
case USB_INT_HSOFI:
return AVR32_USBB.UHINT.hsofi;
case USB_INT_RSTI:
return AVR32_USBB.UHINT.rsti;
case USB_INT_SRPI:
case USB_INT_RXSTPI:
// TODO
return false;
}
return false;
}
/* Includes: */ /* Includes: */
#include "../USBMode.h" #include "../USBMode.h"

Loading…
Cancel
Save