3      Copyright (C) Dean Camera, 2011. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  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. 
  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 
  31 #define  __INCLUDE_FROM_USB_DRIVER 
  32 #include "../USBInterrupt.h" 
  34 void USB_INT_DisableAllInterrupts(void) 
  36         AVR32_USBB
.USBCON
.vbuste 
= false; 
  37         AVR32_USBB
.USBCON
.idte   
= false; 
  39         AVR32_USBB
.uhinteclr     
= -1; 
  40         AVR32_USBB
.udinteclr     
= -1; 
  43 void USB_INT_ClearAllInterrupts(void) 
  45         AVR32_USBB
.USBSTACLR
.vbustic 
= true; 
  46         AVR32_USBB
.USBSTACLR
.idtic   
= true; 
  48         AVR32_USBB
.uhintclr      
= -1; 
  49         AVR32_USBB
.udintclr      
= -1; 
  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
)) 
  58                 USB_INT_Clear(USB_INT_SOFI
); 
  60                 EVENT_USB_Device_StartOfFrame(); 
  64         if (USB_INT_HasOccurred(USB_INT_VBUSTI
) && USB_INT_IsEnabled(USB_INT_VBUSTI
)) 
  66                 USB_INT_Clear(USB_INT_VBUSTI
); 
  68                 if (USB_VBUS_GetStatus()) 
  70                         USB_DeviceState 
= DEVICE_STATE_Powered
; 
  71                         EVENT_USB_Device_Connect(); 
  75                         USB_DeviceState 
= DEVICE_STATE_Unattached
; 
  76                         EVENT_USB_Device_Disconnect(); 
  80         if (USB_INT_HasOccurred(USB_INT_SUSPI
) && USB_INT_IsEnabled(USB_INT_SUSPI
)) 
  82                 USB_INT_Disable(USB_INT_SUSPI
); 
  83                 USB_INT_Enable(USB_INT_WAKEUPI
); 
  87                 USB_DeviceState 
= DEVICE_STATE_Suspended
; 
  88                 EVENT_USB_Device_Suspend(); 
  91         if (USB_INT_HasOccurred(USB_INT_WAKEUPI
) && USB_INT_IsEnabled(USB_INT_WAKEUPI
)) 
  95                 USB_INT_Clear(USB_INT_WAKEUPI
); 
  97                 USB_INT_Disable(USB_INT_WAKEUPI
); 
  98                 USB_INT_Enable(USB_INT_SUSPI
); 
 100                 if (USB_ConfigurationNumber
) 
 101                   USB_DeviceState 
= DEVICE_STATE_Configured
; 
 103                   USB_DeviceState 
= (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured 
: DEVICE_STATE_Powered
; 
 105                 EVENT_USB_Device_WakeUp(); 
 108         if (USB_INT_HasOccurred(USB_INT_EORSTI
) && USB_INT_IsEnabled(USB_INT_EORSTI
)) 
 110                 USB_INT_Clear(USB_INT_EORSTI
); 
 112                 USB_DeviceState         
= DEVICE_STATE_Default
; 
 113                 USB_ConfigurationNumber 
= 0; 
 115                 USB_INT_Clear(USB_INT_SUSPI
); 
 116                 USB_INT_Disable(USB_INT_SUSPI
); 
 117                 USB_INT_Enable(USB_INT_WAKEUPI
); 
 119                 USB_Device_SetDeviceAddress(0); 
 120                 Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP
, EP_TYPE_CONTROL
, 
 121                                            ENDPOINT_DIR_OUT
, USB_ControlEndpointSize
, 
 122                                            ENDPOINT_BANK_SINGLE
); 
 124                 EVENT_USB_Device_Reset(); 
 128         #if defined(USB_CAN_BE_HOST) 
 129         #if !defined(NO_SOF_EVENTS) 
 130         if (USB_INT_HasOccurred(USB_INT_HSOFI
) && USB_INT_IsEnabled(USB_INT_HSOFI
)) 
 132                 USB_INT_Clear(USB_INT_HSOFI
); 
 134                 EVENT_USB_Host_StartOfFrame(); 
 138         if (USB_INT_HasOccurred(USB_INT_DDISCI
) && USB_INT_IsEnabled(USB_INT_DDISCI
)) 
 140                 USB_INT_Clear(USB_INT_DDISCI
); 
 141                 USB_INT_Clear(USB_INT_DCONNI
); 
 142                 USB_INT_Disable(USB_INT_DDISCI
); 
 144                 EVENT_USB_Host_DeviceUnattached(); 
 146                 USB_ResetInterface(); 
 149         if (USB_INT_HasOccurred(USB_INT_VBERRI
) && USB_INT_IsEnabled(USB_INT_VBERRI
)) 
 151                 USB_INT_Clear(USB_INT_VBERRI
); 
 153                 USB_Host_VBUS_Manual_Off(); 
 154                 USB_Host_VBUS_Auto_Off(); 
 156                 EVENT_USB_Host_HostError(HOST_ERROR_VBusVoltageDip
); 
 157                 EVENT_USB_Host_DeviceUnattached(); 
 159                 USB_HostState 
= HOST_STATE_Unattached
; 
 162         if (USB_INT_HasOccurred(USB_INT_DCONNI
) && USB_INT_IsEnabled(USB_INT_DCONNI
)) 
 164                 USB_INT_Clear(USB_INT_DCONNI
); 
 165                 USB_INT_Disable(USB_INT_DCONNI
); 
 167                 EVENT_USB_Host_DeviceAttached(); 
 169                 USB_INT_Enable(USB_INT_DDISCI
); 
 171                 USB_HostState 
= HOST_STATE_Powered
; 
 174         if (USB_INT_HasOccurred(USB_INT_BCERRI
) && USB_INT_IsEnabled(USB_INT_BCERRI
)) 
 176                 USB_INT_Clear(USB_INT_BCERRI
); 
 178                 EVENT_USB_Host_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected
, 0); 
 179                 EVENT_USB_Host_DeviceUnattached(); 
 181                 USB_ResetInterface(); 
 185         #if defined(USB_CAN_BE_BOTH) 
 186         if (USB_INT_HasOccurred(USB_INT_IDTI
) && USB_INT_IsEnabled(USB_INT_IDTI
)) 
 188                 USB_INT_Clear(USB_INT_IDTI
); 
 190                 if (USB_DeviceState 
!= DEVICE_STATE_Unattached
) 
 191                   EVENT_USB_Device_Disconnect(); 
 193                 if (USB_HostState 
!= HOST_STATE_Unattached
) 
 194                   EVENT_USB_Host_DeviceUnattached(); 
 196                 USB_CurrentMode 
= USB_GetUSBModeFromUID(); 
 197                 USB_ResetInterface(); 
 199                 EVENT_USB_UIDChange();