diff --git a/easyflash/inc/easyflash.h b/easyflash/inc/easyflash.h index ecce625..711859d 100644 --- a/easyflash/inc/easyflash.h +++ b/easyflash/inc/easyflash.h @@ -1,7 +1,7 @@ /* * This file is part of the EasyFlash Library. * - * Copyright (c) 2014-2018, Armink, + * Copyright (c) 2014-2019, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -39,24 +39,13 @@ extern "C" { #endif -#if defined(EF_USING_ENV) && (!defined(ENV_USER_SETTING_SIZE) || !defined(ENV_AREA_SIZE)) -#error "Please configure user setting ENV size or ENV area size (in ef_cfg.h)" -#endif - -#if defined(EF_USING_LOG) && !defined(LOG_AREA_SIZE) -#error "Please configure log area size (in ef_cfg.h)" -#endif - -#if !defined(EF_START_ADDR) -#error "Please configure backup area start address (in ef_cfg.h)" -#endif - -#if !defined(EF_ERASE_MIN_SIZE) -#error "Please configure minimum size of flash erasure (in ef_cfg.h)" -#endif /* EasyFlash debug print function. Must be implement by user. */ +#ifdef PRINT_DEBUG #define EF_DEBUG(...) ef_log_debug(__FILE__, __LINE__, __VA_ARGS__) +#else +#define EF_DEBUG(...) +#endif /* EasyFlash routine print function. Must be implement by user. */ #define EF_INFO(...) ef_log_info(__VA_ARGS__) /* EasyFlash assert for developer. */ @@ -108,12 +97,14 @@ typedef enum { EfErrCode easyflash_init(void); #ifdef EF_USING_ENV -/* ef_env.c ef_env_wl.c */ +/* only supported on ef_env.c */ +size_t ef_get_env_blob(const char *key, void *value_buf, size_t buf_len, size_t *value_len); +EfErrCode ef_set_env_blob(const char *key, const void *value_buf, size_t buf_len); + +/* ef_env.c, ef_env_legacy_wl.c and ef_env_legacy.c */ EfErrCode ef_load_env(void); void ef_print_env(void); -size_t ef_get_env_blob(const char *key, void *value_buf, size_t buf_len, size_t *value_len); char *ef_get_env(const char *key); -EfErrCode ef_set_env_blob(const char *key, const void *value_buf, size_t buf_len); EfErrCode ef_set_env(const char *key, const char *value); EfErrCode ef_del_env(const char *key); EfErrCode ef_save_env(void); diff --git a/easyflash/src/easyflash.c b/easyflash/src/easyflash.c index 05c0cf2..07b14ba 100644 --- a/easyflash/src/easyflash.c +++ b/easyflash/src/easyflash.c @@ -1,7 +1,7 @@ /* * This file is part of the EasyFlash Library. * - * Copyright (c) 2014-2016, Armink, + * Copyright (c) 2014-2019, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -26,13 +26,11 @@ * Created on: 2014-09-09 */ -/** +/* * * This all Backup Area Flash storage index. All used flash area configure is under here. * |----------------------------| Storage Size * | Environment variables area | ENV area size @see ENV_AREA_SIZE - * | 1.system section | ENV system section size - * | 2:data section | ENV_AREA_SIZE - ENV system section size * |----------------------------| * | Saved log area | Log area size @see LOG_AREA_SIZE * |----------------------------| @@ -40,23 +38,25 @@ * |----------------------------| * * @note all area sizes must be aligned with EF_ERASE_MIN_SIZE - * @note EasyFlash will use ram to buffer the ENV. At some point flash's EF_ERASE_MIN_SIZE may become too large, - * and if you want to use an smaller ENV size, you must define ENV_USER_SETTING_SIZE for ENV. - * @note ENV area size has some limitations in different modes. - * 1.Normal mode: no limitations - * 2.Wear leveling mode: system section will use an entire flash section and the data section will use at least 2 flash sections - * 3.Power fail safeguard mode: ENV area will keep a backup. It is twice the size of normal mode. - * 4.wear leveling and power fail safeguard mode: The required capacity will be 2 times the total capacity in wear leveling mode. - * For example: - * The EF_ERASE_MIN_SIZE is 128K and the ENV_USER_SETTING_SIZE: 2K. The ENV_AREA_SIZE you can define for the different modes are: - * 1.Normal mode: 1*EF_ERASE_MIN_SIZE - * 2.Wear leveling mode: 3*EF_ERASE_MIN_SIZE (It has 2 data section to store ENV. So ENV can erase at least 200,000 times) - * 3.Power fail safeguard mode: 2*EF_ERASE_MIN_SIZE - * 4.Wear leveling and power fail safeguard mode: 6*EF_ERASE_MIN_SIZE - * @note the log area size must be more than twice of EF_ERASE_MIN_SIZE + * + * The EasyFlash add the NG (Next Generation) mode start from V4.0. All old mode before V4.0, called LEGACY mode. + * + * - NG (Next Generation) mode is default mode from V4.0. It's easy to settings, only defined the ENV_AREA_SIZE. + * - The LEGACY mode has been DEPRECATED. It is NOT RECOMMENDED to continue using. + * Beacuse it will use ram to buffer the ENV and spend more flash erase times. + * If you want use it please using the V3.X version. */ + #include +#if !defined(EF_START_ADDR) +#error "Please configure backup area start address (in ef_cfg.h)" +#endif + +#if !defined(EF_ERASE_MIN_SIZE) +#error "Please configure minimum size of flash erasure (in ef_cfg.h)" +#endif + /** * EasyFlash system initialize. * diff --git a/easyflash/src/ef_env_legacy.c b/easyflash/src/ef_env_legacy.c index 499618c..c71a714 100644 --- a/easyflash/src/ef_env_legacy.c +++ b/easyflash/src/ef_env_legacy.c @@ -30,10 +30,14 @@ #include #include -#ifdef EF_USING_ENV +#if defined(EF_USING_ENV) && defined(EF_ENV_USING_LEGACY_MODE) #ifndef EF_ENV_USING_WL_MODE +#if defined(EF_USING_ENV) && (!defined(ENV_USER_SETTING_SIZE) || !defined(ENV_AREA_SIZE)) +#error "Please configure user setting ENV size or ENV area size (in ef_cfg.h)" +#endif + /** * ENV area has 2 sections * 1. System section @@ -915,4 +919,4 @@ static EfErrCode env_auto_update(void) #endif /* EF_ENV_USING_WL_MODE */ -#endif /* EF_USING_ENV */ +#endif /* defined(EF_USING_ENV) && defined(EF_ENV_USING_LEGACY_MODE) */ diff --git a/easyflash/src/ef_env_legacy_wl.c b/easyflash/src/ef_env_legacy_wl.c index a764012..1630890 100644 --- a/easyflash/src/ef_env_legacy_wl.c +++ b/easyflash/src/ef_env_legacy_wl.c @@ -30,10 +30,14 @@ #include #include -#ifdef EF_USING_ENV +#if defined(EF_USING_ENV) && defined(EF_ENV_USING_LEGACY_MODE) #ifdef EF_ENV_USING_WL_MODE +#if defined(EF_USING_ENV) && (!defined(ENV_USER_SETTING_SIZE) || !defined(ENV_AREA_SIZE)) +#error "Please configure user setting ENV size or ENV area size (in ef_cfg.h)" +#endif + /** * ENV area has 2 sections * 1. System section @@ -1075,4 +1079,4 @@ static EfErrCode env_auto_update(void) #endif /* EF_ENV_USING_WL_MODE */ -#endif /* EF_USING_ENV */ +#endif /* defined(EF_USING_ENV) && defined(EF_ENV_USING_LEGACY_MODE) */ diff --git a/easyflash/src/ef_log.c b/easyflash/src/ef_log.c index 781549e..e7747a3 100644 --- a/easyflash/src/ef_log.c +++ b/easyflash/src/ef_log.c @@ -30,6 +30,10 @@ #ifdef EF_USING_LOG +#if defined(EF_USING_LOG) && !defined(LOG_AREA_SIZE) +#error "Please configure log area size (in ef_cfg.h)" +#endif + /* magic code on every sector header. 'EF' is 0xEF30EF30 */ #define LOG_SECTOR_MAGIC 0xEF30EF30 /* sector header size, includes the sector magic code and status magic code */