Verifying and Initializing Settings
|Top Previous Next|
Initialization is the process of making setting values "sane". To be considered sane, the setting value must have correct checksum, and its members must conform to the constraints of P1 and P2 parameters.
Non-volatile settings are never initialized automatically — it is your responsibility as the developer to decide just when and how this happens. If you load a settings-using application onto a device that has never run this application before, then each non-volatile setting will be invalid because all setting checksums will be wrong. Volatile settings are always initialized when you call stg_start().
A more "automatic" way is to use stg_restore_multiple(). This will restore all settings to their default values as defined in the setting descriptor file. In the following example, settings are initialized if the MD button is kept pressed for more than 2 seconds and then released:
You can also verify the sanity of each setting in your project by calling stg_check_all(). Here is some code you can place in on_sys_init() — it verifies all settings and performs initialization if any setting is found to be invalid. Notice how we check the code returned by stg_check_all(). EN_STG_STATUS_INVALID is a "good" error, that is, we expect it to happen. There are other errors, however, that are "fatal", for example, EN_STG_STATUS_FAILURE. We halt on those.