3      Copyright (C) Dean Camera, 2013. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2013  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 disclaims 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 Interrupt Controller Driver for the AVR32 UC3 microcontrollers. 
  34  *  Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt 
  35  *  handlers within the device. 
  38 /** \ingroup Group_PlatformDrivers_UC3 
  39  *  \defgroup Group_PlatformDrivers_UC3Interrupts Interrupt Controller Driver - LUFA/Platform/UC3/InterruptManagement.h 
  40  *  \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers. 
  42  *  \section Sec_PlatformDrivers_UC3Interrupts_Dependencies Module Source Dependencies 
  43  *  The following files must be built with any user project that uses this module: 
  44  *    - LUFA/Platform/UC3/InterruptManagement.c <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i> 
  45  *    - LUFA/Platform/UC3/Exception.S <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i> 
  47  *  \section Sec_PlatformDrivers_UC3Interrupts_ModDescription Module Description 
  48  *  Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt 
  49  *  handlers within the device. 
  53  *              #include <LUFA/Platform/UC3/InterruptManagement.h> 
  55  *              ISR(USB_Group_IRQ_Handler) 
  57  *                      // USB group handler code here 
  63  *                      INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_Group_IRQ_Handler); 
  70 #ifndef _UC3_INTERRUPT_MANAGEMENT_H_ 
  71 #define _UC3_INTERRUPT_MANAGEMENT_H_ 
  74                 #include "../../Common/Common.h" 
  76         /* Enable C linkage for C++ Compilers: */ 
  77                 #if defined(__cplusplus) 
  81         /* Private Interface - For use in library only: */ 
  82         #if !defined(__DOXYGEN__) 
  84                         typedef void (*InterruptHandlerPtr_t
)(void); 
  86                 /* External Variables: */ 
  87                         #if defined(__INCLUDE_FROM_INTMANAGEMENT_C) 
  88                                 extern const void        EVBA_Table
; 
  90                         extern InterruptHandlerPtr_t InterruptHandlers
[AVR32_INTC_NUM_INT_GRPS
]; 
  91                         extern const uint32_t        Autovector_Table
[]; 
  94         /* Public Interface - May be used in end-application: */ 
  96                         /** Converts a given interrupt index into its associated interrupt group. 
  98                          *  \param[in] IRQIndex  Index of the interrupt request to convert. 
 100                          *  \return Interrupt group number associated with the interrupt index. 
 102                         #define INTC_IRQ_GROUP(IRQIndex)  (IRQIndex / 32) 
 104                         /** Converts a given interrupt index into its associated interrupt line. 
 106                          *  \param[in] IRQIndex  Index of the interrupt request to convert. 
 108                          *  \return Interrupt line number associated with the interrupt index. 
 110                         #define INTC_IRQ_LINE(IRQIndex)   (IRQIndex % 32) 
 112                 /* Function Prototypes: */ 
 113                         /** Initializes the interrupt controller ready to handle interrupts. This must be called at the 
 114                          *  start of the user program before any interrupts are registered or enabled. 
 116                         void INTC_Init(void); 
 118                         /** Retrieves the associated interrupt handler for the interrupt group currently being fired. This 
 119                          *  is called directly from the exception handler routine before dispatching to the ISR. 
 121                          *  \param[in] InterruptLevel  Priority level of the interrupt. 
 123                          *  \return Pointer to the associated interrupt handler function, or NULL if no handler set. 
 125                         InterruptHandlerPtr_t 
INTC_GetInterruptHandler(const uint_reg_t InterruptLevel
); 
 127                 /* Inline Functions: */ 
 128                         /** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by 
 129                          *  peripheral. To save on SRAM used, a single ISR handles all interrupt lines within a single group - to 
 130                          *  determine the exact line that has interrupted within the group ISR handler, use \ref INTC_GetGroupInterrupts(). 
 132                          *  If multiple interrupts with the same group are registered, the last registered handler will become the 
 133                          *  handler called for interrupts raised within that group. 
 135                          *  To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro. 
 137                          *  \param[in] GroupNumber       Group number of the interrupt group to register a handler for. 
 138                          *  \param[in] InterruptLevel    Priority level for the specified interrupt, a \c AVR32_INTC_INT* mask. 
 139                          *  \param[in] Handler           Address of the ISR handler for the interrupt group. 
 141                         static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber
, 
 142                                                                      const uint8_t InterruptLevel
, 
 143                                                                      const InterruptHandlerPtr_t Handler
) ATTR_ALWAYS_INLINE
; 
 144                         static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber
, 
 145                                                                      const uint8_t InterruptLevel
, 
 146                                                                      const InterruptHandlerPtr_t Handler
) 
 148                                 InterruptHandlers
[GroupNumber
] = Handler
; 
 149                                 AVR32_INTC
.ipr
[GroupNumber
]    = Autovector_Table
[InterruptLevel
]; 
 152                         /** Retrieves the pending interrupts for a given interrupt group. The result of this function should be masked 
 153                          *  against interrupt request indexes converted to a request line number via the \ref INTC_IRQ_LINE() macro. To 
 154                          *  obtain the group number of a given interrupt request, use the \ref INTC_IRQ_GROUP() macro. 
 156                          *  \param[in] GroupNumber Group number of the interrupt group to check. 
 158                          *  \return Mask of pending interrupt lines for the given interrupt group. 
 160                         static inline uint_reg_t 
INTC_GetGroupInterrupts(const uint16_t GroupNumber
) ATTR_ALWAYS_INLINE
; 
 161                         static inline uint_reg_t 
INTC_GetGroupInterrupts(const uint16_t GroupNumber
) 
 163                                 return AVR32_INTC
.irr
[GroupNumber
]; 
 166         /* Disable C linkage for C++ Compilers: */ 
 167                 #if defined(__cplusplus)