1
6
7
13
14
15
16
17
18
19
20
21
22
23
24
25
26
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
50
51
56
57
60
61
62
63
64
67
68
71
72
73
76
77
78
79
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
101
102
103
104
105
106
111
112
113
114
115
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
152
153
154
155
160
161
162
169
170
171
177
178
179
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* ... */
/* ... */
#ifndef _BLE_MESH_UTILS_H_
#define _BLE_MESH_UTILS_H_
#include <stddef.h>
#include "esp_bit_defs.h"
#include "mesh/types.h"
#include "utils_loops.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ... */
#ifndef POINTER_TO_UINT
#define POINTER_TO_UINT(x) ((uint32_t) (x))
#endif
#ifndef UINT_TO_POINTER
#define UINT_TO_POINTER(x) ((void *) (x))
#endif
#ifndef POINTER_TO_INT
#define POINTER_TO_INT(x) ((int32_t) (x))
#endif
#ifndef INT_TO_POINTER
#define INT_TO_POINTER(x) ((void *) (x))
#endif
#ifndef ZERO_OR_COMPILE_ERROR
#define ZERO_OR_COMPILE_ERROR(cond) ((int) sizeof(char[1 - 2 * !(cond)]) - 1)
#endif
/* ... */
#ifndef IS_ARRAY
#define IS_ARRAY(array) \
ZERO_OR_COMPILE_ERROR( \
!__builtin_types_compatible_p(__typeof__(array), \
__typeof__(&(array)[0])))...
/* ... */#endif
/* ... */
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif
/* ... */
#ifndef PART_OF_ARRAY
#define PART_OF_ARRAY(array, ptr) \
((ptr) && ((ptr) >= &array[0] && (ptr) < &array[ARRAY_SIZE(array)]))...
/* ... */#endif
#ifndef CONTAINER_OF
#define CONTAINER_OF(ptr, type, field) \
((type *)(((char *)(ptr)) - offsetof(type, field)))...
/* ... */#endif
#ifndef ROUND_UP
#define ROUND_UP(x, align) \
(((unsigned long)(x) + ((unsigned long)align - 1)) & \
~((unsigned long)align - 1))...
/* ... */#endif
#ifndef ROUND_DOWN
#define ROUND_DOWN(x, align) ((unsigned long)(x) & ~((unsigned long)align - 1))
#endif
#ifndef WB_UP
#define WB_UP(x) ROUND_UP(x, sizeof(void *))
#endif
#ifndef WB_DN
#define WB_DN(x) ROUND_DOWN(x, sizeof(void *))
#endif
#ifndef ceiling_fraction
#define ceiling_fraction(numerator, divider) \
(((numerator) + ((divider) - 1)) / (divider))...
/* ... */#endif
#ifndef CHECKIF
#define CHECKIF(expr) if (expr)
#endif
/* ... */
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
/* ... */
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef BIT
#define BIT(n) (1UL << (n))
#endif
#ifndef BIT_MASK
#define BIT_MASK(n) (BIT(n) - 1)
#endif
/* ... */
#define IS_ENABLED(config_macro) Z_IS_ENABLED1(config_macro)
/* ... */
#define Z_IS_ENABLED1(config_macro) Z_IS_ENABLED2(_XXXX##config_macro)
/* ... */
#define _XXXX1 _YYYY,
/* ... */
#define Z_IS_ENABLED2(one_or_two_args) Z_IS_ENABLED3(one_or_two_args true, false)
/* ... */
#define Z_IS_ENABLED3(ignore_this, val, ...) val
#define __DEBRACKET(...) __VA_ARGS__
#define UTIL_CAT(a, ...) UTIL_PRIMITIVE_CAT(a, __VA_ARGS__)
#define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
/* ... */
#define LISTIFY(LEN, F, sep, ...) UTIL_CAT(Z_UTIL_LISTIFY_, LEN)(F, sep, __VA_ARGS__)9 defines
const char *bt_hex(const void *buf, size_t len);
void mem_rcopy(uint8_t *dst, uint8_t const *src, uint16_t len);
#ifdef __cplusplus
}{...}
#endif
/* ... */
#endif