mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-04 02:50:58 +02:00
nvs: make nvs_flash_deinit useable from unit tests
This commit is contained in:
@@ -133,6 +133,23 @@ extern "C" esp_err_t nvs_flash_init(void)
|
|||||||
return nvs_flash_init_partition(NVS_DEFAULT_PART_NAME);
|
return nvs_flash_init_partition(NVS_DEFAULT_PART_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t nvs_flash_erase_partition(const char *part_name)
|
||||||
|
{
|
||||||
|
const esp_partition_t* partition = esp_partition_find_first(
|
||||||
|
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
|
||||||
|
if (partition == NULL) {
|
||||||
|
return ESP_ERR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
return esp_partition_erase_range(partition, 0, partition->size);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" esp_err_t nvs_flash_erase()
|
||||||
|
{
|
||||||
|
return nvs_flash_erase_partition(NVS_DEFAULT_PART_NAME);
|
||||||
|
}
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
|
|
||||||
extern "C" esp_err_t nvs_flash_deinit_partition(const char* partition_name)
|
extern "C" esp_err_t nvs_flash_deinit_partition(const char* partition_name)
|
||||||
{
|
{
|
||||||
Lock::init();
|
Lock::init();
|
||||||
@@ -169,23 +186,6 @@ extern "C" esp_err_t nvs_flash_deinit(void)
|
|||||||
return nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME);
|
return nvs_flash_deinit_partition(NVS_DEFAULT_PART_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" esp_err_t nvs_flash_erase_partition(const char *part_name)
|
|
||||||
{
|
|
||||||
const esp_partition_t* partition = esp_partition_find_first(
|
|
||||||
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, part_name);
|
|
||||||
if (partition == NULL) {
|
|
||||||
return ESP_ERR_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
return esp_partition_erase_range(partition, 0, partition->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" esp_err_t nvs_flash_erase()
|
|
||||||
{
|
|
||||||
return nvs_flash_erase_partition(NVS_DEFAULT_PART_NAME);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static esp_err_t nvs_find_ns_handle(nvs_handle handle, HandleEntry& entry)
|
static esp_err_t nvs_find_ns_handle(nvs_handle handle, HandleEntry& entry)
|
||||||
{
|
{
|
||||||
auto it = find_if(begin(s_nvs_handles), end(s_nvs_handles), [=](HandleEntry& e) -> bool {
|
auto it = find_if(begin(s_nvs_handles), end(s_nvs_handles), [=](HandleEntry& e) -> bool {
|
||||||
@@ -473,11 +473,11 @@ extern "C" esp_err_t nvs_get_stats(const char* part_name, nvs_stats_t* nvs_stats
|
|||||||
|
|
||||||
pStorage = lookup_storage_from_name((part_name == NULL) ? NVS_DEFAULT_PART_NAME : part_name);
|
pStorage = lookup_storage_from_name((part_name == NULL) ? NVS_DEFAULT_PART_NAME : part_name);
|
||||||
if (pStorage == NULL) {
|
if (pStorage == NULL) {
|
||||||
return ESP_ERR_NVS_PART_NOT_FOUND;
|
return ESP_ERR_NVS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!pStorage->isValid()){
|
if(!pStorage->isValid()){
|
||||||
return ESP_ERR_NVS_NOT_INITIALIZED;
|
return ESP_ERR_NVS_INVALID_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pStorage->fillStats(*nvs_stats);
|
return pStorage->fillStats(*nvs_stats);
|
||||||
|
Reference in New Issue
Block a user