TT12-MCU/applications/_main.c
murmur 9b76e1fbe8 添加流程文件
添加主逻辑函数
待完善ttgetinfo 文件
2023-06-01 17:10:00 +08:00

99 lines
2.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-01 murmur the first version
*/
#include <rtthread.h>
#define LOG_TAG "main_scha"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
#include <board.h>
#include <ttmsg/ttmsg.h>
#include <cfg.h>
struct rt_event sw_check;//软件条件
struct rt_event hw_check;//硬件条件
#define FILE_IS_OK 1
#define TIMER_IS_OUT 1<<1
#define TT_IS_OK 1<<2
static maxWaitTime = 4;
static maxRetryCnt = 3;
static init()
{
/* 事 件 控 制 块 */
rt_err_t result = rt_event_init(&sw_check, "SHcheck", RT_IPC_FLAG_FIFO);
if (result != RT_EOK)
{
LOG_E("init event failed.\n");
}
}
/**
* 更新各参数
*/
static void updatecfg()
{
maxWaitTime = get_cfg("maxWaitTime");
maxRetryCnt = get_cfg("maxRetryCnt");
}
/**
* 监控TT状态。需求条件1TT连续5个周期为激活状态且信号强度不低于5。
*/
void checkTT()
{
//上电
pwTT_thread_entry("1");
// rt_thread_create(name, entry, parameter, stack_size, priority, tick)
getTT();
// getTTinfo_thread_entry()
}
void try()
{
static rt_err_t rst = RT_ERROR;
updatecfg();
while(1)
{
int e;
rst = rt_event_recv(&sw_check, FILE_IS_OK | TIMER_IS_OUT, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
RT_WAITING_FOREVER, &e);
if (rst == RT_EOK)
{
//上电
pwTT_thread_entry("1");
}
for (size_t var = 0; var < maxRetryCnt; ++var)
{
rst = rt_event_recv(&sw_check, TT_IS_OK, RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(maxWaitTime * 1000),
&e);
if (rst == RT_ETIMEOUT)
{
pwTT_thread_entry("0");
rt_thread_mdelay(1000);
pwTT_thread_entry("1");
}
else if (rst == RT_EOK)
{
break;
}
else
{
LOG_E("Unknown error.");
}
}
}
}