--- /dev/null
+/*\r
+ LUFA Library\r
+ Copyright (C) Dean Camera, 2010.\r
+\r
+ dean [at] fourwalledcubicle [dot] com\r
+ www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+ Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+ Permission to use, copy, modify, distribute, and sell this\r
+ software and its documentation for any purpose is hereby granted\r
+ without fee, provided that the above copyright notice appear in\r
+ all copies and that both that the copyright notice and this\r
+ permission notice and warranty disclaimer appear in supporting\r
+ documentation, and that the name of the author not be used in\r
+ advertising or publicity pertaining to distribution of the\r
+ software without specific, written prior permission.\r
+\r
+ The author disclaim all warranties with regard to this\r
+ software, including all implied warranties of merchantability\r
+ and fitness. In no event shall the author be liable for any\r
+ special, indirect or consequential damages or any damages\r
+ whatsoever resulting from loss of use, data or profits, whether\r
+ in an action of contract, negligence or other tortious action,\r
+ arising out of or in connection with the use or performance of\r
+ this software.\r
+*/\r
+\r
+/** \file\r
+ *\r
+ * Atomic block header for the 32-bit AVRs, modelled on the 8-bit AVR's util/atomic.h\r
+ * header.\r
+ *\r
+ * \note Do not include this file directly, rather include the Common.h header file instead to gain this file's\r
+ * functionality on the 32-bit AVRs.\r
+ */\r
+\r
+#ifndef __ATOMIC_H__\r
+#define __ATOMIC_H__\r
+\r
+ /* Includes: */\r
+ #include <avr32/io.h>\r
+ #include <stdint.h>\r
+ #include <stdbool.h>\r
+\r
+ /* Public Interface - May be used in end-application: */\r
+ /* Macros: */\r
+ #define ATOMIC_BLOCK(type) for ( type, __ToDo = __iCliRetVal(); \\r
+ __ToDo ; __ToDo = 0 )\r
+ #define NONATOMIC_BLOCK(type) for ( type, __ToDo = __iSeiRetVal(); \\r
+ __ToDo ; __ToDo = 0 )\r
+ #define ATOMIC_RESTORESTATE uint8_t sreg_save \\r
+ __attribute__((__cleanup__(__iRestore))) = 0 /* TODO */\r
+ #define ATOMIC_FORCEON uint8_t sreg_save \\r
+ __attribute__((__cleanup__(__iSeiParam))) = 0\r
+ #define NONATOMIC_RESTORESTATE uint8_t sreg_save \\r
+ __attribute__((__cleanup__(__iRestore))) = 0 /* TODO */\r
+ #define NONATOMIC_FORCEOFF uint8_t sreg_save \\r
+ __attribute__((__cleanup__(__iCliParam))) = 0\r
+\r
+ /* Private Interface - For use in library only: */\r
+ #if !defined(__DOXYGEN__)\r
+ /* Inline Functions: */\r
+ static __inline__ uint8_t __iSeiRetVal(void)\r
+ {\r
+ ((avr32_sr_t*)AVR32_SR_T)->gm = true;\r
+ return 1;\r
+ }\r
+\r
+ static __inline__ uint8_t __iCliRetVal(void)\r
+ {\r
+ ((avr32_sr_t*)AVR32_SR_T)->gm = false;\r
+ return 1;\r
+ }\r
+\r
+ static __inline__ void __iSeiParam(const uint8_t *__s)\r
+ {\r
+ ((avr32_sr_t*)AVR32_SR_T)->gm = true;\r
+ __asm__ volatile ("" ::: "memory");\r
+ (void)__s;\r
+ }\r
+\r
+ static __inline__ void __iCliParam(const uint8_t *__s)\r
+ {\r
+ ((avr32_sr_t*)AVR32_SR_T)->gm = false;\r
+ __asm__ volatile ("" ::: "memory");\r
+ (void)__s;\r
+ }\r
+\r
+ static __inline__ void __iRestore(const uint8_t *__s)\r
+ {\r
+ ((avr32_sr_t*)AVR32_SR_T)->gm = *__s;\r
+ __asm__ volatile ("" ::: "memory");\r
+ }\r
+ #endif\r
+\r
+#endif\r