Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (5.81 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
#define  __INCLUDE_FROM_USB_DRIVER
32
#include "../USBInterrupt.h"
33

    
34
void USB_INT_DisableAllInterrupts(void)
35
{
36
        AVR32_USBB.USBCON.vbuste     = false;
37
        AVR32_USBB.USBCON.idte       = false;
38

    
39
        AVR32_USBB.uhinteclr         = -1;
40
        AVR32_USBB.udinteclr         = -1;
41
}
42

    
43
void USB_INT_ClearAllInterrupts(void)
44
{
45
        AVR32_USBB.USBSTACLR.vbustic = true;
46
        AVR32_USBB.USBSTACLR.idtic   = true;
47

    
48
        AVR32_USBB.uhintclr          = -1;
49
        AVR32_USBB.udintclr          = -1;
50
}
51

    
52
ISR(USB_GEN_vect)
53
{
54
        #if defined(USB_CAN_BE_DEVICE)
55
        #if !defined(NO_SOF_EVENTS)
56
        if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
57
        {
58
                USB_INT_Clear(USB_INT_SOFI);
59

    
60
                EVENT_USB_Device_StartOfFrame();
61
        }
62
        #endif
63

    
64
        if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
65
        {
66
                USB_INT_Clear(USB_INT_VBUSTI);
67

    
68
                if (USB_VBUS_GetStatus())
69
                {
70
                        USB_DeviceState = DEVICE_STATE_Powered;
71
                        EVENT_USB_Device_Connect();
72
                }
73
                else
74
                {
75
                        USB_DeviceState = DEVICE_STATE_Unattached;
76
                        EVENT_USB_Device_Disconnect();
77
                }
78
        }
79

    
80
        if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
81
        {
82
                USB_INT_Disable(USB_INT_SUSPI);
83
                USB_INT_Enable(USB_INT_WAKEUPI);
84

    
85
                USB_CLK_Freeze();
86

    
87
                USB_DeviceState = DEVICE_STATE_Suspended;
88
                EVENT_USB_Device_Suspend();
89
        }
90

    
91
        if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
92
        {
93
                USB_CLK_Unfreeze();
94

    
95
                USB_INT_Clear(USB_INT_WAKEUPI);
96

    
97
                USB_INT_Disable(USB_INT_WAKEUPI);
98
                USB_INT_Enable(USB_INT_SUSPI);
99

    
100
                if (USB_Device_ConfigurationNumber)
101
                  USB_DeviceState = DEVICE_STATE_Configured;
102
                else
103
                  USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
104

    
105
                EVENT_USB_Device_WakeUp();
106
        }
107

    
108
        if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
109
        {
110
                USB_INT_Clear(USB_INT_EORSTI);
111

    
112
                USB_DeviceState                = DEVICE_STATE_Default;
113
                USB_Device_ConfigurationNumber = 0;
114

    
115
                USB_INT_Clear(USB_INT_SUSPI);
116
                USB_INT_Disable(USB_INT_SUSPI);
117
                USB_INT_Enable(USB_INT_WAKEUPI);
118

    
119
                USB_Device_SetDeviceAddress(0);
120
                Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
121
                                           ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
122
                                           ENDPOINT_BANK_SINGLE);
123

    
124
                #if defined(INTERRUPT_CONTROL_ENDPOINT)
125
                USB_INT_Enable(USB_INT_RXSTPI);
126
                #endif
127

    
128
                EVENT_USB_Device_Reset();
129
        }
130
        #endif
131

    
132
        #if defined(USB_CAN_BE_HOST)
133
        #if !defined(NO_SOF_EVENTS)
134
        if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
135
        {
136
                USB_INT_Clear(USB_INT_HSOFI);
137

    
138
                EVENT_USB_Host_StartOfFrame();
139
        }
140
        #endif
141

    
142
        if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
143
        {
144
                USB_INT_Clear(USB_INT_DDISCI);
145
                USB_INT_Clear(USB_INT_DCONNI);
146
                USB_INT_Disable(USB_INT_DDISCI);
147

    
148
                EVENT_USB_Host_DeviceUnattached();
149

    
150
                USB_ResetInterface();
151
        }
152

    
153
        if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
154
        {
155
                USB_INT_Clear(USB_INT_VBERRI);
156

    
157
                USB_Host_VBUS_Manual_Off();
158
                USB_Host_VBUS_Auto_Off();
159

    
160
                EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
161
                EVENT_USB_Host_DeviceUnattached();
162

    
163
                USB_HostState = HOST_STATE_Unattached;
164
        }
165

    
166
        if (USB_INT_HasOccurred(USB_INT_DCONNI) && USB_INT_IsEnabled(USB_INT_DCONNI))
167
        {
168
                USB_INT_Clear(USB_INT_DCONNI);
169
                USB_INT_Disable(USB_INT_DCONNI);
170

    
171
                EVENT_USB_Host_DeviceAttached();
172

    
173
                USB_INT_Enable(USB_INT_DDISCI);
174

    
175
                USB_HostState = HOST_STATE_Powered;
176
        }
177

    
178
        if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
179
        {
180
                USB_INT_Clear(USB_INT_BCERRI);
181

    
182
                EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
183
                EVENT_USB_Host_DeviceUnattached();
184

    
185
                USB_ResetInterface();
186
        }
187
        #endif
188

    
189
        #if defined(USB_CAN_BE_BOTH)
190
        if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
191
        {
192
                USB_INT_Clear(USB_INT_IDTI);
193

    
194
                if (USB_DeviceState != DEVICE_STATE_Unattached)
195
                  EVENT_USB_Device_Disconnect();
196

    
197
                if (USB_HostState != HOST_STATE_Unattached)
198
                  EVENT_USB_Host_DeviceUnattached();
199

    
200
                USB_CurrentMode = USB_GetUSBModeFromUID();
201
                USB_ResetInterface();
202

    
203
                EVENT_USB_UIDChange();
204
        }
205
        #endif
206
}
207

    
208
#if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
209
ISR(USB_COM_vect)
210
{
211
        uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
212

    
213
        Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
214
        USB_INT_Disable(USB_INT_RXSTPI);
215

    
216
        GlobalInterruptEnable();
217

    
218
        USB_Device_ProcessControlRequest();
219

    
220
        Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
221
        USB_INT_Enable(USB_INT_RXSTPI);
222
        Endpoint_SelectEndpoint(PrevSelectedEndpoint);
223
}
224
#endif
225