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 AVR8 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_AVR8_H__
42 #define __USBINTERRUPT_AVR8_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__)
62 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__))
65 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
68 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
75 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
86 /* Inline Functions: */
87 static inline uint_reg_t
USB_INT_GetGlobalEnableState(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
88 static inline uint_reg_t
USB_INT_GetGlobalEnableState(void)
94 static inline void USB_INT_SetGlobalEnableState(uint_reg_t GlobalIntState
) ATTR_ALWAYS_INLINE
;
95 static inline void USB_INT_SetGlobalEnableState(uint_reg_t GlobalIntState
)
98 SREG
= GlobalIntState
;
102 static inline void USB_INT_GlobalEnable(void) ATTR_ALWAYS_INLINE
;
103 static inline void USB_INT_GlobalEnable(void)
105 GCC_MEMORY_BARRIER();
107 GCC_MEMORY_BARRIER();
110 static inline void USB_INT_GlobalDisable(void) ATTR_ALWAYS_INLINE
;
111 static inline void USB_INT_GlobalDisable(void)
113 GCC_MEMORY_BARRIER();
115 GCC_MEMORY_BARRIER();
118 static inline void USB_INT_Enable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
119 static inline void USB_INT_Enable(const uint8_t Interrupt
)
123 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
125 USBCON
|= (1 << VBUSTE
);
128 #if defined(USB_CAN_BE_BOTH)
130 USBCON
|= (1 << IDTE
);
133 #if defined(USB_CAN_BE_DEVICE)
134 case USB_INT_WAKEUPI
:
135 UDIEN
|= (1 << WAKEUPE
);
138 UDIEN
|= (1 << SUSPE
);
141 UDIEN
|= (1 << EORSTE
);
144 UDIEN
|= (1 << SOFE
);
147 UEIENX
|= (1 << RXSTPE
);
150 #if defined(USB_CAN_BE_HOST)
152 UHIEN
|= (1 << HSOFE
);
155 UHIEN
|= (1 << DCONNE
);
158 UHIEN
|= (1 << DDISCE
);
161 UHIEN
|= (1 << RSTE
);
164 OTGIEN
|= (1 << BCERRE
);
167 OTGIEN
|= (1 << VBERRE
);
170 OTGIEN
|= (1 << SRPE
);
176 static inline void USB_INT_Disable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
177 static inline void USB_INT_Disable(const uint8_t Interrupt
)
181 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
183 USBCON
&= ~(1 << VBUSTE
);
186 #if defined(USB_CAN_BE_BOTH)
188 USBCON
&= ~(1 << IDTE
);
191 #if defined(USB_CAN_BE_DEVICE)
192 case USB_INT_WAKEUPI
:
193 UDIEN
&= ~(1 << WAKEUPE
);
196 UDIEN
&= ~(1 << SUSPE
);
199 UDIEN
&= ~(1 << EORSTE
);
202 UDIEN
&= ~(1 << SOFE
);
205 UEIENX
&= ~(1 << RXSTPE
);
208 #if defined(USB_CAN_BE_HOST)
210 UHIEN
&= ~(1 << HSOFE
);
213 UHIEN
&= ~(1 << DCONNE
);
216 UHIEN
&= ~(1 << DDISCE
);
219 UHIEN
&= ~(1 << RSTE
);
222 OTGIEN
&= ~(1 << BCERRE
);
225 OTGIEN
&= ~(1 << VBERRE
);
228 OTGIEN
&= ~(1 << SRPE
);
234 static inline void USB_INT_Clear(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
235 static inline void USB_INT_Clear(const uint8_t Interrupt
)
239 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
241 USBINT
&= ~(1 << VBUSTI
);
244 #if defined(USB_CAN_BE_BOTH)
246 USBINT
&= ~(1 << IDTI
);
249 #if defined(USB_CAN_BE_DEVICE)
250 case USB_INT_WAKEUPI
:
251 UDINT
&= ~(1 << WAKEUPI
);
254 UDINT
&= ~(1 << SUSPI
);
257 UDINT
&= ~(1 << EORSTI
);
260 UDINT
&= ~(1 << SOFI
);
263 UEINTX
&= ~(1 << RXSTPI
);
266 #if defined(USB_CAN_BE_HOST)
268 UHINT
&= ~(1 << HSOFI
);
271 UHINT
&= ~(1 << DCONNI
);
274 UHINT
&= ~(1 << DDISCI
);
277 UHINT
&= ~(1 << RSTI
);
280 OTGINT
&= ~(1 << BCERRI
);
283 OTGINT
&= ~(1 << VBERRI
);
286 OTGINT
&= ~(1 << SRPI
);
292 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
293 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
)
297 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
299 return (USBCON
& (1 << VBUSTE
));
301 #if defined(USB_CAN_BE_BOTH)
303 return (USBCON
& (1 << IDTE
));
305 #if defined(USB_CAN_BE_DEVICE)
306 case USB_INT_WAKEUPI
:
307 return (UDIEN
& (1 << WAKEUPE
));
309 return (UDIEN
& (1 << SUSPE
));
311 return (UDIEN
& (1 << EORSTE
));
313 return (UDIEN
& (1 << SOFE
));
315 return (UEIENX
& (1 << RXSTPE
));
317 #if defined(USB_CAN_BE_HOST)
319 return (UHIEN
& (1 << HSOFE
));
321 return (UHIEN
& (1 << DCONNE
));
323 return (UHIEN
& (1 << DDISCE
));
325 return (UHIEN
& (1 << RSTE
));
327 return (OTGIEN
& (1 << BCERRE
));
329 return (OTGIEN
& (1 << VBERRE
));
331 return (OTGIEN
& (1 << SRPE
));
338 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
339 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
)
343 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
345 return (USBINT
& (1 << VBUSTI
));
347 #if defined(USB_CAN_BE_BOTH)
349 return (USBINT
& (1 << IDTI
));
351 #if defined(USB_CAN_BE_DEVICE)
352 case USB_INT_WAKEUPI
:
353 return (UDINT
& (1 << WAKEUPI
));
355 return (UDINT
& (1 << SUSPI
));
357 return (UDINT
& (1 << EORSTI
));
359 return (UDINT
& (1 << SOFI
));
361 return (UEINTX
& (1 << RXSTPI
));
363 #if defined(USB_CAN_BE_HOST)
365 return (UHINT
& (1 << HSOFI
));
367 return (UHINT
& (1 << DCONNI
));
369 return (UHINT
& (1 << DDISCI
));
371 return (UHINT
& (1 << RSTI
));
373 return (OTGINT
& (1 << BCERRI
));
375 return (OTGINT
& (1 << VBERRI
));
377 return (OTGINT
& (1 << SRPI
));
385 #include "../USBMode.h"
386 #include "../Events.h"
387 #include "../USBController.h"
389 /* Function Prototypes: */
390 void USB_INT_ClearAllInterrupts(void);
391 void USB_INT_DisableAllInterrupts(void);
394 /* Disable C linkage for C++ Compilers: */
395 #if defined(__cplusplus)