+#ifndef _COMPILER_H_\r
+#define _COMPILER_H_\r
+\r
+#define _CC_PRAGMA(x) _Pragma(#x)\r
+\r
+#define PACK_SET(alignment) _CC_PRAGMA(pack(alignment))\r
+#define PACK_RESET() _CC_PRAGMA(pack())\r
+\r
+#if defined(__ICCARM__)\r
+ #define WEAK __weak\r
+ #define CONSTRUCTOR\r
+ #define SECTION(a) _CC_PRAGMA(location = a)\r
+ #define ALIGNED(a) _CC_PRAGMA(data_alignment = a)\r
+#elif defined(__GNUC__)\r
+ #define WEAK __attribute__((weak))\r
+ #define CONSTRUCTOR __attribute__((constructor))\r
+ #define SECTION(a) __attribute__((__section__(a)))\r
+ #define ALIGNED(a) __attribute__((__aligned__(a)))\r
+#else\r
+ #error Unknown compiler!\r
+#endif\r
+\r
+#if defined(__ICCARM__)\r
+ #define DMB() asm("dmb")\r
+ #define DSB() asm("dsb")\r
+ #define ISB() asm("isb")\r
+ #define COMPILER_BARRIER()\r
+#elif defined(__GNUC__)\r
+ #define DMB() asm("dmb":::"memory")\r
+ #define DSB() asm volatile ("dsb":::"memory")\r
+ #define ISB() asm volatile ("isb":::"memory")\r
+ #define COMPILER_BARRIER() asm volatile ("":::"memory")\r
+#else\r
+ #error Unknown compiler!\r
+#endif\r
+\r
+#ifndef NULL\r
+ #define NULL ((void*)0)\r
+#endif\r
+\r
+#define ROUND_UP_MULT(x,m) (((x) + ((m)-1)) & ~((m)-1))\r
+\r
+#define ROUND_INT_DIV(n,d) ((2 * (n) + (d)) / (2 * (d)))\r
+\r
+#define ARRAY_SIZE(x) (sizeof ((x)) / sizeof(*(x)))\r
+\r
+#define _STRINGY_EXPAND(x) #x\r
+#define STRINGIFY(x) _STRINGY_EXPAND(x)\r
+\r
+#if defined(__GNUC__) && \\r
+ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 8))\r
+ #define SWAP(a, b) do { \\r
+ __auto_type _swp = (a); \\r
+ (a) = (b); \\r
+ (b) = _swp; } while (0)\r
+#else\r
+ /* The compiler will replace memcpy calls with direct assignations */\r
+ #define SWAP(a, b) do { \\r
+ uint8_t _swp[sizeof(a) == sizeof(b) ? (signed)sizeof(a) : -1]; \\r
+ memcpy(_swp, &(a), sizeof(a)); \\r
+ memcpy(&(a), &(b), sizeof(a)); \\r
+ memcpy(&(b), _swp, sizeof(a)); } while(0)\r
+#endif\r
+\r
+#define BIG_ENDIAN_TO_HOST(x) (((x) & 0xFF) << 24) | (((x) & 0xFF00) << 8) \\r
+ | (((x) & 0xFF0000) >> 8) | (((x) & 0xFF000000) >> 24)\r
+\r
+#endif /* _COMPILER_H_ */\r