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