]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/lufa/LUFA-git/LUFA/Platform/UC3/InterruptManagement.h
Merge commit '71381457fa1311dfa0b58ba882a96db740640871'
[max/tmk_keyboard.git] / tmk_core / protocol / lufa / LUFA-git / LUFA / Platform / UC3 / InterruptManagement.h
1 /*
2              LUFA Library
3      Copyright (C) Dean Camera, 2014.
4
5   dean [at] fourwalledcubicle [dot] com
6            www.lufa-lib.org
7 */
8
9 /*
10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28   this software.
29 */
30
31 /** \file
32  *  \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.
33  *
34  *  Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt
35  *  handlers within the device.
36  */
37
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.
41  *
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>
46  *
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.
50  *
51  *  Usage Example:
52  *  \code
53  *              #include <LUFA/Platform/UC3/InterruptManagement.h>
54  *
55  *              ISR(USB_Group_IRQ_Handler)
56  *              {
57  *                      // USB group handler code here
58  *              }
59  *
60  *              void main(void)
61  *              {
62  *                      INTC_Init();
63  *                      INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_Group_IRQ_Handler);
64  *              }
65  *  \endcode
66  *
67  *  @{
68  */
69
70 #ifndef _UC3_INTERRUPT_MANAGEMENT_H_
71 #define _UC3_INTERRUPT_MANAGEMENT_H_
72
73         /* Includes: */
74                 #include "../../Common/Common.h"
75
76         /* Enable C linkage for C++ Compilers: */
77                 #if defined(__cplusplus)
78                         extern "C" {
79                 #endif
80
81         /* Private Interface - For use in library only: */
82         #if !defined(__DOXYGEN__)
83                 /* Type Defines: */
84                         typedef void (*InterruptHandlerPtr_t)(void);
85
86                 /* External Variables: */
87                         #if defined(__INCLUDE_FROM_INTMANAGEMENT_C)
88                                 extern const void        EVBA_Table;
89                         #endif
90                         extern InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];
91                         extern const uint32_t        Autovector_Table[];
92         #endif
93
94         /* Public Interface - May be used in end-application: */
95                 /* Macros: */
96                         /** Converts a given interrupt index into its associated interrupt group.
97                          *
98                          *  \param[in] IRQIndex  Index of the interrupt request to convert.
99                          *
100                          *  \return Interrupt group number associated with the interrupt index.
101                          */
102                         #define INTC_IRQ_GROUP(IRQIndex)  (IRQIndex / 32)
103
104                         /** Converts a given interrupt index into its associated interrupt line.
105                          *
106                          *  \param[in] IRQIndex  Index of the interrupt request to convert.
107                          *
108                          *  \return Interrupt line number associated with the interrupt index.
109                          */
110                         #define INTC_IRQ_LINE(IRQIndex)   (IRQIndex % 32)
111
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.
115                          */
116                         void INTC_Init(void);
117
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.
120                          *
121                          *  \param[in] InterruptLevel  Priority level of the interrupt.
122                          *
123                          *  \return Pointer to the associated interrupt handler function, or NULL if no handler set.
124                          */
125                         InterruptHandlerPtr_t INTC_GetInterruptHandler(const uint_reg_t InterruptLevel);
126
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().
131                          *
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.
134                          *
135                          *  To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro.
136                          *
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.
140                          */
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)
147                         {
148                                 InterruptHandlers[GroupNumber] = Handler;
149                                 AVR32_INTC.ipr[GroupNumber]    = Autovector_Table[InterruptLevel];
150                         }
151
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.
155                          *
156                          *  \param[in] GroupNumber Group number of the interrupt group to check.
157                          *
158                          *  \return Mask of pending interrupt lines for the given interrupt group.
159                          */
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)
162                         {
163                                 return AVR32_INTC.irr[GroupNumber];
164                         }
165
166         /* Disable C linkage for C++ Compilers: */
167                 #if defined(__cplusplus)
168                         }
169                 #endif
170
171 #endif
172
173 /** @} */
174