From 486e953adbaf1b0f946749508469abe2151077ae Mon Sep 17 00:00:00 2001 From: armink Date: Wed, 29 Jul 2015 16:55:21 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E5=90=8E?= =?UTF-8?q?=E7=AB=8B=E5=88=BB=E4=BF=9D=E5=AD=98=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E7=AE=80=E5=8C=96=E7=94=A8=E6=88=B7=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- docs/zh/api.md | 13 +++++++++++++ easyflash/inc/easyflash.h | 1 + easyflash/src/ef_env.c | 20 ++++++++++++++++++++ easyflash/src/ef_env_wl.c | 20 ++++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/docs/zh/api.md b/docs/zh/api.md index 65a8415..ef8dcd1 100644 --- a/docs/zh/api.md +++ b/docs/zh/api.md @@ -90,6 +90,19 @@ EfErrCode ef_env_set_default(void) size_t ef_get_env_write_bytes(void) ``` +#### 1.2.8 设置后保存环境变量 + +设置环境变量成功后立刻保存。设置功能参考`ef_set_env`方法。 + +```C +EfErrCode ef_set_and_save_env(const char *key, const char *value) +``` + +|参数 |描述| +|:----- |:----| +|key |环境变量名称| +|value |环境变量值| + ### 1.3 在线升级 #### 1.3.1 擦除备份区中的应用程序 diff --git a/easyflash/inc/easyflash.h b/easyflash/inc/easyflash.h index 47913fc..cc7f374 100644 --- a/easyflash/inc/easyflash.h +++ b/easyflash/inc/easyflash.h @@ -103,6 +103,7 @@ EfErrCode ef_set_env(const char *key, const char *value); EfErrCode ef_save_env(void); EfErrCode ef_env_set_default(void); size_t ef_get_env_write_bytes(void); +EfErrCode ef_set_and_save_env(const char *key, const char *value); #endif #ifdef EF_USING_IAP diff --git a/easyflash/src/ef_env.c b/easyflash/src/ef_env.c index e6708ee..02678c5 100644 --- a/easyflash/src/ef_env.c +++ b/easyflash/src/ef_env.c @@ -734,6 +734,26 @@ static bool env_crc_is_ok(void) { } } +/** + * Set and save an ENV. If set ENV is success then will save it. + * + * @param key ENV name + * @param value ENV value + * + * @return result + */ +EfErrCode ef_set_and_save_env(const char *key, const char *value) { + EfErrCode result = EF_NO_ERR; + + result = ef_set_env(key, value); + + if (result == EF_NO_ERR) { + result = ef_save_env(); + } + + return result; +} + #endif /* EF_ENV_USING_WL_MODE */ #endif /* EF_USING_ENV */ diff --git a/easyflash/src/ef_env_wl.c b/easyflash/src/ef_env_wl.c index a57c846..eb51800 100644 --- a/easyflash/src/ef_env_wl.c +++ b/easyflash/src/ef_env_wl.c @@ -901,6 +901,26 @@ static EfErrCode save_cur_using_data_addr(uint32_t cur_data_addr) { } #endif +/** + * Set and save an ENV. If set ENV is success then will save it. + * + * @param key ENV name + * @param value ENV value + * + * @return result + */ +EfErrCode ef_set_and_save_env(const char *key, const char *value) { + EfErrCode result = EF_NO_ERR; + + result = ef_set_env(key, value); + + if (result == EF_NO_ERR) { + result = ef_save_env(); + } + + return result; +} + #endif /* EF_ENV_USING_WL_MODE */ #endif /* EF_USING_ENV */