From 47fe7c90eec2e5db82fe6d5f57baab912d90cc7d Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Wed, 6 Sep 2023 09:51:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20checkFlash=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=9C=A8=E5=BC=80=E5=A7=8B=E6=97=B6=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=20=E6=9B=B4=E6=96=B0=20checkManualWindow=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20=E4=BF=AE=E5=A4=8D=20SYS=5FCFG=20=E4=B8=AD=20isMaWi?= =?UTF-8?q?n=20=E7=9A=84=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cfg.c 中文件锁采用mutex --- applications/cfg/cfg.c | 21 ++++++++++++--------- applications/core.c | 9 +++++---- applications/func/func.c | 7 +++---- applications/usrcfg.h | 2 +- applications/w25q.c | 10 +++++++--- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/applications/cfg/cfg.c b/applications/cfg/cfg.c index c550f0d..5321ec2 100644 --- a/applications/cfg/cfg.c +++ b/applications/cfg/cfg.c @@ -27,14 +27,15 @@ static rt_mutex_t isCfgOk=RT_NULL; static rt_mutex_t isTosendOk=RT_NULL; void initCfgMutex() { - isCfgOk = rt_mutex_create("cfg", RT_IPC_FLAG_FIFO); - isTosendOk = rt_mutex_create("tosend", RT_IPC_FLAG_FIFO); + isCfgOk = rt_mutex_create("isCfgOk", RT_IPC_FLAG_FIFO); + isTosendOk = rt_mutex_create("isTosendOk", RT_IPC_FLAG_FIFO); } INIT_APP_EXPORT(initCfgMutex); static void setLock() { -// rt_mutex_take(isCfgOk, RT_WAITING_FOREVER); + rt_mutex_take(isCfgOk, RT_WAITING_FOREVER); +// LOG_W("------file locked------"); return; while(islock) { @@ -45,9 +46,9 @@ static void setLock() } static void clearLock() { + rt_mutex_release(isCfgOk); +// LOG_W("=====file unlocked====="); return; -// rt_mutex_release(isCfgOk); -// return; islock=0; LOG_W("------file unlocked"); } @@ -308,8 +309,9 @@ MSH_CMD_EXPORT_ALIAS(clear_sta,clsSta, 重置系统统计数据) volatile size_t nislock=0; static void nsetLock() { -// rt_mutex_take(isTosendOk, RT_WAITING_FOREVER); -// return; + rt_mutex_take(isTosendOk, RT_WAITING_FOREVER); + LOG_W("------file locked------"); + return; // LOG_D("--%d--",nislock); size_t cnt=10; while(nislock) @@ -325,8 +327,9 @@ static void nsetLock() } static void nclearLock() { -// rt_mutex_release(isTosendOk); -// return; + rt_mutex_release(isTosendOk); + LOG_W("=====file unlocked====="); + return; nislock=0; LOG_W("file is unlocked."); } diff --git a/applications/core.c b/applications/core.c index d50483e..b42b25b 100644 --- a/applications/core.c +++ b/applications/core.c @@ -165,7 +165,7 @@ void initFiles() } } - checkFlash(); +// checkFlash(); } /** @@ -182,8 +182,9 @@ static void initCfg(void) scfg.timeout = get_cfg("timeout"); scfg.maxSizePerFile = get_cfg("maxSizePerFile"); scfg.locRepInterval = get_cfg("locRepInterval"); + scfg.isMaWin = get_cfg("isMaWin"); - char str[256]; + char str[sizeof(scfg.openWindowTime)*4]; get_cfgs("openWindowTime", str); size_t len = str2Byte(str, 3, 10, scfg.openWindowTime); // LOG_HEX("win",16,scfg.openWindowTime,len); @@ -196,8 +197,8 @@ static void updatecfg(void) //等待更新 while(1) { - rt_thread_mdelay(10*1000);//10s写入一次数据到文件 - if(rt_sem_take(cfgUpdate, RT_WAITING_NO) == RT_EOK) +// rt_thread_mdelay(10*1000);//10s写入一次数据到文件 + if(rt_sem_take(cfgUpdate, RT_WAITING_FOREVER) == RT_EOK) { updateAllSysCfg(&scfg, 0); } diff --git a/applications/func/func.c b/applications/func/func.c index 1122231..954d346 100644 --- a/applications/func/func.c +++ b/applications/func/func.c @@ -413,8 +413,7 @@ int isManualWindow(void) } void checkManualWindow(void) { - int rst = get_cfg("isMaWin"); - scfg.isMaWin = rst; + int rst = scfg.isMaWin; if (rst < 0) {//none return; } @@ -425,7 +424,7 @@ void checkManualWindow(void) //设置定时器,定时器到则关窗 /* 创建定时器,单次定时器 */ rt_timer_t timer1; - timer1 = rt_timer_create("window", closeWindow, + timer1 = rt_timer_create("manualModeWindow", closeWindow, RT_NULL, rt_tick_from_millisecond(rst*60*1000), RT_TIMER_FLAG_ONE_SHOT); /* 启动定时器 */ @@ -596,7 +595,7 @@ void updateAllSysCfg(uint8_t *cfg, size_t len) rst &= set_cfg("minTTsinal",scfg.minTTsinal); rst &= set_cfg("timeout",scfg.timeout); - char tmpstr[sizeof(scfg.commMode)*4]; + char tmpstr[sizeof(scfg.openWindowTime)*4]; bytes2str(scfg.openWindowTime, 8, 10, ",", tmpstr); rst &= set_cfgs("openWindowTime",tmpstr); diff --git a/applications/usrcfg.h b/applications/usrcfg.h index 312fcaf..530be2e 100644 --- a/applications/usrcfg.h +++ b/applications/usrcfg.h @@ -56,7 +56,7 @@ typedef struct uint8_t selfDesSW; uint8_t locAlert; uint8_t locRepInterval; - uint8_t isMaWin; + int8_t isMaWin; } SYS_CFG; diff --git a/applications/w25q.c b/applications/w25q.c index 3fbc627..49164ce 100644 --- a/applications/w25q.c +++ b/applications/w25q.c @@ -81,10 +81,14 @@ void sdmnt_init(void) } /* 导出到自动初始化 */ INIT_COMPONENT_EXPORT(sdmnt_init); + +/** + * 判断flash是否损坏 + */ void checkFlash() { - //判断flash是否损坏 - if (getFileSize("cfg.ini")==0 && getFileSize("map.geojson")==0) + //间接判断。文件存在但大小为零则认为flash已损坏 + if (isFileExit("cfg.ini") && getFileSize("cfg.ini")==0 && isFileExit("map.geojson") && getFileSize("map.geojson")==0) { LOG_E("the flash is damaged, try formatting to fix."); dfs_mkfs("elm", "W25Q128"); @@ -92,7 +96,7 @@ void checkFlash() } } /* 导出到自动初始化 */ -//INIT_COMPONENT_EXPORT(checkFlash); +INIT_COMPONENT_EXPORT(checkFlash); void bootinfo() {