NVS storage

NVS storage system is used for permanent settings and values storage. nvs_storage.c and nvs_storage.h files provide user interface for accessing and storing values.

Defines

Values and settings are stored in NVS system by their assigned ID. IDs are ordered as follows:

  • Each setting, defined in Main_settings struc is stored by setting ID, defined in Settings.JSON file.

    • Basic settings IDs 0x01 - 0x0F

    • Advanced settings IDs 0x11 - 0x9F

  • Other values that needs to be permanently stored for fimware operation are shifted for 8 bits and start with 0x0100.

nvs_storage.h contains list of stored values IDs, that are not part of Main_settings:

  • STORAGE_unix_time 0x0100

  • STORAGE_latitude 0x0101

  • STORAGE_longitude 0x0102

  • STORAGE_altitude 0x0103

Initialisation

NVS storage is initialised with int nvs_storage_init(void) function, returning 0 on success or negative error code.

Functions

Clearing

To clear whole NVS system, int nvs_storage_clear(void) function is used. To delete only single entry by ID int nvs_storage_delete(uint16_t id) can be used.

Reading and writing

To read from NVS by value ID int nvs_storage_read(uint16_t id, const void *data, size_t len) function returns 0 on sucess.

To write to NVS storage int nvs_storage_write(uint16_t id, const void *data, size_t len) function attempts to write new or existing value.

Last updated