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