Add architecture guards to all architecture-specific files, so that they can be bulk...
[pub/USBasp.git] / LUFA / Drivers / USB / Core / UC3 / USBInterrupt_UC3.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 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 #include "../../../../Common/Common.h"
32 #if (ARCH == ARCH_UC3)
33
34 #define __INCLUDE_FROM_USB_DRIVER
35 #include "../USBInterrupt.h"
36
37 void USB_INT_DisableAllInterrupts(void)
38 {
39 AVR32_USBB.USBCON.vbuste = false;
40 AVR32_USBB.USBCON.idte = false;
41
42 AVR32_USBB.uhinteclr = -1;
43 AVR32_USBB.udinteclr = -1;
44 }
45
46 void USB_INT_ClearAllInterrupts(void)
47 {
48 AVR32_USBB.USBSTACLR.vbustic = true;
49 AVR32_USBB.USBSTACLR.idtic = true;
50
51 AVR32_USBB.uhintclr = -1;
52 AVR32_USBB.udintclr = -1;
53 }
54
55 ISR(USB_GEN_vect)
56 {
57 #if defined(USB_CAN_BE_DEVICE)
58 #if !defined(NO_SOF_EVENTS)
59 if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
60 {
61 USB_INT_Clear(USB_INT_SOFI);
62
63 EVENT_USB_Device_StartOfFrame();
64 }
65 #endif
66
67 if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
68 {
69 USB_INT_Clear(USB_INT_VBUSTI);
70
71 if (USB_VBUS_GetStatus())
72 {
73 USB_DeviceState = DEVICE_STATE_Powered;
74 EVENT_USB_Device_Connect();
75 }
76 else
77 {
78 USB_DeviceState = DEVICE_STATE_Unattached;
79 EVENT_USB_Device_Disconnect();
80 }
81 }
82
83 if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
84 {
85 USB_INT_Disable(USB_INT_SUSPI);
86 USB_INT_Enable(USB_INT_WAKEUPI);
87
88 USB_CLK_Freeze();
89
90 USB_DeviceState = DEVICE_STATE_Suspended;
91 EVENT_USB_Device_Suspend();
92 }
93
94 if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
95 {
96 USB_CLK_Unfreeze();
97
98 USB_INT_Clear(USB_INT_WAKEUPI);
99
100 USB_INT_Disable(USB_INT_WAKEUPI);
101 USB_INT_Enable(USB_INT_SUSPI);
102
103 if (USB_Device_ConfigurationNumber)
104 USB_DeviceState = DEVICE_STATE_Configured;
105 else
106 USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
107
108 EVENT_USB_Device_WakeUp();
109 }
110
111 if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
112 {
113 USB_INT_Clear(USB_INT_EORSTI);
114
115 USB_DeviceState = DEVICE_STATE_Default;
116 USB_Device_ConfigurationNumber = 0;
117
118 USB_INT_Clear(USB_INT_SUSPI);
119 USB_INT_Disable(USB_INT_SUSPI);
120 USB_INT_Enable(USB_INT_WAKEUPI);
121
122 USB_Device_SetDeviceAddress(0);
123 Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
124 ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
125 ENDPOINT_BANK_SINGLE);
126
127 #if defined(INTERRUPT_CONTROL_ENDPOINT)
128 USB_INT_Enable(USB_INT_RXSTPI);
129 #endif
130
131 EVENT_USB_Device_Reset();
132 }
133 #endif
134
135 #if defined(USB_CAN_BE_HOST)
136 #if !defined(NO_SOF_EVENTS)
137 if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
138 {
139 USB_INT_Clear(USB_INT_HSOFI);
140
141 EVENT_USB_Host_StartOfFrame();
142 }
143 #endif
144
145 if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
146 {
147 USB_INT_Clear(USB_INT_DDISCI);
148 USB_INT_Clear(USB_INT_DCONNI);
149 USB_INT_Disable(USB_INT_DDISCI);
150
151 EVENT_USB_Host_DeviceUnattached();
152
153 USB_ResetInterface();
154 }
155
156 if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
157 {
158 USB_INT_Clear(USB_INT_VBERRI);
159
160 USB_Host_VBUS_Manual_Off();
161 USB_Host_VBUS_Auto_Off();
162
163 EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
164 EVENT_USB_Host_DeviceUnattached();
165
166 USB_HostState = HOST_STATE_Unattached;
167 }
168
169 if (USB_INT_HasOccurred(USB_INT_DCONNI) && USB_INT_IsEnabled(USB_INT_DCONNI))
170 {
171 USB_INT_Clear(USB_INT_DCONNI);
172 USB_INT_Disable(USB_INT_DCONNI);
173
174 EVENT_USB_Host_DeviceAttached();
175
176 USB_INT_Enable(USB_INT_DDISCI);
177
178 USB_HostState = HOST_STATE_Powered;
179 }
180
181 if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
182 {
183 USB_INT_Clear(USB_INT_BCERRI);
184
185 EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
186 EVENT_USB_Host_DeviceUnattached();
187
188 USB_ResetInterface();
189 }
190 #endif
191
192 #if defined(USB_CAN_BE_BOTH)
193 if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
194 {
195 USB_INT_Clear(USB_INT_IDTI);
196
197 if (USB_DeviceState != DEVICE_STATE_Unattached)
198 EVENT_USB_Device_Disconnect();
199
200 if (USB_HostState != HOST_STATE_Unattached)
201 EVENT_USB_Host_DeviceUnattached();
202
203 USB_CurrentMode = USB_GetUSBModeFromUID();
204 USB_ResetInterface();
205
206 EVENT_USB_UIDChange();
207 }
208 #endif
209 }
210
211 #if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
212 ISR(USB_COM_vect)
213 {
214 uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
215
216 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
217 USB_INT_Disable(USB_INT_RXSTPI);
218
219 GlobalInterruptEnable();
220
221 USB_Device_ProcessControlRequest();
222
223 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
224 USB_INT_Enable(USB_INT_RXSTPI);
225 Endpoint_SelectEndpoint(PrevSelectedEndpoint);
226 }
227 #endif
228
229 #endif