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