3 Copyright (C) Dean Camera, 2012.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2012 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__)
59 /* External Variables: */
60 extern volatile uint32_t USB_Endpoint_SelectedEndpoint
;
66 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
69 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
76 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
86 /* Inline Functions: */
87 static inline void USB_INT_Enable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
88 static inline void USB_INT_Enable(const uint8_t Interrupt
)
93 AVR32_USBB
.USBCON
.vbuste
= true;
95 #if defined(USB_CAN_BE_BOTH)
97 AVR32_USBB
.USBCON
.idte
= true;
100 #if defined(USB_CAN_BE_DEVICE)
101 case USB_INT_WAKEUPI
:
102 AVR32_USBB
.UDINTESET
.wakeupes
= true;
105 AVR32_USBB
.UDINTESET
.suspes
= true;
108 AVR32_USBB
.UDINTESET
.eorstes
= true;
111 AVR32_USBB
.UDINTESET
.sofes
= true;
114 (&AVR32_USBB
.UECON0SET
)[USB_Endpoint_SelectedEndpoint
].rxstpes
= true;
117 #if defined(USB_CAN_BE_HOST)
119 AVR32_USBB
.UHINTESET
.hsofies
= true;
122 AVR32_USBB
.UHINTESET
.dconnies
= true;
125 AVR32_USBB
.UHINTESET
.ddiscies
= true;
128 AVR32_USBB
.UHINTESET
.rsties
= true;
131 AVR32_USBB
.USBCON
.bcerre
= true;
134 AVR32_USBB
.USBCON
.vberre
= true;
140 static inline void USB_INT_Disable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
141 static inline void USB_INT_Disable(const uint8_t Interrupt
)
146 AVR32_USBB
.USBCON
.vbuste
= false;
148 #if defined(USB_CAN_BE_BOTH)
150 AVR32_USBB
.USBCON
.idte
= false;
153 #if defined(USB_CAN_BE_DEVICE)
154 case USB_INT_WAKEUPI
:
155 AVR32_USBB
.UDINTECLR
.wakeupec
= true;
158 AVR32_USBB
.UDINTECLR
.suspec
= true;
161 AVR32_USBB
.UDINTECLR
.eorstec
= true;
164 AVR32_USBB
.UDINTECLR
.sofec
= true;
167 (&AVR32_USBB
.UECON0CLR
)[USB_Endpoint_SelectedEndpoint
].rxstpec
= true;
170 #if defined(USB_CAN_BE_HOST)
172 AVR32_USBB
.UHINTECLR
.hsofiec
= true;
175 AVR32_USBB
.UHINTECLR
.dconniec
= true;
178 AVR32_USBB
.UHINTECLR
.ddisciec
= true;
181 AVR32_USBB
.UHINTECLR
.rstiec
= true;
184 AVR32_USBB
.USBCON
.bcerre
= false;
187 AVR32_USBB
.USBCON
.vberre
= false;
193 static inline void USB_INT_Clear(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
194 static inline void USB_INT_Clear(const uint8_t Interrupt
)
199 AVR32_USBB
.USBSTACLR
.vbustic
= true;
200 (void)AVR32_USBB
.USBSTACLR
;
202 #if defined(USB_CAN_BE_BOTH)
204 AVR32_USBB
.USBSTACLR
.idtic
= true;
205 (void)AVR32_USBB
.USBSTACLR
;
208 #if defined(USB_CAN_BE_DEVICE)
209 case USB_INT_WAKEUPI
:
210 AVR32_USBB
.UDINTCLR
.wakeupc
= true;
211 (void)AVR32_USBB
.UDINTCLR
;
214 AVR32_USBB
.UDINTCLR
.suspc
= true;
215 (void)AVR32_USBB
.UDINTCLR
;
218 AVR32_USBB
.UDINTCLR
.eorstc
= true;
219 (void)AVR32_USBB
.UDINTCLR
;
222 AVR32_USBB
.UDINTCLR
.sofc
= true;
223 (void)AVR32_USBB
.UDINTCLR
;
226 (&AVR32_USBB
.UESTA0CLR
)[USB_Endpoint_SelectedEndpoint
].rxstpic
= true;
229 #if defined(USB_CAN_BE_HOST)
231 AVR32_USBB
.UHINTCLR
.hsofic
= true;
232 (void)AVR32_USBB
.UHINTCLR
;
235 AVR32_USBB
.UHINTCLR
.dconnic
= true;
236 (void)AVR32_USBB
.UHINTCLR
;
239 AVR32_USBB
.UHINTCLR
.ddiscic
= true;
240 (void)AVR32_USBB
.UHINTCLR
;
243 AVR32_USBB
.UHINTCLR
.rstic
= true;
244 (void)AVR32_USBB
.UHINTCLR
;
247 AVR32_USBB
.USBSTACLR
.bcerric
= true;
248 (void)AVR32_USBB
.USBSTACLR
;
251 AVR32_USBB
.USBSTACLR
.vberric
= true;
252 (void)AVR32_USBB
.USBSTACLR
;
258 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
259 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
)
264 return AVR32_USBB
.USBCON
.vbuste
;
265 #if defined(USB_CAN_BE_BOTH)
267 return AVR32_USBB
.USBCON
.idte
;
269 #if defined(USB_CAN_BE_DEVICE)
270 case USB_INT_WAKEUPI
:
271 return AVR32_USBB
.UDINTE
.wakeupe
;
273 return AVR32_USBB
.UDINTE
.suspe
;
275 return AVR32_USBB
.UDINTE
.eorste
;
277 return AVR32_USBB
.UDINTE
.sofe
;
279 return (&AVR32_USBB
.UECON0
)[USB_Endpoint_SelectedEndpoint
].rxstpe
;
281 #if defined(USB_CAN_BE_HOST)
283 return AVR32_USBB
.UHINTE
.hsofie
;
285 return AVR32_USBB
.UHINTE
.dconnie
;
287 return AVR32_USBB
.UHINTE
.ddiscie
;
289 return AVR32_USBB
.UHINTE
.rstie
;
291 return AVR32_USBB
.USBCON
.bcerre
;
293 return AVR32_USBB
.USBCON
.vberre
;
300 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
301 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
)
306 return AVR32_USBB
.USBSTA
.vbusti
;
307 #if defined(USB_CAN_BE_BOTH)
309 return AVR32_USBB
.USBSTA
.idti
;
311 #if defined(USB_CAN_BE_DEVICE)
312 case USB_INT_WAKEUPI
:
313 return AVR32_USBB
.UDINT
.wakeup
;
315 return AVR32_USBB
.UDINT
.susp
;
317 return AVR32_USBB
.UDINT
.eorst
;
319 return AVR32_USBB
.UDINT
.sof
;
321 return (&AVR32_USBB
.UESTA0
)[USB_Endpoint_SelectedEndpoint
].rxstpi
;
323 #if defined(USB_CAN_BE_HOST)
325 return AVR32_USBB
.UHINT
.hsofi
;
327 return AVR32_USBB
.UHINT
.dconni
;
329 return AVR32_USBB
.UHINT
.ddisci
;
331 return AVR32_USBB
.UHINT
.rsti
;
333 return AVR32_USBB
.USBSTA
.bcerri
;
335 return AVR32_USBB
.USBSTA
.vberri
;
343 #include "../USBMode.h"
344 #include "../Events.h"
345 #include "../USBController.h"
347 /* Function Prototypes: */
348 void USB_INT_ClearAllInterrupts(void);
349 void USB_INT_DisableAllInterrupts(void);
352 /* Public Interface - May be used in end-application: */
353 /* Function Prototypes: */
354 #if defined(__DOXYGEN__)
355 /** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
356 * linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
357 * using the user application's preferred USB controller driver.
359 void USB_GEN_vect(void);
362 /* Disable C linkage for C++ Compilers: */
363 #if defined(__cplusplus)