解决执行deInitTT()时重启的问题

更新cfg部分函数
更新rt_hw_stm32_eth_deinit()函数,解决内存泄露的问题
This commit is contained in:
CSSC-WORK\murmur 2023-08-04 14:09:39 +08:00
parent 685e260d23
commit 196e0b23d6
6 changed files with 60 additions and 46 deletions

View File

@ -82,8 +82,10 @@ void sysSemInit()
// TTReady = rt_sem_create("TTisReady", 0, RT_IPC_FLAG_PRIO); // TTReady = rt_sem_create("TTisReady", 0, RT_IPC_FLAG_PRIO);
cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_PRIO); cfgUpdate = rt_sem_create("cfgUpdate", 0, RT_IPC_FLAG_PRIO);
shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_PRIO); shuntDownTT = rt_sem_create("shuntDNTT", 0, RT_IPC_FLAG_PRIO);
rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);
rt_sem_release(cfgUpdate); //上电更新值 rt_sem_release(cfgUpdate); //上电更新值
updatecfg(); updatecfg();
// LOG_D("sysSemInit DONE."); // LOG_D("sysSemInit DONE.");
} }
@ -95,7 +97,7 @@ void sysSemInit()
static void sysEventInit(void) void sysEventInit(void)
{ {
rt_err_t result = rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO); rt_err_t result = rt_event_init(&chkSta, "chkSta", RT_IPC_FLAG_PRIO);
@ -108,21 +110,24 @@ static void sysEventInit(void)
void sysInit(void) void sysInit(void)
{ {
sysSemInit(); sysSemInit();
sysEventInit(); // sysEventInit();
} }
//INIT_COMPONENT_EXPORT(sysInit); //INIT_COMPONENT_EXPORT(sysInit);
void timerIsReady(void) void timerIsReady(void)
{ {
rt_event_send(&sysInit, TIMER_IS_OUT); rt_event_send(&chkSta, TIMER_IS_OUT);
stopTM();
} }
void fileIsReady(void) void fileIsReady(void)
{ {
rt_event_send(&sysInit, FILE_IS_OK); rt_event_send(&chkSta, FILE_IS_OK);
stopTM();
} }
void TTIsReady(void) void TTIsReady(void)
{ {
rt_event_send(&sysInit, TT_IS_OK); rt_event_send(&chkSta, TT_IS_OK);
stopTM();
} }
void d_upSta() void d_upSta()
{ {
@ -185,7 +190,7 @@ void upSendFile(const char *f, int index)
info.index = index; info.index = index;
/* 创建 serial 线程 */ /* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("upSendFile", upSendFile_thread_entry, (void *) &info, 1024 * 12, 27, 10); rt_thread_t thread = rt_thread_create("upSendFile", upSendFile_thread_entry, (void *) &info, 1024 * 5, 27, 10);
/* 创建成功则启动线程 */ /* 创建成功则启动线程 */
if (thread != RT_NULL) if (thread != RT_NULL)
{ {
@ -225,13 +230,12 @@ void getAndSendFile()
static void chkAndSendFile_thread_entry() static void chkAndSendFile_thread_entry()
{ {
while (1) while (1 && isTTon())
{ {
// int e; // int e;
LOG_I("等待文件就绪(或定时%d分钟超时",scfg.sendInterval); LOG_I("等待文件就绪(或定时%d分钟超时",scfg.sendInterval);
int rst = rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, if (rt_event_recv(&chkSta, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
RT_WAITING_FOREVER, RT_NULL); RT_WAITING_FOREVER, RT_NULL) == RT_EOK) //条件1满足
if (rst == RT_EOK) //条件1满足
{ {
LOG_I("等待TT就绪"); LOG_I("等待TT就绪");
} }
@ -239,7 +243,7 @@ static void chkAndSendFile_thread_entry()
for (size_t var = 0; var < scfg.maxTTRetryCnt; var++) //轮询尝试 for (size_t var = 0; var < scfg.maxTTRetryCnt; var++) //轮询尝试
{ {
LOG_I("第%d/%d次尝试。", var + 1,scfg.maxTTRetryCnt); LOG_I("第%d/%d次尝试。", var + 1,scfg.maxTTRetryCnt);
rst = rt_event_recv(&chkSta, TT_IS_OK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(scfg.maxTTWaitTime*60*1000), int rst = rt_event_recv(&chkSta, TT_IS_OK, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(scfg.maxTTWaitTime*60*1000),
RT_NULL); RT_NULL);
// rst = rt_sem_take(TTReady, rt_tick_from_millisecond(maxTTWaitTime * 60 * 1000)); // rst = rt_sem_take(TTReady, rt_tick_from_millisecond(maxTTWaitTime * 60 * 1000));
if (rst == RT_EOK) //条件2满足 if (rst == RT_EOK) //条件2满足
@ -257,6 +261,7 @@ static void chkAndSendFile_thread_entry()
// continue; // continue;
} }
} }
LOG_E("TT失败");
//continue; //continue;
//发送数据 //发送数据
@ -322,7 +327,7 @@ void resetTM()
rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_SET_TIME,(void*) &t); rt_timer_control(tmrToPNTT, RT_TIMER_CTRL_SET_TIME,(void*) &t);
rt_timer_stop(tmrToPNTT); rt_timer_stop(tmrToPNTT);
rt_timer_start(tmrToPNTT); rt_timer_start(tmrToPNTT);
// LOG_D("timer reseted."); LOG_D("%d minutes from now to power down TT.",scfg.timeout);
} }
void d_getRemain() void d_getRemain()
{ {
@ -336,19 +341,10 @@ void d_getRemain()
/* 定时器超时函数 */ /* 定时器超时函数 */
static void timeoutFunc(void *parameter) static void timeoutFunc(void *parameter)
{ {
// rt_kprintf("periodic timer is timeout %d\n", cnt); LOG_W("time to shunt down TT");
// rt_thread_mdelay(3000);// no delay
// rt_timer_stop(timer1);
LOG_W("3s to shunt down TT");
rt_thread_mdelay(1000);
LOG_W("2s to shunt down TT");
rt_thread_mdelay(1000);
LOG_W("1s to shunt down TT");
rt_thread_mdelay(1000);
deInitTT();//Function[rt_mutex_take] shall not be used in ISR deInitTT();//Function[rt_mutex_take] shall not be used in ISR
// rt_sem_release(shuntDownTT); // list_thread();
// toPN =1;
} }
//RT_TICK_PER_SECOND //RT_TICK_PER_SECOND
@ -358,17 +354,18 @@ void initTT_thread_entry()
{ {
pwTT_thread_entry("1"); pwTT_thread_entry("1");
while (1) while (1 && isTTon())
{ {
if (!isTTon()) {
break;
}
if (!tmrToPNTT) { if (!tmrToPNTT) {
tmrToPNTT = rt_timer_create("TTtimeout", timeoutFunc, tmrToPNTT = rt_timer_create("TTtimeout", timeoutFunc,
RT_NULL, rt_tick_from_millisecond(scfg.timeout*60*1000), RT_NULL, rt_tick_from_millisecond(scfg.timeout*60*1000),
RT_TIMER_FLAG_ONE_SHOT);//|RT_TIMER_FLAG_SOFT_TIMER); RT_TIMER_FLAG_ONE_SHOT);//|RT_TIMER_FLAG_SOFT_TIMER);
// rt_timer_start(tmrToPNTT);
}
if (!isTTon()) {
break;
} }
if (!isEthUP()) if (!isEthUP())
{ //只初始化一次 { //只初始化一次
LOG_D("init eth..."); LOG_D("init eth...");
@ -387,6 +384,7 @@ void initTT_thread_entry()
LOG_D("TCP is ready."); LOG_D("TCP is ready.");
tcpRecMQ(); //开启tcp接收线程 tcpRecMQ(); //开启tcp接收线程
recTT(); recTT();
chkAndSendFile();
} }
} }
@ -397,23 +395,19 @@ void initTT_thread_entry()
void deInitTT_thread_entry() void deInitTT_thread_entry()
{ {
if (rt_sem_take(shuntDownTT, RT_WAITING_FOREVER) == RT_EOK) if (rt_sem_take(shuntDownTT, RT_WAITING_FOREVER) == RT_EOK)
// if (toPN)
{ {
pwTT_thread_entry("0"); tcpClose();
rt_hw_stm32_eth_deinit(); //qu激活网口 rt_hw_stm32_eth_deinit(); //qu激活网口
if (tmrToPNTT)
pwTT_thread_entry("0");
if (0&& tmrToPNTT)
{ {
rt_timer_delete(tmrToPNTT); //关闭倒计时 rt_timer_delete(tmrToPNTT); //关闭倒计时
tmrToPNTT = RT_NULL; tmrToPNTT = RT_NULL;
} }
tcpClose();
LOG_W("shunt down TT DONE"); LOG_W("shunt down TT DONE");
// break;
} }
// rt_thread_mdelay(1000);
// }
} }
//INIT_APP_EXPORT(deInitTT_thread_entry); //INIT_APP_EXPORT(deInitTT_thread_entry);
@ -473,6 +467,7 @@ void deInitTT()
#define FUNC_DEMO #define FUNC_DEMO
#ifdef FUNC_DEMO //测试时导出命令到控制台 #ifdef FUNC_DEMO //测试时导出命令到控制台
MSH_CMD_EXPORT(d_upSta,FILE_IS_OK); MSH_CMD_EXPORT(d_upSta,FILE_IS_OK);
MSH_CMD_EXPORT(fileIsReady,fileIsReady);
MSH_CMD_EXPORT(chkAndSendFile, chkAndSendFile); MSH_CMD_EXPORT(chkAndSendFile, chkAndSendFile);
MSH_CMD_EXPORT(upSendFile, upSendFile); MSH_CMD_EXPORT(upSendFile, upSendFile);
MSH_CMD_EXPORT(initTT,TT); MSH_CMD_EXPORT(initTT,TT);

View File

@ -35,13 +35,14 @@ static void clearLock()
islock=0; islock=0;
} }
extern rt_sem_t cfgUpdate; extern rt_sem_t cfgUpdate;
int get_cfg(const char *k);
static struct rt_messagequeue upfilelist; static struct rt_messagequeue upfilelist;
typedef struct typedef struct
{ {
char fname[60]; char fname[60];
uint8_t index; uint8_t index;
}FILE_INFO; }FILE_INFO;
static uint8_t msg_pool[512] ; static uint8_t msg_pool[512] ;
void addToList_thread_entry(void *parameter); void addToList_thread_entry(void *parameter);
static void iniUFMsg(void) static void iniUFMsg(void)
@ -79,12 +80,19 @@ INIT_APP_EXPORT(iniUFMsg);
*/ */
int set_cfg(const char *k, long v) int set_cfg(const char *k, long v)
{ {
setLock(); // setLock();
if (rt_strcmp(v,"NULL") == 0) {//delete key if (rt_strcmp(v,"NULL") == 0) {//delete key
v = NULL; v = NULL;
} }
// clearLock();
if (v == get_cfg(k)) {
LOG_D("nothing needs to change.");
clearLock();
return 1;
}
setLock();
// int rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME); // int rst = ini_puts("config",k,v,LJW_CFG_FILE_NAME);
int rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME); int rst = ini_putl("config", k, v, LJW_CFG_FILE_NAME);
if (rst == 1) { if (rst == 1) {
@ -128,7 +136,11 @@ int set_cfgs(const char *k, const char * v)
clearLock(); clearLock();
return rst; return rst;
} }
/**
*
* @param k
* @return
*/
int get_cfg(const char *k) int get_cfg(const char *k)
{ {
setLock(); setLock();
@ -196,7 +208,7 @@ static void cfg(int argc, char ** argv)
get_cfg(argv[1]); get_cfg(argv[1]);
} }
if (argc == 3) {//有键有值,设置 if (argc == 3) {//有键有值,设置
set_cfg(argv[1], argv[2]); set_cfgs(argv[1], argv[2]);
} }
} }

View File

@ -411,7 +411,7 @@ static int cryptLocMsg(uint8_t *din, size_t len, uint8_t *dout);
int reportDepth(uint8_t *din,size_t len) int reportDepth(uint8_t *din,size_t len)
{ {
// 000000000000000000005AA53E320608000A170407101B33FFFFFFFF24ED // 000000000000000000005AA53E320608000A170407101B33FFFFFFFF24ED
LOG_I("FUNC = reportDepth");
//获取并更新位置信息 //获取并更新位置信息
uint8_t dout[200]; uint8_t dout[200];
memset(dout,0,200); memset(dout,0,200);
@ -501,10 +501,10 @@ void reportSysCfg()
rst[++p] = 0xED; rst[++p] = 0xED;
size = p+1; size = p+1;
// upSend(rst, size); upSend(rst, size);
// LOG_HEX("scfg",16,&scfg,size); // LOG_HEX("scfg",16,&scfg,size);
LOG_HEX("cfg",16,rst,p+1); // LOG_HEX("cfg",16,rst,p+1);
// updateSysCfg(rst+8, rst[7]); // updateSysCfg(rst+8, rst[7]);
} }
@ -825,6 +825,7 @@ void ttRunCMD(uint8_t *din, size_t len)
RT_WEAK int formatAndSendTo3S(uint8_t * din, size_t len) RT_WEAK int formatAndSendTo3S(uint8_t * din, size_t len)
{ {
// LOG_D("直接调用小彭的函数进行处理。"); // LOG_D("直接调用小彭的函数进行处理。");
LOG_I("FUNC = forward to 3S");
char str[200] = "RCV:"; char str[200] = "RCV:";
int cmd = (din[4] << 8) + din[5]; int cmd = (din[4] << 8) + din[5];
@ -922,6 +923,7 @@ void parse3SData(uint8_t *din, size_t count)
} }
// upSend(din, count); // upSend(din, count);
} }
LOG_W("无法解析的目标地址");
} }
void chkACK(uint8_t *msg, size_t size) void chkACK(uint8_t *msg, size_t size)

