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