Statistics
| Branch: | Tag: | Revision:

root / LUFA / Drivers / USB / Core / UC3 / USBInterrupt_UC3.h @ 978b99e5

History | View | Annotate | Download (10.8 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 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
                #include "../Endpoint.h"
47

    
48
        /* Enable C linkage for C++ Compilers: */
49
                #if defined(__cplusplus)
50
                        extern "C" {
51
                #endif
52

    
53
        /* Preprocessor Checks: */
54
                #if !defined(__INCLUDE_FROM_USB_DRIVER)
55
                        #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
56
                #endif
57

    
58
        /* Private Interface - For use in library only: */
59
        #if !defined(__DOXYGEN__)                
60
                /* Enums: */
61
                        enum USB_Interrupts_t
62
                        {
63
                                USB_INT_VBUSTI  = 0,
64
                                #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__))
65
                                USB_INT_IDTI    = 1,
66
                                #endif
67
                                #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__))
68
                                USB_INT_WAKEUPI = 2,
69
                                USB_INT_SUSPI   = 3,
70
                                USB_INT_EORSTI  = 4,
71
                                USB_INT_SOFI    = 5,
72
                                USB_INT_RXSTPI  = 6,
73
                                #endif
74
                                #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__))                        
75
                                USB_INT_HSOFI   = 7,
76
                                USB_INT_DCONNI  = 8,
77
                                USB_INT_DDISCI  = 9,
78
                                USB_INT_RSTI    = 10,
79
                                USB_INT_BCERRI  = 11,
80
                                USB_INT_VBERRI  = 12,
81
                                #endif
82
                        };
83
                
84
                /* Inline Functions: */
85
                        static inline void USB_INT_Enable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
86
                        static inline void USB_INT_Enable(const uint8_t Interrupt)
87
                        {                        
88
                                switch (Interrupt)
89
                                {
90
                                        case USB_INT_VBUSTI:
91
                                                AVR32_USBB.USBCON.vbuste      = true;
92
                                                break;
93
                                        #if defined(USB_CAN_BE_BOTH)
94
                                        case USB_INT_IDTI:
95
                                                AVR32_USBB.USBCON.idte        = true;
96
                                                break;
97
                                        #endif
98
                                        #if defined(USB_CAN_BE_DEVICE)
99
                                        case USB_INT_WAKEUPI:
100
                                                AVR32_USBB.UDINTESET.wakeupes = true;
101
                                                break;
102
                                        case USB_INT_SUSPI:
103
                                                AVR32_USBB.UDINTESET.suspes   = true;
104
                                                break;
105
                                        case USB_INT_EORSTI:
106
                                                AVR32_USBB.UDINTESET.eorstes  = true;
107
                                                break;
108
                                        case USB_INT_SOFI:
109
                                                AVR32_USBB.UDINTESET.sofes    = true;
110
                                                break;
111
                                        case USB_INT_RXSTPI:
112
                                                (&AVR32_USBB.UECON0SET)[USB_SelectedEndpoint].rxstpes = true;
113
                                                break;
114
                                        #endif
115
                                        #if defined(USB_CAN_BE_HOST)
116
                                        case USB_INT_HSOFI:
117
                                                AVR32_USBB.UHINTESET.hsofies  = true;
118
                                                break;
119
                                        case USB_INT_DCONNI:
120
                                                AVR32_USBB.UHINTESET.dconnies = true;
121
                                                break;
122
                                        case USB_INT_DDISCI:
123
                                                AVR32_USBB.UHINTESET.ddiscies = true;
124
                                                break;
125
                                        case USB_INT_RSTI:
126
                                                AVR32_USBB.UHINTESET.rsties   = true;
127
                                                break;
128
                                        case USB_INT_BCERRI:
129
                                                AVR32_USBB.USBCON.bcerre      = true;
130
                                                break;
131
                                        case USB_INT_VBERRI:
132
                                                AVR32_USBB.USBCON.vberre      = true;
133
                                                break;
134
                                        #endif
135
                                }
136
                        }
137

    
138
                        static inline void USB_INT_Disable(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
139
                        static inline void USB_INT_Disable(const uint8_t Interrupt)
140
                        {
141
                                switch (Interrupt)
142
                                {
143
                                        case USB_INT_VBUSTI:
144
                                                AVR32_USBB.USBCON.vbuste      = false;
145
                                                break;
146
                                        #if defined(USB_CAN_BE_BOTH)
147
                                        case USB_INT_IDTI:
148
                                                AVR32_USBB.USBCON.idte        = false;
149
                                                break;
150
                                        #endif
151
                                        #if defined(USB_CAN_BE_DEVICE)
152
                                        case USB_INT_WAKEUPI:
153
                                                AVR32_USBB.UDINTECLR.wakeupec = true;
154
                                                break;
155
                                        case USB_INT_SUSPI:
156
                                                AVR32_USBB.UDINTECLR.suspec   = true;
157
                                                break;
158
                                        case USB_INT_EORSTI:
159
                                                AVR32_USBB.UDINTECLR.eorstec  = true;
160
                                                break;
161
                                        case USB_INT_SOFI:
162
                                                AVR32_USBB.UDINTECLR.sofec    = true;
163
                                                break;
164
                                        case USB_INT_RXSTPI:
165
                                                (&AVR32_USBB.UECON0CLR)[USB_SelectedEndpoint].rxstpec = true;
166
                                                break;
167
                                        #endif
168
                                        #if defined(USB_CAN_BE_HOST)
169
                                        case USB_INT_HSOFI:
170
                                                AVR32_USBB.UHINTECLR.hsofiec  = true;
171
                                                break;
172
                                        case USB_INT_DCONNI:
173
                                                AVR32_USBB.UHINTECLR.dconniec = true;
174
                                                break;
175
                                        case USB_INT_DDISCI:
176
                                                AVR32_USBB.UHINTECLR.ddisciec = true;
177
                                                break;
178
                                        case USB_INT_RSTI:
179
                                                AVR32_USBB.UHINTECLR.rstiec   = true;
180
                                                break;
181
                                        case USB_INT_BCERRI:
182
                                                AVR32_USBB.USBCON.bcerre      = false;
183
                                                break;
184
                                        case USB_INT_VBERRI:
185
                                                AVR32_USBB.USBCON.vberre      = false;
186
                                                break;
187
                                        #endif
188
                                }
189
                        }
190
                        
191
                        static inline void USB_INT_Clear(const uint8_t Interrupt) ATTR_ALWAYS_INLINE;
192
                        static inline void USB_INT_Clear(const uint8_t Interrupt)
193
                        {
194
                                switch (Interrupt)
195
                                {
196
                                        case USB_INT_VBUSTI:
197
                                                AVR32_USBB.USBSTACLR.vbustic = true;
198
                                                (void)AVR32_USBB.USBSTACLR;
199
                                                break;
200
                                        #if defined(USB_CAN_BE_BOTH)
201
                                        case USB_INT_IDTI:
202
                                                AVR32_USBB.USBSTACLR.idtic   = true;
203
                                                (void)AVR32_USBB.USBSTACLR;
204
                                                break;
205
                                        #endif
206
                                        #if defined(USB_CAN_BE_DEVICE)
207
                                        case USB_INT_WAKEUPI:
208
                                                AVR32_USBB.UDINTCLR.wakeupc  = true;
209
                                                (void)AVR32_USBB.UDINTCLR;
210
                                                break;
211
                                        case USB_INT_SUSPI:
212
                                                AVR32_USBB.UDINTCLR.suspc    = true;
213
                                                (void)AVR32_USBB.UDINTCLR;
214
                                                break;
215
                                        case USB_INT_EORSTI:
216
                                                AVR32_USBB.UDINTCLR.eorstc   = true;
217
                                                (void)AVR32_USBB.UDINTCLR;
218
                                                break;
219
                                        case USB_INT_SOFI:
220
                                                AVR32_USBB.UDINTCLR.sofc     = true;
221
                                                (void)AVR32_USBB.UDINTCLR;
222
                                                break;
223
                                        case USB_INT_RXSTPI:
224
                                                (&AVR32_USBB.UESTA0CLR)[USB_SelectedEndpoint].rxstpic = true;
225
                                                break;
226
                                        #endif
227
                                        #if defined(USB_CAN_BE_HOST)
228
                                        case USB_INT_HSOFI:
229
                                                AVR32_USBB.UHINTCLR.hsofic   = true;
230
                                                (void)AVR32_USBB.UHINTCLR;
231
                                                break;
232
                                        case USB_INT_DCONNI:
233
                                                AVR32_USBB.UHINTCLR.dconnic  = true;
234
                                                (void)AVR32_USBB.UHINTCLR;
235
                                                break;
236
                                        case USB_INT_DDISCI:
237
                                                AVR32_USBB.UHINTCLR.ddiscic  = true;
238
                                                (void)AVR32_USBB.UHINTCLR;
239
                                                break;
240
                                        case USB_INT_RSTI:
241
                                                AVR32_USBB.UHINTCLR.rstic    = true;
242
                                                (void)AVR32_USBB.UHINTCLR;
243
                                                break;
244
                                        case USB_INT_BCERRI:
245
                                                AVR32_USBB.USBSTACLR.bcerric = true;
246
                                                (void)AVR32_USBB.USBSTACLR;
247
                                                break;
248
                                        case USB_INT_VBERRI:
249
                                                AVR32_USBB.USBSTACLR.vberric = true;
250
                                                (void)AVR32_USBB.USBSTACLR;
251
                                                break;
252
                                        #endif
253
                                }
254
                        }
255
                        
256
                        static inline bool USB_INT_IsEnabled(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
257
                        static inline bool USB_INT_IsEnabled(const uint8_t Interrupt)
258
                        {
259
                                switch (Interrupt)
260
                                {
261
                                        case USB_INT_VBUSTI:
262
                                                return AVR32_USBB.USBCON.vbuste;
263
                                        #if defined(USB_CAN_BE_BOTH)
264
                                        case USB_INT_IDTI:
265
                                                return AVR32_USBB.USBCON.idte;
266
                                        #endif
267
                                        #if defined(USB_CAN_BE_DEVICE)
268
                                        case USB_INT_WAKEUPI:
269
                                                return AVR32_USBB.UDINTE.wakeupe;
270
                                        case USB_INT_SUSPI:
271
                                                return AVR32_USBB.UDINTE.suspe;
272
                                        case USB_INT_EORSTI:
273
                                                return AVR32_USBB.UDINTE.eorste;
274
                                        case USB_INT_SOFI:
275
                                                return AVR32_USBB.UDINTE.sofe;
276
                                        case USB_INT_RXSTPI:
277
                                                return (&AVR32_USBB.UECON0)[USB_SelectedEndpoint].rxstpe;
278
                                        #endif
279
                                        #if defined(USB_CAN_BE_HOST)                                        
280
                                        case USB_INT_HSOFI:
281
                                                return AVR32_USBB.UHINTE.hsofie;
282
                                        case USB_INT_DCONNI:
283
                                                return AVR32_USBB.UHINTE.dconnie;
284
                                        case USB_INT_DDISCI:
285
                                                return AVR32_USBB.UHINTE.ddiscie;
286
                                        case USB_INT_RSTI:
287
                                                return AVR32_USBB.UHINTE.rstie;
288
                                        case USB_INT_BCERRI:
289
                                                return AVR32_USBB.USBCON.bcerre;
290
                                        case USB_INT_VBERRI:
291
                                                return AVR32_USBB.USBCON.vberre;
292
                                        #endif
293
                                }
294
                                
295
                                return false;
296
                        }
297
                
298
                        static inline bool USB_INT_HasOccurred(const uint8_t Interrupt) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
299
                        static inline bool USB_INT_HasOccurred(const uint8_t Interrupt)
300
                        {
301
                                switch (Interrupt)
302
                                {
303
                                        case USB_INT_VBUSTI:
304
                                                return AVR32_USBB.USBSTA.vbusti;
305
                                        #if defined(USB_CAN_BE_BOTH)
306
                                        case USB_INT_IDTI:
307
                                                return AVR32_USBB.USBSTA.idti;
308
                                        #endif
309
                                        #if defined(USB_CAN_BE_DEVICE)
310
                                        case USB_INT_WAKEUPI:
311
                                                return AVR32_USBB.UDINT.wakeup;
312
                                        case USB_INT_SUSPI:
313
                                                return AVR32_USBB.UDINT.susp;
314
                                        case USB_INT_EORSTI:
315
                                                return AVR32_USBB.UDINT.eorst;
316
                                        case USB_INT_SOFI:
317
                                                return AVR32_USBB.UDINT.sof;
318
                                        case USB_INT_RXSTPI:
319
                                                return (&AVR32_USBB.UESTA0)[USB_SelectedEndpoint].rxstpi;
320
                                        #endif
321
                                        #if defined(USB_CAN_BE_HOST)
322
                                        case USB_INT_HSOFI:
323
                                                return AVR32_USBB.UHINT.hsofi;
324
                                        case USB_INT_DCONNI:
325
                                                return AVR32_USBB.UHINT.dconni;
326
                                        case USB_INT_DDISCI:
327
                                                return AVR32_USBB.UHINT.ddisci;
328
                                        case USB_INT_RSTI:
329
                                                return AVR32_USBB.UHINT.rsti;
330
                                        case USB_INT_BCERRI:
331
                                                return AVR32_USBB.USBSTA.bcerri;
332
                                        case USB_INT_VBERRI:
333
                                                return AVR32_USBB.USBSTA.vberri;
334
                                        #endif
335
                                }
336

    
337
                                return false;
338
                        }
339

    
340
                /* Includes: */
341
                        #include "../USBMode.h"
342
                        #include "../Events.h"
343
                        #include "../USBController.h"
344

    
345
                /* Function Prototypes: */
346
                        void USB_INT_ClearAllInterrupts(void);
347
                        void USB_INT_DisableAllInterrupts(void);
348
        #endif
349

    
350
        /* Public Interface - May be used in end-application: */
351
                /* ISR Prototypes: */
352
                        #if defined(__DOXYGEN__)
353
                                /** Interrupt service routine handler for the USB controller ISR group. This interrupt routine <b>must</b> be
354
                                 *  linked to the entire USB controller ISR vector group inside the AVR32's interrupt controller peripheral,
355
                                 *  using the user application's preferred USB controller driver.
356
                                 */
357
                                void USB_GEN_vect(void);
358
                        #else
359
                                ISR(USB_GEN_vect);
360
                        #endif
361
                        
362
        /* Disable C linkage for C++ Compilers: */
363
                #if defined(__cplusplus)
364
                        }
365
                #endif
366

    
367
#endif
368