]> git.donarmstrong.com Git - qmk_firmware.git/blob - protocol/lufa/LUFA-120730/LUFA/Platform/UC3/InterruptManagement.h
Squashed 'tmk_core/' content from commit 05caacc
[qmk_firmware.git] / protocol / lufa / LUFA-120730 / LUFA / Platform / UC3 / InterruptManagement.h
1 /*\r
2              LUFA Library\r
3      Copyright (C) Dean Camera, 2012.\r
4 \r
5   dean [at] fourwalledcubicle [dot] com\r
6            www.lufa-lib.org\r
7 */\r
8 \r
9 /*\r
10   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
11 \r
12   Permission to use, copy, modify, distribute, and sell this\r
13   software and its documentation for any purpose is hereby granted\r
14   without fee, provided that the above copyright notice appear in\r
15   all copies and that both that the copyright notice and this\r
16   permission notice and warranty disclaimer appear in supporting\r
17   documentation, and that the name of the author not be used in\r
18   advertising or publicity pertaining to distribution of the\r
19   software without specific, written prior permission.\r
20 \r
21   The author disclaim all warranties with regard to this\r
22   software, including all implied warranties of merchantability\r
23   and fitness.  In no event shall the author be liable for any\r
24   special, indirect or consequential damages or any damages\r
25   whatsoever resulting from loss of use, data or profits, whether\r
26   in an action of contract, negligence or other tortious action,\r
27   arising out of or in connection with the use or performance of\r
28   this software.\r
29 */\r
30 \r
31 /** \file\r
32  *  \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.\r
33  *\r
34  *  Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt\r
35  *  handlers within the device.\r
36  */\r
37 \r
38 /** \ingroup Group_PlatformDrivers_UC3\r
39  *  \defgroup Group_PlatformDrivers_UC3Interrupts Interrupt Controller Driver - LUFA/Platform/UC3/InterruptManagement.h\r
40  *  \brief Interrupt Controller Driver for the AVR32 UC3 microcontrollers.\r
41  *\r
42  *  \section Sec_Dependencies Module Source Dependencies\r
43  *  The following files must be built with any user project that uses this module:\r
44  *    - LUFA/Platform/UC3/InterruptManagement.c <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i>\r
45  *    - LUFA/Platform/UC3/Exception.S <i>(Makefile source module name: LUFA_SRC_PLATFORM)</i>\r
46  *\r
47  *  \section Sec_ModDescription Module Description\r
48  *  Interrupt controller driver for the AVR32 UC3 microcontrollers, for the configuration of interrupt\r
49  *  handlers within the device.\r
50  *\r
51  *  Usage Example:\r
52  *  \code\r
53  *              #include <LUFA/Platform/UC3/InterruptManagement.h>\r
54  *      \r
55  *              ISR(USB_Group_IRQ_Handler)\r
56  *              {\r
57  *                      // USB group handler code here\r
58  *              }\r
59  *      \r
60  *              void main(void)\r
61  *              {\r
62  *                      INTC_Init();\r
63  *                      INTC_RegisterGroupHandler(INTC_IRQ_GROUP(AVR32_USBB_IRQ), AVR32_INTC_INT0, USB_Group_IRQ_Handler);\r
64  *              }\r
65  *  \endcode\r
66  *\r
67  *  @{\r
68  */\r
69 \r
70 #ifndef _UC3_INTERRUPT_MANAGEMENT_H_\r
71 #define _UC3_INTERRUPT_MANAGEMENT_H_\r
72 \r
73         /* Includes: */\r
74                 #include "../../Common/Common.h"\r
75 \r
76         /* Enable C linkage for C++ Compilers: */\r
77                 #if defined(__cplusplus)\r
78                         extern "C" {\r
79                 #endif\r
80 \r
81         /* Private Interface - For use in library only: */\r
82         #if !defined(__DOXYGEN__)\r
83                 /* Type Defines: */\r
84                         typedef void (*InterruptHandlerPtr_t)(void);\r
85 \r
86                 /* External Variables: */\r
87                         #if defined(__INCLUDE_FROM_INTMANAGEMENT_C)\r
88                                 extern const void        EVBA_Table;\r
89                         #endif\r
90                         extern InterruptHandlerPtr_t InterruptHandlers[AVR32_INTC_NUM_INT_GRPS];\r
91                         extern const uint32_t        Autovector_Table[];\r
92         #endif\r
93 \r
94         /* Public Interface - May be used in end-application: */\r
95                 /* Macros: */\r
96                         /** Converts a given interrupt index into its associated interrupt group.\r
97                          *\r
98                          *  \param[in] IRQIndex  Index of the interrupt request to convert.\r
99                          *\r
100                          *  \return Interrupt group number associated with the interrupt index.\r
101                          */\r
102                         #define INTC_IRQ_GROUP(IRQIndex)  (IRQIndex / 32)\r
103 \r
104                         /** Converts a given interrupt index into its associated interrupt line.\r
105                          *\r
106                          *  \param[in] IRQIndex  Index of the interrupt request to convert.\r
107                          *\r
108                          *  \return Interrupt line number associated with the interrupt index.\r
109                          */\r
110                         #define INTC_IRQ_LINE(IRQIndex)   (IRQIndex % 32)\r
111 \r
112                 /* Function Prototypes: */\r
113                         void INTC_Init(void);                   \r
114                         InterruptHandlerPtr_t INTC_GetInterruptHandler(const uint_reg_t InterruptLevel);\r
115 \r
116                 /* Inline Functions: */\r
117                         /** Registers a handler for a given interrupt group. On the AVR32 UC3 devices, interrupts are grouped by\r
118                          *  peripheral. To save on SRAM used, a single ISR handles all interrupt lines within a single group - to\r
119                          *  determine the exact line that has interrupted within the group ISR handler, use \ref INTC_GetGroupInterrupts().\r
120                          *\r
121                          *  If multiple interrupts with the same group are registered, the last registered handler will become the\r
122                          *  handler called for interrupts raised within that group.\r
123                          *\r
124                          *  To obtain the group number of a specific interrupt index, use the \ref INTC_IRQ_GROUP() macro.\r
125                          *\r
126                          *  \param[in] GroupNumber       Group number of the interrupt group to register a handler for.\r
127                          *  \param[in] InterruptLevel    Priority level for the specified interrupt, a \c AVR32_INTC_INT* mask.\r
128                          *  \param[in] Handler           Address of the ISR handler for the interrupt group.\r
129                          */\r
130                         static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,\r
131                                                                      const uint8_t InterruptLevel,\r
132                                                                      const InterruptHandlerPtr_t Handler) ATTR_ALWAYS_INLINE;\r
133                         static inline void INTC_RegisterGroupHandler(const uint16_t GroupNumber,\r
134                                                                      const uint8_t InterruptLevel,\r
135                                                                      const InterruptHandlerPtr_t Handler)\r
136                         {\r
137                                 InterruptHandlers[GroupNumber] = Handler;\r
138                                 AVR32_INTC.ipr[GroupNumber]    = Autovector_Table[InterruptLevel];\r
139                         }\r
140 \r
141                         /** Retrieves the pending interrupts for a given interrupt group. The result of this function should be masked\r
142                          *  against interrupt request indexes converted to a request line number via the \ref INTC_IRQ_LINE() macro. To\r
143                          *  obtain the group number of a given interrupt request, use the \ref INTC_IRQ_GROUP() macro.\r
144                          *\r
145                          *  \param[in] GroupNumber Group number of the interrupt group to check.\r
146                          *\r
147                          *  \return Mask of pending interrupt lines for the given interrupt group.\r
148                          */\r
149                         static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber) ATTR_ALWAYS_INLINE;\r
150                         static inline uint_reg_t INTC_GetGroupInterrupts(const uint16_t GroupNumber)\r
151                         {\r
152                                 return AVR32_INTC.irr[GroupNumber];\r
153                         }\r
154 \r
155         /* Disable C linkage for C++ Compilers: */\r
156                 #if defined(__cplusplus)\r
157                         }\r
158                 #endif\r
159 \r
160 #endif\r
161 \r
162 /** @} */\r
163 \r