From 3208261f9729c8ffd1699cadbd84b62f026b81e7 Mon Sep 17 00:00:00 2001 From: kerms Date: Sat, 6 Jul 2024 15:29:25 +0800 Subject: [PATCH] feat(wt_nvs) add set/get once, simpler to use when only call one time --- project_components/wt_storage/wt_nvs.c | 18 ++++++++++++++++++ project_components/wt_storage/wt_nvs.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/project_components/wt_storage/wt_nvs.c b/project_components/wt_storage/wt_nvs.c index 26fdc4b..4ec9974 100644 --- a/project_components/wt_storage/wt_nvs.c +++ b/project_components/wt_storage/wt_nvs.c @@ -95,3 +95,21 @@ int wt_nvs_get_once(const char* namespace, const uint32_t key, void *data, uint3 wt_nvs_close(handle); return 0; } + +int wt_nvs_set_once(const char* namespace, const uint32_t key, void *data, uint32_t data_size) +{ + nvs_handle_t handle; + int err; + err = wt_nvs_open(namespace, &handle); + if (err) { + return err; + } + + err = wt_nvs_set(handle, key, data, data_size); + if (err) { + return err; + } + + wt_nvs_close(handle); + return 0; +} diff --git a/project_components/wt_storage/wt_nvs.h b/project_components/wt_storage/wt_nvs.h index d8556a4..dff93f7 100644 --- a/project_components/wt_storage/wt_nvs.h +++ b/project_components/wt_storage/wt_nvs.h @@ -20,6 +20,9 @@ int wt_nvs_get(nvs_handle_t handle, uint32_t key, void *data, uint32_t data_size int wt_nvs_set(nvs_handle_t handle, uint32_t key, void *data, uint32_t data_size); +int wt_nvs_get_once(const char* namespace, const uint32_t key, void *data, uint32_t data_size); +int wt_nvs_set_once(const char* namespace, const uint32_t key, void *data, uint32_t data_size); + int wt_nvs_flush(nvs_handle_t handle); void wt_nvs_init();