Zephyr API Documentation
4.1.99
A Scalable Open Source RTOS
4.1.99
Toggle main menu visibility
Main Page
Related Pages
Topics
Data Structures
Data Structures
Data Structure Index
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Enumerations
Enumerator
Files
File List
Globals
All
$
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Variables
$
a
b
c
d
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
x
z
Typedefs
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Macros
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
▼
Zephyr API Documentation
►
Introduction
Deprecated List
►
Topics
►
Data Structures
▼
Files
▼
File List
►
doc
►
kernel
►
lib
►
subsys
▼
zephyr
►
acpi
►
app_memory
►
arch
►
audio
►
bluetooth
►
canbus
►
console
►
crypto
►
data
►
debug
►
devicetree
►
dfu
►
display
►
drivers
►
dsp
►
dt-bindings
►
fs
►
input
►
internal
►
ipc
►
kernel
►
linker
►
llext
►
logging
►
lorawan
►
math
►
mctp
►
mem_mgmt
►
mgmt
►
misc
►
modbus
►
modem
►
multi_heap
►
net
►
platform
►
pm
►
portability
►
posix
►
psa
►
random
►
retention
►
rtio
►
sd
►
sensing
►
settings
►
shell
►
sip_svc
►
stats
►
storage
▼
sys
►
internal
►
__assert.h
►
atomic.h
►
atomic_arch.h
►
atomic_builtin.h
►
atomic_c.h
►
atomic_types.h
►
barrier.h
barrier_builtin.h
►
base64.h
►
bitarray.h
►
byteorder.h
►
cbprintf.h
cbprintf_cxx.h
►
cbprintf_enums.h
►
cbprintf_internal.h
►
check.h
►
crc.h
►
device_mmio.h
►
dlist.h
errno_private.h
►
fdtable.h
►
hash_function.h
►
hash_map.h
►
hash_map_api.h
►
hash_map_cxx.h
►
hash_map_oa_lp.h
►
hash_map_sc.h
►
heap_listener.h
►
iterable_sections.h
►
kobject.h
►
libc-hooks.h
►
linear_range.h
list_gen.h
►
math_extras.h
►
math_extras_impl.h
►
mem_blocks.h
►
mem_manage.h
►
mem_stats.h
►
mpsc_lockfree.h
►
mpsc_packet.h
►
mpsc_pbuf.h
►
multi_heap.h
►
mutex.h
►
notify.h
►
onoff.h
►
p4wq.h
►
poweroff.h
►
printk-hooks.h
►
printk.h
►
rb.h
►
reboot.h
►
ring_buffer.h
►
sem.h
►
sflist.h
►
slist.h
►
speculation.h
►
spsc_lockfree.h
►
spsc_pbuf.h
►
sys_heap.h
►
sys_io.h
►
time_units.h
►
timeutil.h
►
util.h
►
util_internal.h
util_internal_is_eq.h
util_internal_util_dec.h
util_internal_util_inc.h
util_internal_util_x2.h
util_listify.h
util_loops.h
►
util_macro.h
►
winstream.h
►
task_wdt
►
timing
►
toolchain
►
tracing
►
usb
►
usb_c
►
xen
►
zbus
►
zvfs
►
bindesc.h
►
cache.h
►
device.h
►
devicetree.h
►
fatal.h
►
fatal_types.h
►
init.h
►
irq.h
►
irq_multilevel.h
►
irq_nextlevel.h
►
irq_offload.h
►
kernel.h
kernel_includes.h
►
kernel_structs.h
►
kernel_version.h
►
net_buf.h
►
shared_irq.h
►
smf.h
►
spinlock.h
►
sw_isr_table.h
►
sys_clock.h
►
syscall.h
►
toolchain.h
types.h
►
Globals
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
Loading...
Searching...
No Matches
util_macro.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011-2014, Wind River Systems, Inc.
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
17
#ifndef ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_
18
#define ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_
19
20
#ifdef __cplusplus
21
extern
"C"
{
22
#endif
23
29
/*
30
* Most of the eldritch implementation details for all the macrobatics
31
* below (APIs like IS_ENABLED(), COND_CODE_1(), etc.) are hidden away
32
* in this file.
33
*/
34
#include <
zephyr/sys/util_internal.h
>
35
36
#ifndef BIT
37
#if defined(_ASMLANGUAGE)
38
#define BIT(n) (1 << (n))
39
#else
44
#define BIT(n) (1UL << (n))
45
#endif
46
#endif
47
49
#define BIT64(_n) (1ULL << (_n))
50
61
#define WRITE_BIT(var, bit, set) \
62
((var) = (set) ? ((var) | BIT(bit)) : ((var) & ~BIT(bit)))
61
#define WRITE_BIT(var, bit, set) \
…
63
68
#define BIT_MASK(n) (BIT(n) - 1UL)
69
74
#define BIT64_MASK(n) (BIT64(n) - 1ULL)
75
77
#define IS_POWER_OF_TWO(x) (((x) != 0U) && (((x) & ((x) - 1U)) == 0U))
78
87
#define IS_SHIFTED_BIT_MASK(m, s) (!(((m) >> (s)) & (((m) >> (s)) + 1U)))
88
94
#define IS_BIT_MASK(m) IS_SHIFTED_BIT_MASK(m, 0)
95
102
#define IS_BIT_SET(value, bit) ((((value) >> (bit)) & (0x1)) != 0)
103
105
#define LSB_GET(value) ((value) & -(value))
106
111
#define FIELD_GET(mask, value) (((value) & (mask)) / LSB_GET(mask))
112
118
#define FIELD_PREP(mask, value) (((value) * LSB_GET(mask)) & (mask))
119
148
#define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
149
/* INTERNAL: the first pass above is just to expand any existing
150
* macros, we need the macro value to be e.g. a literal "1" at
151
* expansion time in the next macro, not "(1)", etc... Standard
152
* recursive expansion does not work.
153
*/
154
203
#define COND_CODE_1(_flag, _if_1_code, _else_code) \
204
Z_COND_CODE_1(_flag, _if_1_code, _else_code)
203
#define COND_CODE_1(_flag, _if_1_code, _else_code) \
…
205
219
#define COND_CODE_0(_flag, _if_0_code, _else_code) \
220
Z_COND_CODE_0(_flag, _if_0_code, _else_code)
219
#define COND_CODE_0(_flag, _if_0_code, _else_code) \
…
221
247
#define IF_ENABLED(_flag, _code) \
248
COND_CODE_1(_flag, _code, ())
247
#define IF_ENABLED(_flag, _code) \
…
249
271
#define IF_DISABLED(_flag, _code) \
272
COND_CODE_1(_flag, (), _code)
271
#define IF_DISABLED(_flag, _code) \
…
273
301
#define IS_EMPTY(...) Z_IS_EMPTY_(__VA_ARGS__)
302
322
#define IS_EQ(a, b) Z_IS_EQ(a, b)
323
351
#define LIST_DROP_EMPTY(...) \
352
Z_LIST_DROP_FIRST(FOR_EACH(Z_LIST_NO_EMPTIES, (), __VA_ARGS__))
351
#define LIST_DROP_EMPTY(...) \
…
353
371
#define EMPTY
372
381
#define IDENTITY(V) V
382
391
#define GET_ARG_N(N, ...) Z_GET_ARG_##N(__VA_ARGS__)
392
401
#define GET_ARGS_LESS_N(N, ...) Z_GET_ARGS_LESS_##N(__VA_ARGS__)
402
414
#define UTIL_OR(a, b) COND_CODE_1(UTIL_BOOL(a), (a), (b))
415
427
#define UTIL_AND(a, b) COND_CODE_1(UTIL_BOOL(a), (b), (0))
428
435
#define UTIL_INC(x) UTIL_PRIMITIVE_CAT(Z_UTIL_INC_, x)
436
443
#define UTIL_DEC(x) UTIL_PRIMITIVE_CAT(Z_UTIL_DEC_, x)
444
449
#define UTIL_X2(y) UTIL_PRIMITIVE_CAT(Z_UTIL_X2_, y)
450
451
478
#define LISTIFY(LEN, F, sep, ...) UTIL_CAT(Z_UTIL_LISTIFY_, LEN)(F, sep, __VA_ARGS__)
479
501
#define FOR_EACH(F, sep, ...) \
502
Z_FOR_EACH(F, sep, REVERSE_ARGS(__VA_ARGS__))
501
#define FOR_EACH(F, sep, ...) \
…
503
556
#define FOR_EACH_NONEMPTY_TERM(F, term, ...) \
557
COND_CODE_0( \
558
/* are there zero non-empty arguments ? */
\
559
NUM_VA_ARGS_LESS_1(LIST_DROP_EMPTY(__VA_ARGS__, _)), \
560
/* if so, expand to nothing */
\
561
(), \
562
/* otherwise, expand to: */
\
563
(
/* FOR_EACH() on nonempty elements, */
\
564
FOR_EACH(F, term, LIST_DROP_EMPTY(__VA_ARGS__)) \
565
/* plus a final terminator */
\
566
__DEBRACKET term \
567
))
556
#define FOR_EACH_NONEMPTY_TERM(F, term, ...) \
…
568
593
#define FOR_EACH_IDX(F, sep, ...) \
594
Z_FOR_EACH_IDX(F, sep, REVERSE_ARGS(__VA_ARGS__))
593
#define FOR_EACH_IDX(F, sep, ...) \
…
595
621
#define FOR_EACH_FIXED_ARG(F, sep, fixed_arg, ...) \
622
Z_FOR_EACH_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__))
621
#define FOR_EACH_FIXED_ARG(F, sep, fixed_arg, ...) \
…
623
649
#define FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, ...) \
650
Z_FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, REVERSE_ARGS(__VA_ARGS__))
649
#define FOR_EACH_IDX_FIXED_ARG(F, sep, fixed_arg, ...) \
…
651
656
#define REVERSE_ARGS(...) \
657
Z_FOR_EACH_ENGINE(Z_FOR_EACH_EXEC, (,), Z_BYPASS, _, __VA_ARGS__)
656
#define REVERSE_ARGS(...) \
…
658
667
#define NUM_VA_ARGS_LESS_1(...) \
668
NUM_VA_ARGS_LESS_1_IMPL(__VA_ARGS__, 63, 62, 61, \
669
60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
670
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
671
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
672
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
673
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
674
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, ~)
667
#define NUM_VA_ARGS_LESS_1(...) \
…
675
684
#define NUM_VA_ARGS(...) \
685
COND_CODE_1(IS_EMPTY(__VA_ARGS__), (0), (UTIL_INC(NUM_VA_ARGS_LESS_1(__VA_ARGS__))))
684
#define NUM_VA_ARGS(...) \
…
686
707
#define MACRO_MAP_CAT(...) MACRO_MAP_CAT_(__VA_ARGS__)
708
722
#define MACRO_MAP_CAT_N(N, ...) MACRO_MAP_CAT_N_(N, __VA_ARGS__)
723
728
#ifdef __cplusplus
729
}
730
#endif
731
732
#endif
/* ZEPHYR_INCLUDE_SYS_UTIL_MACROS_H_ */
util_internal.h
Misc utilities.
zephyr
sys
util_macro.h
Generated on Fri Mar 14 2025 00:06:43 for Zephyr API Documentation by
1.12.0