View File

@ -47,7 +47,8 @@ int main(void)
rt_pin_write(TR485_RE, PIN_LOW); rt_pin_write(TR485_RE, PIN_LOW);
//sysSemInit //sysSemInit
sysSemInit(); sysInit();
// sysEventInit();
if (isInWindowZone()) {//开机检查是否在开窗区间内是则给TT开机 if (isInWindowZone()) {//开机检查是否在开窗区间内是则给TT开机
initTT(); initTT();
// pwTT_thread_entry("1"); // pwTT_thread_entry("1");

View File

@ -481,6 +481,7 @@ void pwTT_thread_entry(void *parameter)
} }
rt_pin_write(TT_EN, flag);// rt_pin_write(TT_EN, flag);//
rt_thread_mdelay(300);
// if (!flag) { // if (!flag) {
// initTT(); // initTT();
@ -559,6 +560,7 @@ void recTT_thread_entry()
LOG_HEX("TTrec", 16, msg.data, msg.size); LOG_HEX("TTrec", 16, msg.data, msg.size);
//此处调用处理函数 //此处调用处理函数
// LOG_D("try to parse data."); // LOG_D("try to parse data.");
resetTM();
parseTTData(msg.data,msg.size); parseTTData(msg.data,msg.size);
} }
} }

View File

@ -672,6 +672,8 @@ __exit:
*/ */
void rt_hw_stm32_eth_deinit() void rt_hw_stm32_eth_deinit()
{ {
// HAL_ETH_DeInit(&EthHandle);
rt_timer_delete(stm32_eth_device.poll_link_timer);
eth_device_deinit(&(stm32_eth_device.parent)); eth_device_deinit(&(stm32_eth_device.parent));
if (Rx_Buff) if (Rx_Buff)
{ {