Add in USB_INT_RegisterHandlers() internal function to register the interrupt handler...
[pub/USBasp.git] / LUFA / Drivers / USB / Core / AVR8 / USBInterrupt_AVR8.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2011.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 * \brief USB Controller Interrupt definitions for the AVR8 microcontrollers.
33 *
34 * This file contains definitions required for the correct handling of low level USB service routine interrupts
35 * from the USB controller.
36 *
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.
39 */
40
41 #ifndef __USBINTERRUPT_AVR8_H__
42 #define __USBINTERRUPT_AVR8_H__
43
44 /* Includes: */
45 #include "../../../../Common/Common.h"
46
47 /* Enable C linkage for C++ Compilers: */
48 #if defined(__cplusplus)
49 extern "C" {
50 #endif
51
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.
55 #endif
56
57 /* Private Interface - For use in library only: */
58 #if !defined(__DOXYGEN__)
59 /* Enums: */
60 enum USB_Interrupts_t
61 {
62 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__))
63 USB_INT_VBUSTI = 0,
64 #endif
65 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
66 USB_INT_IDTI = 1,
67 #endif
68 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
69 USB_INT_WAKEUPI = 2,
70 USB_INT_SUSPI = 3,
71 USB_INT_EORSTI = 4,
72 USB_INT_SOFI = 5,
73 USB_INT_RXSTPI = 6,
74 #endif
75 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
76 USB_INT_HSOFI = 7,
77 USB_INT_DCONNI = 8,
78 USB_INT_DDISCI = 9,
79 USB_INT_RSTI = 10,
80 USB_INT_BCERRI = 11,
81 USB_INT_VBERRI = 12,
82 USB_INT_SRPI = 13,
83 #endif
84 };
85
86 /* Inline Functions: */
87 static inline void USB_INT_RegisterHandlers(void)
88 {
89 // Not required for AVR8
90 }
91
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)
94 {
95 switch (Interrupt)
96 {
97 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
98 case USB_INT_VBUSTI:
99 USBCON |= (1 << VBUSTE);
100 break;
101 #endif
102 #if defined(USB_CAN_BE_BOTH)
103 case USB_INT_IDTI:
104 USBCON |= (1 << IDTE);
105 break;
106 #endif
107 #if defined(USB_CAN_BE_DEVICE)
108 case USB_INT_WAKEUPI:
109 UDIEN |= (1 << WAKEUPE);
110 break;
111 case USB_INT_SUSPI:
112 UDIEN |= (1 << SUSPE);
113 break;
114 case USB_INT_EORSTI:
115 UDIEN |= (1 << EORSTE);
116 break;
117 case USB_INT_SOFI:
118 UDIEN |= (1 << SOFE);
119 break;
120 case USB_INT_RXSTPI:
121 UEIENX |= (1 << RXSTPE);
122 break;
123 #endif
124 #if defined(USB_CAN_BE_HOST)
125 case USB_INT_HSOFI:
126 UHIEN |= (1 << HSOFE);
127 break;
128 case USB_INT_DCONNI:
129 UHIEN |= (1 << DCONNE);
130 break;
131 case USB_INT_DDISCI:
132 UHIEN |= (1 << DDISCE);
133 break;
134 case USB_INT_RSTI:
135 UHIEN |= (1 << RSTE);
136 break;
137 case USB_INT_BCERRI:
138 OTGIEN |= (1 << BCERRE);
139 break;
140 case USB_INT_VBERRI:
141 OTGIEN |= (1 << VBERRE);
142 break;
143 case USB_INT_SRPI:
144 OTGIEN |= (1 << SRPE);
145 break;
146 #endif
147 }
148 }
149
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)
152 {
153 switch (Interrupt)
154 {
155 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
156 case USB_INT_VBUSTI:
157 USBCON &= ~(1 << VBUSTE);
158 break;
159 #endif
160 #if defined(USB_CAN_BE_BOTH)
161 case USB_INT_IDTI:
162 USBCON &= ~(1 << IDTE);
163 break;
164 #endif
165 #if defined(USB_CAN_BE_DEVICE)
166 case USB_INT_WAKEUPI:
167 UDIEN &= ~(1 << WAKEUPE);
168 break;
169 case USB_INT_SUSPI:
170 UDIEN &= ~(1 << SUSPE);
171 break;
172 case USB_INT_EORSTI:
173 UDIEN &= ~(1 << EORSTE);
174 break;
175 case USB_INT_SOFI:
176 UDIEN &= ~(1 << SOFE);
177 break;
178 case USB_INT_RXSTPI:
179 UEIENX &= ~(1 << RXSTPE);
180 break;
181 #endif
182 #if defined(USB_CAN_BE_HOST)
183 case USB_INT_HSOFI:
184 UHIEN &= ~(1 << HSOFE);
185 break;
186 case USB_INT_DCONNI:
187 UHIEN &= ~(1 << DCONNE);
188 break;
189 case USB_INT_DDISCI:
190 UHIEN &= ~(1 << DDISCE);
191 break;
192 case USB_INT_RSTI:
193 UHIEN &= ~(1 << RSTE);
194 break;
195 case USB_INT_BCERRI:
196 OTGIEN &= ~(1 << BCERRE);
197 break;
198 case USB_INT_VBERRI:
199 OTGIEN &= ~(1 << VBERRE);
200 break;
201 case USB_INT_SRPI:
202 OTGIEN &= ~(1 << SRPE);
203 break;
204 #endif
205 }
206 }
207
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)
210 {
211 switch (Interrupt)
212 {
213 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
214 case USB_INT_VBUSTI:
215 USBINT &= ~(1 << VBUSTI);
216 break;
217 #endif
218 #if defined(USB_CAN_BE_BOTH)
219 case USB_INT_IDTI:
220 USBINT &= ~(1 << IDTI);
221 break;
222 #endif
223 #if defined(USB_CAN_BE_DEVICE)
224 case USB_INT_WAKEUPI:
225 UDINT &= ~(1 << WAKEUPI);
226 break;
227 case USB_INT_SUSPI:
228 UDINT &= ~(1 << SUSPI);
229 break;
230 case USB_INT_EORSTI:
231 UDINT &= ~(1 << EORSTI);
232 break;
233 case USB_INT_SOFI:
234 UDINT &= ~(1 << SOFI);
235 break;
236 case USB_INT_RXSTPI:
237 UEINTX &= ~(1 << RXSTPI);
238 break;
239 #endif
240 #if defined(USB_CAN_BE_HOST)
241 case USB_INT_HSOFI:
242 UHINT &= ~(1 << HSOFI);
243 break;
244 case USB_INT_DCONNI:
245 UHINT &= ~(1 << DCONNI);
246 break;
247 case USB_INT_DDISCI:
248 UHINT &= ~(1 << DDISCI);
249 break;
250 case USB_INT_RSTI:
251 UHINT &= ~(1 << RSTI);
252 break;
253 case USB_INT_BCERRI:
254 OTGINT &= ~(1 << BCERRI);
255 break;
256 case USB_INT_VBERRI:
257 OTGINT &= ~(1 << VBERRI);
258 break;
259 case USB_INT_SRPI:
260 OTGINT &= ~(1 << SRPI);
261 break;
262 #endif
263 }
264 }
265
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)
268 {
269 switch (Interrupt)
270 {
271 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
272 case USB_INT_VBUSTI:
273 return (USBCON & (1 << VBUSTE));
274 #endif
275 #if defined(USB_CAN_BE_BOTH)
276 case USB_INT_IDTI:
277 return (USBCON & (1 << IDTE));
278 #endif
279 #if defined(USB_CAN_BE_DEVICE)
280 case USB_INT_WAKEUPI:
281 return (UDIEN & (1 << WAKEUPE));
282 case USB_INT_SUSPI:
283 return (UDIEN & (1 << SUSPE));
284 case USB_INT_EORSTI:
285 return (UDIEN & (1 << EORSTE));
286 case USB_INT_SOFI:
287 return (UDIEN & (1 << SOFE));
288 case USB_INT_RXSTPI:
289 return (UEIENX & (1 << RXSTPE));
290 #endif
291 #if defined(USB_CAN_BE_HOST)
292 case USB_INT_HSOFI:
293 return (UHIEN & (1 << HSOFE));
294 case USB_INT_DCONNI:
295 return (UHIEN & (1 << DCONNE));
296 case USB_INT_DDISCI:
297 return (UHIEN & (1 << DDISCE));
298 case USB_INT_RSTI:
299 return (UHIEN & (1 << RSTE));
300 case USB_INT_BCERRI:
301 return (OTGIEN & (1 << BCERRE));
302 case USB_INT_VBERRI:
303 return (OTGIEN & (1 << VBERRE));
304 case USB_INT_SRPI:
305 return (OTGIEN & (1 << SRPE));
306 #endif
307 }
308
309 return false;
310 }
311
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)
314 {
315 switch (Interrupt)
316 {
317 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
318 case USB_INT_VBUSTI:
319 return (USBINT & (1 << VBUSTI));
320 #endif
321 #if defined(USB_CAN_BE_BOTH)
322 case USB_INT_IDTI:
323 return (USBINT & (1 << IDTI));
324 #endif
325 #if defined(USB_CAN_BE_DEVICE)
326 case USB_INT_WAKEUPI:
327 return (UDINT & (1 << WAKEUPI));
328 case USB_INT_SUSPI:
329 return (UDINT & (1 << SUSPI));
330 case USB_INT_EORSTI:
331 return (UDINT & (1 << EORSTI));
332 case USB_INT_SOFI:
333 return (UDINT & (1 << SOFI));
334 case USB_INT_RXSTPI:
335 return (UEINTX & (1 << RXSTPI));
336 #endif
337 #if defined(USB_CAN_BE_HOST)
338 case USB_INT_HSOFI:
339 return (UHINT & (1 << HSOFI));
340 case USB_INT_DCONNI:
341 return (UHINT & (1 << DCONNI));
342 case USB_INT_DDISCI:
343 return (UHINT & (1 << DDISCI));
344 case USB_INT_RSTI:
345 return (UHINT & (1 << RSTI));
346 case USB_INT_BCERRI:
347 return (OTGINT & (1 << BCERRI));
348 case USB_INT_VBERRI:
349 return (OTGINT & (1 << VBERRI));
350 case USB_INT_SRPI:
351 return (OTGINT & (1 << SRPI));
352 #endif
353 }
354
355 return false;
356 }
357
358 /* Includes: */
359 #include "../USBMode.h"
360 #include "../Events.h"
361 #include "../USBController.h"
362
363 /* Function Prototypes: */
364 void USB_INT_ClearAllInterrupts(void);
365 void USB_INT_DisableAllInterrupts(void);
366 #endif
367
368 /* Disable C linkage for C++ Compilers: */
369 #if defined(__cplusplus)
370 }
371 #endif
372
373 #endif
374