diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2020-09-21 10:49:13 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-01 19:14:06 +0000 |
commit | 0ced06f23926b4670e538f027f3943b55a5c2231 (patch) | |
tree | b9c4bcb3d115a714b5bcf407cd5d462e14755308 /include | |
parent | f8c8ab55241620fe047077f02ae0cce1d8e56d19 (diff) | |
download | chrome-ec-0ced06f23926b4670e538f027f3943b55a5c2231.tar.gz |
zephyr: make compile_time_macros.h compatible with Zephyr
Include sys/util.h in Zephyr, which provides the same definition of
most of these macros. Guard the platform/ec implementations where
appropriate.
BUG=b:167590251
BRANCH=none
TEST=compiles
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: Icba8e1f7d846cc731ec3acf4f3472e108e4cd6f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2427091
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/compile_time_macros.h | 14 |
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 */ |