CAF: Settings loader module

The Settings loader module of the Common Application Framework (CAF) is a simple, stateless module responsible for calling the settings_load() function. If any of the application modules relies on settings, this module ensures that the data stored in non-volatile memory is read after completing all necessary initialization.

Configuration

The following Kconfig options are required:

The following Kconfig options are also available for the module:

To use the module, you must complete the following steps:

  1. Enable the CONFIG_CAF_SETTINGS_LOADER and CONFIG_SETTINGS Kconfig options.

  2. Add the configuration file that implements the function get_req_modules(), which sets bits of modules that are required to be initialized before settings are loaded. For example, the file content could look like follows:

    #include <caf/events/module_state_event.h>
    
    static inline void get_req_modules(struct module_flags *mf)
    {
            module_flags_set_bit(mf, MODULE_IDX(main));
    #if CONFIG_CAF_BLE_ADV
            module_flags_set_bit(mf, MODULE_IDX(ble_adv));
    #endif
    };
    

This function is called on the settings loader module initialization. After each of modules that sets bit in get_req_modules() is initialized, the Settings loader module calls settings_load() function and starts loading all the settings from non-volatile memory.

Implementation details

Getting the required modules is wrapped into the get_req_modules() function due to implementation limitations.

Settings are loaded in the Application Event Manager handler, which by default is invoked from a system workqueue context. This blocks the workqueue until the operation is finished. You can set the CONFIG_CAF_SETTINGS_LOADER_USE_THREAD Kconfig option to load the settings in a separate thread in the background instead of using the system workqueue for that purpose. This prevents blocking the system workqueue, but it requires creating an additional thread. The stack size for the background thread is defined in the CONFIG_CAF_SETTINGS_LOADER_THREAD_STACK_SIZE Kconfig option.