|
Zephyr API 3.6.99
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
17#ifndef ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_
18#define ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_
37#if defined(_ASMLANGUAGE)
38#define BIT(n) (1 << (n))
44#define BIT(n) (1UL << (n))
49#define BIT64(_n) (1ULL << (_n))
61#define WRITE_BIT(var, bit, set) \
62 ((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit)))
68#define BIT_MASK(n) (BIT(n) - 1UL)
74#define BIT64_MASK(n) (BIT64(n) - 1ULL)
77#define IS_POWER_OF_TWO(x) (((x) != 0U) && (((x) & ((x) - 1U)) == 0U))
87#define IS_SHIFTED_BIT_MASK(m, s) (!(((m) >> (s)) & (((m) >> (s)) + 1U)))
94#define IS_BIT_MASK(m) IS_SHIFTED_BIT_MASK(m, 0)
124#define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
179#define COND_CODE_1(_flag, _if_1_code, _else_code) \
180 Z_COND_CODE_1(_flag, _if_1_code, _else_code)
195#define COND_CODE_0(_flag, _if_0_code, _else_code) \
196 Z_COND_CODE_0(_flag, _if_0_code, _else_code)
223#define IF_ENABLED(_flag, _code) \
224 COND_CODE_1(_flag, _code, ())
247#define IF_DISABLED(_flag, _code) \
248 COND_CODE_1(_flag, (), _code)
277#define IS_EMPTY(...) Z_IS_EMPTY_(__VA_ARGS__)
286#define IS_EQ(a, b) Z_IS_EQ(a, b)
315#define LIST_DROP_EMPTY(...) \
316 Z_LIST_DROP_FIRST(FOR_EACH(Z_LIST_NO_EMPTIES, (), __VA_ARGS__))
355#define GET_ARG_N(N, ...) Z_GET_ARG_##N(__VA_ARGS__)
365#define GET_ARGS_LESS_N(N, ...) Z_GET_ARGS_LESS_##N(__VA_ARGS__)
378#define UTIL_OR(a, b) COND_CODE_1(UTIL_BOOL(a), (a), (b))
391#define UTIL_AND(a, b) COND_CODE_1(UTIL_BOOL(a), (b), (0))
399#define UTIL_INC(x) UTIL_PRIMITIVE_CAT(Z_UTIL_INC_, x)
407#define UTIL_DEC(x) UTIL_PRIMITIVE_CAT(Z_UTIL_DEC_, x)
413#define UTIL_X2(y) UTIL_PRIMITIVE_CAT(Z_UTIL_X2_, y)
442#define LISTIFY(LEN, F, sep, ...) UTIL_CAT(Z_UTIL_LISTIFY_, LEN)(F, sep, __VA_ARGS__)
465#define FOR_EACH(F, sep, ...) \
466 Z_FOR_EACH(F, sep, REVERSE_ARGS(__VA_ARGS__))
520#define FOR_EACH_NONEMPTY_TERM(F, term, ...) \
523 NUM_VA_ARGS_LESS_1(LIST_DROP_EMPTY(__VA_ARGS__, _)), \
528 FOR_EACH(F, term, LIST_DROP_EMPTY(__VA_ARGS__)) \
557#define FOR_EACH_IDX(F, sep, ...) \
558 Z_FOR_EACH_IDX(F, sep, REVERSE_ARGS(__VA_ARGS__))
585#define FOR_EACH_FIXED_ARG(F, sep, fixed_arg, ...) \
586 Z_FOR_EACH_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__))
613#define FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, ...) \
614 Z_FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__))
620#define REVERSE_ARGS(...) \
621 Z_FOR_EACH_ENGINE(Z_FOR_EACH_EXEC, (,), Z_BYPASS, _, __VA_ARGS__)
631#define NUM_VA_ARGS_LESS_1(...) \
632 NUM_VA_ARGS_LESS_1_IMPL(__VA_ARGS__, 63, 62, 61, \
633 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
634 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
635 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
636 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
637 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
638 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ~)
648#define NUM_VA_ARGS(...) \
649 COND_CODE_1(IS_EMPTY(__VA_ARGS__), (0), (UTIL_INC(NUM_VA_ARGS_LESS_1(__VA_ARGS__))))
671#define MACRO_MAP_CAT(...) MACRO_MAP_CAT_(__VA_ARGS__)
686#define MACRO_MAP_CAT_N(N, ...) MACRO_MAP_CAT_N_(N, __VA_ARGS__)