summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/compile_time_macros.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h
index ae6ac267eb..15432549d3 100644
--- a/include/compile_time_macros.h
+++ b/include/compile_time_macros.h
@@ -8,12 +8,20 @@
#ifndef __CROS_EC_COMPILE_TIME_MACROS_H
#define __CROS_EC_COMPILE_TIME_MACROS_H
+/* sys/util.h in zephyr provides equivalents to most of these macros */
+#ifdef CONFIG_ZEPHYR
+#include <sys/util.h>
+#endif
+
/* Test an important condition at compile time, not run time */
#define _BA1_(cond, file, line, msg) \
_Static_assert(cond, file ":" #line ": " msg)
#define _BA0_(c, f, l, msg) _BA1_(c, f, l, msg)
/* Pass in an option message to display after condition */
+
+#ifndef CONFIG_ZEPHYR
#define BUILD_ASSERT(cond, ...) _BA0_(cond, __FILE__, __LINE__, __VA_ARGS__)
+#endif
/*
* Test an important condition inside code path at run time, taking advantage of
@@ -31,8 +39,10 @@
* This version is type-safe and will not allow pointers, causing a
* compile-time divide by zero error if a pointer is passed.
*/
+#ifndef CONFIG_ZEPHYR
#define ARRAY_SIZE(arr) \
BUILD_CHECK_INLINE(sizeof(arr) / sizeof((arr)[0]), _IS_ARRAY(arr))
+#endif
/* Make for loops that iterate over pointers to array entries more readable */
#define ARRAY_BEGIN(array) \
@@ -53,7 +63,9 @@
/*
* Bit operation macros.
*/
+#ifndef CONFIG_ZEPHYR
#define BIT(nr) (1U << (nr))
+#endif
#define BIT_ULL(nr) (1ULL << (nr))
/*
@@ -69,7 +81,9 @@
* Note that we shift after using BIT() to avoid compiler
* warnings for BIT(31+1).
*/
+#ifndef CONFIG_ZEPHYR
#define GENMASK(h, l) (((BIT(h)<<1) - 1) ^ (BIT(l) - 1))
+#endif
#define GENMASK_ULL(h, l) (((BIT_ULL(h)<<1) - 1) ^ (BIT_ULL(l) - 1))
#endif /* __CROS_EC_COMPILE_TIME_MACROS_H */