Fix incorrect Event call name in USBInterrupt.c.
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / USBInterrupt.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 "USBInterrupt.h"
32
33 void USB_INT_DisableAllInterrupts(void)
34 {
35 #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
36 USBCON &= ~((1 << VBUSTE) | (1 << IDTE));
37 #elif defined(USB_SERIES_4_AVR)
38 USBCON &= ~(1 << VBUSTE);
39 #endif
40
41 #if defined(USB_CAN_BE_HOST)
42 UHIEN = 0;
43 OTGIEN = 0;
44 #endif
45
46 #if defined(USB_CAN_BE_DEVICE)
47 UDIEN = 0;
48 #endif
49 }
50
51 void USB_INT_ClearAllInterrupts(void)
52 {
53 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
54 USBINT = 0;
55 #endif
56
57 #if defined(USB_CAN_BE_HOST)
58 UHINT = 0;
59 OTGINT = 0;
60 #endif
61
62 #if defined(USB_CAN_BE_DEVICE)
63 UDINT = 0;
64 #endif
65 }
66
67 ISR(USB_GEN_vect, ISR_BLOCK)
68 {
69 #if defined(USB_CAN_BE_DEVICE)
70 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
71 if (USB_INT_HasOccurred(USB_INT_VBUS) && USB_INT_IsEnabled(USB_INT_VBUS))
72 {
73 USB_INT_Clear(USB_INT_VBUS);
74
75 if (USB_VBUS_GetStatus())
76 {
77 USB_DeviceState = DEVICE_STATE_Powered;
78 EVENT_USB_Device_Connect();
79 }
80 else
81 {
82 USB_DeviceState = DEVICE_STATE_Unattached;
83 EVENT_USB_Device_Disconnect();
84 }
85 }
86 #endif
87
88 if (USB_INT_HasOccurred(USB_INT_SUSPEND) && USB_INT_IsEnabled(USB_INT_SUSPEND))
89 {
90 USB_INT_Clear(USB_INT_SUSPEND);
91
92 USB_INT_Disable(USB_INT_SUSPEND);
93 USB_INT_Enable(USB_INT_WAKEUP);
94
95 USB_CLK_Freeze();
96
97 if (!(USB_Options & USB_OPT_MANUAL_PLL))
98 USB_PLL_Off();
99
100 #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
101 USB_DeviceState = DEVICE_STATE_Unattached;
102 EVENT_USB_Device_Disconnect();
103 #else
104 USB_DeviceState = DEVICE_STATE_Suspended;
105 EVENT_USB_Device_Suspend();
106 #endif
107 }
108
109 if (USB_INT_HasOccurred(USB_INT_WAKEUP) && USB_INT_IsEnabled(USB_INT_WAKEUP))
110 {
111 if (!(USB_Options & USB_OPT_MANUAL_PLL))
112 {
113 USB_PLL_On();
114 while (!(USB_PLL_IsReady()));
115 }
116
117 USB_CLK_Unfreeze();
118
119 USB_INT_Clear(USB_INT_WAKEUP);
120
121 USB_INT_Disable(USB_INT_WAKEUP);
122 USB_INT_Enable(USB_INT_SUSPEND);
123
124 #if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
125 USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
126 EVENT_USB_Device_Connect();
127 #else
128 USB_DeviceState = (USB_ConfigurationNumber) ? DEVICE_STATE_Configured : DEVICE_STATE_Addressed;
129 EVENT_USB_Device_WakeUp();
130 #endif
131 }
132
133 if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
134 {
135 USB_INT_Clear(USB_INT_EORSTI);
136
137 USB_DeviceState = DEVICE_STATE_Default;
138 USB_ConfigurationNumber = 0;
139
140 USB_INT_Clear(USB_INT_SUSPEND);
141 USB_INT_Disable(USB_INT_SUSPEND);
142 USB_INT_Enable(USB_INT_WAKEUP);
143
144 Endpoint_ClearEndpoints();
145
146 Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
147 ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
148 ENDPOINT_BANK_SINGLE);
149
150 #if defined(INTERRUPT_CONTROL_ENDPOINT)
151 USB_INT_Enable(USB_INT_ENDPOINT_SETUP);
152 #endif
153
154 EVENT_USB_Device_Reset();
155 }
156 #endif
157
158 #if defined(USB_CAN_BE_HOST)
159 if (USB_INT_HasOccurred(USB_INT_DDISCI) && USB_INT_IsEnabled(USB_INT_DDISCI))
160 {
161 USB_INT_Clear(USB_INT_DDISCI);
162 USB_INT_Clear(USB_INT_DCONNI);
163 USB_INT_Disable(USB_INT_DDISCI);
164
165 EVENT_USB_Host_DeviceUnattached();
166
167 USB_ResetInterface();
168 }
169
170 if (USB_INT_HasOccurred(USB_INT_VBERRI) && USB_INT_IsEnabled(USB_INT_VBERRI))
171 {
172 USB_INT_Clear(USB_INT_VBERRI);
173
174 USB_Host_VBUS_Manual_Off();
175 USB_Host_VBUS_Auto_Off();
176
177 EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip);
178 EVENT_USB_Host_DeviceUnattached();
179
180 USB_HostState = HOST_STATE_Unattached;
181 }
182
183 if (USB_INT_HasOccurred(USB_INT_SRPI) && USB_INT_IsEnabled(USB_INT_SRPI))
184 {
185 USB_INT_Clear(USB_INT_SRPI);
186 USB_INT_Disable(USB_INT_SRPI);
187
188 EVENT_USB_Host_DeviceAttached();
189
190 USB_INT_Enable(USB_INT_DDISCI);
191
192 USB_HostState = HOST_STATE_Powered;
193 }
194
195 if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
196 {
197 USB_INT_Clear(USB_INT_BCERRI);
198
199 EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
200 EVENT_USB_Host_DeviceUnattached();
201
202 USB_ResetInterface();
203 }
204 #endif
205
206 #if defined(USB_CAN_BE_BOTH)
207 if (USB_INT_HasOccurred(USB_INT_IDTI) && USB_INT_IsEnabled(USB_INT_IDTI))
208 {
209 USB_INT_Clear(USB_INT_IDTI);
210
211 if (USB_DeviceState != DEVICE_STATE_Unattached)
212 EVENT_USB_Device_Disconnect();
213
214 if (USB_HostState != HOST_STATE_Unattached)
215 EVENT_USB_Host_DeviceUnattached();
216
217 USB_CurrentMode = USB_GetUSBModeFromUID();
218 EVENT_USB_UIDChange();
219
220 USB_ResetInterface();
221 }
222 #endif
223 }
224
225 #if defined(INTERRUPT_CONTROL_ENDPOINT)
226 ISR(USB_COM_vect, ISR_NOBLOCK)
227 {
228 uint8_t PrevSelectedEndpoint = Endpoint_GetCurrentEndpoint();
229
230 USB_USBTask();
231
232 USB_INT_Clear(USB_INT_ENDPOINT_SETUP);
233
234 Endpoint_SelectEndpoint(PrevSelectedEndpoint);
235 }
236 #endif