nRF5 SDK v11.0.0
Experimental: Section variables

Section variables are an experimental technique to declare configuration data at compile time. They are placed in a named section at compile time. When the code runs, section variables rely on compiler-generated symbols to find the beginning and the end of the named sections.

Using section variables removes the requirement to dynamically assign configuration data during the initialization of the module or alternatively handle multiple registrations through a shared header file.

This method is currently used in Experimental: Flash Storage and Experimental: Flash Data Storage to provide registrations of flash page usage.

Registration

Registrations are done by invoking macros leading to struct instances placed in sections identified by a qualified name.

Every registration in a named section is assumed to be of the same type. It is also assumed that they are using the same access modifier to ensure that the registrations are placed contiguously within the named section.

Registrations are isolated into code units by having a static placement. If const is used as a modifier for the instance registration, the registration will be in read-only flash for added data safety.

Note that it is not possible to control the order of the registrations in a named section across compiler versions and across compilations.

Section variables provide macro definitions to facilitate simple registration of types in named sections.

Module usage

The module that processes the registrations has access to the named section by using compiler-generated symbols. Using this method, there is no need to call functions at run time to register usage.

Any initialization by the module that requires registration can be done without relying on requests from the registered users. The module that requires initialization based on the registrations only needs access to the named section holding the registrations and the number of registrations inside that named section to iterate over the registrations one by one.

Section variables provide macro definitions to facilitate locating, counting, and iterating over the registrations.

See Usage for code examples for using the module.


Documentation feedback | Developer Zone | Updated