Commit 46367ff1 authored by Aksel Skauge Mellbye's avatar Aksel Skauge Mellbye Committed by Fabio Baltieri
Browse files

sys: util: Make FIELD_* available from device tree



Move FIELD_* macros from zephyr/sys/util.h to zephyr/sys/util_macro.h,
as zephyr/sys/util.h cannot be used from device tree.

Device tree uses zephyr/dt-bindings/dt-util.h, which includes
zephyr/sys/util_macro.h.

Signed-off-by: default avatarAksel Skauge Mellbye <aksel.mellbye@silabs.com>
parent 1299dc74
Loading
Loading
Loading
Loading
+0 −16
Original line number Diff line number Diff line
@@ -77,22 +77,6 @@ extern "C" {
#define GENMASK64(h, l) \
	(((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))

/** @brief Extract the Least Significant Bit from @p value. */
#define LSB_GET(value) ((value) & -(value))

/**
 * @brief Extract a bitfield element from @p value corresponding to
 *	  the field mask @p mask.
 */
#define FIELD_GET(mask, value)  (((value) & (mask)) / LSB_GET(mask))

/**
 * @brief Prepare a bitfield element using @p value with @p mask representing
 *	  its field position and width. The result should be combined
 *	  with other fields using a logical OR.
 */
#define FIELD_PREP(mask, value) (((value) * LSB_GET(mask)) & (mask))

/** @brief 0 if @p cond is true-ish; causes a compile error otherwise. */
#define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)

+16 −0
Original line number Diff line number Diff line
@@ -93,6 +93,22 @@ extern "C" {
 */
#define IS_BIT_MASK(m) IS_SHIFTED_BIT_MASK(m, 0)

/** @brief Extract the Least Significant Bit from @p value. */
#define LSB_GET(value) ((value) & -(value))

/**
 * @brief Extract a bitfield element from @p value corresponding to
 *	  the field mask @p mask.
 */
#define FIELD_GET(mask, value)  (((value) & (mask)) / LSB_GET(mask))

/**
 * @brief Prepare a bitfield element using @p value with @p mask representing
 *	  its field position and width. The result should be combined
 *	  with other fields using a logical OR.
 */
#define FIELD_PREP(mask, value) (((value) * LSB_GET(mask)) & (mask))

/**
 * @brief Check for macro definition in compiler-visible expressions
 *