Add missing doxygen group terminator to the new CompilerSpecific.h header file.
[pub/USBasp.git] / LUFA / Drivers / USB / Core / AVR8 / USBInterrupt_AVR8.c
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 #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
37 USBCON &= ~((1 << VBUSTE) | (1 << IDTE));
38 #elif defined(USB_SERIES_4_AVR)
39 USBCON &= ~(1 << VBUSTE);
40 #endif
41
42 #if defined(USB_CAN_BE_BOTH)
43 OTGIEN = 0;
44 #endif
45
46 #if defined(USB_CAN_BE_HOST)
47 UHIEN = 0;
48 #endif
49
50 #if defined(USB_CAN_BE_DEVICE)
51 UDIEN = 0;
52 #endif
53 }
54
55 void USB_INT_ClearAllInterrupts(void)
56 {
57 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
58 USBINT = 0;
59 #endif
60
61 #if defined(USB_CAN_BE_BOTH)
62 OTGINT = 0;
63 #endif
64
65 #if defined(USB_CAN_BE_HOST)
66 UHINT = 0;
67 #endif
68
69 #if defined(USB_CAN_BE_DEVICE)
70 UDINT = 0;
71 #endif
72 }
73
74 ISR(USB_GEN_vect, ISR_BLOCK)
75 {
76 #if defined(USB_CAN_BE_DEVICE)
77 #if !defined(NO_SOF_EVENTS)
78 if (USB_INT_HasOccurred(USB_INT_SOFI) && USB_INT_IsEnabled(USB_INT_SOFI))
79 {
80 USB_INT_Clear(USB_INT_SOFI);
81
82 EVENT_USB_Device_StartOfFrame();
83 }
84 #endif
85
86 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
87 if (USB_INT_HasOccurred(USB_INT_VBUSTI) && USB_INT_IsEnabled(USB_INT_VBUSTI))
88 {
89 USB_INT_Clear(USB_INT_VBUSTI);
90
91 if (USB_VBUS_GetStatus())
92 {
93 if (!(USB_Options & USB_OPT_MANUAL_PLL))
94 {
95 USB_PLL_On();
96 while (!(USB_PLL_IsReady()));
97 }
98
99 USB_DeviceState = DEVICE_STATE_Powered;
100 EVENT_USB_Device_Connect();
101 }
102 else
103 {
104 if (!(USB_Options & USB_OPT_MANUAL_PLL))
105 USB_PLL_Off();
106
107 USB_DeviceState = DEVICE_STATE_Unattached;
108 EVENT_USB_Device_Disconnect();
109 }
110 }
111 #endif
112
113 if (USB_INT_HasOccurred(USB_INT_SUSPI) && USB_INT_IsEnabled(USB_INT_SUSPI))
114 {
115 USB_INT_Disable(USB_INT_SUSPI);
116 USB_INT_Enable(USB_INT_WAKEUPI);
117
118 USB_CLK_Freeze();
119
120 if (!(USB_Options & USB_OPT_MANUAL_PLL))
121 USB_PLL_Off();
122
123 #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
124 USB_DeviceState = DEVICE_STATE_Unattached;
125 EVENT_USB_Device_Disconnect();
126 #else
127 USB_DeviceState = DEVICE_STATE_Suspended;
128 EVENT_USB_Device_Suspend();
129 #endif
130 }
131
132 if (USB_INT_HasOccurred(USB_INT_WAKEUPI) && USB_INT_IsEnabled(USB_INT_WAKEUPI))
133 {
134 if (!(USB_Options & USB_OPT_MANUAL_PLL))
135 {
136 USB_PLL_On();
137 while (!(USB_PLL_IsReady()));
138 }
139
140 USB_CLK_Unfreeze();
141
142 USB_INT_Clear(USB_INT_WAKEUPI);
143
144 USB_INT_Disable(USB_INT_WAKEUPI);
145 USB_INT_Enable(USB_INT_SUSPI);
146
147 if (USB_ConfigurationNumber)
148 USB_DeviceState = DEVICE_STATE_Configured;
149 else
150 USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
151
152 #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
153 EVENT_USB_Device_Connect();
154 #else
155 EVENT_USB_Device_WakeUp();
156 #endif
157 }
158
159 if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
160 {
161 USB_INT_Clear(USB_INT_EORSTI);
162
163 USB_DeviceState = DEVICE_STATE_Default;
164 USB_ConfigurationNumber = 0;
165
166 USB_INT_Clear(USB_INT_SUSPI);
167 USB_INT_Disable(USB_INT_SUSPI);
168 USB_INT_Enable(USB_INT_WAKEUPI);
169
170 Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
171 ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
172 ENDPOINT_BANK_SINGLE);
173
174 #if defined(INTERRUPT_CONTROL_ENDPOINT)
175 USB_INT_Enable(USB_INT_RXSTPI);
176 #endif
177
178 EVENT_USB_Device_Reset();
179 }
180 #endif
181
182 #if defined(USB_CAN_BE_HOST)
183 #if !defined(NO_SOF_EVENTS)
184 if (USB_INT_HasOccurred(USB_INT_HSOFI) && USB_INT_IsEnabled(USB_INT_HSOFI))
185 {
186 USB_INT_Clear(USB_INT_HSOFI);
187
188 EVENT_USB_Host_StartOfFrame();
189 }
190 #endif
191
192 if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
193 {
194 USB_INT_Clear(USB_INT_DDISCI);
195 USB_INT_Clear(USB_INT_DCONNI);
196 USB_INT_Disable(USB_INT_DDISCI);
197
198 EVENT_USB_Host_DeviceUnattached();
199
200 USB_ResetInterface();
201 }
202
203 if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
204 {
205 USB_INT_Clear(USB_INT_VBERRI);
206
207 USB_Host_VBUS_Manual_Off();
208 USB_Host_VBUS_Auto_Off();
209
210 EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
211 EVENT_USB_Host_DeviceUnattached();
212
213 USB_HostState = HOST_STATE_Unattached;
214 }
215
216 if (USB_INT_HasOccurred(USB_INT_SRPI) && USB_INT_IsEnabled(USB_INT_SRPI))
217 {
218 USB_INT_Clear(USB_INT_SRPI);
219 USB_INT_Disable(USB_INT_SRPI);
220
221 EVENT_USB_Host_DeviceAttached();
222
223 USB_INT_Enable(USB_INT_DDISCI);
224
225 USB_HostState = HOST_STATE_Powered;
226 }
227
228 if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
229 {
230 USB_INT_Clear(USB_INT_BCERRI);
231
232 EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
233 EVENT_USB_Host_DeviceUnattached();
234
235 USB_ResetInterface();
236 }
237 #endif
238
239 #if defined(USB_CAN_BE_BOTH)
240 if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
241 {
242 USB_INT_Clear(USB_INT_IDTI);
243
244 if (USB_DeviceState != DEVICE_STATE_Unattached)
245 EVENT_USB_Device_Disconnect();
246
247 if (USB_HostState != HOST_STATE_Unattached)
248 EVENT_USB_Host_DeviceUnattached();
249
250 USB_CurrentMode = USB_GetUSBModeFromUID();
251 USB_ResetInterface();
252
253 EVENT_USB_UIDChange();
254 }
255 #endif
256 }
257
258 #if defined(INTERRUPT_CONTROL_ENDPOINT) && defined(USB_CAN_BE_DEVICE)
259 ISR(USB_COM_vect, ISR_BLOCK)
260 {
261 uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
262
263 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
264 USB_INT_Disable(USB_INT_RXSTPI);
265
266 GlobalInterruptEnable();
267
268 USB_Device_ProcessControlRequest();
269
270 Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
271 USB_INT_Enable(USB_INT_RXSTPI);
272 Endpoint_SelectEndpoint(PrevSelectedEndpoint);
273 }
274 #endif
275