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__)
78 /* Inline Functions: */
79 static inline void USB_INT_Enable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
80 static inline void USB_INT_Enable(const uint8_t Interrupt
)
85 USBCON
|= (1 << VBUSTE
);
88 USBCON
|= (1 << IDTE
);
91 UDIEN
|= (1 << WAKEUPE
);
94 UDIEN
|= (1 << SUSPE
);
97 UDIEN
|= (1 << EORSTE
);
100 UDIEN
|= (1 << SOFE
);
103 UHIEN
|= (1 << HSOFE
);
106 UHIEN
|= (1 << DCONNE
);
109 UHIEN
|= (1 << DDISCE
);
112 UHIEN
|= (1 << RSTE
);
115 OTGIEN
|= (1 << BCERRE
);
118 OTGIEN
|= (1 << VBERRE
);
121 OTGIEN
|= (1 << SRPE
);
124 UEIENX
|= (1 << RXSTPE
);
129 static inline void USB_INT_Disable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
130 static inline void USB_INT_Disable(const uint8_t Interrupt
)
135 USBCON
&= ~(1 << VBUSTE
);
138 USBCON
&= ~(1 << IDTE
);
140 case USB_INT_WAKEUPI
:
141 UDIEN
&= ~(1 << WAKEUPE
);
144 UDIEN
&= ~(1 << SUSPE
);
147 UDIEN
&= ~(1 << EORSTE
);
150 UDIEN
&= ~(1 << SOFE
);
153 UHIEN
&= ~(1 << HSOFE
);
156 UHIEN
&= ~(1 << DCONNE
);
159 UHIEN
&= ~(1 << DDISCE
);
162 UHIEN
&= ~(1 << RSTE
);
165 OTGIEN
&= ~(1 << BCERRE
);
168 OTGIEN
&= ~(1 << VBERRE
);
171 OTGIEN
&= ~(1 << SRPE
);
174 UEIENX
&= ~(1 << RXSTPE
);
179 static inline void USB_INT_Clear(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
;
180 static inline void USB_INT_Clear(const uint8_t Interrupt
)
185 USBINT
&= ~(1 << VBUSTI
);
188 USBINT
&= ~(1 << IDTI
);
190 case USB_INT_WAKEUPI
:
191 UDINT
&= ~(1 << WAKEUPI
);
194 UDINT
&= ~(1 << SUSPI
);
197 UDINT
&= ~(1 << EORSTI
);
200 UDINT
&= ~(1 << SOFI
);
203 UHINT
&= ~(1 << HSOFI
);
206 UHINT
&= ~(1 << DCONNI
);
209 UHINT
&= ~(1 << DDISCI
);
212 UHINT
&= ~(1 << RSTI
);
215 OTGINT
&= ~(1 << BCERRI
);
218 OTGINT
&= ~(1 << VBERRI
);
221 OTGINT
&= ~(1 << SRPI
);
224 UEINTX
&= ~(1 << RXSTPI
);
229 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
230 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
)
235 return (USBCON
& (1 << VBUSTE
));
237 return (USBCON
& (1 << IDTE
));
238 case USB_INT_WAKEUPI
:
239 return (UDIEN
& (1 << WAKEUPE
));
241 return (UDIEN
& (1 << SUSPE
));
243 return (UDIEN
& (1 << EORSTE
));
245 return (UDIEN
& (1 << SOFE
));
247 return (UHIEN
& (1 << HSOFE
));
249 return (UHIEN
& (1 << DCONNE
));
251 return (UHIEN
& (1 << DDISCE
));
253 return (UHIEN
& (1 << RSTE
));
255 return (OTGIEN
& (1 << BCERRE
));
257 return (OTGIEN
& (1 << VBERRE
));
259 return (OTGIEN
& (1 << SRPE
));
261 return (UEIENX
& (1 << RXSTPE
));
268 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
;
269 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
)
274 return (USBINT
& (1 << VBUSTI
));
276 return (USBINT
& (1 << IDTI
));
277 case USB_INT_WAKEUPI
:
278 return (UDINT
& (1 << WAKEUPI
));
280 return (UDINT
& (1 << SUSPI
));
282 return (UDINT
& (1 << EORSTI
));
284 return (UDINT
& (1 << SOFI
));
286 return (UHINT
& (1 << HSOFI
));
288 return (UHINT
& (1 << DCONNI
));
290 return (UHINT
& (1 << DDISCI
));
292 return (UHINT
& (1 << RSTI
));
294 return (OTGINT
& (1 << BCERRI
));
296 return (OTGINT
& (1 << VBERRI
));
298 return (OTGINT
& (1 << SRPI
));
300 return (UEINTX
& (1 << RXSTPI
));
307 #include "../USBMode.h"
308 #include "../Events.h"
309 #include "../USBController.h"
311 /* Function Prototypes: */
312 void USB_INT_ClearAllInterrupts(void);
313 void USB_INT_DisableAllInterrupts(void);
316 /* Disable C linkage for C++ Compilers: */
317 #if defined(__cplusplus)