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 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_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_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 <LUFA/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, nulling out all interrupt handlers ready for new registration. This 
 114                          *  function should be called once on startup to ensure the interrupt controller is ready for use. 
 116                         void INTC_Init(void); 
 118                 /* Inline Functions: */ 
 119                         /** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by 
 120                          *  peripheral. To save on SRAM used, a single ISR handles all interrupt lines within a single group - to 
 121                          *  determine the exact line that has interrupted within the group ISR handler, use \ref INTC_GetGroupInterrupts(). 
 123                          *  If multiple interrupts with the same group are registered, the last registered handler will become the 
 124                          *  handler called for interrupts raised within that group. 
 126                          *  To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro. 
 128                          *  \param[in] GroupNumber       Group number of the interrupt group to register a handler for. 
 129                          *  \param[in] InterruptLevel    Priority level for the specified interrupt, a \c AVR32_INTC_INT* mask. 
 130                          *  \param[in] Handler           Address of the ISR handler for the interrupt group. 
 132                         static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber
, 
 133                                                                      const uint8_t InterruptLevel
, 
 134                                                                      const InterruptHandlerPtr_t Handler
) ATTR_ALWAYS_INLINE
; 
 135                         static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber
, 
 136                                                                      const uint8_t InterruptLevel
, 
 137                                                                      const InterruptHandlerPtr_t Handler
) 
 139                                 InterruptHandlers
[GroupNumber
] = Handler
; 
 140                                 AVR32_INTC
.ipr
[GroupNumber
]    = Autovector_Table
[InterruptLevel
]; 
 143                         /** Retrieves the pending interrupts for a given interrupt group. The result of this function should be masked 
 144                          *  against interrupt request indexes converted to a request line number via the \ref INTC_IRQ_LINE() macro. To 
 145                          *  obtain the group number of a given interrupt request, use the \ref INTC_IRQ_GROUP() macro. 
 147                          *  \param[in] GroupNumber Group number of the interrupt group to check. 
 149                          *  \return Mask of pending interrupt lines for the given interrupt group. 
 151                         static inline uint_reg_t 
INTC_GetGroupInterrupts(const uint16_t GroupNumber
) ATTR_ALWAYS_INLINE
; 
 152                         static inline uint_reg_t 
INTC_GetGroupInterrupts(const uint16_t GroupNumber
) 
 154                                 return AVR32_INTC
.irr
[GroupNumber
]; 
 157         /* Disable C linkage for C++ Compilers: */ 
 158                 #if defined(__cplusplus)