ebefd1903b4a7f733908c3f1c3a8252ae400ef94
[pub/USBasp.git] / LUFA / Drivers / USB / Core / AVR8 / USBInterrupt_AVR8.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 AVR8 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_AVR8_H__
42 #define __USBINTERRUPT_AVR8_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 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 USBCON |= (1 << VBUSTE);
86 break;
87 case USB_INT_IDTI:
88 USBCON |= (1 << IDTE);
89 break;
90 case USB_INT_WAKEUPI:
91 UDIEN |= (1 << WAKEUPE);
92 break;
93 case USB_INT_SUSPI:
94 UDIEN |= (1 << SUSPE);
95 break;
96 case USB_INT_EORSTI:
97 UDIEN |= (1 << EORSTE);
98 break;
99 case USB_INT_SOFI:
100 UDIEN |= (1 << SOFE);
101 break;
102 case USB_INT_HSOFI:
103 UHIEN |= (1 << HSOFE);
104 break;
105 case USB_INT_DCONNI:
106 UHIEN |= (1 << DCONNE);
107 break;
108 case USB_INT_DDISCI:
109 UHIEN |= (1 << DDISCE);
110 break;
111 case USB_INT_RSTI:
112 UHIEN |= (1 << RSTE);
113 break;
114 case USB_INT_BCERRI:
115 OTGIEN |= (1 << BCERRE);
116 break;
117 case USB_INT_VBERRI:
118 OTGIEN |= (1 << VBERRE);
119 break;
120 case USB_INT_SRPI:
121 OTGIEN |= (1 << SRPE);
122 break;
123 case USB_INT_RXSTPI:
124 UEIENX |= (1 << RXSTPE);
125 break;
126 }
127 }
128
129 static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
130 static inline void USB_INT_Disable(const uint8_t Interrupt)
131 {
132 switch (Interrupt)
133 {
134 case USB_INT_VBUSTI:
135 USBCON &= ~(1 << VBUSTE);
136 break;
137 case USB_INT_IDTI:
138 USBCON &= ~(1 << IDTE);
139 break;
140 case USB_INT_WAKEUPI:
141 UDIEN &= ~(1 << WAKEUPE);
142 break;
143 case USB_INT_SUSPI:
144 UDIEN &= ~(1 << SUSPE);
145 break;
146 case USB_INT_EORSTI:
147 UDIEN &= ~(1 << EORSTE);
148 break;
149 case USB_INT_SOFI:
150 UDIEN &= ~(1 << SOFE);
151 break;
152 case USB_INT_HSOFI:
153 UHIEN &= ~(1 << HSOFE);
154 break;
155 case USB_INT_DCONNI:
156 UHIEN &= ~(1 << DCONNE);
157 break;
158 case USB_INT_DDISCI:
159 UHIEN &= ~(1 << DDISCE);
160 break;
161 case USB_INT_RSTI:
162 UHIEN &= ~(1 << RSTE);
163 break;
164 case USB_INT_BCERRI:
165 OTGIEN &= ~(1 << BCERRE);
166 break;
167 case USB_INT_VBERRI:
168 OTGIEN &= ~(1 << VBERRE);
169 break;
170 case USB_INT_SRPI:
171 OTGIEN &= ~(1 << SRPE);
172 break;
173 case USB_INT_RXSTPI:
174 UEIENX &= ~(1 << RXSTPE);
175 break;
176 }
177 }
178
179 static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
180 static inline void USB_INT_Clear(const uint8_t Interrupt)
181 {
182 switch (Interrupt)
183 {
184 case USB_INT_VBUSTI:
185 USBINT &= ~(1 << VBUSTI);
186 break;
187 case USB_INT_IDTI:
188 USBINT &= ~(1 << IDTI);
189 break;
190 case USB_INT_WAKEUPI:
191 UDINT &= ~(1 << WAKEUPI);
192 break;
193 case USB_INT_SUSPI:
194 UDINT &= ~(1 << SUSPI);
195 break;
196 case USB_INT_EORSTI:
197 UDINT &= ~(1 << EORSTI);
198 break;
199 case USB_INT_SOFI:
200 UDINT &= ~(1 << SOFI);
201 break;
202 case USB_INT_HSOFI:
203 UHINT &= ~(1 << HSOFI);
204 break;
205 case USB_INT_DCONNI:
206 UHINT &= ~(1 << DCONNI);
207 break;
208 case USB_INT_DDISCI:
209 UHINT &= ~(1 << DDISCI);
210 break;
211 case USB_INT_RSTI:
212 UHINT &= ~(1 << RSTI);
213 break;
214 case USB_INT_BCERRI:
215 OTGINT &= ~(1 << BCERRI);
216 break;
217 case USB_INT_VBERRI:
218 OTGINT &= ~(1 << VBERRI);
219 break;
220 case USB_INT_SRPI:
221 OTGINT &= ~(1 << SRPI);
222 break;
223 case USB_INT_RXSTPI:
224 UEINTX &= ~(1 << RXSTPI);
225 break;
226 }
227 }
228
229 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
230 static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
231 {
232 switch (Interrupt)
233 {
234 case USB_INT_VBUSTI:
235 return (USBCON & (1 << VBUSTE));
236 case USB_INT_IDTI:
237 return (USBCON & (1 << IDTE));
238 case USB_INT_WAKEUPI:
239 return (UDIEN & (1 << WAKEUPE));
240 case USB_INT_SUSPI:
241 return (UDIEN & (1 << SUSPE));
242 case USB_INT_EORSTI:
243 return (UDIEN & (1 << EORSTE));
244 case USB_INT_SOFI:
245 return (UDIEN & (1 << SOFE));
246 case USB_INT_HSOFI:
247 return (UHIEN & (1 << HSOFE));
248 case USB_INT_DCONNI:
249 return (UHIEN & (1 << DCONNE));
250 case USB_INT_DDISCI:
251 return (UHIEN & (1 << DDISCE));
252 case USB_INT_RSTI:
253 return (UHIEN & (1 << RSTE));
254 case USB_INT_BCERRI:
255 return (OTGIEN & (1 << BCERRE));
256 case USB_INT_VBERRI:
257 return (OTGIEN & (1 << VBERRE));
258 case USB_INT_SRPI:
259 return (OTGIEN & (1 << SRPE));
260 case USB_INT_RXSTPI:
261 return (UEIENX & (1 << RXSTPE));
262 break;
263 }
264
265 return false;
266 }
267
268 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
269 static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
270 {
271 switch (Interrupt)
272 {
273 case USB_INT_VBUSTI:
274 return (USBINT & (1 << VBUSTI));
275 case USB_INT_IDTI:
276 return (USBINT & (1 << IDTI));
277 case USB_INT_WAKEUPI:
278 return (UDINT & (1 << WAKEUPI));
279 case USB_INT_SUSPI:
280 return (UDINT & (1 << SUSPI));
281 case USB_INT_EORSTI:
282 return (UDINT & (1 << EORSTI));
283 case USB_INT_SOFI:
284 return (UDINT & (1 << SOFI));
285 case USB_INT_HSOFI:
286 return (UHINT & (1 << HSOFI));
287 case USB_INT_DCONNI:
288 return (UHINT & (1 << DCONNI));
289 case USB_INT_DDISCI:
290 return (UHINT & (1 << DDISCI));
291 case USB_INT_RSTI:
292 return (UHINT & (1 << RSTI));
293 case USB_INT_BCERRI:
294 return (OTGINT & (1 << BCERRI));
295 case USB_INT_VBERRI:
296 return (OTGINT & (1 << VBERRI));
297 case USB_INT_SRPI:
298 return (OTGINT & (1 << SRPI));
299 case USB_INT_RXSTPI:
300 return (UEINTX & (1 << RXSTPI));
301 }
302
303 return false;
304 }
305
306 /* Includes: */
307 #include "../USBMode.h"
308 #include "../Events.h"
309 #include "../USBController.h"
310
311 /* Function Prototypes: */
312 void USB_INT_ClearAllInterrupts(void);
313 void USB_INT_DisableAllInterrupts(void);
314 #endif
315
316 /* Disable C linkage for C++ Compilers: */
317 #if defined(__cplusplus)
318 }
319 #endif
320
321 #endif
322