3      Copyright (C) Dean Camera, 2012. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2012  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 
  32  *  \brief USB Controller Interrupt definitions for the AVR8 microcontrollers. 
  34  *  This file contains definitions required for the correct handling of low level USB service routine interrupts 
  35  *  from the USB controller. 
  37  *  \note This file should not be included directly. It is automatically included as needed by the USB driver 
  38  *        dispatch header located in LUFA/Drivers/USB/USB.h. 
  41 #ifndef __USBINTERRUPT_AVR8_H__ 
  42 #define __USBINTERRUPT_AVR8_H__ 
  45                 #include "../../../../Common/Common.h" 
  47         /* Enable C linkage for C++ Compilers: */ 
  48                 #if defined(__cplusplus) 
  52         /* Preprocessor Checks: */ 
  53                 #if !defined(__INCLUDE_FROM_USB_DRIVER) 
  54                         #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead. 
  57         /* Private Interface - For use in library only: */ 
  58         #if !defined(__DOXYGEN__) 
  62                                 #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)) 
  65                                 #if (defined(USB_CAN_BE_BOTH) || defined(__DOXYGEN__)) 
  68                                 #if (defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)) 
  75                                 #if (defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)) 
  86                 /* Inline Functions: */ 
  87                         static inline void USB_INT_Enable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
; 
  88                         static inline void USB_INT_Enable(const uint8_t Interrupt
) 
  92                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
  94                                                 USBCON 
|= (1 << VBUSTE
); 
  97                                         #if defined(USB_CAN_BE_BOTH) 
  99                                                 USBCON 
|= (1 << IDTE
); 
 102                                         #if defined(USB_CAN_BE_DEVICE) 
 103                                         case USB_INT_WAKEUPI
: 
 104                                                 UDIEN  
|= (1 << WAKEUPE
); 
 107                                                 UDIEN  
|= (1 << SUSPE
); 
 110                                                 UDIEN  
|= (1 << EORSTE
); 
 113                                                 UDIEN  
|= (1 << SOFE
); 
 116                                                 UEIENX 
|= (1 << RXSTPE
); 
 119                                         #if defined(USB_CAN_BE_HOST) 
 121                                                 UHIEN  
|= (1 << HSOFE
); 
 124                                                 UHIEN  
|= (1 << DCONNE
); 
 127                                                 UHIEN  
|= (1 << DDISCE
); 
 130                                                 UHIEN  
|= (1 << RSTE
); 
 133                                                 OTGIEN 
|= (1 << BCERRE
); 
 136                                                 OTGIEN 
|= (1 << VBERRE
); 
 139                                                 OTGIEN 
