The settings storage can be used to store and retrieve various configurable parameters. This storage is a RAM-based map (for fast access), but one or more files can be used too (so values can persist across system reboots).
This is a thread-safe implementation. Different threads may access the settings simultaneously.
Each setting is a key/value pair.
The key is always a string, while there are many value types supported.
All strings, whether they represent a key or a string value, must use a specific format. They must be ASCII, NULL-terminated strings, and they are always case-sensitive. They must obey to the following rules:
Since each setting has its own type, it is the user's responsibility to access the setting using the correct type. Some “casts” are possible (e.g. between bool and int), but generally reading with the wrong type will lead to failure.
The following types are currently supported.
Kconfig is used to determine the size of the various fields used:
A POSIX signal can be chosen via Kconfig and is used to send notifications when a setting has been changed. <CONFIG_SYSTEM_SETTINGS_MAX_SIGNALS> is used to determine the maximum number of signals that can be registered for the settings storage functions.
There are also various types of files that can be used. Each file type is using a different data format to parse the stored data. Every type is expected to be best suited for a specific file system or medium type, or be better performing while used with external systems. In any case, all configured files are automatically synchronized whenever a value changes.
It is possible to enable cached saves, via Kconfig, along with the time (in ms) that should elapse after the last storage value was updated before a write to the file or files should be initiated.
The current storage types are defined in and are as follows.
Data is stored as “raw” binary. Bool, int and float data are stored using the maximum number of bytes needed, as determined by the size of the union used for these settings; this will be architecture dependent.
All data is converted to ASCII characters making the storage easily human-readable.
This is the usual sequence of calls to use the settings utility.
Other functions exist to assist the user program.
The settings functions provide negated error return codes that can be used as required by the user application to deal with unexpected behaviour.
There is an example app available to demonstrate the usage of many of the settings features CONFIG_EXAMPLES_SETTINGS.