summaryrefslogtreecommitdiff
path: root/include/compile_time_macros.h
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2022-04-14 17:03:20 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-18 21:19:33 +0000
commit8ecd1a5f99e8472409cd773580f56632d8cc73f3 (patch)
treea3b932db4fa07a165923dc40133ee63bd139fb8c /include/compile_time_macros.h
parent13850ecd4c30a5ab0f15c62f666c4f4a7a7d27f1 (diff)
downloadchrome-ec-8ecd1a5f99e8472409cd773580f56632d8cc73f3.tar.gz
compile_time_macros: Add WRITE_BIT
WRITE_BIT macro sets a bit if a given condition is true or clears it if not. BUG=None BRANCH=None TEST=make run-compile_time_macros Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Id3a73afbc48a49ec9df9dcf8f494974fb274b192 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3587152 Reviewed-by: Parth Malkan <parthmalkan@google.com> Reviewed-by: Rob Barnes <robbarnes@google.com> Reviewed-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-by: Bobby Casey <bobbycasey@google.com> Reviewed-by: Craig Hesling <hesling@chromium.org>
Diffstat (limited to 'include/compile_time_macros.h')
-rw-r--r--include/compile_time_macros.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h
index 23e5d56867..afb2c30d19 100644
--- a/include/compile_time_macros.h
+++ b/include/compile_time_macros.h
@@ -79,6 +79,12 @@
*/
#ifndef CONFIG_ZEPHYR
#define BIT(nr) (1U << (nr))
+/*
+ * Set or clear <bit> of <var> depending on <set>.
+ * It also supports setting and clearing (e.g. SET_BIT, CLR_BIT) macros.
+ */
+#define WRITE_BIT(var, bit, set) \
+ ((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit)))
#endif
#define BIT_ULL(nr) (1ULL << (nr))