Skip to content

[feat]增加cache预加载接口 #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions easyflash/inc/easyflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ 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);
EfErrCode ef_del_and_save_env(const char *key);
EfErrCode ef_prefetch_cache_env(void);
#endif

#ifdef EF_USING_IAP
Expand Down
45 changes: 45 additions & 0 deletions easyflash/src/ef_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,51 @@ EfErrCode ef_load_env(void)
return result;
}

#ifdef EF_ENV_USING_CACHE
static bool prefetch_cache_env_cb(env_node_obj_t env, void *arg1, void *arg2)
{
uint32_t *cache_count = arg1;

if (env->crc_is_ok && env->status == ENV_WRITE) {
update_env_cache(env->name, env->name_len, env->addr.start);
(*cache_count)++;

if (*cache_count >= EF_ENV_CACHE_TABLE_SIZE) {
return true;
}
}

return false;
}

/**
* Prefetch kv into cache.
*
* @return result
*/
EfErrCode ef_prefetch_cache_env(void)
{
EfErrCode result = EF_NO_ERR;
struct env_node_obj env;
uint32_t cache_count = 0;

if (!init_ok) {
EF_INFO("ENV isn't initialize OK.\r\n");
return EF_ENV_INIT_FAILED;
}

/* lock the ENV cache */
ef_port_env_lock();

env_iterator(&env, &cache_count, NULL, prefetch_cache_env_cb);

/* unlock the ENV cache */
ef_port_env_unlock();

return result;
}
#endif

/**
* Flash ENV initialize.
*
Expand Down