summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2020-09-23 08:01:44 -0600
committerCommit Bot <commit-bot@chromium.org>2020-10-01 19:14:15 +0000
commit472d96e4b3e6a6215ce5b02f89f5881c5cefdd1b (patch)
treeb2ba1119603ec3e178d4490f329d611bf6590df4
parentde4f55aa1cd9521b03aa3fc05ede62746948aa14 (diff)
downloadchrome-ec-472d96e4b3e6a6215ce5b02f89f5881c5cefdd1b.tar.gz
zephyr: make IS_ENABLED compatible with shim
Since we are using Zephyr headers and EC sources together, we need to make an IS_ENABLED macro which is compatible with both the Zephyr concept of being enabled, and the CrOS EC concept (since we inherit many default options from config.h). The Zephyr concept of being enabled is defined, specifically only to the token "1". The CrOS EC concept of being enabled is defined, specifically to no tokens. Thus a macro which allows both concepts defines "enabled" as defined, either to no tokens, or the token "1". BUG=b:167590251 BRANCH=none TEST=compile common/timer.c in follow-up CLs Change-Id: Ieded05e65d0d7c27070f40ef1dd4d24db73b9de4 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2427093 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--include/common.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h
index 92731182dc..8ba86d7454 100644
--- a/include/common.h
+++ b/include/common.h
@@ -10,8 +10,13 @@
#include <stdint.h>
#include <inttypes.h>
+
#include "compile_time_macros.h"
+#ifdef CONFIG_ZEPHYR
+#include <sys/util.h>
+#endif
+
/*
* Macros to concatenate 2 - 4 tokens together to form a single token.
* Multiple levels of nesting are required to convince the preprocessor to
@@ -411,7 +416,24 @@ enum ec_error_list {
* Note: This macro will only function inside a code block due to the way
* it checks for unknown values.
*/
+#ifndef CONFIG_ZEPHYR
#define IS_ENABLED(option) __config_enabled(#option, option)
+#else
+/* IS_ENABLED previously defined in sys/util.h */
+#undef IS_ENABLED
+/*
+ * For Zephyr, we must create a new version of IS_ENABLED which is
+ * compatible with both Kconfig enables (for Zephyr code), which have
+ * the value defined to 1 upon enablement, and CrOS EC defines (which
+ * are defined to the empty string).
+ *
+ * To do this, we use __cfg_select from this codebase to determine if
+ * the option was defined to nothing ("enabled" in CrOS EC terms). If
+ * not, we then check using Zephyr's Z_IS_ENABLED1 macro to determine
+ * if the config option is enabled by Zephyr's definition.
+ */
+#define IS_ENABLED(option) __cfg_select(option, 1, Z_IS_ENABLED1(option))
+#endif /* CONFIG_ZEPHYR */
/**
* Makes a global variable static when a config option is enabled,