Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
util_macro.h File Reference

Macro utilities. More...

Go to the source code of this file.

Macros

#define BIT(n)   (1UL << (n))
 Unsigned integer with bit position n set (signed in assembly language).
 
#define BIT64(_n)   (1ULL << (_n))
 64-bit unsigned integer with bit position _n set.
 
#define WRITE_BIT(var, bit, set)    ((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit)))
 Set or clear a bit depending on a boolean value.
 
#define BIT_MASK(n)   (BIT(n) - 1UL)
 Bit mask with bits 0 through n-1 (inclusive) set, or 0 if n is 0.
 
#define BIT64_MASK(n)   (BIT64(n) - 1ULL)
 64-bit bit mask with bits 0 through n-1 (inclusive) set, or 0 if n is 0.
 
#define IS_POWER_OF_TWO(x)   (((x) != 0U) && (((x) & ((x) - 1U)) == 0U))
 Check if a x is a power of two.
 
#define IS_SHIFTED_BIT_MASK(m, s)   (!(((m) >> (s)) & (((m) >> (s)) + 1U)))
 Check if bits are set continuously from the specified bit.
 
#define IS_BIT_MASK(m)   IS_SHIFTED_BIT_MASK(m, 0)
 Check if bits are set continuously from the LSB.
 
#define IS_ENABLED(config_macro)   Z_IS_ENABLED1(config_macro)
 Check for macro definition in compiler-visible expressions.
 
#define COND_CODE_1(_flag, _if_1_code, _else_code)    Z_COND_CODE_1(_flag, _if_1_code, _else_code)
 Insert code depending on whether _flag expands to 1 or not.
 
#define COND_CODE_0(_flag, _if_0_code, _else_code)    Z_COND_CODE_0(_flag, _if_0_code, _else_code)
 Like COND_CODE_1() except tests if _flag is 0.
 
#define IF_ENABLED(_flag, _code)    COND_CODE_1(_flag, _code, ())
 Insert code if _flag is defined and equals 1.
 
#define IF_DISABLED(_flag, _code)    COND_CODE_1(_flag, (), _code)
 Insert code if _flag is not defined as 1.
 
#define IS_EMPTY(...)   Z_IS_EMPTY_(__VA_ARGS__)
 Check if a macro has a replacement expression.
 
#define IS_EQ(a, b)   Z_IS_EQ(a, b)
 Like a == b, but does evaluation and short-circuiting at C preprocessor time.
 
#define LIST_DROP_EMPTY(...)    Z_LIST_DROP_FIRST(FOR_EACH(Z_LIST_NO_EMPTIES, (), __VA_ARGS__))
 Remove empty arguments from list.
 
#define EMPTY
 Macro with an empty expansion.
 
#define IDENTITY(V)   V
 Macro that expands to its argument.
 
#define GET_ARG_N(N, ...)   Z_GET_ARG_##N(__VA_ARGS__)
 Get nth argument from argument list.
 
#define GET_ARGS_LESS_N(N, ...)   Z_GET_ARGS_LESS_##N(__VA_ARGS__)
 Strips n first arguments from the argument list.
 
#define UTIL_OR(a, b)   COND_CODE_1(UTIL_BOOL(a), (a), (b))
 Like a || b, but does evaluation and short-circuiting at C preprocessor time.
 
#define UTIL_AND(a, b)   COND_CODE_1(UTIL_BOOL(a), (b), (0))
 Like a && b, but does evaluation and short-circuiting at C preprocessor time.
 
#define UTIL_INC(x)   UTIL_PRIMITIVE_CAT(Z_UTIL_INC_, x)
 UTIL_INC(x) for an integer literal x from 0 to 4095 expands to an integer literal whose value is x+1.
 
#define UTIL_DEC(x)   UTIL_PRIMITIVE_CAT(Z_UTIL_DEC_, x)
 UTIL_DEC(x) for an integer literal x from 0 to 4095 expands to an integer literal whose value is x-1.
 
#define UTIL_X2(y)   UTIL_PRIMITIVE_CAT(Z_UTIL_X2_, y)
 UTIL_X2(y) for an integer literal y from 0 to 4095 expands to an integer literal whose value is 2y.
 
#define LISTIFY(LEN, F, sep, ...)   UTIL_CAT(Z_UTIL_LISTIFY_, LEN)(F, sep, __VA_ARGS__)
 Generates a sequence of code with configurable separator.
 
#define FOR_EACH(F, sep, ...)    Z_FOR_EACH(F, sep, REVERSE_ARGS(__VA_ARGS__))
 Call a macro F on each provided argument with a given separator between each call.
 
#define FOR_EACH_NONEMPTY_TERM(F, term, ...)
 Like FOR_EACH(), but with a terminator instead of a separator, and drops empty elements from the argument list.
 
#define FOR_EACH_IDX(F, sep, ...)    Z_FOR_EACH_IDX(F, sep, REVERSE_ARGS(__VA_ARGS__))
 Call macro F on each provided argument, with the argument's index as an additional parameter.
 
#define FOR_EACH_FIXED_ARG(F, sep, fixed_arg, ...)    Z_FOR_EACH_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__))
 Call macro F on each provided argument, with an additional fixed argument as a parameter.
 
#define FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, ...)    Z_FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__))
 Calls macro F for each variable argument with an index and fixed argument.
 
#define REVERSE_ARGS(...)    Z_FOR_EACH_ENGINE(Z_FOR_EACH_EXEC, (,), Z_BYPASS, _, __VA_ARGS__)
 Reverse arguments order.
 
#define NUM_VA_ARGS_LESS_1(...)
 Number of arguments in the variable arguments list minus one.
 
#define NUM_VA_ARGS(...)    COND_CODE_1(IS_EMPTY(__VA_ARGS__), (0), (UTIL_INC(NUM_VA_ARGS_LESS_1(__VA_ARGS__))))
 Number of arguments in the variable arguments list.
 
#define MACRO_MAP_CAT(...)   MACRO_MAP_CAT_(__VA_ARGS__)
 Mapping macro that pastes results together.
 
#define MACRO_MAP_CAT_N(N, ...)   MACRO_MAP_CAT_N_(N, __VA_ARGS__)
 Mapping macro that pastes a fixed number of results together.
 

Detailed Description

Macro utilities.

Macro utilities are the public interface for C/C++ code and device tree related implementation. In general, C/C++ will include <sys/util.h> instead this file directly. For device tree implementation, this file should be include instead <sys/util_internal.h>