Zephyr API Documentation
3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
iterable_sections.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2020, Intel Corporation
3
* Copyright (C) 2023, Nordic Semiconductor ASA
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef INCLUDE_ZEPHYR_SYS_ITERABLE_SECTIONS_H_
8
#define INCLUDE_ZEPHYR_SYS_ITERABLE_SECTIONS_H_
9
10
#include <
zephyr/sys/__assert.h
>
11
#include <
zephyr/toolchain.h
>
12
13
#ifdef __cplusplus
14
extern
"C"
{
15
#endif
16
42
#define TYPE_SECTION_ITERABLE(type, varname, secname, section_postfix) \
43
Z_DECL_ALIGN(type) varname \
44
__in_section(_##secname, static, _CONCAT(section_postfix, _)) __used __noasan
45
55
#define TYPE_SECTION_START(secname) _CONCAT(_##secname, _list_start)
56
65
#define TYPE_SECTION_END(secname) _CONCAT(_##secname, _list_end)
66
78
#define TYPE_SECTION_START_EXTERN(type, secname) \
79
extern type TYPE_SECTION_START(secname)[]
80
92
#define TYPE_SECTION_END_EXTERN(type, secname) \
93
extern type TYPE_SECTION_END(secname)[]
94
105
#define TYPE_SECTION_FOREACH(type, secname, iterator) \
106
TYPE_SECTION_START_EXTERN(type, secname); \
107
TYPE_SECTION_END_EXTERN(type, secname); \
108
for (type * iterator = TYPE_SECTION_START(secname); ({ \
109
__ASSERT(iterator <= TYPE_SECTION_END(secname),\
110
"unexpected list end location"
); \
111
iterator < TYPE_SECTION_END(secname); \
112
}); \
113
iterator++)
114
125
#define TYPE_SECTION_GET(type, secname, i, dst) do { \
126
TYPE_SECTION_START_EXTERN(type, secname); \
127
*(dst) = &TYPE_SECTION_START(secname)[i]; \
128
} while (0)
129
137
#define TYPE_SECTION_COUNT(type, secname, dst) do { \
138
TYPE_SECTION_START_EXTERN(type, secname); \
139
TYPE_SECTION_END_EXTERN(type, secname); \
140
*(dst) = ((uintptr_t)TYPE_SECTION_END(secname) - \
141
(uintptr_t)TYPE_SECTION_START(secname)) / sizeof(type); \
142
} while (0)
143
149
#define STRUCT_SECTION_START(struct_type) \
150
TYPE_SECTION_START(struct_type)
151
159
#define STRUCT_SECTION_START_EXTERN(struct_type) \
160
TYPE_SECTION_START_EXTERN(struct struct_type, struct_type)
161
167
#define STRUCT_SECTION_END(struct_type) \
168
TYPE_SECTION_END(struct_type)
169
177
#define STRUCT_SECTION_END_EXTERN(struct_type) \
178
TYPE_SECTION_END_EXTERN(struct struct_type, struct_type)
179
188
#define STRUCT_SECTION_ITERABLE_ALTERNATE(secname, struct_type, varname) \
189
TYPE_SECTION_ITERABLE(struct struct_type, varname, secname, varname)
190
197
#define STRUCT_SECTION_ITERABLE_ARRAY_ALTERNATE(secname, struct_type, varname, \
198
size) \
199
TYPE_SECTION_ITERABLE(struct struct_type, varname[size], secname, \
200
varname)
201
216
#define STRUCT_SECTION_ITERABLE(struct_type, varname) \
217
STRUCT_SECTION_ITERABLE_ALTERNATE(struct_type, struct_type, varname)
218
224
#define STRUCT_SECTION_ITERABLE_ARRAY(struct_type, varname, size) \
225
STRUCT_SECTION_ITERABLE_ARRAY_ALTERNATE(struct_type, struct_type, \
226
varname, size)
227
234
#define STRUCT_SECTION_ITERABLE_NAMED(struct_type, name, varname) \
235
TYPE_SECTION_ITERABLE(struct struct_type, varname, struct_type, name)
236
244
#define STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE(struct_type, secname, name, varname) \
245
TYPE_SECTION_ITERABLE(struct struct_type, varname, secname, name)
246
257
#define STRUCT_SECTION_FOREACH_ALTERNATE(secname, struct_type, iterator) \
258
TYPE_SECTION_FOREACH(struct struct_type, secname, iterator)
259
270
#define STRUCT_SECTION_FOREACH(struct_type, iterator) \
271
STRUCT_SECTION_FOREACH_ALTERNATE(struct_type, struct_type, iterator)
272
282
#define STRUCT_SECTION_GET(struct_type, i, dst) \
283
TYPE_SECTION_GET(struct struct_type, struct_type, i, dst)
284
291
#define STRUCT_SECTION_COUNT(struct_type, dst) \
292
TYPE_SECTION_COUNT(struct struct_type, struct_type, dst);
293
/* end of struct_section_apis */
297
298
#ifdef __cplusplus
299
}
300
#endif
301
302
#endif
/* INCLUDE_ZEPHYR_SYS_ITERABLE_SECTIONS_H_ */
__assert.h
toolchain.h
Macros to abstract toolchain specific capabilities.
zephyr
sys
iterable_sections.h
Generated on Thu Jul 4 2024 12:22:47 for Zephyr API Documentation by
1.9.6