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