Commit 028a3c4a authored by Dean Camera's avatar Dean Camera

XMEGA port improvements; connection and disconnection are now detected...

XMEGA port improvements; connection and disconnection are now detected correctly. Fixed incorrect interrupt priority levels being set for XMEGA devices.
parent 6519aaa5
......@@ -142,7 +142,7 @@
static inline uint16_t USB_Device_GetFrameNumber(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline uint16_t USB_Device_GetFrameNumber(void)
{
return (((uint16_t)USB_EndpointTable.FRAMENUMH << 8) | USB_EndpointTable.FRAMENUML);
return USB_EndpointTable.FrameNum;
}
#if !defined(NO_SOF_EVENTS)
......
......@@ -39,8 +39,31 @@
uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
#endif
volatile uint8_t Endpoint_SelectedEndpoint;
volatile USB_EP_t* Endpoint_SelectedEndpointHandle;
Endpoint_AuxData_t Endpoint_AuxData[ENDPOINT_DETAILS_MAXEP * 2];
volatile uint8_t Endpoint_SelectedEndpoint;
volatile USB_EP_t* Endpoint_SelectedEndpointHandle;
volatile Endpoint_AuxData_t* Endpoint_SelectedEndpointAux;
bool Endpoint_ConfigureEndpoint_PRV(const uint8_t Number,
const uint8_t Direction,
const uint8_t Config,
const uint8_t Size)
{
Endpoint_SelectEndpoint(Number | Direction);
Endpoint_SelectedEndpointHandle->CTRL = 0;
Endpoint_SelectedEndpointHandle->STATUS = (Direction == ENDPOINT_DIR_IN) ? USB_EP_BUSNACK0_bm : 0;
Endpoint_SelectedEndpointHandle->CTRL = Config;
Endpoint_SelectedEndpointHandle->CNT = 0;
Endpoint_SelectedEndpointHandle->DATAPTR = (intptr_t)&Endpoint_SelectedEndpointAux->Data;
Endpoint_SelectedEndpointAux->BankSize = Size;
Endpoint_SelectedEndpointAux->FIFOLength = (Direction == ENDPOINT_DIR_IN) ? Size : 0;
Endpoint_SelectedEndpointAux->FIFOPosition = 0;
return true;
}
void Endpoint_ClearEndpoints(void)
{
......
......@@ -40,7 +40,7 @@ volatile uint8_t USB_CurrentMode = USB_MODE_None;
volatile uint8_t USB_Options;
#endif
USB_EP_TABLE_t USB_EndpointTable ATTR_ALIGNED(4);
USB_EndpointTable_t USB_EndpointTable ATTR_ALIGNED(4);
void USB_Init(
#if defined(USB_CAN_BE_BOTH)
......@@ -73,6 +73,7 @@ void USB_Init(
USB.CAL1 = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBCAL1));
USB.EPPTR = (intptr_t)&USB_EndpointTable;
USB.CTRLA = (USB_STFRNUM_bm | USB_MAXEP_gm);
if ((USB_Options & USB_OPT_BUSEVENT_PRIHIGH) == USB_OPT_BUSEVENT_PRIHIGH)
USB.INTCTRLA = (3 << USB_INTLVL_gp);
......
......@@ -57,8 +57,20 @@
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Type Defines: */
typedef struct
{
uint16_t FrameNum;
struct
{
USB_EP_t OUT;
USB_EP_t IN;
} Endpoints[16];
} ATTR_PACKED USB_EndpointTable_t;
/* External Variables: */
extern USB_EP_TABLE_t USB_EndpointTable;
extern USB_EndpointTable_t USB_EndpointTable;
#endif
/* Includes: */
......@@ -90,17 +102,17 @@
/** Sets the USB bus interrupt priority level to be low priority. The USB bus interrupt is used for Start of Frame events, bus suspend
* and resume events, bus reset events and other events related to the management of the USB bus.
*/
#define USB_OPT_BUSEVENT_PRILOW ((0 << 1) | (0 << 1))
#define USB_OPT_BUSEVENT_PRILOW ((0 << 2) | (0 << 1))
/** Sets the USB bus interrupt priority level to be medium priority. The USB bus interrupt is used for Start of Frame events, bus suspend
* and resume events, bus reset events and other events related to the management of the USB bus.
*/
#define USB_OPT_BUSEVENT_PRIMED ((0 << 1) | (1 << 1))
#define USB_OPT_BUSEVENT_PRIMED ((0 << 2) | (1 << 1))
/** Sets the USB bus interrupt priority level to be high priority. The USB bus interrupt is used for Start of Frame events, bus suspend
* and resume events, bus reset events and other events related to the management of the USB bus.
*/
#define USB_OPT_BUSEVENT_PRIHIGH ((1 << 1) | (0 << 1))
#define USB_OPT_BUSEVENT_PRIHIGH ((1 << 2) | (0 << 1))
//@}
#if !defined(USB_STREAM_TIMEOUT_MS) || defined(__DOXYGEN__)
......@@ -263,7 +275,7 @@
static inline void USB_Controller_Enable(void) ATTR_ALWAYS_INLINE;
static inline void USB_Controller_Enable(void)
{
USB.CTRLA |= (USB_ENABLE_bm | USB_STFRNUM_bm | USB_MAXEP_gm);
USB.CTRLA |= USB_ENABLE_bm;
}
static inline void USB_Controller_Disable(void) ATTR_ALWAYS_INLINE;
......
......@@ -33,7 +33,7 @@
void USB_INT_DisableAllInterrupts(void)
{
USB.INTCTRLA = 0;
USB.INTCTRLA &= USB_INTLVL_gm;
USB.INTCTRLB = 0;
}
......
......@@ -121,9 +121,9 @@
switch (Interrupt)
{
case USB_INT_BUSEVENTI:
return (USB.INTCTRLA & USB_BUSEVIE_bm);
return ((USB.INTCTRLA & USB_BUSEVIE_bm) ? true : false);
case USB_INT_SOFI:
return (USB.INTCTRLA & USB_SOFIE_bm);
return ((USB.INTCTRLA & USB_SOFIE_bm) ? true : false);
}
return false;
......@@ -135,13 +135,13 @@
switch (Interrupt)
{
case USB_INT_BUSEVENTI_Suspend:
return (USB.INTFLAGSACLR & USB_SUSPENDIF_bm);
return ((USB.INTFLAGSACLR & USB_SUSPENDIF_bm) ? true : false);
case USB_INT_BUSEVENTI_Resume:
return (USB.INTFLAGSACLR & USB_RESUMEIF_bm);
return ((USB.INTFLAGSACLR & USB_RESUMEIF_bm) ? true : false);
case USB_INT_BUSEVENTI_Reset:
return (USB.INTFLAGSACLR & USB_RSTIF_bm);
return ((USB.INTFLAGSACLR & USB_RSTIF_bm) ? true : false);
case USB_INT_SOFI:
return (USB.INTFLAGSACLR & USB_SOFIF_bm);
return ((USB.INTFLAGSACLR & USB_SOFIF_bm) ? true : false);
}
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment