Statistics
| Branch: | Tag: | Revision:

root / LUFA / Drivers / USB / Core / AVR8 / USBInterrupt_AVR8.h @ 978b99e5

History | View | Annotate | Download (10.3 KB)

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
                                #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__))
63
                                USB_INT_VBUSTI  = 0,
64
                                #endif
65
                                #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
66
                                USB_INT_IDTI    = 1,
67
                                #endif
68
                                #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
69
                                USB_INT_WAKEUPI = 2,
70
                                USB_INT_SUSPI   = 3,
71
                                USB_INT_EORSTI  = 4,
72
                                USB_INT_SOFI    = 5,
73
                                USB_INT_RXSTPI  = 6,
74
                                #endif
75
                                #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))
76
                                USB_INT_HSOFI   = 7,
77
                                USB_INT_DCONNI  = 8,
78
                                USB_INT_DDISCI  = 9,
79
                                USB_INT_RSTI    = 10,
80
                                USB_INT_BCERRI  = 11,
81
                                USB_INT_VBERRI  = 12,
82
                                USB_INT_SRPI    = 13,
83
                                #endif
84
                        };
85

    
86
                /* Inline Functions: */
87
                        static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
88
                        static inline void USB_INT_Enable(const uint8_t Interrupt)
89
                        {
90
                                switch (Interrupt)
91
                                {
92
                                        #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
93
                                        case USB_INT_VBUSTI:
94
                                                USBCON |= (1 << VBUSTE);
95
                                                break;
96
                                        #endif
97
                                        #if defined(USB_CAN_BE_BOTH)
98
                                        case USB_INT_IDTI:
99
                                                USBCON |= (1 << IDTE);
100
                                                break;
101
                                        #endif
102
                                        #if defined(USB_CAN_BE_DEVICE)
103
                                        case USB_INT_WAKEUPI:
104
                                                UDIEN  |= (1 << WAKEUPE);
105
                                                break;
106
                                        case USB_INT_SUSPI:
107
                                                UDIEN  |= (1 << SUSPE);
108
                                                break;
109
                                        case USB_INT_EORSTI:
110
                                                UDIEN  |= (1 << EORSTE);
111
                                                break;
112
                                        case USB_INT_SOFI:
113
                                                UDIEN  |= (1 << SOFE);
114
                                                break;
115
                                        case USB_INT_RXSTPI:
116
                                                UEIENX |= (1 << RXSTPE);
117
                                                break;
118
                                        #endif
119
                                        #if defined(USB_CAN_BE_HOST)
120
                                        case USB_INT_HSOFI:
121
                                                UHIEN  |= (1 << HSOFE);
122
                                                break;
123
                                        case USB_INT_DCONNI:
124
                                                UHIEN  |= (1 << DCONNE);
125
                                                break;
126
                                        case USB_INT_DDISCI:
127
                                                UHIEN  |= (1 << DDISCE);
128
                                                break;
129
                                        case USB_INT_RSTI:
130
                                                UHIEN  |= (1 << RSTE);
131
                                                break;
132
                                        case USB_INT_BCERRI:
133
                                                OTGIEN |= (1 << BCERRE);
134
                                                break;
135
                                        case USB_INT_VBERRI:
136
                                                OTGIEN |= (1 << VBERRE);
137
                                                break;
138
                                        case USB_INT_SRPI:
139
                                                OTGIEN |= (1 << SRPE);                                                
140
                                                break;
141
                                        #endif
142
                                }
143
                        }
144

    
145
                        static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
146
                        static inline void USB_INT_Disable(const uint8_t Interrupt)
147
                        {
148
                                switch (Interrupt)
149
                                {
150
                                        #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
151
                                        case USB_INT_VBUSTI:
152
                                                USBCON &= ~(1 << VBUSTE);
153
                                                break;
154
                                        #endif
155
                                        #if defined(USB_CAN_BE_BOTH)
156
                                        case USB_INT_IDTI:
157
                                                USBCON &= ~(1 << IDTE);
158
                                                break;
159
                                        #endif
160
                                        #if defined(USB_CAN_BE_DEVICE)
161
                                        case USB_INT_WAKEUPI:
162
                                                UDIEN  &= ~(1 << WAKEUPE);
163
                                                break;
164
                                        case USB_INT_SUSPI:
165
                                                UDIEN  &= ~(1 << SUSPE);
166
                                                break;
167
                                        case USB_INT_EORSTI:
168
                                                UDIEN  &= ~(1 << EORSTE);
169
                                                break;
170
                                        case USB_INT_SOFI:
171
                                                UDIEN  &= ~(1 << SOFE);
172
                                                break;
173
                                        case USB_INT_RXSTPI:
174
                                                UEIENX &= ~(1 << RXSTPE);
175
                                                break;
176
                                        #endif
177
                                        #if defined(USB_CAN_BE_HOST)
178
                                        case USB_INT_HSOFI:
179
                                                UHIEN  &= ~(1 << HSOFE);
180
                                                break;
181
                                        case USB_INT_DCONNI:
182
                                                UHIEN  &= ~(1 << DCONNE);
183
                                                break;
184
                                        case USB_INT_DDISCI:
185
                                                UHIEN  &= ~(1 << DDISCE);
186
                                                break;
187
                                        case USB_INT_RSTI:
188
                                                UHIEN  &= ~(1 << RSTE);
189
                                                break;
190
                                        case USB_INT_BCERRI:
191
                                                OTGIEN &= ~(1 << BCERRE);
192
                                                break;
193
                                        case USB_INT_VBERRI:
194
                                                OTGIEN &= ~(1 << VBERRE);
195
                                                break;
196
                                        case USB_INT_SRPI:
197
                                                OTGIEN &= ~(1 << SRPE);                                                
198
                                                break;
199
                                        #endif
200
                                }
201
                        }
202
                        
203
                        static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
204
                        static inline void USB_INT_Clear(const uint8_t Interrupt)
205
                        {
206
                                switch (Interrupt)
207
                                {
208
                                        #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
209
                                        case USB_INT_VBUSTI:
210
                                                USBINT &= ~(1 << VBUSTI);
211
                                                break;
212
                                        #endif
213
                                        #if defined(USB_CAN_BE_BOTH)
214
                                        case USB_INT_IDTI:
215
                                                USBINT &= ~(1 << IDTI);
216
                                                break;
217
                                        #endif
218
                                        #if defined(USB_CAN_BE_DEVICE)
219
                                        case USB_INT_WAKEUPI:
220
                                                UDINT  &= ~(1 << WAKEUPI);
221
                                                break;
222
                                        case USB_INT_SUSPI:
223
                                                UDINT  &= ~(1 << SUSPI);
224
                                                break;
225
                                        case USB_INT_EORSTI:
226
                                                UDINT  &= ~(1 << EORSTI);
227
                                                break;
228
                                        case USB_INT_SOFI:
229
                                                UDINT  &= ~(1 << SOFI);
230
                                                break;
231
                                        case USB_INT_RXSTPI:
232
                                                UEINTX &= ~(1 << RXSTPI);
233
                                                break;
234
                                        #endif
235
                                        #if defined(USB_CAN_BE_HOST)
236
                                        case USB_INT_HSOFI:
237
                                                UHINT  &= ~(1 << HSOFI);
238
                                                break;
239
                                        case USB_INT_DCONNI:
240
                                                UHINT  &= ~(1 << DCONNI);
241
                                                break;
242
                                        case USB_INT_DDISCI:
243
                                                UHINT  &= ~(1 << DDISCI);
244
                                                break;
245
                                        case USB_INT_RSTI:
246
                                                UHINT  &= ~(1 << RSTI);
247
                                                break;
248
                                        case USB_INT_BCERRI:
249
                                                OTGINT &= ~(1 << BCERRI);
250
                                                break;
251
                                        case USB_INT_VBERRI:
252
                                                OTGINT &= ~(1 << VBERRI);
253
                                                break;
254
                                        case USB_INT_SRPI:
255
                                                OTGINT &= ~(1 << SRPI);
256
                                                break;
257
                                        #endif
258
                                }
259
                        }
260
                        
261
                        static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
262
                        static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
