00001 #ifndef _MEMORY_BARRIER_H_ 00002 #define _MEMORY_BARRIER_H_ 00003 00004 #include <util/atomic.h> 00005 #include <avr/version.h> 00006 00007 // Provide a memory barrier to the compiler. This informs 00008 // the compiler that is should write any cached values that 00009 // are destined for a global variable and discard any other 00010 // cached values from global variables. 00011 // 00012 // Note that this behavior does apply to all global variables, 00013 // not just volatile ones. However, cached local variables 00014 // are not affected as they are not externally visible. 00015 00016 #define MEMORY_BARRIER() __asm volatile( "" ::: "memory" ) 00017 00018 // There is a bug in the CLI/SEI functions in older versions of 00019 // avr-libc - they should be defined to include a memory barrier. 00020 // This macro is used to define the barrier in the code so that 00021 // it will be easy to remove once the bug has become ancient history. 00022 // At the moment the bug is included in most of the distributed 00023 // compilers. 00024 00025 #if __AVR_LIBC_VERSION__ < 10700UL 00026 #define CLI_SEI_BUG_MEMORY_BARRIER() MEMORY_BARRIER() 00027 #else 00028 #define CLI_SEI_BUG_MEMORY_BARRIER() 00029 #endif 00030 00031 #endif