diff --git a/include/HFlashServer.h b/include/HFlashServer.h index ac18dcc..bbe7a8e 100644 --- a/include/HFlashServer.h +++ b/include/HFlashServer.h @@ -369,9 +369,10 @@ uint32_t HFlashGetUseSize(HFlashAddr_t addr); * @brief HFlashSetUseSize 设置Flash数据的使用大小 * @param addr 需要注册的地址 * @param size 使用大小 + * @param delayCrc32 是否延迟计算CRC 1: 是 0: 否 * @return 1: 设置成功 0: 设置失败 */ -uint8_t HFlashSetUseSize(HFlashAddr_t addr, uint32_t size); +uint8_t HFlashSetUseSize(HFlashAddr_t addr, uint32_t size, uint8_t delayCrc32); /** * @brief HFlashGetSize 获取Flash数据的大小 diff --git a/src/HFlashMem.c b/src/HFlashMem.c index 8a75fe8..0b36036 100644 --- a/src/HFlashMem.c +++ b/src/HFlashMem.c @@ -59,6 +59,13 @@ static HTimer_t sCheckTimer = HTIMER_INVALID; static void WatiErase(); static void CheckSyncCache(); +static void ResetCacheState() +{ + if (sOpts && sOpts->cache && sOpts->cacheSize) { + memset(sOpts->cache, 0, sizeof(HFlashMemCache) * sOpts->cacheSize); + } +} + // 对齐页地址, 向下取整 static inline uint32_t Align4K(uint32_t addr) { return addr & ~(HFLASH_BLOCK_SIZE - 1); @@ -627,6 +634,8 @@ void HFlashMemInit(HFlashMemOpts *opts) HTimerRemove(sCheckTimer); sCheckTimer = HTIMER_INVALID; } + + ResetCacheState(); } const HFlashMemOpts *HFlashMemGetOpt() @@ -787,5 +796,6 @@ void HFlashMemFreeCache() HTimerRemove(sCheckTimer); sCheckTimer = HTIMER_INVALID; } + ResetCacheState(); memset(&sInfo, 0, sizeof(sInfo)); } diff --git a/src/HFlashServer.c b/src/HFlashServer.c index 9c81b3c..84dc63a 100644 --- a/src/HFlashServer.c +++ b/src/HFlashServer.c @@ -1898,7 +1898,7 @@ void HFlashDefaultUpdateVersion(HFlashAddr_t addr, uint16_t oldVersion, uint16_t void HFlashDeleteData(HFlashAddr_t addr) { - HFlashSetUseSize(addr, 0); + HFlashSetUseSize(addr, 0, 0); } uint32_t HFlashGetUseSize(HFlashAddr_t addr) @@ -1912,7 +1912,7 @@ uint32_t HFlashGetUseSize(HFlashAddr_t addr) return cache->info.useSize; } -uint8_t HFlashSetUseSize(HFlashAddr_t addr, uint32_t size) +uint8_t HFlashSetUseSize(HFlashAddr_t addr, uint32_t size, uint8_t delayCrc32) { HFlashCacheInfo *cache = FindCache(addr); if (cache == NULL) { @@ -1926,7 +1926,7 @@ uint8_t HFlashSetUseSize(HFlashAddr_t addr, uint32_t size) } cache->info.useSize = size; - cache->info.crc32 = GetFlashCrc32(addr, size); + cache->waitCrc = !!delayCrc32; WriteCachePage(cache); if (size) { AddBackupAddr(addr, size); diff --git a/src/HTimer.c b/src/HTimer.c index d0bc356..bc04684 100644 --- a/src/HTimer.c +++ b/src/HTimer.c @@ -120,6 +120,7 @@ uint8_t HTimerRegisterTimerInfo(uint8_t id, HTimerInfo *info, uint16_t infoLen) return 0; } + memset(info, 0, infoLen); sTimeRegisters[id].timers = info; sTimeRegisters[id].len = infoLen; sTimeRegisters[id].enable = 1;