]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.h
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / LUFA / Drivers / USB / Core / UC3 / USBInterrupt_UC3.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2014 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 disclaims 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 AVR32 UC3 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_UC3_H__
42 #define __USBINTERRUPT_UC3_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 /* External Variables: */
60 extern volatile uint32_t USB_Endpoint_SelectedEndpoint;
61
62 /* Enums: */
63 enum USB_Interrupts_t
64 {
65 USB_INT_VBUSTI = 0,
66 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
67 USB_INT_IDTI = 1,
68 #endif
69 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
70 USB_INT_WAKEUPI = 2,
71 USB_INT_SUSPI = 3,
72 USB_INT_EORSTI = 4,
73 USB_INT_SOFI = 5,
74 USB_INT_RXSTPI = 6,
75 #endif
76 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
77 USB_INT_HSOFI = 7,
78 USB_INT_DCONNI = 8,
79 USB_INT_DDISCI = 9,
80 USB_INT_RSTI = 10,
81 USB_INT_BCERRI = 11,
82 USB_INT_VBERRI = 12,
83 #endif
84 };
85
86 /* Inline Functions: */
87 static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
88 static inline void USB_INT_Enable(const uint8_t Interrupt)
89 {
90 switch (Interrupt)
91 {
92 case USB_INT_VBUSTI:
93 AVR32_USBB.USBCON.vbuste = true;
94 break;
95 #if defined(USB_CAN_BE_BOTH)
96 case USB_INT_IDTI:
97 AVR32_USBB.USBCON.idte = true;
98 break;
99 #endif
100 #if defined(USB_CAN_BE_DEVICE)
101 case USB_INT_WAKEUPI:
102 AVR32_USBB.UDINTESET.wakeupes = true;
103 break;
104 case USB_INT_SUSPI:
105 AVR32_USBB.UDINTESET.suspes = true;
106 break;
107 case USB_INT_EORSTI:
108 AVR32_USBB.UDINTESET.eorstes = true;
109 break;
110 case USB_INT_SOFI:
111 AVR32_USBB.UDINTESET.sofes = true;
112 break;
113 case USB_INT_RXSTPI:
114 (&AVR32_USBB.UECON0SET)[USB_Endpoint_SelectedEndpoint].rxstpes = true;
115 break;
116 #endif
117 #if defined(USB_CAN_BE_HOST)
118 case USB_INT_HSOFI:
119 AVR32_USBB.UHINTESET.hsofies = true;
120 break;
121 case USB_INT_DCONNI:
122 AVR32_USBB.UHINTESET.dconnies = true;
123 break;
124 case USB_INT_DDISCI:
125 AVR32_USBB.UHINTESET.ddiscies = true;
126 break;
127 case USB_INT_RSTI:
128 AVR32_USBB.UHINTESET.rsties = true;
129 break;
130 case USB_INT_BCERRI:
131 AVR32_USBB.USBCON.bcerre = true;
132 break;
133 case USB_INT_VBERRI:
134 AVR32_USBB.USBCON.vberre = true;
135 break;
136 #endif
137 default:
138 break;
139 }
140 }
141
142 static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
143 static inline void USB_INT_Disable(const uint8_t Interrupt)
144 {
145 switch (Interrupt)
146 {
147 case USB_INT_VBUSTI:
148 AVR32_USBB.USBCON.vbuste = false;
149 break;
150 #if defined(USB_CAN_BE_BOTH)
151 case USB_INT_IDTI:
152 AVR32_USBB.USBCON.idte = false;
153 break;
154 #endif
155 #if defined(USB_CAN_BE_DEVICE)
156 case USB_INT_WAKEUPI:
157 AVR32_USBB.UDINTECLR.wakeupec = true;
158 break;
159 case USB_INT_SUSPI:
160 AVR32_USBB.UDINTECLR.suspec = true;
161 break;
162 case USB_INT_EORSTI:
163 AVR32_USBB.UDINTECLR.eorstec = true;
164 break;
165 case USB_INT_SOFI:
166 AVR32_USBB.UDINTECLR.sofec = true;
167 break;
168 case USB_INT_RXSTPI:
169 (&AVR32_USBB.UECON0CLR)[USB_Endpoint_SelectedEndpoint].rxstpec = true;
170 break;
171 #endif
172 #if defined(USB_CAN_BE_HOST)
173 case USB_INT_HSOFI:
174 AVR32_USBB.UHINTECLR.hsofiec = true;
175 break;
176 case USB_INT_DCONNI:
177 AVR32_USBB.UHINTECLR.dconniec = true;
178 break;
179 case USB_INT_DDISCI:
180 AVR32_USBB.UHINTECLR.ddisciec = true;
181 break;
182 case USB_INT_RSTI:
183 AVR32_USBB.UHINTECLR.rstiec = true;
184 break;
185 case USB_INT_BCERRI:
186 AVR32_USBB.USBCON.bcerre = false;
187 break;
188 case USB_INT_VBERRI:
189 AVR32_USBB.USBCON.vberre = false;
190 break;
191 #endif
192 default:
193 break;
194 }
195 }
196
197 static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
198 static inline void USB_INT_Clear(const uint8_t Interrupt)
199 {
200 switch (Interrupt)
201 {
202 case USB_INT_VBUSTI:
203 AVR32_USBB.USBSTACLR.vbustic = true;
204 (void)AVR32_USBB.USBSTACLR;
205 break;
206 #if defined(USB_CAN_BE_BOTH)
207 case USB_INT_IDTI:
208 AVR32_USBB.USBSTACLR.idtic = true;
209 (void)AVR32_USBB.USBSTACLR;
210 break;
211 #endif
212 #if defined(USB_CAN_BE_DEVICE)
213 case USB_INT_WAKEUPI:
214 AVR32_USBB.UDINTCLR.wakeupc = true;
215 (void)AVR32_USBB.UDINTCLR;
216 break;
217 case USB_INT_SUSPI:
218 AVR32_USBB.UDINTCLR.suspc = true;
219 (void)AVR32_USBB.UDINTCLR;
220 break;
221 case USB_INT_EORSTI:
222 AVR32_USBB.UDINTCLR.eorstc = true;
223 (void)AVR32_USBB.UDINTCLR;
224 break;
225 case USB_INT_SOFI:
226 AVR32_USBB.UDINTCLR.sofc = true;
227 (void)AVR32_USBB.UDINTCLR;
228 break;
229 case USB_INT_RXSTPI:
230 (&AVR32_USBB.UESTA0CLR)[USB_Endpoint_SelectedEndpoint].rxstpic = true;
231 break;
232 #endif
233 #if defined(USB_CAN_BE_HOST)
234 case USB_INT_HSOFI:
235 AVR32_USBB.UHINTCLR.hsofic = true;
236 (void)AVR32_USBB.UHINTCLR;
237 break;
238 case USB_INT_DCONNI:
239 AVR32_USBB.UHINTCLR.dconnic = true;
240 (void)AVR32_USBB.UHINTCLR;
241 break;
242 case USB_INT_DDISCI:
243 AVR32_USBB.UHINTCLR.ddiscic = true;
244 (void)AVR32_USBB.UHINTCLR;
245 break;
246 case USB_INT_RSTI:
247 AVR32_USBB.UHINTCLR.rstic = true;
248 (void)AVR32_USBB.UHINTCLR;
249 break;
250 case USB_INT_BCERRI:
251 AVR32_USBB.USBSTACLR.bcerric = true;
252 (void)AVR32_USBB.USBSTACLR;
253 break;
254 case USB_INT_VBERRI:
255 AVR32_USBB.USBSTACLR.vberric = true;
256 (void)AVR32_USBB.USBSTACLR;
257 break;
258 #endif
259 default:
260 break;
261 }
262 }
263
264 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
265 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
266 {
267 switch (Interrupt)
268 {
269 case USB_INT_VBUSTI:
270 return AVR32_USBB.USBCON.vbuste;
271 #if defined(USB_CAN_BE_BOTH)
272 case USB_INT_IDTI:
273 return AVR32_USBB.USBCON.idte;
274 #endif
275 #if defined(USB_CAN_BE_DEVICE)
276 case USB_INT_WAKEUPI:
277 return AVR32_USBB.UDINTE.wakeupe;
278 case USB_INT_SUSPI:
279 return AVR32_USBB.UDINTE.suspe;
280 case USB_INT_EORSTI:
281 return AVR32_USBB.UDINTE.eorste;
282 case USB_INT_SOFI:
283 return AVR32_USBB.UDINTE.sofe;
284 case USB_INT_RXSTPI:
285 return (&AVR32_USBB.UECON0)[USB_Endpoint_SelectedEndpoint].rxstpe;
286 #endif
287 #if defined(USB_CAN_BE_HOST)
288 case USB_INT_HSOFI:
289 return AVR32_USBB.UHINTE.hsofie;
290 case USB_INT_DCONNI:
291 return AVR32_USBB.UHINTE.dconnie;
292 case USB_INT_DDISCI:
293 return AVR32_USBB.UHINTE.ddiscie;
294 case USB_INT_RSTI:
295 return AVR32_USBB.UHINTE.rstie;
296 case USB_INT_BCERRI:
297 return AVR32_USBB.USBCON.bcerre;
298 case USB_INT_VBERRI:
299 return AVR32_USBB.USBCON.vberre;
300 #endif
301 default:
302 return false;
303 }
304 }
305
306 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
307 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
308 {
309 switch (Interrupt)
310 {
311 case USB_INT_VBUSTI:
312 return AVR32_USBB.USBSTA.vbusti;
313 #if defined(USB_CAN_BE_BOTH)
314 case USB_INT_IDTI:
315 return AVR32_USBB.USBSTA.idti;
316 #endif
317 #if defined(USB_CAN_BE_DEVICE)
318 case USB_INT_WAKEUPI:
319 return AVR32_USBB.UDINT.wakeup;
320 case USB_INT_SUSPI:
321 return AVR32_USBB.UDINT.susp;
322 case USB_INT_EORSTI:
323 return AVR32_USBB.UDINT.eorst;
324 case USB_INT_SOFI:
325 return AVR32_USBB.UDINT.sof;
326 case USB_INT_RXSTPI:
327 return (&AVR32_USBB.UESTA0)[USB_Endpoint_SelectedEndpoint].rxstpi;
328 #endif
329 #if defined(USB_CAN_BE_HOST)
330 case USB_INT_HSOFI:
331 return AVR32_USBB.UHINT.hsofi;
332 case USB_INT_DCONNI:
333 return AVR32_USBB.UHINT.dconni;
334 case USB_INT_DDISCI:
335 return AVR32_USBB.UHINT.ddisci;
336 case USB_INT_RSTI:
337 return AVR32_USBB.UHINT.rsti;
338 case USB_INT_BCERRI:
339 return AVR32_USBB.USBSTA.bcerri;
340 case USB_INT_VBERRI:
341 return AVR32_USBB.USBSTA.vberri;
342 #endif
343 default:
344 return false;
345 }
346 }
347
348 /* Includes: */
349 #include "../USBMode.h"
350 #include "../Events.h"
351 #include "../USBController.h"
352
353 /* Function Prototypes: */
354 void USB_INT_ClearAllInterrupts(void);
355 void USB_INT_DisableAllInterrupts(void);
356 #endif
357
358 /* Public Interface - May be used in end-application: */
359 /* Function Prototypes: */
360 #if defined(__DOXYGEN__)
361 /** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
362 * linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
363 * using the user application's preferred USB controller driver.
364 */
365 void USB_GEN_vect(void);
366 #else
367 ISR(USB_GEN_vect);
368 #endif
369
370 /* Disable C linkage for C++ Compilers: */
371 #if defined(__cplusplus)
372 }
373 #endif
374
375 #endif
376
Imprint / Impressum