1. 增加Flash修改使用大小延迟计算Crc32

This commit is contained in:
coffee 2026-03-27 16:42:14 +08:00
parent a2c2ec8c83
commit 1a2afd46f6
4 changed files with 16 additions and 4 deletions

View File

@ -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数据的大小

View File

@ -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));
}

View File

@ -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);

View File

@ -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;