boot_count++;
ESP_LOGI(TAG, "boot count %d", boot_count);
const esp_partition_t *cur_app = get_running_firmware();
- nvs_handle handle = 0;
+ nvs_handle_t handle = 0;
int boot_count_nvs = 0;
switch (boot_count) {
case 2:
static const char *cache_key = "gattc_cache_key";
static const char *cache_addr = "cache_addr_tab";
-nvs_handle nvs_fp;
+nvs_handle_t nvs_fp;
typedef struct {
//save the service data in the list according to the address
- nvs_handle cache_fp;
+ nvs_handle_t cache_fp;
BOOLEAN is_open;
BD_ADDR addr;
hash_key_t hash_key;
typedef struct {
//save the address list in the cache
- nvs_handle addr_fp;
+ nvs_handle_t addr_fp;
BOOLEAN is_open;
UINT8 num_addr;
cache_addr_info_t cache_addr[MAX_DEVICE_IN_CACHE];
void bta_gattc_co_cache_addr_init(void)
{
- nvs_handle fp;
+ nvs_handle_t fp;
esp_err_t err_code;
UINT8 num_addr;
UINT8 *p_buf = osi_malloc(MAX_ADDR_LIST_CACHE_BUF);
memcpy(cache_env.cache_addr[num - 1].hash_key, hash_key, sizeof(hash_key_t));
}
- nvs_handle *fp = &cache_env.addr_fp;
+ nvs_handle_t *fp = &cache_env.addr_fp;
UINT16 length = num*(sizeof(BD_ADDR) + sizeof(hash_key_t));
for (UINT8 i = 0; i < num; i++) {
// Empty definition; this type is aliased to list_node_t.
struct config_section_iter_t {};
-static void config_parse(nvs_handle fp, config_t *config);
+static void config_parse(nvs_handle_t fp, config_t *config);
static section_t *section_new(const char *name);
static void section_free(void *ptr);
}
esp_err_t err;
- nvs_handle fp;
+ nvs_handle_t fp;
err = nvs_open(filename, NVS_READWRITE, &fp);
if (err != ESP_OK) {
if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
return total_size;
}
-static int get_config_size_from_flash(nvs_handle fp)
+static int get_config_size_from_flash(nvs_handle_t fp)
{
assert(fp != 0);
esp_err_t err;
int err_code = 0;
- nvs_handle fp;
+ nvs_handle_t fp;
char *line = osi_calloc(1024);
const size_t keyname_bufsz = sizeof(CONFIG_KEY) + 5 + 1; // including log10(sizeof(i))
char *keyname = osi_calloc(keyname_bufsz);
return str;
}
-static void config_parse(nvs_handle fp, config_t *config)
+static void config_parse(nvs_handle_t fp, config_t *config)
{
assert(fp != 0);
assert(config != NULL);
static const char* PHY_CAL_MAC_KEY = "cal_mac";
static const char* PHY_CAL_DATA_KEY = "cal_data";
-static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
+static esp_err_t load_cal_data_from_nvs_handle(nvs_handle_t handle,
esp_phy_calibration_data_t* out_cal_data);
-static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
+static esp_err_t store_cal_data_to_nvs_handle(nvs_handle_t handle,
const esp_phy_calibration_data_t* cal_data);
esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data)
{
- nvs_handle handle;
+ nvs_handle_t handle;
esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READONLY, &handle);
if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
ESP_LOGE(TAG, "%s: NVS has not been initialized. "
esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data)
{
- nvs_handle handle;
+ nvs_handle_t handle;
esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READWRITE, &handle);
if (err != ESP_OK) {
ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
esp_err_t esp_phy_erase_cal_data_in_nvs(void)
{
- nvs_handle handle;
+ nvs_handle_t handle;
esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READWRITE, &handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "%s: failed to open NVS phy namespace (0x%x)", __func__, err);
return err;
}
-static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
+static esp_err_t load_cal_data_from_nvs_handle(nvs_handle_t handle,
esp_phy_calibration_data_t* out_cal_data)
{
esp_err_t err;
return ESP_OK;
}
-static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
+static esp_err_t store_cal_data_to_nvs_handle(nvs_handle_t handle,
const esp_phy_calibration_data_t* cal_data)
{
esp_err_t err;
bool dhcp_ip_addr_restore(void *netif)
{
- nvs_handle nvs;
+ nvs_handle_t nvs;
bool err = false;
struct netif *net = (struct netif *)netif;
struct dhcp *dhcp = netif_dhcp_data(net);
void dhcp_ip_addr_store(void *netif)
{
- nvs_handle nvs;
+ nvs_handle_t nvs;
struct netif *net = (struct netif *)netif;
struct dhcp *dhcp = netif_dhcp_data(net);
uint32_t ip_addr = dhcp->offered_ip_addr.addr;
void dhcp_ip_addr_erase(void *netif)
{
- nvs_handle nvs;
+ nvs_handle_t nvs;
struct netif *net = (struct netif *)netif;
esp_interface_t netif_id = tcpip_adapter_get_esp_if(net);
/**
* Opaque pointer type representing non-volatile storage handle
*/
-typedef uint32_t nvs_handle;
+typedef uint32_t nvs_handle_t;
+
+/*
+ * Pre-IDF V4.0 uses nvs_handle, so leaving the original typedef here for compatibility.
+ */
+typedef nvs_handle_t nvs_handle;
#define ESP_ERR_NVS_BASE 0x1100 /*!< Starting number of error codes */
#define ESP_ERR_NVS_NOT_INITIALIZED (ESP_ERR_NVS_BASE + 0x01) /*!< The storage driver is not initialized */
#define ESP_ERR_NVS_CONTENT_DIFFERS (ESP_ERR_NVS_BASE + 0x18) /*!< Internal error; never returned by nvs API functions. NVS key is different in comparison */
#define NVS_DEFAULT_PART_NAME "nvs" /*!< Default partition name of the NVS partition in the partition table */
+
/**
* @brief Mode of opening the non-volatile storage
- *
*/
typedef enum {
NVS_READONLY, /*!< Read only */
NVS_READWRITE /*!< Read and write */
-} nvs_open_mode;
+} nvs_open_mode_t;
+
+/*
+ * Pre-IDF V4.0 uses nvs_open_mode, so leaving the original typedef here for compatibility.
+ */
+typedef nvs_open_mode_t nvs_open_mode
typedef enum {
NVS_TYPE_U8 = 0x01,
* - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
* - other error codes from the underlying storage driver
*/
-esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle);
+esp_err_t nvs_open(const char* name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle);
/**
* @brief Open non-volatile storage with a given namespace from specified partition
* - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
* - other error codes from the underlying storage driver
*/
-esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode open_mode, nvs_handle *out_handle);
+esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle);
/**@{*/
/**
* flash operation doesn't fail again.
* - ESP_ERR_NVS_VALUE_TOO_LONG if the string value is too long
*/
-esp_err_t nvs_set_i8 (nvs_handle handle, const char* key, int8_t value);
-esp_err_t nvs_set_u8 (nvs_handle handle, const char* key, uint8_t value);
-esp_err_t nvs_set_i16 (nvs_handle handle, const char* key, int16_t value);
-esp_err_t nvs_set_u16 (nvs_handle handle, const char* key, uint16_t value);
-esp_err_t nvs_set_i32 (nvs_handle handle, const char* key, int32_t value);
-esp_err_t nvs_set_u32 (nvs_handle handle, const char* key, uint32_t value);
-esp_err_t nvs_set_i64 (nvs_handle handle, const char* key, int64_t value);
-esp_err_t nvs_set_u64 (nvs_handle handle, const char* key, uint64_t value);
-esp_err_t nvs_set_str (nvs_handle handle, const char* key, const char* value);
+esp_err_t nvs_set_i8 (nvs_handle_t handle, const char* key, int8_t value);
+esp_err_t nvs_set_u8 (nvs_handle_t handle, const char* key, uint8_t value);
+esp_err_t nvs_set_i16 (nvs_handle_t handle, const char* key, int16_t value);
+esp_err_t nvs_set_u16 (nvs_handle_t handle, const char* key, uint16_t value);
+esp_err_t nvs_set_i32 (nvs_handle_t handle, const char* key, int32_t value);
+esp_err_t nvs_set_u32 (nvs_handle_t handle, const char* key, uint32_t value);
+esp_err_t nvs_set_i64 (nvs_handle_t handle, const char* key, int64_t value);
+esp_err_t nvs_set_u64 (nvs_handle_t handle, const char* key, uint64_t value);
+esp_err_t nvs_set_str (nvs_handle_t handle, const char* key, const char* value);
/**@}*/
/**
* flash operation doesn't fail again.
* - ESP_ERR_NVS_VALUE_TOO_LONG if the value is too long
*/
-esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length);
+esp_err_t nvs_set_blob(nvs_handle_t handle, const char* key, const void* value, size_t length);
/**@{*/
/**
* - ESP_ERR_NVS_INVALID_NAME if key name doesn't satisfy constraints
* - ESP_ERR_NVS_INVALID_LENGTH if length is not sufficient to store data
*/
-esp_err_t nvs_get_i8 (nvs_handle handle, const char* key, int8_t* out_value);
-esp_err_t nvs_get_u8 (nvs_handle handle, const char* key, uint8_t* out_value);
-esp_err_t nvs_get_i16 (nvs_handle handle, const char* key, int16_t* out_value);
-esp_err_t nvs_get_u16 (nvs_handle handle, const char* key, uint16_t* out_value);
-esp_err_t nvs_get_i32 (nvs_handle handle, const char* key, int32_t* out_value);
-esp_err_t nvs_get_u32 (nvs_handle handle, const char* key, uint32_t* out_value);
-esp_err_t nvs_get_i64 (nvs_handle handle, const char* key, int64_t* out_value);
-esp_err_t nvs_get_u64 (nvs_handle handle, const char* key, uint64_t* out_value);
+esp_err_t nvs_get_i8 (nvs_handle_t handle, const char* key, int8_t* out_value);
+esp_err_t nvs_get_u8 (nvs_handle_t handle, const char* key, uint8_t* out_value);
+esp_err_t nvs_get_i16 (nvs_handle_t handle, const char* key, int16_t* out_value);
+esp_err_t nvs_get_u16 (nvs_handle_t handle, const char* key, uint16_t* out_value);
+esp_err_t nvs_get_i32 (nvs_handle_t handle, const char* key, int32_t* out_value);
+esp_err_t nvs_get_u32 (nvs_handle_t handle, const char* key, uint32_t* out_value);
+esp_err_t nvs_get_i64 (nvs_handle_t handle, const char* key, int64_t* out_value);
+esp_err_t nvs_get_u64 (nvs_handle_t handle, const char* key, uint64_t* out_value);
/**@}*/
/**
* - ESP_ERR_NVS_INVALID_LENGTH if length is not sufficient to store data
*/
/**@{*/
-esp_err_t nvs_get_str (nvs_handle handle, const char* key, char* out_value, size_t* length);
-esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size_t* length);
+esp_err_t nvs_get_str (nvs_handle_t handle, const char* key, char* out_value, size_t* length);
+esp_err_t nvs_get_blob(nvs_handle_t handle, const char* key, void* out_value, size_t* length);
/**@}*/
/**
* - ESP_ERR_NVS_NOT_FOUND if the requested key doesn't exist
* - other error codes from the underlying storage driver
*/
-esp_err_t nvs_erase_key(nvs_handle handle, const char* key);
+esp_err_t nvs_erase_key(nvs_handle_t handle, const char* key);
/**
* @brief Erase all key-value pairs in a namespace
* - ESP_ERR_NVS_READ_ONLY if handle was opened as read only
* - other error codes from the underlying storage driver
*/
-esp_err_t nvs_erase_all(nvs_handle handle);
+esp_err_t nvs_erase_all(nvs_handle_t handle);
/**
* @brief Write any pending changes to non-volatile storage
* - ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
* - other error codes from the underlying storage driver
*/
-esp_err_t nvs_commit(nvs_handle handle);
+esp_err_t nvs_commit(nvs_handle_t handle);
/**
* @brief Close the storage handle and free any allocated resources
*
* @param[in] handle Storage handle to close
*/
-void nvs_close(nvs_handle handle);
+void nvs_close(nvs_handle_t handle);
/**
* @note Info about storage space NVS.
*
* \code{c}
* // Example of nvs_get_used_entry_count() to get amount of all key-value pairs in one namespace:
- * nvs_handle handle;
+ * nvs_handle_t handle;
* nvs_open("namespace1", NVS_READWRITE, &handle);
* ...
* size_t used_entries;
* - Other error codes from the underlying storage driver.
* Return param used_entries will be filled 0.
*/
-esp_err_t nvs_get_used_entry_count(nvs_handle handle, size_t* used_entries);
+esp_err_t nvs_get_used_entry_count(nvs_handle_t handle, size_t* used_entries);
#ifdef __cplusplus
} // extern "C"
{
}
- nvs_handle mHandle;
+ nvs_handle_t mHandle;
uint8_t mReadOnly;
uint8_t mNsIndex;
nvs::Storage* mStoragePtr;
return nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME);
}
-static esp_err_t nvs_find_ns_handle(nvs_handle handle, HandleEntry& entry)
+static esp_err_t nvs_find_ns_handle(nvs_handle_t handle, HandleEntry& entry)
{
auto it = find_if(begin(s_nvs_handles), end(s_nvs_handles), [=](HandleEntry& e) -> bool {
return e.mHandle == handle;
return ESP_OK;
}
-extern "C" esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode open_mode, nvs_handle *out_handle)
+extern "C" esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle)
{
Lock lock;
ESP_LOGD(TAG, "%s %s %d", __func__, name, open_mode);
return ESP_OK;
}
-extern "C" esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle)
+extern "C" esp_err_t nvs_open(const char* name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle)
{
if (s_nvs_storage_list.size() == 0) {
return ESP_ERR_NVS_NOT_INITIALIZED;
return nvs_open_from_partition(NVS_DEFAULT_PART_NAME, name, open_mode, out_handle);
}
-extern "C" void nvs_close(nvs_handle handle)
+extern "C" void nvs_close(nvs_handle_t handle)
{
Lock lock;
ESP_LOGD(TAG, "%s %d", __func__, handle);
delete static_cast<HandleEntry*>(it);
}
-extern "C" esp_err_t nvs_erase_key(nvs_handle handle, const char* key)
+extern "C" esp_err_t nvs_erase_key(nvs_handle_t handle, const char* key)
{
Lock lock;
ESP_LOGD(TAG, "%s %s\r\n", __func__, key);
return entry.mStoragePtr->eraseItem(entry.mNsIndex, key);
}
-extern "C" esp_err_t nvs_erase_all(nvs_handle handle)
+extern "C" esp_err_t nvs_erase_all(nvs_handle_t handle)
{
Lock lock;
ESP_LOGD(TAG, "%s\r\n", __func__);
}
template<typename T>
-static esp_err_t nvs_set(nvs_handle handle, const char* key, T value)
+static esp_err_t nvs_set(nvs_handle_t handle, const char* key, T value)
{
Lock lock;
ESP_LOGD(TAG, "%s %s %d %d", __func__, key, sizeof(T), (uint32_t) value);
return entry.mStoragePtr->writeItem(entry.mNsIndex, key, value);
}
-extern "C" esp_err_t nvs_set_i8 (nvs_handle handle, const char* key, int8_t value)
+extern "C" esp_err_t nvs_set_i8 (nvs_handle_t handle, const char* key, int8_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_set_u8 (nvs_handle handle, const char* key, uint8_t value)
+extern "C" esp_err_t nvs_set_u8 (nvs_handle_t handle, const char* key, uint8_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_set_i16 (nvs_handle handle, const char* key, int16_t value)
+extern "C" esp_err_t nvs_set_i16 (nvs_handle_t handle, const char* key, int16_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_set_u16 (nvs_handle handle, const char* key, uint16_t value)
+extern "C" esp_err_t nvs_set_u16 (nvs_handle_t handle, const char* key, uint16_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_set_i32 (nvs_handle handle, const char* key, int32_t value)
+extern "C" esp_err_t nvs_set_i32 (nvs_handle_t handle, const char* key, int32_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_set_u32 (nvs_handle handle, const char* key, uint32_t value)
+extern "C" esp_err_t nvs_set_u32 (nvs_handle_t handle, const char* key, uint32_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_set_i64 (nvs_handle handle, const char* key, int64_t value)
+extern "C" esp_err_t nvs_set_i64 (nvs_handle_t handle, const char* key, int64_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_set_u64 (nvs_handle handle, const char* key, uint64_t value)
+extern "C" esp_err_t nvs_set_u64 (nvs_handle_t handle, const char* key, uint64_t value)
{
return nvs_set(handle, key, value);
}
-extern "C" esp_err_t nvs_commit(nvs_handle handle)
+extern "C" esp_err_t nvs_commit(nvs_handle_t handle)
{
Lock lock;
// no-op for now, to be used when intermediate cache is added
return nvs_find_ns_handle(handle, entry);
}
-extern "C" esp_err_t nvs_set_str(nvs_handle handle, const char* key, const char* value)
+extern "C" esp_err_t nvs_set_str(nvs_handle_t handle, const char* key, const char* value)
{
Lock lock;
ESP_LOGD(TAG, "%s %s %s", __func__, key, value);
return entry.mStoragePtr->writeItem(entry.mNsIndex, nvs::ItemType::SZ, key, value, strlen(value) + 1);
}
-extern "C" esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length)
+extern "C" esp_err_t nvs_set_blob(nvs_handle_t handle, const char* key, const void* value, size_t length)
{
Lock lock;
ESP_LOGD(TAG, "%s %s %d", __func__, key, length);
template<typename T>
-static esp_err_t nvs_get(nvs_handle handle, const char* key, T* out_value)
+static esp_err_t nvs_get(nvs_handle_t handle, const char* key, T* out_value)
{
Lock lock;
ESP_LOGD(TAG, "%s %s %d", __func__, key, sizeof(T));
return entry.mStoragePtr->readItem(entry.mNsIndex, key, *out_value);
}
-extern "C" esp_err_t nvs_get_i8 (nvs_handle handle, const char* key, int8_t* out_value)
+extern "C" esp_err_t nvs_get_i8 (nvs_handle_t handle, const char* key, int8_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-extern "C" esp_err_t nvs_get_u8 (nvs_handle handle, const char* key, uint8_t* out_value)
+extern "C" esp_err_t nvs_get_u8 (nvs_handle_t handle, const char* key, uint8_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-extern "C" esp_err_t nvs_get_i16 (nvs_handle handle, const char* key, int16_t* out_value)
+extern "C" esp_err_t nvs_get_i16 (nvs_handle_t handle, const char* key, int16_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-extern "C" esp_err_t nvs_get_u16 (nvs_handle handle, const char* key, uint16_t* out_value)
+extern "C" esp_err_t nvs_get_u16 (nvs_handle_t handle, const char* key, uint16_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-extern "C" esp_err_t nvs_get_i32 (nvs_handle handle, const char* key, int32_t* out_value)
+extern "C" esp_err_t nvs_get_i32 (nvs_handle_t handle, const char* key, int32_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-extern "C" esp_err_t nvs_get_u32 (nvs_handle handle, const char* key, uint32_t* out_value)
+extern "C" esp_err_t nvs_get_u32 (nvs_handle_t handle, const char* key, uint32_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-extern "C" esp_err_t nvs_get_i64 (nvs_handle handle, const char* key, int64_t* out_value)
+extern "C" esp_err_t nvs_get_i64 (nvs_handle_t handle, const char* key, int64_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-extern "C" esp_err_t nvs_get_u64 (nvs_handle handle, const char* key, uint64_t* out_value)
+extern "C" esp_err_t nvs_get_u64 (nvs_handle_t handle, const char* key, uint64_t* out_value)
{
return nvs_get(handle, key, out_value);
}
-static esp_err_t nvs_get_str_or_blob(nvs_handle handle, nvs::ItemType type, const char* key, void* out_value, size_t* length)
+static esp_err_t nvs_get_str_or_blob(nvs_handle_t handle, nvs::ItemType type, const char* key, void* out_value, size_t* length)
{
Lock lock;
ESP_LOGD(TAG, "%s %s", __func__, key);
return entry.mStoragePtr->readItem(entry.mNsIndex, type, key, out_value, dataSize);
}
-extern "C" esp_err_t nvs_get_str(nvs_handle handle, const char* key, char* out_value, size_t* length)
+extern "C" esp_err_t nvs_get_str(nvs_handle_t handle, const char* key, char* out_value, size_t* length)
{
return nvs_get_str_or_blob(handle, nvs::ItemType::SZ, key, out_value, length);
}
-extern "C" esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size_t* length)
+extern "C" esp_err_t nvs_get_blob(nvs_handle_t handle, const char* key, void* out_value, size_t* length)
{
return nvs_get_str_or_blob(handle, nvs::ItemType::BLOB, key, out_value, length);
}
return pStorage->fillStats(*nvs_stats);
}
-extern "C" esp_err_t nvs_get_used_entry_count(nvs_handle handle, size_t* used_entries)
+extern "C" esp_err_t nvs_get_used_entry_count(nvs_handle_t handle, size_t* used_entries)
{
Lock lock;
if(used_entries == NULL){
TEST_CASE("various nvs tests", "[nvs]")
{
- nvs_handle handle_1;
+ nvs_handle_t handle_1;
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGW(TAG, "nvs_flash_init failed (0x%x), erasing partition and retrying", err);
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x12345678));
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x23456789));
- nvs_handle handle_2;
+ nvs_handle_t handle_2;
TEST_ESP_OK(nvs_open("test_namespace3", NVS_READWRITE, &handle_2));
TEST_ESP_OK(nvs_erase_all(handle_2));
TEST_ESP_OK(nvs_set_i32(handle_2, "foo", 0x3456789a));
TEST_ASSERT_TRUE(stat1.total_entries == 0);
TEST_ASSERT_TRUE(stat1.used_entries == 0);
- nvs_handle handle = 0;
+ nvs_handle_t handle = 0;
size_t h_count_entries;
TEST_ESP_ERR(nvs_get_used_entry_count(handle, &h_count_entries), ESP_ERR_NVS_INVALID_HANDLE);
TEST_ASSERT_TRUE(h_count_entries == 0);
TEST_ASSERT_TRUE(stat1.used_entries == 0);
// create namespace test_k1
- nvs_handle handle_1;
+ nvs_handle_t handle_1;
TEST_ESP_OK(nvs_open("test_k1", NVS_READWRITE, &handle_1));
TEST_ESP_OK(nvs_get_stats(NULL, &stat2));
TEST_ASSERT_TRUE(stat2.free_entries + 1 == stat1.free_entries);
TEST_ESP_OK(nvs_get_used_entry_count(handle_1, &h1_count_entries));
TEST_ASSERT_TRUE(h1_count_entries == 2);
- nvs_handle handle_2;
+ nvs_handle_t handle_2;
// create namespace test_k2
TEST_ESP_OK(nvs_open("test_k2", NVS_READWRITE, &handle_2));
TEST_ESP_OK(nvs_get_stats(NULL, &stat2));
h2_count_entries = temp;
TEST_ESP_ERR(nvs_get_used_entry_count(handle_1, NULL), ESP_ERR_INVALID_ARG);
- nvs_handle handle_3;
+ nvs_handle_t handle_3;
// create namespace test_k3
TEST_ESP_OK(nvs_open("test_k3", NVS_READWRITE, &handle_3));
TEST_ESP_OK(nvs_get_stats(NULL, &stat2));
TEST_ESP_OK( err );
for (int i = 0; i < 500; ++i) {
- nvs_handle my_handle;
+ nvs_handle_t my_handle;
uint8_t key[20] = {0};
TEST_ESP_OK( nvs_open("test_namespace1", NVS_READWRITE, &my_handle) );
}
TEST_ESP_OK(nvs_flash_secure_init(&cfg));
- nvs_handle handle_1;
+ nvs_handle_t handle_1;
TEST_ESP_ERR(nvs_open("namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND);
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x12345678));
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x23456789));
- nvs_handle handle_2;
+ nvs_handle_t handle_2;
TEST_ESP_OK(nvs_open("namespace2", NVS_READWRITE, &handle_2));
TEST_ESP_OK(nvs_set_i32(handle_2, "foo", 0x3456789a));
const char* str = "value 0123456789abcdef0123456789abcdef";
TEST_IGNORE_MESSAGE("flash encryption disabled, skipping nvs_api tests with encryption enabled");
}
- nvs_handle handle;
+ nvs_handle_t handle;
nvs_sec_cfg_t xts_cfg;
extern const char nvs_key_start[] asm("_binary_encryption_keys_bin_start");
SpiFlashEmulator emu(10);
emu.randomize(100);
- nvs_handle handle_1;
+ nvs_handle_t handle_1;
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x12345678));
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x23456789));
- nvs_handle handle_2;
+ nvs_handle_t handle_2;
TEST_ESP_OK(nvs_open("namespace2", NVS_READWRITE, &handle_2));
TEST_ESP_OK(nvs_set_i32(handle_2, "foo", 0x3456789a));
const char* str = "value 0123456789abcdef0123456789abcdef";
emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
- nvs_handle misc_handle;
+ nvs_handle_t misc_handle;
TEST_ESP_OK(nvs_open("nvs.net80211", NVS_READWRITE, &misc_handle));
char log[33];
size_t log_size = sizeof(log);
strcpy(log, "foobarbazfizzz");
TEST_ESP_OK(nvs_set_str(misc_handle, "log", log));
- nvs_handle net80211_handle;
+ nvs_handle_t net80211_handle;
TEST_ESP_OK(nvs_open("nvs.net80211", NVS_READWRITE, &net80211_handle));
uint8_t opmode = 2;
SpiFlashEmulator emu(10);
emu.randomize(42);
- nvs_handle handle;
+ nvs_handle_t handle;
const uint32_t NVS_FLASH_SECTOR = 5;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
- nvs_handle handle_1;
+ nvs_handle_t handle_1;
TEST_ESP_ERR(nvs_open("namespace1", NVS_READONLY, &handle_1), ESP_ERR_NVS_NOT_FOUND);
TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle_1));
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x12345678));
for (size_t i = 0; i < 500; ++i) {
- nvs_handle handle_2;
+ nvs_handle_t handle_2;
TEST_ESP_OK(nvs_open("namespace2", NVS_READWRITE, &handle_2));
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x23456789 % (i + 1)));
TEST_ESP_OK(nvs_set_i32(handle_2, "foo", static_cast<int32_t>(i)));
}
template<typename TGen>
- esp_err_t doRandomThings(nvs_handle handle, TGen gen, size_t& count) {
+ esp_err_t doRandomThings(nvs_handle_t handle, TGen gen, size_t& count) {
const char* keys[] = {"foo", "bar", "longkey_0123456", "another key", "param1", "param2", "param3", "param4", "param5", "singlepage", "multipage"};
const ItemType types[] = {ItemType::I32, ItemType::I32, ItemType::U64, ItemType::U64, ItemType::SZ, ItemType::SZ, ItemType::SZ, ItemType::SZ, ItemType::SZ, ItemType::BLOB, ItemType::BLOB};
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle));
RandomTest test;
size_t count = 1000;
}
- nvs_handle handle;
+ nvs_handle_t handle;
size_t count = iter_count;
if (nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN) == ESP_OK) {
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
for (int i = 0; i < 100000; ++i) {
- nvs_handle light_handle = 0;
+ nvs_handle_t light_handle = 0;
char lightbulb[1024] = {12, 13, 14, 15, 16};
TEST_ESP_OK(nvs_open("light", NVS_READWRITE, &light_handle));
TEST_ESP_OK(nvs_set_blob(light_handle, "key", lightbulb, sizeof(lightbulb)));
nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3);
for (int attempts = 0; attempts < 3; ++attempts) {
int i = 0;
- nvs_handle light_handle = 0;
+ nvs_handle_t light_handle = 0;
char key[15] = {0};
char data[76] = {12, 13, 14, 15, 16};
uint8_t number = 20;
uint8_t blob[blob_size] = {0};
SpiFlashEmulator emu(5);
TEST_ESP_OK( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5) );
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK( nvs_open("test", NVS_READWRITE, &handle) );
// Fill first page
TEST_ESP_OK( nvs_set_blob(handle, "1a", blob, blob_size) );
SpiFlashEmulator emu(10);
TEST_ESP_OK( nvs_flash_init_custom("nvs1", 0, 5) );
TEST_ESP_OK( nvs_flash_init_custom("nvs2", 5, 5) );
- nvs_handle handle1, handle2;
+ nvs_handle_t handle1, handle2;
TEST_ESP_OK( nvs_open_from_partition("nvs1", "test", NVS_READWRITE, &handle1) );
TEST_ESP_OK( nvs_open_from_partition("nvs2", "test", NVS_READWRITE, &handle2) );
TEST_ESP_OK( nvs_set_i32(handle1, "foo", 0xdeadbeef));
uint8_t blob[blob_size] = {0};
SpiFlashEmulator emu(3);
TEST_ESP_OK( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3) );
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK( nvs_open("test", NVS_READWRITE, &handle) );
// Fill first page
TEST_ESP_OK( nvs_set_blob(handle, "1a", blob, blob_size/3) );
CHECK(stat1.total_entries == 0);
CHECK(stat1.used_entries == 0);
- nvs_handle handle = 0;
+ nvs_handle_t handle = 0;
size_t h_count_entries;
TEST_ESP_ERR(nvs_get_used_entry_count(handle, &h_count_entries), ESP_ERR_NVS_INVALID_HANDLE);
CHECK(h_count_entries == 0);
CHECK(stat1.used_entries == 0);
// create namespace test_k1
- nvs_handle handle_1;
+ nvs_handle_t handle_1;
TEST_ESP_OK(nvs_open("test_k1", NVS_READWRITE, &handle_1));
TEST_ESP_OK(nvs_get_stats(NULL, &stat2));
CHECK(stat2.free_entries + 1 == stat1.free_entries);
TEST_ESP_OK(nvs_get_used_entry_count(handle_1, &h1_count_entries));
CHECK(h1_count_entries == 2);
- nvs_handle handle_2;
+ nvs_handle_t handle_2;
// create namespace test_k2
TEST_ESP_OK(nvs_open("test_k2", NVS_READWRITE, &handle_2));
TEST_ESP_OK(nvs_get_stats(NULL, &stat2));
h2_count_entries = temp;
TEST_ESP_ERR(nvs_get_used_entry_count(handle_1, NULL), ESP_ERR_INVALID_ARG);
- nvs_handle handle_3;
+ nvs_handle_t handle_3;
// create namespace test_k3
TEST_ESP_OK(nvs_open("test_k3", NVS_READWRITE, &handle_3));
TEST_ESP_OK(nvs_get_stats(NULL, &stat2));
uint8_t blob[blob_size] = {0x11};
SpiFlashEmulator emu(3);
TEST_ESP_OK( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3) );
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK( nvs_open("test", NVS_READWRITE, &handle) );
emu.clearStats();
uint8_t blob[blob_size] = {0};
SpiFlashEmulator emu(3);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3));
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("test", NVS_READWRITE, &handle));
// Fill first page
TEST_ESP_OK(nvs_set_blob(handle, "1a", blob, blob_size/3));
uint8_t blob[blob_size] = {0};
SpiFlashEmulator emu(5);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5));
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("test", NVS_READWRITE, &handle));
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, blob_size));
TEST_ESP_OK(nvs_commit(handle));
uint8_t blob[blob_size] = {0};
SpiFlashEmulator emu(5);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5));
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("test", NVS_READWRITE, &handle));
TEST_ESP_ERR(nvs_set_blob(handle, "abc", blob, blob_size), ESP_ERR_NVS_VALUE_TOO_LONG);
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, Page::CHUNK_MAX_SIZE*2));
size_t read_size = blob_size;
SpiFlashEmulator emu(5);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5));
- nvs_handle handle;
+ nvs_handle_t handle;
memset(blob, 0x11, blob_size);
memset(blob_read, 0xee, blob_size);
TEST_ESP_OK(nvs_open("readTest", NVS_READWRITE, &handle));
size_t read_size = blob_size;
SpiFlashEmulator emu(6);
TEST_ESP_OK( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 6) );
- nvs_handle handle;
+ nvs_handle_t handle;
memset(blob, 0x11, blob_size);
memset(blob2, 0x22, blob_size);
memset(blob3, 0x33, blob_size);
size_t read_size = blob_size;
SpiFlashEmulator emu(5);
TEST_ESP_OK( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5) );
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("Test", NVS_READWRITE, &handle) );
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, Page::CHUNK_MAX_SIZE/2));
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, blob_size));
size_t read_size = blob_size;
SpiFlashEmulator emu(5);
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 5) );
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("Test", NVS_READWRITE, &handle) );
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, blob_size));
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, Page::CHUNK_MAX_SIZE/2));
CHECK(blob != NULL);
memset(blob, 0xEE, BLOB_SIZE);
const uint32_t magic = 0xff33eaeb;
- nvs_handle h;
+ nvs_handle_t h;
TEST_ESP_OK( nvs_open("blob_tests", NVS_READWRITE, &h) );
for (int i = 0; i < 128; i++) {
INFO("Iteration " << i << "...\n");
TEST_CASE("Check that NVS supports old blob format without blob index", "[nvs]")
{
SpiFlashEmulator emu("../nvs_partition_generator/part_old_blob_format.bin");
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK( nvs_flash_init_custom("test", 0, 2) );
TEST_ESP_OK( nvs_open_from_partition("test", "dummyNamespace", NVS_READONLY, &handle));
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle));
RandomTest test;
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3));
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle));
uint8_t hexdata[] = {0x01, 0x02, 0x03, 0xab, 0xcd, 0xef};
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3));
- nvs_handle handle;
+ nvs_handle_t handle;
TEST_ESP_OK(nvs_open("namespace1", NVS_READWRITE, &handle));
uint8_t hexdata[] = {0x01, 0x02, 0x03, 0xab, 0xcd, 0xef};
static void check_nvs_part_gen_args(char const *part_name, int size, char const *filename, bool is_encr, nvs_sec_cfg_t* xts_cfg)
{
- nvs_handle handle;
+ nvs_handle_t handle;
if (is_encr)
TEST_ESP_OK(nvs_flash_secure_init_custom(part_name, 0, size, xts_cfg));
SpiFlashEmulator emu(10);
emu.randomize(100);
- nvs_handle handle_1;
+ nvs_handle_t handle_1;
const uint32_t NVS_FLASH_SECTOR = 6;
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 3;
emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x12345678));
TEST_ESP_OK(nvs_set_i32(handle_1, "foo", 0x23456789));
- nvs_handle handle_2;
+ nvs_handle_t handle_2;
TEST_ESP_OK(nvs_open("namespace2", NVS_READWRITE, &handle_2));
TEST_ESP_OK(nvs_set_i32(handle_2, "foo", 0x3456789a));
const char* str = "value 0123456789abcdef0123456789abcdef";
*/
esp_err_t save_restart_counter(void)
{
- nvs_handle my_handle;
+ nvs_handle_t my_handle;
esp_err_t err;
// Open
*/
esp_err_t save_run_time(void)
{
- nvs_handle my_handle;
+ nvs_handle_t my_handle;
esp_err_t err;
// Open
*/
esp_err_t print_what_saved(void)
{
- nvs_handle my_handle;
+ nvs_handle_t my_handle;
esp_err_t err;
// Open
// Open
printf("\n");
printf("Opening Non-Volatile Storage (NVS) handle... ");
- nvs_handle my_handle;
+ nvs_handle_t my_handle;
err = nvs_open("storage", NVS_READWRITE, &my_handle);
if (err != ESP_OK) {
printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
return NVS_TYPE_ANY;
}
-static esp_err_t store_blob(nvs_handle nvs, const char *key, const char *str_values)
+static esp_err_t store_blob(nvs_handle_t nvs, const char *key, const char *str_values)
{
uint8_t value;
size_t str_len = strlen(str_values);
static esp_err_t set_value_in_nvs(const char *key, const char *str_type, const char *str_value)
{
esp_err_t err;
- nvs_handle nvs;
+ nvs_handle_t nvs;
bool range_error = false;
nvs_type_t type = str_to_type(str_type);
static esp_err_t get_value_from_nvs(const char *key, const char *str_type)
{
- nvs_handle nvs;
+ nvs_handle_t nvs;
esp_err_t err;
nvs_type_t type = str_to_type(str_type);
static esp_err_t erase(const char *key)
{
- nvs_handle nvs;
+ nvs_handle_t nvs;
esp_err_t err = nvs_open(current_namespace, NVS_READWRITE, &nvs);
if (err == ESP_OK) {
static esp_err_t erase_all(const char *name)
{
- nvs_handle nvs;
+ nvs_handle_t nvs;
esp_err_t err = nvs_open(current_namespace, NVS_READWRITE, &nvs);
if (err == ESP_OK) {
const char* count_key = "count";
ESP_ERROR_CHECK( nvs_flash_init() );
- nvs_handle handle;
+ nvs_handle_t handle;
ESP_ERROR_CHECK( nvs_open(namespace, NVS_READWRITE, &handle));
uint32_t pulse_count = 0;
esp_err_t err = nvs_get_u32(handle, count_key, &pulse_count);