263
                        {
264
                                switch (Interrupt)
265
                                {
266
                                        #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
267
                                        case USB_INT_VBUSTI:
268
                                                return (USBCON & (1 << VBUSTE));
269
                                        #endif
270
                                        #if defined(USB_CAN_BE_BOTH)
271
                                        case USB_INT_IDTI:
272
                                                return (USBCON & (1 << IDTE));
273
                                        #endif
274
                                        #if defined(USB_CAN_BE_DEVICE)
275
                                        case USB_INT_WAKEUPI:
276
                                                return (UDIEN  & (1 << WAKEUPE));
277
                                        case USB_INT_SUSPI:
278
                                                return (UDIEN  & (1 << SUSPE));
279
                                        case USB_INT_EORSTI:
280
                                                return (UDIEN  & (1 << EORSTE));
281
                                        case USB_INT_SOFI:
282
                                                return (UDIEN  & (1 << SOFE));
283
                                        case USB_INT_RXSTPI:
284
                                                return (UEIENX & (1 << RXSTPE));
285
                                        #endif
286
                                        #if defined(USB_CAN_BE_HOST)
287
                                        case USB_INT_HSOFI:
288
                                                return (UHIEN  & (1 << HSOFE));
289
                                        case USB_INT_DCONNI:
290
                                                return (UHIEN  & (1 << DCONNE));
291
                                        case USB_INT_DDISCI:
292
                                                return (UHIEN  & (1 << DDISCE));
293
                                        case USB_INT_RSTI:
294
                                                return (UHIEN  & (1 << RSTE));
295
                                        case USB_INT_BCERRI:
296
                                                return (OTGIEN & (1 << BCERRE));
297
                                        case USB_INT_VBERRI:
298
                                                return (OTGIEN & (1 << VBERRE));
299
                                        case USB_INT_SRPI:
300
                                                return (OTGIEN & (1 << SRPE));
301
                                        #endif
302
                                }
303
                                
304
                                return false;
305
                        }
306
                
307
                        static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
308
                        static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
309
                        {
310
                                switch (Interrupt)
311
                                {
312
                                        #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR))
313
                                        case USB_INT_VBUSTI:
314
                                                return (USBINT & (1 << VBUSTI));
315
                                        #endif
316
                                        #if defined(USB_CAN_BE_BOTH)
317
                                        case USB_INT_IDTI:
318
                                                return (USBINT & (1 << IDTI));
319
                                        #endif
320
                                        #if defined(USB_CAN_BE_DEVICE)
321
                                        case USB_INT_WAKEUPI:
322
                                                return (UDINT  & (1 << WAKEUPI));
323
                                        case USB_INT_SUSPI:
324
                                                return (UDINT  & (1 << SUSPI));
325
                                        case USB_INT_EORSTI:
326
                                                return (UDINT  & (1 << EORSTI));
327
                                        case USB_INT_SOFI:
328
                                                return (UDINT  & (1 << SOFI));
329
                                        case USB_INT_RXSTPI:
330
                                                return (UEINTX & (1 << RXSTPI));
331
                                        #endif
332
                                        #if defined(USB_CAN_BE_HOST)
333
                                        case USB_INT_HSOFI:
334
                                                return (UHINT  & (1 << HSOFI));
335
                                        case USB_INT_DCONNI:
336
                                                return (UHINT  & (1 << DCONNI));
337
                                        case USB_INT_DDISCI:
338
                                                return (UHINT  & (1 << DDISCI));
339
                                        case USB_INT_RSTI:
340
                                                return (UHINT  & (1 << RSTI));
341
                                        case USB_INT_BCERRI:
342
                                                return (OTGINT & (1 << BCERRI));
343
                                        case USB_INT_VBERRI:
344
                                                return (OTGINT & (1 << VBERRI));
345
                                        case USB_INT_SRPI:
346
                                                return (OTGINT & (1 << SRPI));
347
                                        #endif
348
                                }
349

    
350
                                return false;
351
                        }
352

    
353
                /* Includes: */
354
                        #include "../USBMode.h"
355
                        #include "../Events.h"
356
                        #include "../USBController.h"
357

    
358
                /* Function Prototypes: */
359
                        void USB_INT_ClearAllInterrupts(void);
360
                        void USB_INT_DisableAllInterrupts(void);
361
        #endif
362

    
363
        /* Disable C linkage for C++ Compilers: */
364
                #if defined(__cplusplus)
365
                        }
366
                #endif
367

    
368
#endif
369