|
Modbus Vault v1.0
|
Implementation of the NVS manager. More...
#include "esp_log.h"#include "esp_timer.h"#include "freertos/FreeRTOS.h"#include "freertos/semphr.h"#include "nvs_manager_internal.h"#include "utils.h"#include <string.h>Functions | |
| static const key_map_t * | find_map_helper (nvs_keys_t key) |
| Find entry in config map. | |
| static esp_err_t | save_config_internal (void) |
| Save configuration to flash. | |
| static esp_err_t | load_config_internal (void) |
| Load configuration from flash. | |
| static void | check_dirty_commit_callback (void *arg_void_ptr) |
| Callback for timer. | |
| static esp_err_t | write_to_cfg_struct_helper (app_config_t *config_ptr, nvs_keys_t key, const void *value_void_ptr, size_t value_size) |
| Write to configuration structure using an NVS key. | |
| esp_err_t | nvs_manager_init (nvs_manager_ops_t *ops_ptr) |
| Initialize NVS manager. | |
| esp_err_t | nvs_manager_set_default (nvs_keys_t key, const void *value_void_ptr, size_t value_size) |
| Set configuration default. | |
| esp_err_t | nvs_manager_write_cfg (nvs_keys_t key, const void *value_void_ptr, size_t value_size) |
| Write configuration to flash. | |
| esp_err_t | nvs_manager_read_cfg (nvs_keys_t key, void *value_void_ptr) |
| Read configuration from flash. | |
| esp_err_t | nvs_manager_flush_cfg (void) |
| Flush configuration structure to flash. | |
| void | nvs_manager_deinit (void) |
| Deinitialize NVS manager. | |
Variables | |
| static const char * | TAG = "NVS_MANAGER" |
| static const key_map_t | config_map [] |
| static app_config_t | default_config = {.version = NVS_MANAGER_CONFIG_VERSION} |
| static SemaphoreHandle_t | config_lock = NULL |
Implementation of the NVS manager.
|
static |
Callback for timer.
Callback function for periodic timer. It checks for dirty configuration then commit it if so
| arg_void_ptr | Void pointer to callback argument |
|
static |
Find entry in config map.
| key | Key chosen from nvs_keys_t |
|
static |
Load configuration from flash.
Load configuration from flash. On success compare version and verify it's crc16 if all checks update shadow structure then return
| ESP_OK | Write success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| any | Any error from down layers propagates upward |
| void nvs_manager_deinit | ( | void | ) |
Deinitialize NVS manager.
Deinitialize NVS manager by commit data, close handle, delete timer and deinit flash
| esp_err_t nvs_manager_flush_cfg | ( | void | ) |
Flush configuration structure to flash.
| ESP_OK | Flush success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| any | Any error from down layers propagates upward |
| esp_err_t nvs_manager_init | ( | nvs_manager_ops_t * | ops_ptr | ) |
Initialize NVS manager.
Initialize NVS manager by calling flash init, if succeeded load config, If failed with 'flash full' or 'new NVS version' erase flash then try to call flash init again. Finally initiate periodic timer to commit configuration if it was flagged dirty and newer than shadow structure
| ops_ptr | Pointer to NVS manager operations structure |
| ESP_OK | Initialize success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| any | Any error from down layers propagates upward |
| esp_err_t nvs_manager_read_cfg | ( | nvs_keys_t | key, |
| void * | value_void_ptr | ||
| ) |
Read configuration from flash.
Read configuration from flash cached in configuration structure
| key | Key chosen from nvs_keys_t |
| value_void_ptr | Pointer to data |
| ESP_OK | Read success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| esp_err_t nvs_manager_set_default | ( | nvs_keys_t | key, |
| const void * | value_void_ptr, | ||
| size_t | value_size | ||
| ) |
Set configuration default.
Set configuration default values in case it was missing from flash
| key | Key chosen from nvs_keys_t |
| value_void_ptr | Pointer to data |
| value_size | Value size |
| ESP_OK | Set success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| esp_err_t nvs_manager_write_cfg | ( | nvs_keys_t | key, |
| const void * | value_void_ptr, | ||
| size_t | value_size | ||
| ) |
Write configuration to flash.
Write configuration to flash by writing to configuration structure and flush it when preset time has passed
| key | Key chosen from nvs_keys_t |
| value_void_ptr | Pointer to data |
| value_size | Value size |
| ESP_OK | Write success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
|
static |
Save configuration to flash.
Save configuration structure to flash as a blob and update shadow structure if save succeeded
| ESP_OK | Save success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
| any | Any error from down layers propagates upward |
|
static |
Write to configuration structure using an NVS key.
| config_ptr | Pointer to configuration structure |
| key | Key chosen from nvs_keys_t |
| value_void_ptr | Void pointer to value |
| value_size | Value size |
| ESP_OK | Write success |
| ESP_ERR_INVALID_ARG | Provided invalid argument(s) |
|
static |
App configuration lock
|
static |
Helps in write/read management
|
static |
Defaulting value when no data in NVS
|
static |
NVS Manager TAG name