nRF5 SDK v17.0.2
Experimental: Section variables iterator

Section variables iterator is an extension of Experimental: Section variables which allows you to control the order of the variables. This is achieved by introducing nrf_section_set_t.

Creating a section set

nrf_section_set_t is an ordered group of sections. Similarly to the Experimental: Section variables, creating it requires two steps:

  1. Instead of creating a single section with the NRF_SECTION_DEF macro, use NRF_SECTION_SET_DEF with an additional parameter - count (count of sections in the set).
  2. If you are using GCC, modify the section definition in the linker script to accept wildcard matches and to sort it. To do so, add the following definition to the root level of the linker script that is used in the compilation (replace set_name with the name of your section):
    SECTIONS
    {
    .set_name :
    {
    PROVIDE(__start_set_name = .);
    KEEP(*(SORT(.set_name*)))
    PROVIDE(__stop_set_name = .);
    } > RAM
    } INSERT AFTER .data;

Registering section set variables

In the code of the registrant module, use the NRF_SECTION_SET_ITEM_REGISTER macro to register a section set variable. The following code example shows how to register the variable var_name of type data_type_t in the section set named section_set_name at index priority and assign to it the value var_value:

NRF_SECTION_SET_ITEM_REGISTER(section_set_name, priority, data_type_t var_name ) = { var_value };

Variables registered with lower priority value are placed before the ones with higher value. For example, a variable with priority set to 0 is placed before a variable with priority set to 1. You cannot control the order of variables within one priority.

Using section set iterator

The following code example shows how to iterate through all variables in the set:

NRF_SECTION_SET_DEF(set_name, data_type_t, count);
static void user_func(void)
{
for (nrf_section_iter_init(&iter, &set_name);
nrf_section_iter_get(&iter) != NULL;
{
void * p_item = nrf_section_iter_get(&iter);
(...)
}
}

Documentation feedback | Developer Zone | Subscribe | Updated