3 Copyright (C) Dean Camera, 2011.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
32 * \brief USB Controller Interrupt definitions for the AVR32 UC3 microcontrollers.
34 * This file contains definitions required for the correct handling of low level USB service routine interrupts
35 * from the USB controller.
37 * \note This file should not be included directly. It is automatically included as needed by the USB driver
38 * dispatch header located in LUFA/Drivers/USB/USB.h.
41 #ifndef __USBINTERRUPT_UC3_H__
42 #define __USBINTERRUPT_UC3_H__
45 #include "../../../../Common/Common.h"
47 /* Enable C linkage for C++ Compilers: */
48 #if defined(__cplusplus)
52 /* Preprocessor Checks: */
53 #if !defined(__INCLUDE_FROM_USB_DRIVER)
54 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
57 /* Private Interface - For use in library only: */
58 #if !defined(__DOXYGEN__)
60 #define LUFA_ISR(Name) void Name (void) __attribute__((__interrupt__)); void Name (void)
66 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
69 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
75 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
85 /* Inline Functions: */
86 static inline uint_reg_t
USB_INT_GetGlobalEnableState(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
87 static inline uint_reg_t
USB_INT_GetGlobalEnableState(void)
90 return (__builtin_mfsr(AVR32_SR
) & AVR32_SR_GM
);
93 static inline void USB_INT_SetGlobalEnableState(uint_reg_t GlobalIntState
) ATTR_ALWAYS_INLINE
;
94 static inline void USB_INT_SetGlobalEnableState(uint_reg_t GlobalIntState
)
97 __builtin_ssrf(AVR32_SR_GM_OFFSET
, GlobalIntState
);
101 static inline void USB_INT_GlobalEnable(void) ATTR_ALWAYS_INLINE
;
102 static inline void USB_INT_GlobalEnable(void)
104 GCC_MEMORY_BARRIER();
105 __builtin_csrf(AVR32_SR_GM_OFFSET
);
106 GCC_MEMORY_BARRIER();
109 static inline void USB_INT_GlobalDisable(void) ATTR_ALWAYS_INLINE
;
110 static inline void USB_INT_GlobalDisable(void)
112 GCC_MEMORY_BARRIER();
113 __builtin_ssrf(AVR32_SR_GM_OFFSET
);
114 GCC_MEMORY_BARRIER();
117 static inline void USB_INT_Enable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
118 static inline void USB_INT_Enable(const uint8_t Interrupt
)
123 AVR32_USBB
.USBCON
.vbuste
= true;
125 #if defined(USB_CAN_BE_BOTH)
127 AVR32_USBB
.USBCON
.idte
= true;
130 #if defined(USB_CAN_BE_DEVICE)
131 case USB_INT_WAKEUPI
:
132 AVR32_USBB
.UDINTESET
.wakeupes
= true;
135 AVR32_USBB
.UDINTESET
.suspes
= true;
138 AVR32_USBB
.UDINTESET
.eorstes
= true;
141 AVR32_USBB
.UDINTESET
.sofes
= true;
144 #if defined(USB_CAN_BE_HOST)
146 AVR32_USBB
.UHINTESET
.hsofies
= true;
149 AVR32_USBB
.UHINTESET
.dconnies
= true;
152 AVR32_USBB
.UHINTESET
.ddiscies
= true;
155 AVR32_USBB
.UHINTESET
.rsties
= true;
158 AVR32_USBB
.USBCON
.bcerre
= true;
161 AVR32_USBB
.USBCON
.vberre
= true;
167 static inline void USB_INT_Disable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
168 static inline void USB_INT_Disable(const uint8_t Interrupt
)
173 AVR32_USBB
.USBCON
.vbuste
= false;
175 #if defined(USB_CAN_BE_BOTH)
177 AVR32_USBB
.USBCON
.idte
= false;
180 #if defined(USB_CAN_BE_DEVICE)
181 case USB_INT_WAKEUPI
:
182 AVR32_USBB
.UDINTECLR
.wakeupec
= true;
185 AVR32_USBB
.UDINTECLR
.suspec
= true;
188 AVR32_USBB
.UDINTECLR
.eorstec
= true;
191 AVR32_USBB
.UDINTECLR
.sofec
= true;
194 #if defined(USB_CAN_BE_HOST)
196 AVR32_USBB
.UHINTECLR
.hsofiec
= true;
199 AVR32_USBB
.UHINTECLR
.dconniec
= true;
202 AVR32_USBB
.UHINTECLR
.ddisciec
= true;
205 AVR32_USBB
.UHINTECLR
.rstiec
= true;
208 AVR32_USBB
.USBCON
.bcerre
= false;
211 AVR32_USBB
.USBCON
.vberre
= false;
217 static inline void USB_INT_Clear(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
218 static inline void USB_INT_Clear(const uint8_t Interrupt
)
223 AVR32_USBB
.USBSTACLR
.vbustic
= true;
224 (void)AVR32_USBB
.USBSTACLR
;
226 #if defined(USB_CAN_BE_BOTH)
228 AVR32_USBB
.USBSTACLR
.idtic
= true;
229 (void)AVR32_USBB
.USBSTACLR
;
232 #if defined(USB_CAN_BE_DEVICE)
233 case USB_INT_WAKEUPI
:
234 AVR32_USBB
.UDINTCLR
.wakeupc
= true;
235 (void)AVR32_USBB
.UDINTCLR
;
238 AVR32_USBB
.UDINTCLR
.suspc
= true;
239 (void)AVR32_USBB
.UDINTCLR
;
242 AVR32_USBB
.UDINTCLR
.eorstc
= true;
243 (void)AVR32_USBB
.UDINTCLR
;
246 AVR32_USBB
.UDINTCLR
.sofc
= true;
247 (void)AVR32_USBB
.UDINTCLR
;
250 #if defined(USB_CAN_BE_HOST)
252 AVR32_USBB
.UHINTCLR
.hsofic
= true;
253 (void)AVR32_USBB
.UHINTCLR
;
256 AVR32_USBB
.UHINTCLR
.dconnic
= true;
257 (void)AVR32_USBB
.UHINTCLR
;
260 AVR32_USBB
.UHINTCLR
.ddiscic
= true;
261 (void)AVR32_USBB
.UHINTCLR
;
264 AVR32_USBB
.UHINTCLR
.rstic
= true;
265 (void)AVR32_USBB
.UHINTCLR
;
268 AVR32_USBB
.USBSTACLR
.bcerric
= true;
269 (void)AVR32_USBB
.USBSTACLR
;
272 AVR32_USBB
.USBSTACLR
.vberric
= true;
273 (void)AVR32_USBB
.USBSTACLR
;
279 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
280 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
)
285 return AVR32_USBB
.USBCON
.vbuste
;
286 #if defined(USB_CAN_BE_BOTH)
288 return AVR32_USBB
.USBCON
.idte
;
290 #if defined(USB_CAN_BE_DEVICE)
291 case USB_INT_WAKEUPI
:
292 return AVR32_USBB
.UDINTE
.wakeupe
;
294 return AVR32_USBB
.UDINTE
.suspe
;
296 return AVR32_USBB
.UDINTE
.eorste
;
298 return AVR32_USBB
.UDINTE
.sofe
;
300 #if defined(USB_CAN_BE_HOST)
302 return AVR32_USBB
.UHINTE
.hsofie
;
304 return AVR32_USBB
.UHINTE
.dconnie
;
306 return AVR32_USBB
.UHINTE
.ddiscie
;
308 return AVR32_USBB
.UHINTE
.rstie
;
310 return AVR32_USBB
.USBCON
.bcerre
;
312 return AVR32_USBB
.USBCON
.vberre
;
319 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
320 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
)
325 return AVR32_USBB
.USBSTA
.vbusti
;
326 #if defined(USB_CAN_BE_BOTH)
328 return AVR32_USBB
.USBSTA
.idti
;
330 #if defined(USB_CAN_BE_DEVICE)
331 case USB_INT_WAKEUPI
:
332 return AVR32_USBB
.UDINT
.wakeup
;
334 return AVR32_USBB
.UDINT
.susp
;
336 return AVR32_USBB
.UDINT
.eorst
;
338 return AVR32_USBB
.UDINT
.sof
;
340 #if defined(USB_CAN_BE_HOST)
342 return AVR32_USBB
.UHINT
.hsofi
;
344 return AVR32_USBB
.UHINT
.dconni
;
346 return AVR32_USBB
.UHINT
.ddisci
;
348 return AVR32_USBB
.UHINT
.rsti
;
350 return AVR32_USBB
.USBSTA
.bcerri
;
352 return AVR32_USBB
.USBSTA
.vberri
;
360 #include "../USBMode.h"
361 #include "../Events.h"
362 #include "../USBController.h"
364 /* Function Prototypes: */
365 void USB_INT_ClearAllInterrupts(void);
366 void USB_INT_DisableAllInterrupts(void);
369 /* Public Interface - May be used in end-application: */
370 /* ISR Prototypes: */
371 #if defined(__DOXYGEN__)
372 /** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
373 * linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
374 * using the user application's preferred USB controller driver.
376 void USB_GEN_vect(void);
378 LUFA_ISR(USB_GEN_vect
);
381 /* Disable C linkage for C++ Compilers: */
382 #if defined(__cplusplus)