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"
46 #include "../Endpoint.h"
48 /* Enable C linkage for C++ Compilers: */
49 #if defined(__cplusplus)
53 /* Preprocessor Checks: */
54 #if !defined(__INCLUDE_FROM_USB_DRIVER)
55 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
58 /* Private Interface - For use in library only: */
59 #if !defined(__DOXYGEN__)
64 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
67 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
74 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
84 /* Inline Functions: */
85 static inline void USB_INT_Enable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
86 static inline void USB_INT_Enable(const uint8_t Interrupt
)
91 AVR32_USBB
.USBCON
.vbuste
= true;
93 #if defined(USB_CAN_BE_BOTH)
95 AVR32_USBB
.USBCON
.idte
= true;
98 #if defined(USB_CAN_BE_DEVICE)
100 AVR32_USBB
.UDINTESET
.wakeupes
= true;
103 AVR32_USBB
.UDINTESET
.suspes
= true;
106 AVR32_USBB
.UDINTESET
.eorstes
= true;
109 AVR32_USBB
.UDINTESET
.sofes
= true;
112 (&AVR32_USBB
.UECON0SET
)[USB_SelectedEndpoint
].rxstpes
= true;
115 #if defined(USB_CAN_BE_HOST)
117 AVR32_USBB
.UHINTESET
.hsofies
= true;
120 AVR32_USBB
.UHINTESET
.dconnies
= true;
123 AVR32_USBB
.UHINTESET
.ddiscies
= true;
126 AVR32_USBB
.UHINTESET
.rsties
= true;
129 AVR32_USBB
.USBCON
.bcerre
= true;
132 AVR32_USBB
.USBCON
.vberre
= true;
138 static inline void USB_INT_Disable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
139 static inline void USB_INT_Disable(const uint8_t Interrupt
)
144 AVR32_USBB
.USBCON
.vbuste
= false;
146 #if defined(USB_CAN_BE_BOTH)
148 AVR32_USBB
.USBCON
.idte
= false;
151 #if defined(USB_CAN_BE_DEVICE)
152 case USB_INT_WAKEUPI
:
153 AVR32_USBB
.UDINTECLR
.wakeupec
= true;
156 AVR32_USBB
.UDINTECLR
.suspec
= true;
159 AVR32_USBB
.UDINTECLR
.eorstec
= true;
162 AVR32_USBB
.UDINTECLR
.sofec
= true;
165 (&AVR32_USBB
.UECON0CLR
)[USB_SelectedEndpoint
].rxstpec
= true;
168 #if defined(USB_CAN_BE_HOST)
170 AVR32_USBB
.UHINTECLR
.hsofiec
= true;
173 AVR32_USBB
.UHINTECLR
.dconniec
= true;
176 AVR32_USBB
.UHINTECLR
.ddisciec
= true;
179 AVR32_USBB
.UHINTECLR
.rstiec
= true;
182 AVR32_USBB
.USBCON
.bcerre
= false;
185 AVR32_USBB
.USBCON
.vberre
= false;
191 static inline void USB_INT_Clear(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
192 static inline void USB_INT_Clear(const uint8_t Interrupt
)
197 AVR32_USBB
.USBSTACLR
.vbustic
= true;
198 (void)AVR32_USBB
.USBSTACLR
;
200 #if defined(USB_CAN_BE_BOTH)
202 AVR32_USBB
.USBSTACLR
.idtic
= true;
203 (void)AVR32_USBB
.USBSTACLR
;
206 #if defined(USB_CAN_BE_DEVICE)
207 case USB_INT_WAKEUPI
:
208 AVR32_USBB
.UDINTCLR
.wakeupc
= true;
209 (void)AVR32_USBB
.UDINTCLR
;
212 AVR32_USBB
.UDINTCLR
.suspc
= true;
213 (void)AVR32_USBB
.UDINTCLR
;
216 AVR32_USBB
.UDINTCLR
.eorstc
= true;
217 (void)AVR32_USBB
.UDINTCLR
;
220 AVR32_USBB
.UDINTCLR
.sofc
= true;
221 (void)AVR32_USBB
.UDINTCLR
;
224 (&AVR32_USBB
.UESTA0CLR
)[USB_SelectedEndpoint
].rxstpic
= true;
227 #if defined(USB_CAN_BE_HOST)
229 AVR32_USBB
.UHINTCLR
.hsofic
= true;
230 (void)AVR32_USBB
.UHINTCLR
;
233 AVR32_USBB
.UHINTCLR
.dconnic
= true;
234 (void)AVR32_USBB
.UHINTCLR
;
237 AVR32_USBB
.UHINTCLR
.ddiscic
= true;
238 (void)AVR32_USBB
.UHINTCLR
;
241 AVR32_USBB
.UHINTCLR
.rstic
= true;
242 (void)AVR32_USBB
.UHINTCLR
;
245 AVR32_USBB
.USBSTACLR
.bcerric
= true;
246 (void)AVR32_USBB
.USBSTACLR
;
249 AVR32_USBB
.USBSTACLR
.vberric
= true;
250 (void)AVR32_USBB
.USBSTACLR
;
256 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
257 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
)
262 return AVR32_USBB
.USBCON
.vbuste
;
263 #if defined(USB_CAN_BE_BOTH)
265 return AVR32_USBB
.USBCON
.idte
;
267 #if defined(USB_CAN_BE_DEVICE)
268 case USB_INT_WAKEUPI
:
269 return AVR32_USBB
.UDINTE
.wakeupe
;
271 return AVR32_USBB
.UDINTE
.suspe
;
273 return AVR32_USBB
.UDINTE
.eorste
;
275 return AVR32_USBB
.UDINTE
.sofe
;
277 return (&AVR32_USBB
.UECON0
)[USB_SelectedEndpoint
].rxstpe
;
279 #if defined(USB_CAN_BE_HOST)
281 return AVR32_USBB
.UHINTE
.hsofie
;
283 return AVR32_USBB
.UHINTE
.dconnie
;
285 return AVR32_USBB
.UHINTE
.ddiscie
;
287 return AVR32_USBB
.UHINTE
.rstie
;
289 return AVR32_USBB
.USBCON
.bcerre
;
291 return AVR32_USBB
.USBCON
.vberre
;
298 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
299 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
)
304 return AVR32_USBB
.USBSTA
.vbusti
;
305 #if defined(USB_CAN_BE_BOTH)
307 return AVR32_USBB
.USBSTA
.idti
;
309 #if defined(USB_CAN_BE_DEVICE)
310 case USB_INT_WAKEUPI
:
311 return AVR32_USBB
.UDINT
.wakeup
;
313 return AVR32_USBB
.UDINT
.susp
;
315 return AVR32_USBB
.UDINT
.eorst
;
317 return AVR32_USBB
.UDINT
.sof
;
319 return (&AVR32_USBB
.UESTA0
)[USB_SelectedEndpoint
].rxstpi
;
321 #if defined(USB_CAN_BE_HOST)
323 return AVR32_USBB
.UHINT
.hsofi
;
325 return AVR32_USBB
.UHINT
.dconni
;
327 return AVR32_USBB
.UHINT
.ddisci
;
329 return AVR32_USBB
.UHINT
.rsti
;
331 return AVR32_USBB
.USBSTA
.bcerri
;
333 return AVR32_USBB
.USBSTA
.vberri
;
341 #include "../USBMode.h"
342 #include "../Events.h"
343 #include "../USBController.h"
345 /* Function Prototypes: */
346 void USB_INT_ClearAllInterrupts(void);
347 void USB_INT_DisableAllInterrupts(void);
350 /* Public Interface - May be used in end-application: */
351 /* ISR Prototypes: */
352 #if defined(__DOXYGEN__)
353 /** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
354 * linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
355 * using the user application's preferred USB controller driver.
357 void USB_GEN_vect(void);
362 /* Disable C linkage for C++ Compilers: */
363 #if defined(__cplusplus)