From 1292ac8fc2c3430d72648ea7627ef2608c33ac31 Mon Sep 17 00:00:00 2001 From: coffee Date: Thu, 25 Dec 2025 19:28:57 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=88=A0=E9=99=A4=E5=BB=B6=E5=90=8E?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8,=20=E4=BD=BF=E7=94=A8=E7=AB=8B?= =?UTF-8?q?=E5=88=BB=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/HFlashMem.h | 2 +- include/HFlashServer.h | 5 +++++ src/HFlashMem.c | 2 +- src/HFlashServer.c | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/include/HFlashMem.h b/include/HFlashMem.h index b6edfaa..a824a3c 100644 --- a/include/HFlashMem.h +++ b/include/HFlashMem.h @@ -104,6 +104,6 @@ void HFlashMemSync(); /** * @brief 释放缓存页 */ -void HFlashFreeCache(); +void HFlashMemFreeCache(); #endif // __H_FLASH_MEM_H__ diff --git a/include/HFlashServer.h b/include/HFlashServer.h index 4defd24..05f50df 100644 --- a/include/HFlashServer.h +++ b/include/HFlashServer.h @@ -314,4 +314,9 @@ uint32_t HFlashCalcCrc32(HFlashAddr_t addr); */ void HFlashSync(); +/** + * @brief HFlashFreeCache 释放缓存 + */ +void HFlashFreeCache(); + #endif // __H_FLASH_SERVER_H__ diff --git a/src/HFlashMem.c b/src/HFlashMem.c index 1c05dfa..8d6b6ed 100644 --- a/src/HFlashMem.c +++ b/src/HFlashMem.c @@ -453,7 +453,7 @@ void HFlashMemSync() SyncCache(); } -void HFlashFreeCache() +void HFlashMemFreeCache() { HFlashMemSync(); sInfo.useNum = 0; diff --git a/src/HFlashServer.c b/src/HFlashServer.c index b2b6fb1..5f0963f 100644 --- a/src/HFlashServer.c +++ b/src/HFlashServer.c @@ -108,11 +108,13 @@ static union PageInfo sPageInfo; // 备份定时器 static HTimer_t sBackupTimer = HTIMER_INVALID; +#ifndef USE_FLASH_MEM // 同步页定时器 static HTimer_t sSyncPageTimer = HTIMER_INVALID; -// 同步定时器 +// 同步页表缓存定时器 static HTimer_t sSyncCacheTimer = HTIMER_INVALID; +#endif // 存储需要备份的保护区地址页偏移 static HVECTOR_DEFINE32(sNeedBackupOffset, 10); @@ -537,10 +539,12 @@ static uint8_t RestorePage(uint32_t index) static void SyncPageInfo() { +#ifndef USE_FLASH_MEM if (sSyncPageTimer != HTIMER_INVALID) { HTimerRemove(sSyncPageTimer); sSyncPageTimer = HTIMER_INVALID; } +#endif const uint32_t crcValue = GetFlashCrc32(AdjustPageAddr(sInfo.pageAddr), AdjustPageByte(sPageInfo.useNum)); if (crcValue == sPageInfo.crc32) { @@ -552,6 +556,7 @@ static void SyncPageInfo() StartSyncBackupTimer(); } +#ifndef USE_FLASH_MEM static void StartSyncPageInfo() { if (sSyncPageTimer != HTIMER_INVALID) { @@ -562,6 +567,7 @@ static void StartSyncPageInfo() sSyncPageTimer = HTimerAdd(HFLASH_TIMER_ID, HFLASH_SYNC_PAGE_INFO_TIME, SyncPageInfo, kHTimerOnce); StartSyncBackupTimer(); } +#endif static void ReadPage(uint32_t index, HFlashPageInfo *info) { @@ -583,16 +589,22 @@ static void WritePage(uint32_t index, HFlashPageInfo *info) const HFlashAddr_t addr = AdjustPageAddrOffset(sInfo.pageAddr, index); WriteFlash(addr, info, sizeof(HFlashPageInfo)); +#ifdef USE_FLASH_MEM + SyncPageInfo(); +#else StartSyncPageInfo(); +#endif } static void SyncCachePage() { +#ifndef USE_FLASH_MEM if (sSyncCacheTimer != HTIMER_INVALID) { HTimerRemove(sSyncCacheTimer); sSyncCacheTimer = HTIMER_INVALID; } +#endif for (uint32_t i = 0; i < sInfo.pageCacheUseNum; ++i) { // 更新Crc32 @@ -608,9 +620,14 @@ static void SyncCachePage() } } +#ifdef USE_FLASH_MEM + SyncPageInfo(); +#else StartSyncPageInfo(); +#endif } +#ifndef USE_FLASH_MEM static void StartSyncCachePage() { if (sSyncCacheTimer != HTIMER_INVALID) { @@ -621,12 +638,18 @@ static void StartSyncCachePage() sSyncCacheTimer = HTimerAdd(HFLASH_TIMER_ID, HFLASH_SYNC_CACHE_PAGE_TIME, SyncCachePage, kHTimerOnce); StartSyncPageInfo(); } +#endif static void WriteCachePage(HFlashCacheInfo *info) { ++info->info.modifyCount; info->waitWrite = 1; +#ifdef USE_FLASH_MEM + SyncCachePage(); + SyncPageInfo(); +#else StartSyncCachePage(); +#endif } /// 检查是否重叠, 重叠返回1, 非重叠返回0 @@ -1425,3 +1448,12 @@ void HFlashSync() HFlashMemSync(); #endif } + +void HFlashFreeCache() +{ + HFlashSync(); + sInfo.pageCacheUseNum = 0; +#ifdef USE_FLASH_MEM + HFlashMemFreeCache(); +#endif +}