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 void USB_INT_RegisterHandlers(void)
89 // Not required for AVR8
92 static inline void USB_INT_Enable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
93 static inline void USB_INT_Enable(const uint8_t Interrupt
)
97 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
99 USBCON
|= (1 << VBUSTE
);
102 #if defined(USB_CAN_BE_BOTH)
104 USBCON
|= (1 << IDTE
);
107 #if defined(USB_CAN_BE_DEVICE)
108 case USB_INT_WAKEUPI
:
109 UDIEN
|= (1 << WAKEUPE
);
112 UDIEN
|= (1 << SUSPE
);
115 UDIEN
|= (1 << EORSTE
);
118 UDIEN
|= (1 << SOFE
);
121 UEIENX
|= (1 << RXSTPE
);
124 #if defined(USB_CAN_BE_HOST)
126 UHIEN
|= (1 << HSOFE
);
129 UHIEN
|= (1 << DCONNE
);
132 UHIEN
|= (1 << DDISCE
);
135 UHIEN
|= (1 << RSTE
);
138 OTGIEN
|= (1 << BCERRE
);
141 OTGIEN
|= (1 << VBERRE
);
144 OTGIEN
|= (1 << SRPE
);
150 static inline void USB_INT_Disable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
151 static inline void USB_INT_Disable(const uint8_t Interrupt
)
155 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
157 USBCON
&= ~(1 << VBUSTE
);
160 #if defined(USB_CAN_BE_BOTH)
162 USBCON
&= ~(1 << IDTE
);
165 #if defined(USB_CAN_BE_DEVICE)
166 case USB_INT_WAKEUPI
:
167 UDIEN
&= ~(1 << WAKEUPE
);
170 UDIEN
&= ~(1 << SUSPE
);
173 UDIEN
&= ~(1 << EORSTE
);
176 UDIEN
&= ~(1 << SOFE
);
179 UEIENX
&= ~(1 << RXSTPE
);
182 #if defined(USB_CAN_BE_HOST)
184 UHIEN
&= ~(1 << HSOFE
);
187 UHIEN
&= ~(1 << DCONNE
);
190 UHIEN
&= ~(1 << DDISCE
);
193 UHIEN
&= ~(1 << RSTE
);
196 OTGIEN
&= ~(1 << BCERRE
);
199 OTGIEN
&= ~(1 << VBERRE
);
202 OTGIEN
&= ~(1 << SRPE
);
208 static inline void USB_INT_Clear(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
209 static inline void USB_INT_Clear(const uint8_t Interrupt
)
213 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
215 USBINT
&= ~(1 << VBUSTI
);
218 #if defined(USB_CAN_BE_BOTH)
220 USBINT
&= ~(1 << IDTI
);
223 #if defined(USB_CAN_BE_DEVICE)
224 case USB_INT_WAKEUPI
:
225 UDINT
&= ~(1 << WAKEUPI
);
228 UDINT
&= ~(1 << SUSPI
);
231 UDINT
&= ~(1 << EORSTI
);
234 UDINT
&= ~(1 << SOFI
);
237 UEINTX
&= ~(1 << RXSTPI
);
240 #if defined(USB_CAN_BE_HOST)
242 UHINT
&= ~(1 << HSOFI
);
245 UHINT
&= ~(1 << DCONNI
);
248 UHINT
&= ~(1 << DDISCI
);
251 UHINT
&= ~(1 << RSTI
);
254 OTGINT
&= ~(1 << BCERRI
);
257 OTGINT
&= ~(1 << VBERRI
);
260 OTGINT
&= ~(1 << SRPI
);
266 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
267 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
)
271 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
273 return (USBCON
& (1 << VBUSTE
));
275 #if defined(USB_CAN_BE_BOTH)
277 return (USBCON
& (1 << IDTE
));
279 #if defined(USB_CAN_BE_DEVICE)
280 case USB_INT_WAKEUPI
:
281 return (UDIEN
& (1 << WAKEUPE
));
283 return (UDIEN
& (1 << SUSPE
));
285 return (UDIEN
& (1 << EORSTE
));
287 return (UDIEN
& (1 << SOFE
));
289 return (UEIENX
& (1 << RXSTPE
));
291 #if defined(USB_CAN_BE_HOST)
293 return (UHIEN
& (1 << HSOFE
));
295 return (UHIEN
& (1 << DCONNE
));
297 return (UHIEN
& (1 << DDISCE
));
299 return (UHIEN
& (1 << RSTE
));
301 return (OTGIEN
& (1 << BCERRE
));
303 return (OTGIEN
& (1 << VBERRE
));
305 return (OTGIEN
& (1 << SRPE
));
312 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
313 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
)
317 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
319 return (USBINT
& (1 << VBUSTI
));
321 #if defined(USB_CAN_BE_BOTH)
323 return (USBINT
& (1 << IDTI
));
325 #if defined(USB_CAN_BE_DEVICE)
326 case USB_INT_WAKEUPI
:
327 return (UDINT
& (1 << WAKEUPI
));
329 return (UDINT
& (1 << SUSPI
));
331 return (UDINT
& (1 << EORSTI
));
333 return (UDINT
& (1 << SOFI
));
335 return (UEINTX
& (1 << RXSTPI
));
337 #if defined(USB_CAN_BE_HOST)
339 return (UHINT
& (1 << HSOFI
));
341 return (UHINT
& (1 << DCONNI
));
343 return (UHINT
& (1 << DDISCI
));
345 return (UHINT
& (1 << RSTI
));
347 return (OTGINT
& (1 << BCERRI
));
349 return (OTGINT
& (1 << VBERRI
));
351 return (OTGINT
& (1 << SRPI
));
359 #include "../USBMode.h"
360 #include "../Events.h"
361 #include "../USBController.h"
363 /* Function Prototypes: */
364 void USB_INT_ClearAllInterrupts(void);
365 void USB_INT_DisableAllInterrupts(void);
368 /* Disable C linkage for C++ Compilers: */
369 #if defined(__cplusplus)