ca60e7f0fa8045144d32c62b0f243e6c16f37a4e
[pub/USBasp.git] / LUFA / Drivers / USB / Core / UC3B / USBInterrupt_UC3B.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 AVR32 UC3B 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_UC3B_H__
42 #define __USBINTERRUPT_UC3B_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 /* Macros: */
60 enum USB_Interrupts_t
61 {
62 USB_INT_VBUSTI = 0,
63 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
64 USB_INT_IDTI = 1,
65 #endif
66 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
67 USB_INT_WAKEUPI = 2,
68 USB_INT_SUSPI = 3,
69 USB_INT_EORSTI = 4,
70 USB_INT_SOFI = 5,
71 #endif
72 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
73 USB_INT_HSOFI = 6,
74 USB_INT_DCONNI = 7,
75 USB_INT_DDISCI = 8,
76 USB_INT_RSTI = 9,
77 USB_INT_BCERRI = 10,
78 USB_INT_VBERRI = 11,
79 #endif
80 };
81
82 /* ISR Prototypes: */
83 ISR(USB_GEN_vect);
84
85 /* Inline Functions: */
86 static inline void USB_INT_RegisterHandlers(void)
87 {
88 AVR32_INTC.IPR[AVR32_USBB_IRQ % 32].autovector = (uintptr_t)&USB_GEN_vect;
89 }
90
91 static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
92 static inline void USB_INT_Enable(const uint8_t Interrupt)
93 {
94 switch (Interrupt)
95 {
96 case USB_INT_VBUSTI:
97 AVR32_USBB.USBCON.vbuste = true;
98 break;
99 #if defined(USB_CAN_BE_BOTH)
100 case USB_INT_IDTI:
101 AVR32_USBB.USBCON.idte = true;
102 break;
103 #endif
104 #if defined(USB_CAN_BE_DEVICE)
105 case USB_INT_WAKEUPI:
106 AVR32_USBB.UDINTESET.wakeupes = true;
107 break;
108 case USB_INT_SUSPI:
109 AVR32_USBB.UDINTESET.suspes = true;
110 break;
111 case USB_INT_EORSTI:
112 AVR32_USBB.UDINTESET.eorstes = true;
113 break;
114 case USB_INT_SOFI:
115 AVR32_USBB.UDINTESET.sofes = true;
116 break;
117 #endif
118 #if defined(USB_CAN_BE_HOST)
119 case USB_INT_HSOFI:
120 AVR32_USBB.UHINTESET.hsofies = true;
121 break;
122 case USB_INT_DCONNI:
123 AVR32_USBB.UHINTESET.dconnies = true;
124 break;
125 case USB_INT_DDISCI:
126 AVR32_USBB.UHINTESET.ddiscies = true;
127 break;
128 case USB_INT_RSTI:
129 AVR32_USBB.UHINTESET.rsties = true;
130 break;
131 case USB_INT_BCERRI:
132 AVR32_USBB.USBCON.bcerre = true;
133 break;
134 case USB_INT_VBERRI:
135 AVR32_USBB.USBCON.vberre = true;
136 break;
137 #endif
138 }
139 }
140
141 static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
142 static inline void USB_INT_Disable(const uint8_t Interrupt)
143 {
144 switch (Interrupt)
145 {
146 case USB_INT_VBUSTI:
147 AVR32_USBB.USBCON.vbuste = false;
148 break;
149 #if defined(USB_CAN_BE_BOTH)
150 case USB_INT_IDTI:
151 AVR32_USBB.USBCON.idte = false;
152 break;
153 #endif
154 #if defined(USB_CAN_BE_DEVICE)
155 case USB_INT_WAKEUPI:
156 AVR32_USBB.UDINTECLR.wakeupec = true;
157 break;
158 case USB_INT_SUSPI:
159 AVR32_USBB.UDINTECLR.suspec = true;
160 break;
161 case USB_INT_EORSTI:
162 AVR32_USBB.UDINTECLR.eorstec = true;
163 break;
164 case USB_INT_SOFI:
165 AVR32_USBB.UDINTECLR.sofec = true;
166 break;
167 #endif
168 #if defined(USB_CAN_BE_HOST)
169 case USB_INT_HSOFI:
170 AVR32_USBB.UHINTECLR.hsofiec = true;
171 break;
172 case USB_INT_DCONNI:
173 AVR32_USBB.UHINTECLR.dconniec = true;
174 break;
175 case USB_INT_DDISCI:
176 AVR32_USBB.UHINTECLR.ddisciec = true;
177 break;
178 case USB_INT_RSTI:
179 AVR32_USBB.UHINTECLR.rstiec = true;
180 break;
181 case USB_INT_BCERRI:
182 AVR32_USBB.USBCON.bcerre = false;
183 break;
184 case USB_INT_VBERRI:
185 AVR32_USBB.USBCON.vberre = false;
186 break;
187 #endif
188 }
189 }
190
191 static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
192 static inline void USB_INT_Clear(const uint8_t Interrupt)
193 {
194 switch (Interrupt)
195 {
196 case USB_INT_VBUSTI:
197 AVR32_USBB.USBSTACLR.vbustic = true;
198 (void)AVR32_USBB.USBSTACLR;
199 break;
200 #if defined(USB_CAN_BE_BOTH)
201 case USB_INT_IDTI:
202 AVR32_USBB.USBSTACLR.idtic = true;
203 (void)AVR32_USBB.USBSTACLR;
204 break;
205 #endif
206 #if defined(USB_CAN_BE_DEVICE)
207 case USB_INT_WAKEUPI:
208 AVR32_USBB.UDINTCLR.wakeupc = true;
209 (void)AVR32_USBB.UDINTCLR;
210 break;
211 case USB_INT_SUSPI:
212 AVR32_USBB.UDINTCLR.suspc = true;
213 (void)AVR32_USBB.UDINTCLR;
214 break;
215 case USB_INT_EORSTI:
216 AVR32_USBB.UDINTCLR.eorstc = true;
217 (void)AVR32_USBB.UDINTCLR;
218 break;
219 case USB_INT_SOFI:
220 AVR32_USBB.UDINTCLR.sofc = true;
221 (void)AVR32_USBB.UDINTCLR;
222 break;
223 #endif
224 #if defined(USB_CAN_BE_HOST)
225 case USB_INT_HSOFI:
226 AVR32_USBB.UHINTCLR.hsofic = true;
227 (void)AVR32_USBB.UHINTCLR;
228 break;
229 case USB_INT_DCONNI:
230 AVR32_USBB.UHINTCLR.dconnic = true;
231 (void)AVR32_USBB.UHINTCLR;
232 break;
233 case USB_INT_DDISCI:
234 AVR32_USBB.UHINTCLR.ddiscic = true;
235 (void)AVR32_USBB.UHINTCLR;
236 break;
237 case USB_INT_RSTI:
238 AVR32_USBB.UHINTCLR.rstic = true;
239 (void)AVR32_USBB.UHINTCLR;
240 break;
241 case USB_INT_BCERRI:
242 AVR32_USBB.USBSTACLR.bcerric = true;
243 (void)AVR32_USBB.USBSTACLR;
244 break;
245 case USB_INT_VBERRI:
246 AVR32_USBB.USBSTACLR.vberric = true;
247 (void)AVR32_USBB.USBSTACLR;
248 break;
249 #endif
250 }
251 }
252
253 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
254 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
255 {
256 switch (Interrupt)
257 {
258 case USB_INT_VBUSTI:
259 return AVR32_USBB.USBCON.vbuste;
260 #if defined(USB_CAN_BE_BOTH)
261 case USB_INT_IDTI:
262 return AVR32_USBB.USBCON.idte;
263 #endif
264 #if defined(USB_CAN_BE_DEVICE)
265 case USB_INT_WAKEUPI:
266 return AVR32_USBB.UDINTE.wakeupe;
267 case USB_INT_SUSPI:
268 return AVR32_USBB.UDINTE.suspe;
269 case USB_INT_EORSTI:
270 return AVR32_USBB.UDINTE.eorste;
271 case USB_INT_SOFI:
272 return AVR32_USBB.UDINTE.sofe;
273 #endif
274 #if defined(USB_CAN_BE_HOST)
275 case USB_INT_HSOFI:
276 return AVR32_USBB.UHINTE.hsofie;
277 case USB_INT_DCONNI:
278 return AVR32_USBB.UHINTE.dconnie;
279 case USB_INT_DDISCI:
280 return AVR32_USBB.UHINTE.ddiscie;
281 case USB_INT_RSTI:
282 return AVR32_USBB.UHINTE.rstie;
283 case USB_INT_BCERRI:
284 return AVR32_USBB.USBCON.bcerre;
285 case USB_INT_VBERRI:
286 return AVR32_USBB.USBCON.vberre;
287 #endif
288 }
289
290 return false;
291 }
292
293 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
294 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
295 {
296 switch (Interrupt)
297 {
298 case USB_INT_VBUSTI:
299 return AVR32_USBB.USBSTA.vbusti;
300 #if defined(USB_CAN_BE_BOTH)
301 case USB_INT_IDTI:
302 return AVR32_USBB.USBSTA.idti;
303 #endif
304 #if defined(USB_CAN_BE_DEVICE)
305 case USB_INT_WAKEUPI:
306 return AVR32_USBB.UDINT.wakeup;
307 case USB_INT_SUSPI:
308 return AVR32_USBB.UDINT.susp;
309 case USB_INT_EORSTI:
310 return AVR32_USBB.UDINT.eorst;
311 case USB_INT_SOFI:
312 return AVR32_USBB.UDINT.sof;
313 #endif
314 #if defined(USB_CAN_BE_HOST)
315 case USB_INT_HSOFI:
316 return AVR32_USBB.UHINT.hsofi;
317 case USB_INT_DCONNI:
318 return AVR32_USBB.UHINT.dconni;
319 case USB_INT_DDISCI:
320 return AVR32_USBB.UHINT.ddisci;
321 case USB_INT_RSTI:
322 return AVR32_USBB.UHINT.rsti;
323 case USB_INT_BCERRI:
324 return AVR32_USBB.USBSTA.bcerri;
325 case USB_INT_VBERRI:
326 return AVR32_USBB.USBSTA.vberri;
327 #endif
328 }
329
330 return false;
331 }
332
333 /* Includes: */
334 #include "../USBMode.h"
335 #include "../Events.h"
336 #include "../USBController.h"
337
338 /* Function Prototypes: */
339 void USB_INT_ClearAllInterrupts(void);
340 void USB_INT_DisableAllInterrupts(void);
341 #endif
342
343 /* Disable C linkage for C++ Compilers: */
344 #if defined(__cplusplus)
345 }
346 #endif
347
348 #endif
349