Commit 04526d28 authored by Dean Camera's avatar Dean Camera

Changed over the AVR8 USB controller interrupt management macros to be inlined...

Changed over the AVR8 USB controller interrupt management macros to be inlined functions instead, for better compile-time validity checking and to keep the per-architecture source files as uniform as possible.
parent 92b3553a
......@@ -197,7 +197,7 @@ static void USB_Init_Device(void)
else
USB_Device_SetFullSpeed();
USB_INT_Enable(USB_INT_VBUS);
USB_INT_Enable(USB_INT_VBUSTI);
#endif
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
......
......@@ -84,9 +84,9 @@ ISR(USB_GEN_vect, ISR_BLOCK)
#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_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
{
USB_INT_Clear(USB_INT_VBUS);
USB_INT_Clear(USB_INT_VBUSTI);
if (USB_VBUS_GetStatus())
{
......
......@@ -56,32 +56,252 @@
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#define USB_INT_Enable(int) MACROS{ USB_INT_GET_EN_REG(int) |= USB_INT_GET_EN_MASK(int); }MACROE
#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
#define USB_INT_IsEnabled(int) ((USB_INT_GET_EN_REG(int) & USB_INT_GET_EN_MASK(int)) ? true : false)
#define USB_INT_HasOccurred(int) ((USB_INT_GET_INT_REG(int) & USB_INT_GET_INT_MASK(int)) ? true : false)
#define USB_INT_GET_EN_REG(EnableReg, EnableMask, FlagReg, FlagMask) EnableReg
#define USB_INT_GET_EN_MASK(EnableReg, EnableMask, FlagReg, FlagMask) EnableMask
#define USB_INT_GET_INT_REG(EnableReg, EnableMask, FlagReg, FlagMask) FlagReg
#define USB_INT_GET_INT_MASK(EnableReg, EnableMask, FlagReg, FlagMask) FlagMask
/* Enums: */
enum USB_Interrupts_t
{
USB_INT_VBUSTI = 0,
USB_INT_IDTI = 1,
USB_INT_WAKEUPI = 2,
USB_INT_SUSPI = 3,
USB_INT_EORSTI = 4,
USB_INT_SOFI = 5,
USB_INT_HSOFI = 6,
USB_INT_DCONNI = 7,
USB_INT_DDISCI = 8,
USB_INT_RSTI = 9,
USB_INT_BCERRI = 10,
USB_INT_VBERRI = 11,
USB_INT_SRPI = 12,
USB_INT_RXSTPI = 13,
};
/* Inline Functions: */
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Enable(const uint8_t Interrupt)
{
switch (Interrupt)
{
case USB_INT_VBUSTI:
USBCON |= (1 << VBUSTE);
break;
case USB_INT_IDTI:
USBCON |= (1 << IDTE);
break;
case USB_INT_WAKEUPI:
UDIEN |= (1 << WAKEUPE);
break;
case USB_INT_SUSPI:
UDIEN |= (1 << SUSPE);
break;
case USB_INT_EORSTI:
UDIEN |= (1 << EORSTE);
break;
case USB_INT_SOFI:
UDIEN |= (1 << SOFE);
break;
case USB_INT_HSOFI:
UHIEN |= (1 << HSOFE);
break;
case USB_INT_DCONNI:
UHIEN |= (1 << DCONNE);
break;
case USB_INT_DDISCI:
UHIEN |= (1 << DDISCE);
break;
case USB_INT_RSTI:
UHIEN |= (1 << RSTE);
break;
case USB_INT_BCERRI:
OTGIEN |= (1 << BCERRE);
break;
case USB_INT_VBERRI:
OTGIEN |= (1 << VBERRE);
break;
case USB_INT_SRPI:
OTGIEN |= (1 << SRPE);
break;
case USB_INT_RXSTPI:
UEIENX |= (1 << RXSTPE);
break;
}
}
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_VBUSTI:
USBCON &= ~(1 << VBUSTE);
break;
case USB_INT_IDTI:
USBCON &= ~(1 << IDTE);
break;
case USB_INT_WAKEUPI:
UDIEN &= ~(1 << WAKEUPE);
break;
case USB_INT_SUSPI:
UDIEN &= ~(1 << SUSPE);
break;
case USB_INT_EORSTI:
UDIEN &= ~(1 << EORSTE);
break;
case USB_INT_SOFI:
UDIEN &= ~(1 << SOFE);
break;
case USB_INT_HSOFI:
UHIEN &= ~(1 << HSOFE);
break;
case USB_INT_DCONNI:
UHIEN &= ~(1 << DCONNE);
break;
case USB_INT_DDISCI:
UHIEN &= ~(1 << DDISCE);
break;
case USB_INT_RSTI:
UHIEN &= ~(1 << RSTE);
break;
case USB_INT_BCERRI:
OTGIEN &= ~(1 << BCERRE);
break;
case USB_INT_VBERRI:
OTGIEN &= ~(1 << VBERRE);
break;
case USB_INT_SRPI:
OTGIEN &= ~(1 << SRPE);
break;
case USB_INT_RXSTPI:
UEIENX &= ~(1 << RXSTPE);
break;
}
}
#define USB_INT_VBUS USBCON, (1 << VBUSTE) , USBINT, (1 << VBUSTI)
#define USB_INT_IDTI USBCON, (1 << IDTE) , USBINT, (1 << IDTI)
#define USB_INT_WAKEUPI UDIEN , (1 << WAKEUPE), UDINT , (1 << WAKEUPI)
#define USB_INT_SUSPI UDIEN , (1 << SUSPE) , UDINT , (1 << SUSPI)
#define USB_INT_EORSTI UDIEN , (1 << EORSTE) , UDINT , (1 << EORSTI)
#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)
#define USB_INT_VBERRI OTGIEN, (1 << VBERRE) , OTGINT, (1 << VBERRI)
#define USB_INT_SOFI UDIEN, (1 << SOFE) , UDINT , (1 << SOFI)
#define USB_INT_HSOFI UHIEN, (1 << HSOFE) , UHINT , (1 << HSOFI)
#define USB_INT_RSTI UHIEN , (1 << RSTE) , UHINT , (1 << RSTI)
#define USB_INT_SRPI OTGIEN, (1 << SRPE) , OTGINT, (1 << SRPI)
#define USB_INT_RXSTPI UEIENX, (1 << RXSTPE) , UEINTX, (1 << RXSTPI)
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_VBUSTI:
USBINT &= ~(1 << VBUSTI);
break;
case USB_INT_IDTI:
USBINT &= ~(1 << IDTI);
break;
case USB_INT_WAKEUPI:
UDINT &= ~(1 << WAKEUPI);
break;
case USB_INT_SUSPI:
UDINT &= ~(1 << SUSPI);
break;
case USB_INT_EORSTI:
UDINT &= ~(1 << EORSTI);
break;
case USB_INT_SOFI:
UDINT &= ~(1 << SOFI);
break;
case USB_INT_HSOFI:
UHINT &= ~(1 << HSOFI);
break;
case USB_INT_DCONNI:
UHINT &= ~(1 << DCONNI);
break;
case USB_INT_DDISCI:
UHINT &= ~(1 << DDISCI);
break;
case USB_INT_RSTI:
UHINT &= ~(1 << RSTI);
break;
case USB_INT_BCERRI:
OTGINT &= ~(1 << BCERRI);
break;
case USB_INT_VBERRI:
OTGINT &= ~(1 << VBERRI);
break;
case USB_INT_SRPI:
OTGINT &= ~(1 << SRPI);
break;
case USB_INT_RXSTPI:
UEINTX &= ~(1 << RXSTPI);
break;
}
}
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_VBUSTI:
return (USBCON & (1 << VBUSTE));
case USB_INT_IDTI:
return (USBCON & (1 << IDTE));
case USB_INT_WAKEUPI:
return (UDIEN & (1 << WAKEUPE));
case USB_INT_SUSPI:
return (UDIEN & (1 << SUSPE));
case USB_INT_EORSTI:
return (UDIEN & (1 << EORSTE));
case USB_INT_SOFI:
return (UDIEN & (1 << SOFE));
case USB_INT_HSOFI:
return (UHIEN & (1 << HSOFE));
case USB_INT_DCONNI:
return (UHIEN & (1 << DCONNE));
case USB_INT_DDISCI:
return (UHIEN & (1 << DDISCE));
case USB_INT_RSTI:
return (UHIEN & (1 << RSTE));
case USB_INT_BCERRI:
return (OTGIEN & (1 << BCERRE));
case USB_INT_VBERRI:
return (OTGIEN & (1 << VBERRE));
case USB_INT_SRPI:
return (OTGIEN & (1 << SRPE));
case USB_INT_RXSTPI:
return (UEIENX & (1 << RXSTPE));
break;
}
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_VBUSTI:
return (USBINT & (1 << VBUSTI));
case USB_INT_IDTI:
return (USBINT & (1 << IDTI));
case USB_INT_WAKEUPI:
return (UDINT & (1 << WAKEUPI));
case USB_INT_SUSPI:
return (UDINT & (1 << SUSPI));
case USB_INT_EORSTI:
return (UDINT & (1 << EORSTI));
case USB_INT_SOFI:
return (UDINT & (1 << SOFI));
case USB_INT_HSOFI:
return (UHINT & (1 << HSOFI));
case USB_INT_DCONNI:
return (UHINT & (1 << DCONNI));
case USB_INT_DDISCI:
return (UHINT & (1 << DDISCI));
case USB_INT_RSTI:
return (UHINT & (1 << RSTI));
case USB_INT_BCERRI:
return (OTGINT & (1 << BCERRI));
case USB_INT_VBERRI:
return (OTGINT & (1 << VBERRI));
case USB_INT_SRPI:
return (OTGINT & (1 << SRPI));
case USB_INT_RXSTPI:
return (UEINTX & (1 << RXSTPI));
}
return false;
}
/* Includes: */
#include "../USBMode.h"
......
......@@ -160,7 +160,7 @@ static void USB_Init_Device(void)
else
USB_Device_SetFullSpeed();
USB_INT_Enable(USB_INT_VBUS);
USB_INT_Enable(USB_INT_VBUSTI);
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
......
......@@ -61,9 +61,9 @@ ISR(USB_GEN_vect)
}
#endif
if (USB_INT_HasOccurred(USB_INT_VBUS) && USB_INT_IsEnabled(USB_INT_VBUS))
if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
{
USB_INT_Clear(USB_INT_VBUS);
USB_INT_Clear(USB_INT_VBUSTI);
if (USB_VBUS_GetStatus())
{
......
......@@ -59,28 +59,29 @@
/* Macros: */
enum USB_Interrupts_t
{
USB_INT_VBUS = 0,
USB_INT_VBUSTI = 0,
USB_INT_IDTI = 1,
USB_INT_WAKEUPI = 2,
USB_INT_SUSPI = 3,
USB_INT_EORSTI = 4,
USB_INT_DCONNI = 5,
USB_INT_DDISCI = 6,
USB_INT_BCERRI = 7,
USB_INT_VBERRI = 8,
USB_INT_SOFI = 9,
USB_INT_HSOFI = 10,
USB_INT_RSTI = 11,
USB_INT_SOFI = 5,
USB_INT_HSOFI = 6,
USB_INT_DCONNI = 7,
USB_INT_DDISCI = 8,
USB_INT_RSTI = 9,
USB_INT_BCERRI = 10,
USB_INT_VBERRI = 11,
USB_INT_SRPI = 12,
USB_INT_RXSTPI = 13,
};
/* Inline Functions: */
static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
static inline void USB_INT_Enable(const uint8_t Interrupt)
{
switch (Interrupt)
{
case USB_INT_VBUS:
case USB_INT_VBUSTI:
AVR32_USBB.USBCON.vbuste = true;
break;
case USB_INT_IDTI:
......@@ -95,27 +96,27 @@
case USB_INT_EORSTI:
AVR32_USBB.UDINTESET.eorstes = 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_DCONNI:
AVR32_USBB.UHINTESET.dconnies = true;
break;
case USB_INT_DDISCI:
AVR32_USBB.UHINTESET.ddiscies = true;
break;
case USB_INT_RSTI:
AVR32_USBB.UHINTESET.rsties = 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
......@@ -128,7 +129,7 @@
{
switch (Interrupt)
{
case USB_INT_VBUS:
case USB_INT_VBUSTI:
AVR32_USBB.USBCON.vbuste = false;
break;
case USB_INT_IDTI:
......@@ -143,27 +144,27 @@
case USB_INT_EORSTI:
AVR32_USBB.UDINTECLR.eorstec = true;
break;
case USB_INT_SOFI:
AVR32_USBB.UDINTECLR.sofec = true;
break;
case USB_INT_HSOFI:
AVR32_USBB.UHINTECLR.hsofiec = 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_RSTI:
AVR32_USBB.UHINTECLR.rstiec = 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
......@@ -176,7 +177,7 @@
{
switch (Interrupt)
{
case USB_INT_VBUS:
case USB_INT_VBUSTI:
AVR32_USBB.USBSTACLR.vbustic = true;
break;
case USB_INT_IDTI:
......@@ -191,27 +192,27 @@
case USB_INT_EORSTI:
AVR32_USBB.UDINTCLR.eorstc = 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_DCONNI:
AVR32_USBB.UHINTCLR.dconnic = true;
break;
case USB_INT_DDISCI:
AVR32_USBB.UHINTCLR.ddiscic = true;
break;
case USB_INT_RSTI:
AVR32_USBB.UHINTCLR.rstic = 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
......@@ -224,7 +225,7 @@
{
switch (Interrupt)
{
case USB_INT_VBUS:
case USB_INT_VBUSTI:
return AVR32_USBB.USBCON.vbuste;
case USB_INT_IDTI:
return AVR32_USBB.USBCON.idte;
......@@ -234,20 +235,20 @@
return AVR32_USBB.UDINTE.suspe;
case USB_INT_EORSTI:
return AVR32_USBB.UDINTE.eorste;
case USB_INT_SOFI:
return AVR32_USBB.UDINTE.sofe;
case USB_INT_HSOFI:
return AVR32_USBB.UHINTE.hsofie;
case USB_INT_DCONNI:
return AVR32_USBB.UHINTE.dconnie;
case USB_INT_DDISCI:
return AVR32_USBB.UHINTE.ddiscie;
case USB_INT_RSTI:
return AVR32_USBB.UHINTE.rstie;
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
......@@ -262,7 +263,7 @@
{
switch (Interrupt)
{
case USB_INT_VBUS:
case USB_INT_VBUSTI:
return AVR32_USBB.USBSTA.vbusti;
case USB_INT_IDTI:
return AVR32_USBB.USBSTA.idti;
......@@ -272,20 +273,20 @@
return AVR32_USBB.UDINT.susp;
case USB_INT_EORSTI:
return AVR32_USBB.UDINT.eorst;
case USB_INT_SOFI:
return AVR32_USBB.UDINT.sof;
case USB_INT_HSOFI:
return AVR32_USBB.UHINT.hsofi;
case USB_INT_DCONNI:
return AVR32_USBB.UHINT.dconni;
case USB_INT_DDISCI:
return AVR32_USBB.UHINT.ddisci;
case USB_INT_RSTI:
return AVR32_USBB.UHINT.rsti;
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
......
......@@ -40,7 +40,7 @@
* into difficulties or need some advice. In addition, you can also email the library author to receive personalized
* support when you need it (subject to author's schedule).
*
* <small>* Atmel Stack Mouse Device Demo 4218 bytes, LUFA Mouse Low Level Device Demo 3472 bytes, under identical build
* <small>* Atmel Stack Mouse Device Demo 4218 bytes, LUFA Mouse Low Level Device Demo 3526 bytes, under identical build
* environments</small>
*/
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