123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- #ifndef NRF_SECTION_ITER_H__
- #define NRF_SECTION_ITER_H__
- #include <stddef.h>
- #include "nrf_section.h"
- #include "nrf_assert.h"
- #include "app_util.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- void * p_start;
- void * p_end;
- } nrf_section_t;
- typedef struct
- {
- #if defined(__GNUC__)
- nrf_section_t section;
-
- #else
- nrf_section_t const * p_first;
- nrf_section_t const * p_last;
- #endif
- size_t item_size;
- } nrf_section_set_t;
- typedef struct
- {
- nrf_section_set_t const * p_set;
- #if !defined(__GNUC__)
- nrf_section_t const * p_section;
-
- #endif
- void * p_item;
- } nrf_section_iter_t;
- #if defined(__GNUC__)
- #define NRF_SECTION_SET_DEF(_name, _type, _count) \
- \
- NRF_SECTION_DEF(_name, _type); \
- static nrf_section_set_t const _name = \
- { \
- .section = \
- { \
- .p_start = NRF_SECTION_START_ADDR(_name), \
- .p_end = NRF_SECTION_END_ADDR(_name), \
- }, \
- .item_size = sizeof(_type), \
- }
- #else
- #define NRF_SECTION_SET_DEF(_name, _type, _count) \
- \
- MACRO_REPEAT_FOR(_count, NRF_SECTION_DEF_, _name, _type) \
- static nrf_section_t const CONCAT_2(_name, _array)[] = \
- { \
- MACRO_REPEAT_FOR(_count, NRF_SECTION_SET_DEF_, _name) \
- }; \
- \
- static nrf_section_set_t const _name = \
- { \
- .p_first = CONCAT_2(_name, _array), \
- .p_last = CONCAT_2(_name, _array) + ARRAY_SIZE(CONCAT_2(_name, _array)), \
- .item_size = sizeof(_type), \
- }
- #ifndef DOXYGEN
- #define NRF_SECTION_DEF_(_priority, _name, _type) \
- NRF_SECTION_DEF(CONCAT_2(_name, _priority), _type);
- #define NRF_SECTION_SET_DEF_(_priority, _name) \
- { \
- .p_start = NRF_SECTION_START_ADDR(CONCAT_2(_name, _priority)), \
- .p_end = NRF_SECTION_END_ADDR(CONCAT_2(_name, _priority)), \
- },
- #endif
- #endif
- #define NRF_SECTION_SET_ITEM_REGISTER(_name, _priority, _var) \
- NRF_SECTION_ITEM_REGISTER(CONCAT_2(_name, _priority), _var)
- void nrf_section_iter_init(nrf_section_iter_t * p_iter, nrf_section_set_t const * p_set);
- void nrf_section_iter_next(nrf_section_iter_t * p_iter);
- static inline void * nrf_section_iter_get(nrf_section_iter_t const * p_iter)
- {
- ASSERT(p_iter);
- return p_iter->p_item;
- }
- #ifdef __cplusplus
- }
- #endif
- #endif
|