]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/src/ASF/common/utils/interrupt/interrupt_sam_nvic.h
Rename DummyTCB_t to StaticTCB_t.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAME70_Xplained_AtmelStudio / src / ASF / common / utils / interrupt / interrupt_sam_nvic.h
1 /**\r
2  * \file\r
3  *\r
4  * \brief Global interrupt management for SAM D20, SAM3 and SAM4 (NVIC based)\r
5  *\r
6  * Copyright (c) 2012-2015 Atmel Corporation. All rights reserved.\r
7  *\r
8  * \asf_license_start\r
9  *\r
10  * \page License\r
11  *\r
12  * Redistribution and use in source and binary forms, with or without\r
13  * modification, are permitted provided that the following conditions are met:\r
14  *\r
15  * 1. Redistributions of source code must retain the above copyright notice,\r
16  *    this list of conditions and the following disclaimer.\r
17  *\r
18  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
19  *    this list of conditions and the following disclaimer in the documentation\r
20  *    and/or other materials provided with the distribution.\r
21  *\r
22  * 3. The name of Atmel may not be used to endorse or promote products derived\r
23  *    from this software without specific prior written permission.\r
24  *\r
25  * 4. This software may only be redistributed and used in connection with an\r
26  *    Atmel microcontroller product.\r
27  *\r
28  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED\r
29  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
31  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR\r
32  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
37  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
38  * POSSIBILITY OF SUCH DAMAGE.\r
39  *\r
40  * \asf_license_stop\r
41  *\r
42  */\r
43 /*\r
44  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>\r
45  */\r
46 \r
47 #ifndef UTILS_INTERRUPT_INTERRUPT_H\r
48 #define UTILS_INTERRUPT_INTERRUPT_H\r
49 \r
50 #include <compiler.h>\r
51 #include <parts.h>\r
52 \r
53 #ifdef __cplusplus\r
54 extern "C" {\r
55 #endif\r
56 \r
57 /**\r
58  * \weakgroup interrupt_group\r
59  *\r
60  * @{\r
61  */\r
62 \r
63 /**\r
64  * \name Interrupt Service Routine definition\r
65  *\r
66  * @{\r
67  */\r
68 \r
69 /**\r
70  * \brief Define service routine\r
71  *\r
72  * \note For NVIC devices the interrupt service routines are predefined to\r
73  *       add to vector table in binary generation, so there is no service\r
74  *       register at run time. The routine collections are in exceptions.h.\r
75  *\r
76  * Usage:\r
77  * \code\r
78         ISR(foo_irq_handler)\r
79         {\r
80              // Function definition\r
81              ...\r
82         }\r
83 \endcode\r
84  *\r
85  * \param func Name for the function.\r
86  */\r
87 #  define ISR(func)   \\r
88         void func (void)\r
89 \r
90 /**\r
91  * \brief Initialize interrupt vectors\r
92  *\r
93  * For NVIC the interrupt vectors are put in vector table. So nothing\r
94  * to do to initialize them, except defined the vector function with\r
95  * right name.\r
96  *\r
97  * This must be called prior to \ref irq_register_handler.\r
98  */\r
99 #  define irq_initialize_vectors()   \\r
100         do {                             \\r
101         } while(0)\r
102 \r
103 /**\r
104  * \brief Register handler for interrupt\r
105  *\r
106  * For NVIC the interrupt vectors are put in vector table. So nothing\r
107  * to do to register them, except defined the vector function with\r
108  * right name.\r
109  *\r
110  * Usage:\r
111  * \code\r
112         irq_initialize_vectors();\r
113         irq_register_handler(foo_irq_handler);\r
114 \endcode\r
115  *\r
116  * \note The function \a func must be defined with the \ref ISR macro.\r
117  * \note The functions prototypes can be found in the device exception header\r
118  *       files (exceptions.h).\r
119  */\r
120 #  define irq_register_handler(int_num, int_prio)                      \\r
121         NVIC_ClearPendingIRQ(    (IRQn_Type)int_num);                      \\r
122         NVIC_SetPriority(    (IRQn_Type)int_num, int_prio);                \\r
123         NVIC_EnableIRQ(      (IRQn_Type)int_num);                          \\r
124 \r
125 //@}\r
126 \r
127 #  define cpu_irq_enable()                     \\r
128         do {                                       \\r
129                 g_interrupt_enabled = true;            \\r
130                 __DMB();                               \\r
131                 __enable_irq();                        \\r
132         } while (0)\r
133 #  define cpu_irq_disable()                    \\r
134         do {                                       \\r
135                 __disable_irq();                       \\r
136                 __DMB();                               \\r
137                 g_interrupt_enabled = false;           \\r
138         } while (0)\r
139 \r
140 typedef uint32_t irqflags_t;\r
141 \r
142 #if !defined(__DOXYGEN__)\r
143 extern volatile bool g_interrupt_enabled;\r
144 #endif\r
145 \r
146 #define cpu_irq_is_enabled()    (__get_PRIMASK() == 0)\r
147 \r
148 static volatile uint32_t cpu_irq_critical_section_counter;\r
149 static volatile bool     cpu_irq_prev_interrupt_state;\r
150 \r
151 static inline irqflags_t cpu_irq_save(void)\r
152 {\r
153         irqflags_t flags = cpu_irq_is_enabled();\r
154         cpu_irq_disable();\r
155         return flags;\r
156 }\r
157 \r
158 static inline bool cpu_irq_is_enabled_flags(irqflags_t flags)\r
159 {\r
160         return (flags);\r
161 }\r
162 \r
163 static inline void cpu_irq_restore(irqflags_t flags)\r
164 {\r
165         if (cpu_irq_is_enabled_flags(flags))\r
166                 cpu_irq_enable();\r
167 }\r
168 \r
169 void cpu_irq_enter_critical(void);\r
170 void cpu_irq_leave_critical(void);\r
171 \r
172 /**\r
173  * \weakgroup interrupt_deprecated_group\r
174  * @{\r
175  */\r
176 \r
177 #define Enable_global_interrupt()            cpu_irq_enable()\r
178 #define Disable_global_interrupt()           cpu_irq_disable()\r
179 #define Is_global_interrupt_enabled()        cpu_irq_is_enabled()\r
180 \r
181 //@}\r
182 \r
183 //@}\r
184 \r
185 #ifdef __cplusplus\r
186 }\r
187 #endif\r
188 \r
189 #endif /* UTILS_INTERRUPT_INTERRUPT_H */\r