|= (1 << SRPE
); 
 145                         static inline void USB_INT_Disable(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
; 
 146                         static inline void USB_INT_Disable(const uint8_t Interrupt
) 
 150                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 152                                                 USBCON 
&= ~(1 << VBUSTE
); 
 155                                         #if defined(USB_CAN_BE_BOTH) 
 157                                                 USBCON 
&= ~(1 << IDTE
); 
 160                                         #if defined(USB_CAN_BE_DEVICE) 
 161                                         case USB_INT_WAKEUPI
: 
 162                                                 UDIEN  
&= ~(1 << WAKEUPE
); 
 165                                                 UDIEN  
&= ~(1 << SUSPE
); 
 168                                                 UDIEN  
&= ~(1 << EORSTE
); 
 171                                                 UDIEN  
&= ~(1 << SOFE
); 
 174                                                 UEIENX 
&= ~(1 << RXSTPE
); 
 177                                         #if defined(USB_CAN_BE_HOST) 
 179                                                 UHIEN  
&= ~(1 << HSOFE
); 
 182                                                 UHIEN  
&= ~(1 << DCONNE
); 
 185                                                 UHIEN  
&= ~(1 << DDISCE
); 
 188                                                 UHIEN  
&= ~(1 << RSTE
); 
 191                                                 OTGIEN 
&= ~(1 << BCERRE
); 
 194                                                 OTGIEN 
&= ~(1 << VBERRE
); 
 197                                                 OTGIEN 
&= ~(1 << SRPE
); 
 203                         static inline void USB_INT_Clear(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE
; 
 204                         static inline void USB_INT_Clear(const uint8_t Interrupt
) 
 208                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 210                                                 USBINT 
&= ~(1 << VBUSTI
); 
 213                                         #if defined(USB_CAN_BE_BOTH) 
 215                                                 USBINT 
&= ~(1 << IDTI
); 
 218                                         #if defined(USB_CAN_BE_DEVICE) 
 219                                         case USB_INT_WAKEUPI
: 
 220                                                 UDINT  
&= ~(1 << WAKEUPI
); 
 223                                                 UDINT  
&= ~(1 << SUSPI
); 
 226                                                 UDINT  
&= ~(1 << EORSTI
); 
 229                                                 UDINT  
&= ~(1 << SOFI
); 
 232                                                 UEINTX 
&= ~(1 << RXSTPI
); 
 235                                         #if defined(USB_CAN_BE_HOST) 
 237                                                 UHINT  
&= ~(1 << HSOFI
); 
 240                                                 UHINT  
&= ~(1 << DCONNI
); 
 243                                                 UHINT  
&= ~(1 << DDISCI
); 
 246                                                 UHINT  
&= ~(1 << RSTI
); 
 249                                                 OTGINT 
&= ~(1 << BCERRI
); 
 252                                                 OTGINT 
&= ~(1 << VBERRI
); 
 255                                                 OTGINT 
&= ~(1 << SRPI
); 
 261                         static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
; 
 262                         static inline bool USB_INT_IsEnabled(const uint8_t Interrupt
) 
 266                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 268                                                 return (USBCON 
& (1 << VBUSTE
)); 
 270                                         #if defined(USB_CAN_BE_BOTH) 
 272                                                 return (USBCON 
& (1 << IDTE
)); 
 274                                         #if defined(USB_CAN_BE_DEVICE) 
 275                                         case USB_INT_WAKEUPI
: 
 276                                                 return (UDIEN  
& (1 << WAKEUPE
)); 
 278                                                 return (UDIEN  
& (1 << SUSPE
)); 
 280                                                 return (UDIEN  
& (1 << EORSTE
)); 
 282                                                 return (UDIEN  
& (1 << SOFE
)); 
 284                                                 return (UEIENX 
& (1 << RXSTPE
)); 
 286                                         #if defined(USB_CAN_BE_HOST) 
 288                                                 return (UHIEN  
& (1 << HSOFE
)); 
 290                                                 return (UHIEN  
& (1 << DCONNE
)); 
 292                                                 return (UHIEN  
& (1 << DDISCE
)); 
 294                                                 return (UHIEN  
& (1 << RSTE
)); 
 296                                                 return (OTGIEN 
& (1 << BCERRE
)); 
 298                                                 return (OTGIEN 
& (1 << VBERRE
)); 
 300                                                 return (OTGIEN 
& (1 << SRPE
)); 
 307                         static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT
; 
 308                         static inline bool USB_INT_HasOccurred(const uint8_t Interrupt
) 
 312                                         #if (defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)) 
 314                                                 return (USBINT 
& (1 << VBUSTI
)); 
 316                                         #if defined(USB_CAN_BE_BOTH) 
 318                                                 return (USBINT 
& (1 << IDTI
)); 
 320                                         #if defined(USB_CAN_BE_DEVICE) 
 321                                         case USB_INT_WAKEUPI
: 
 322                                                 return (UDINT  
& (1 << WAKEUPI
)); 
 324                                                 return (UDINT  
& (1 << SUSPI
)); 
 326                                                 return (UDINT  
& (1 << EORSTI
)); 
 328                                                 return (UDINT  
& (1 << SOFI
)); 
 330                                                 return (UEINTX 
& (1 << RXSTPI
)); 
 332                                         #if defined(USB_CAN_BE_HOST) 
 334                                                 return (UHINT  
& (1 << HSOFI
)); 
 336                                                 return (UHINT  
& (1 << DCONNI
)); 
 338                                                 return (UHINT  
& (1 << DDISCI
)); 
 340                                                 return (UHINT  
& (1 << RSTI
)); 
 342                                                 return (OTGINT 
& (1 << BCERRI
)); 
 344                                                 return (OTGINT 
& (1 << VBERRI
)); 
 346                                                 return (OTGINT 
& (1 << SRPI
)); 
 354                         #include "../USBMode.h" 
 355                         #include "../Events.h" 
 356                         #include "../USBController.h" 
 358                 /* Function Prototypes: */ 
 359                         void USB_INT_ClearAllInterrupts(void); 
 360                         void USB_INT_DisableAllInterrupts(void); 
 363         /* Disable C linkage for C++ Compilers: */ 
 364                 #if defined(__cplusplus)