nvs: allow nvs_flash_init to be called more than once

Also don’t assert in nvs_* functions if nvs_flash_init wasn’t called,
and make nvs_flash_init_custom an internal API for unit tests.
This commit is contained in:
Ivan Grokhotkov
2016-11-15 18:24:56 +08:00
parent 51021b06f8
commit 6e97936bac
7 changed files with 73 additions and 23 deletions
+12 -9
View File
@@ -16,9 +16,6 @@
#ifdef ESP_PLATFORM
#define NVS_DEBUGV(...) ets_printf(__VA_ARGS__)
#include "rom/ets_sys.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
@@ -30,19 +27,23 @@ class Lock
public:
Lock()
{
assert(mSemaphore);
xSemaphoreTake(mSemaphore, portMAX_DELAY);
if (mSemaphore) {
xSemaphoreTake(mSemaphore, portMAX_DELAY);
}
}
~Lock()
{
assert(mSemaphore);
xSemaphoreGive(mSemaphore);
if (mSemaphore) {
xSemaphoreGive(mSemaphore);
}
}
static esp_err_t init()
{
assert(mSemaphore == nullptr);
if (mSemaphore) {
return ESP_OK;
}
mSemaphore = xSemaphoreCreateMutex();
if (!mSemaphore) {
return ESP_ERR_NO_MEM;
@@ -52,7 +53,9 @@ public:
static void uninit()
{
vSemaphoreDelete(mSemaphore);
if (mSemaphore) {
vSemaphoreDelete(mSemaphore);
}
mSemaphore = nullptr;
}