forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_macro.h
More file actions
151 lines (137 loc) · 4.03 KB
/
util_macro.h
File metadata and controls
151 lines (137 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright (c) 2011-2014, Wind River Systems, Inc.
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
/**
* @file
* @brief Nordic macro utilities
*
* Additional utility macros
*/
#ifndef UTIL_MACROS_H_
#define UTIL_MACROS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <util/util_internal.h>
#include <zephyr/sys/util_macro.h>
/**
* @addtogroup sys-util
* @{
*/
/**
* @brief Check multiple macro definitions to see if all are set in
* compiler-visible expressions
*
* This utilizes the same methodology as IS_ENABLED but on an variable number
* of argument. It will resolve as true (1) if all of the arguments in the input
* are defined to 1.
*
* Example usage:
*
* if (IS_ENABLED_ALL(CONFIG_FOO, CONFIG_BAR)) {
* do_something_if_all_of_these
* }
*
* This is cleaner since the compiler can generate errors and warnings
* for @p do_something_if_all_of_these even when @p CONFIG_FOO and/or
* @p CONFIG_BAR is undefined.
*
* @param ... Arguments to check if all are defined to 1
* @return 1 if all params in @p ... are defined to 1, otherwise 0
*/
#define IS_ENABLED_ALL(...) Z_IS_ENABLED_ALL(__VA_ARGS__)
/**
* @brief Check multiple macro definitions to see if any is set in
* compiler-visible expressions
*
* This utilizes the same methodology as IS_ENABLED but on an variable number
* of argument. It will resolve as true (1) if any of the arguments in the input
* are defined to 1.
*
* Example usage:
*
* if (IS_ENABLED_ANY(CONFIG_FOO, CONFIG_BAR)) {
* do_something_if_any_of_these
* }
*
* This is cleaner since the compiler can generate errors and warnings
* for @p do_something_if_any_of_these even when @p CONFIG_FOO and/or
* @p CONFIG_BAR is undefined.
*
* @param ... Arguments to check if at least one is defined to 1
* @return 1 if at least one param in @p ... is defined to 1, otherwise 0
*/
#define IS_ENABLED_ANY(...) Z_IS_ENABLED_ANY(__VA_ARGS__)
/**
* @brief Insert code if all @p _flags are defined and equals 1.
*
* Like IF_ENABLED(), this emits code if @p _flags are all defined and
* set to 1; it expands to nothing otherwise.
*
* Example:
*
* IF_ENABLED_ALL((CONFIG_FOO, CONFIG_BAR), uint32_t foo;)
*
* If @p CONFIG_FOO and @p CONFIG_BAR are defined to 1, this expands to:
*
* uint32_t foo;
*
* and to nothing otherwise.
*
* @param _flags evaluated flags; must be in parentheses
* @param ... Emitted code if all @p _flags are defined to 1
*/
#define IF_ENABLED_ALL(_flags, ...) \
Z_IF_ENABLED_ALL((__VA_ARGS__), __DEBRACKET _flags)
/**
* @brief Insert code if any @p _flags are defined to 1.
*
* Like IF_ENABLED(), this emits code if any @p _flags are defined to 1;
* it expands to nothing otherwise.
*
* Example:
*
* IF_ENABLED_ANY((CONFIG_FOO, CONFIG_BAR), uint32_t foo;)
*
* If @p CONFIG_FOO or @p CONFIG_BAR defined to 1, this expands to:
*
* uint32_t foo;
*
* and to nothing otherwise.
*
* @param _flags evaluated flags; must be in parentheses
* @param ... Emitted code if any @p _flags expands to 1
*/
#define IF_ENABLED_ANY(_flags, ...) \
Z_IF_ENABLED_ANY((__VA_ARGS__), __DEBRACKET _flags)
/**
* @brief Concatenates all arguments with "&&" between them into a single token
*
* This macro does primitive concatenation and doesn't try to process the
* parameters in preprocessor.
*
* @param ... Arguments to concatenate with @p && between them
* @return A concatenation of all the arguments with @p && between them or a
* single argument
*/
#define UTIL_CONCAT_AND(...) Z_UTIL_CONCAT_AND(__VA_ARGS__)
/**
* @brief Concatenates all arguments with "||" between them into a single token
*
* This macro does primitive concatenation and doesn't try to process the
* parameters in preprocessor.
*
* @param ... Arguments to concatenate with @p || between them
* @return A concatenation of all the arguments with @p || between them or a
* single argument
*/
#define UTIL_CONCAT_OR(...) Z_UTIL_CONCAT_OR(__VA_ARGS__)
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* UTIL_MACROS_H_ */