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 */