--- /dev/null
+/**\r
+ * \file\r
+ *\r
+ * \brief Global interrupt management for SAM D20, SAM3 and SAM4 (NVIC based)\r
+ *\r
+ * Copyright (c) 2012-2015 Atmel Corporation. All rights reserved.\r
+ *\r
+ * \asf_license_start\r
+ *\r
+ * \page License\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright notice,\r
+ * this list of conditions and the following disclaimer.\r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright notice,\r
+ * this list of conditions and the following disclaimer in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ *\r
+ * 3. The name of Atmel may not be used to endorse or promote products derived\r
+ * from this software without specific prior written permission.\r
+ *\r
+ * 4. This software may only be redistributed and used in connection with an\r
+ * Atmel microcontroller product.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
+ * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR\r
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\r
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * \asf_license_stop\r
+ *\r
+ */\r
+/*\r
+ * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>\r
+ */\r
+\r
+#include "interrupt_sam_nvic.h"\r
+\r
+#if !defined(__DOXYGEN__)\r
+/* Deprecated - global flag to determine the global interrupt state. Required by\r
+ * QTouch library, however new applications should use cpu_irq_is_enabled()\r
+ * which probes the true global interrupt state from the CPU special registers.\r
+ */\r
+volatile bool g_interrupt_enabled = true;\r
+#endif\r
+\r
+void cpu_irq_enter_critical(void)\r
+{\r
+ if (cpu_irq_critical_section_counter == 0) {\r
+ if (cpu_irq_is_enabled()) {\r
+ cpu_irq_disable();\r
+ cpu_irq_prev_interrupt_state = true;\r
+ } else {\r
+ /* Make sure the to save the prev state as false */\r
+ cpu_irq_prev_interrupt_state = false;\r
+ }\r
+\r
+ }\r
+\r
+ cpu_irq_critical_section_counter++;\r
+}\r
+\r
+void cpu_irq_leave_critical(void)\r
+{\r
+ /* Check if the user is trying to leave a critical section when not in a critical section */\r
+ Assert(cpu_irq_critical_section_counter > 0);\r
+\r
+ cpu_irq_critical_section_counter--;\r
+\r
+ /* Only enable global interrupts when the counter reaches 0 and the state of the global interrupt flag\r
+ was enabled when entering critical state */\r
+ if ((cpu_irq_critical_section_counter == 0) && (cpu_irq_prev_interrupt_state)) {\r
+ cpu_irq_enable();\r
+ }\r
+}\r
+\r