Correct UC3 global interrupt functions.
[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 uint_reg_t USB_INT_GetGlobalEnableState(void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
88 static inline uint_reg_t USB_INT_GetGlobalEnableState(void)
89 {
90 GCC_MEMORY_BARRIER();
91 return SREG;
92 }
93
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)
96 {
97 GCC_MEMORY_BARRIER();
98 SREG = GlobalIntState;
99 GCC_MEMORY_BARRIER();
100 }
101
102 static inline void USB_INT_GlobalEnable(void) ATTR_ALWAYS_INLINE;
103 static inline void USB_INT_GlobalEnable(void)
104 {
105 GCC_MEMORY_BARRIER();
106 sei();
107 GCC_MEMORY_BARRIER();
108 }
109
110 static inline void USB_INT_GlobalDisable(void) ATTR_ALWAYS_INLINE;
111 static inline void USB_INT_GlobalDisable(void)
112 {
113 GCC_MEMORY_BARRIER();
114 cli();
115 GCC_MEMORY_BARRIER();
116 }
117
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)
120 {
121 switch (Interrupt)
122 {
123 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
124 case USB_INT_VBUSTI:
125 USBCON |= (1 << VBUSTE);
126 break;
127 #endif
128 #if defined(USB_CAN_BE_BOTH)
129 case USB_INT_IDTI:
130 USBCON |= (1 << IDTE);
131 break;
132 #endif
133 #if defined(USB_CAN_BE_DEVICE)
134 case USB_INT_WAKEUPI:
135 UDIEN |= (1 << WAKEUPE);
136 break;
137 case USB_INT_SUSPI:
138 UDIEN |= (1 << SUSPE);
139 break;
140 case USB_INT_EORSTI:
141 UDIEN |= (1 << EORSTE);
142 break;
143 case USB_INT_SOFI:
144 UDIEN |= (1 << SOFE);
145 break;
146 case USB_INT_RXSTPI:
147 UEIENX |= (1 << RXSTPE);
148 break;
149 #endif
150 #if defined(USB_CAN_BE_HOST)
151 case USB_INT_HSOFI:
152 UHIEN |= (1 << HSOFE);
153 break;
154 case USB_INT_DCONNI:
155 UHIEN |= (1 << DCONNE);
156 break;
157 case USB_INT_DDISCI:
158 UHIEN |= (1 << DDISCE);
159 break;
160 case USB_INT_RSTI:
161 UHIEN |= (1 << RSTE);
162 break;
163 case USB_INT_BCERRI:
164 OTGIEN |= (1 << BCERRE);
165 break;
166 case USB_INT_VBERRI:
167 OTGIEN |= (1 << VBERRE);
168 break;
169 case USB_INT_SRPI:
170 OTGIEN |= (1 << SRPE);
171 break;
172 #endif
173 }
174 }
175
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)
178 {
179 switch (Interrupt)
180 {
181 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
182 case USB_INT_VBUSTI:
183 USBCON &= ~(1 << VBUSTE);
184 break;
185 #endif
186 #if defined(USB_CAN_BE_BOTH)
187 case USB_INT_IDTI:
188 USBCON &= ~(1 << IDTE);
189 break;
190 #endif
191 #if defined(USB_CAN_BE_DEVICE)
192 case USB_INT_WAKEUPI:
193 UDIEN &= ~(1 << WAKEUPE);
194 break;
195 case USB_INT_SUSPI:
196 UDIEN &= ~(1 << SUSPE);
197 break;
198 case USB_INT_EORSTI:
199 UDIEN &= ~(1 << EORSTE);
200 break;
201 case USB_INT_SOFI:
202 UDIEN &= ~(1 << SOFE);
203 break;
204 case USB_INT_RXSTPI:
205 UEIENX &= ~(1 << RXSTPE);
206 break;
207 #endif
208 #if defined(USB_CAN_BE_HOST)
209 case USB_INT_HSOFI:
210 UHIEN &= ~(1 << HSOFE);
211 break;
212 case USB_INT_DCONNI:
213 UHIEN &= ~(1 << DCONNE);
214 break;
215 case USB_INT_DDISCI:
216 UHIEN &= ~(1 << DDISCE);
217 break;
218 case USB_INT_RSTI:
219 UHIEN &= ~(1 << RSTE);
220 break;
221 case USB_INT_BCERRI:
222 OTGIEN &= ~(1 << BCERRE);
223 break;
224 case USB_INT_VBERRI:
225 OTGIEN &= ~(1 << VBERRE);
226 break;
227 case USB_INT_SRPI:
228 OTGIEN &= ~(1 << SRPE);
229 break;
230 #endif
231 }
232 }
233
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)
236 {
237 switch (Interrupt)
238 {
239 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
240 case USB_INT_VBUSTI:
241 USBINT &= ~(1 << VBUSTI);
242 break;
243 #endif
244 #if defined(USB_CAN_BE_BOTH)
245 case USB_INT_IDTI:
246 USBINT &= ~(1 << IDTI);
247 break;
248 #endif
249 #if defined(USB_CAN_BE_DEVICE)
250 case USB_INT_WAKEUPI:
251 UDINT &= ~(1 << WAKEUPI);
252 break;
253 case USB_INT_SUSPI:
254 UDINT &= ~(1 << SUSPI);
255 break;
256 case USB_INT_EORSTI:
257 UDINT &= ~(1 << EORSTI);
258 break;
259 case USB_INT_SOFI:
260 UDINT &= ~(1 << SOFI);
261 break;
262 case USB_INT_RXSTPI:
263 UEINTX &= ~(1 << RXSTPI);
264 break;
265 #endif
266 #if defined(USB_CAN_BE_HOST)
267 case USB_INT_HSOFI:
268 UHINT &= ~(1 << HSOFI);
269 break;
270 case USB_INT_DCONNI:
271 UHINT &= ~(1 << DCONNI);
272 break;
273 case USB_INT_DDISCI:
274 UHINT &= ~(1 << DDISCI);
275 break;
276 case USB_INT_RSTI:
277 UHINT &= ~(1 << RSTI);
278 break;
279 case USB_INT_BCERRI:
280 OTGINT &= ~(1 << BCERRI);
281 break;
282 case USB_INT_VBERRI:
283 OTGINT &= ~(1 << VBERRI);
284 break;
285 case USB_INT_SRPI:
286 OTGINT &= ~(1 << SRPI);
287 break;
288 #endif
289 }
290 }
291
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)
294 {
295 switch (Interrupt)
296 {
297 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
298 case USB_INT_VBUSTI:
299 return (USBCON & (1 << VBUSTE));
300 #endif
301 #if defined(USB_CAN_BE_BOTH)
302 case USB_INT_IDTI:
303 return (USBCON & (1 << IDTE));
304 #endif
305 #if defined(USB_CAN_BE_DEVICE)
306 case USB_INT_WAKEUPI:
307 return (UDIEN & (1 << WAKEUPE));
308 case USB_INT_SUSPI:
309 return (UDIEN & (1 << SUSPE));
310 case USB_INT_EORSTI:
311 return (UDIEN & (1 << EORSTE));
312 case USB_INT_SOFI:
313 return (UDIEN & (1 << SOFE));
314 case USB_INT_RXSTPI:
315 return (UEIENX & (1 << RXSTPE));
316 #endif
317 #if defined(USB_CAN_BE_HOST)
318 case USB_INT_HSOFI:
319 return (UHIEN & (1 << HSOFE));
320 case USB_INT_DCONNI:
321 return (UHIEN & (1 << DCONNE));
322 case USB_INT_DDISCI:
323 return (UHIEN & (1 << DDISCE));
324 case USB_INT_RSTI:
325 return (UHIEN & (1 << RSTE));
326 case USB_INT_BCERRI:
327 return (OTGIEN & (1 << BCERRE));
328 case USB_INT_VBERRI:
329 return (OTGIEN & (1 << VBERRE));
330 case USB_INT_SRPI:
331 return (OTGIEN & (1 << SRPE));
332 #endif
333 }
334
335 return false;
336 }
337
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)
340 {
341 switch (Interrupt)
342 {
343 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
344 case USB_INT_VBUSTI:
345 return (USBINT & (1 << VBUSTI));
346 #endif
347 #if defined(USB_CAN_BE_BOTH)
348 case USB_INT_IDTI:
349 return (USBINT & (1 << IDTI));
350 #endif
351 #if defined(USB_CAN_BE_DEVICE)
352 case USB_INT_WAKEUPI:
353 return (UDINT & (1 << WAKEUPI));
354 case USB_INT_SUSPI:
355 return (UDINT & (1 << SUSPI));
356 case USB_INT_EORSTI:
357 return (UDINT & (1 << EORSTI));
358 case USB_INT_SOFI:
359 return (UDINT & (1 << SOFI));
360 case USB_INT_RXSTPI:
361 return (UEINTX & (1 << RXSTPI));
362 #endif
363 #if defined(USB_CAN_BE_HOST)
364 case USB_INT_HSOFI:
365 return (UHINT & (1 << HSOFI));
366 case USB_INT_DCONNI:
367 return (UHINT & (1 << DCONNI));
368 case USB_INT_DDISCI:
369 return (UHINT & (1 << DDISCI));
370 case USB_INT_RSTI:
371 return (UHINT & (1 << RSTI));
372 case USB_INT_BCERRI:
373 return (OTGINT & (1 << BCERRI));
374 case USB_INT_VBERRI:
375 return (OTGINT & (1 << VBERRI));
376 case USB_INT_SRPI:
377 return (OTGINT & (1 << SRPI));
378 #endif
379 }
380
381 return false;
382 }
383
384 /* Includes: */
385 #include "../USBMode.h"
386 #include "../Events.h"
387 #include "../USBController.h"
388
389 /* Function Prototypes: */
390 void USB_INT_ClearAllInterrupts(void);
391 void USB_INT_DisableAllInterrupts(void);
392 #endif
393
394 /* Disable C linkage for C++ Compilers: */
395 #if defined(__cplusplus)
396 }
397 #endif
398
399 #endif
400