rt_timer_create改成init
This commit is contained in:
parent
53c5853e31
commit
4f54d897ed
|
@ -71,7 +71,7 @@
|
|||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.floatequal.134298453" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.floatequal" useByScannerDiscovery="true" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.toerrors.1117291056" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.toerrors" useByScannerDiscovery="true" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.other.1918769559" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.other" useByScannerDiscovery="true" value="" valueType="string"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.1204865254" name="Debug level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.max" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.1204865254" name="Debug level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.default" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.867779652" name="Debug format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.default" valueType="enumerated"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.prof.2131276390" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.prof" useByScannerDiscovery="true" value="false" valueType="boolean"/>
|
||||
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.gprof.1910159761" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.gprof" useByScannerDiscovery="true" value="false" valueType="boolean"/>
|
||||
|
|
|
@ -135,7 +135,7 @@
|
|||
"other_warning_flags": ""
|
||||
},
|
||||
"debugging": {
|
||||
"debug_level": "max",
|
||||
"debug_level": "default",
|
||||
"debug_format": "default",
|
||||
"generate_prof_information": false,
|
||||
"generate_gprof_information": false,
|
||||
|
@ -773,7 +773,7 @@
|
|||
"address": "0x08000000",
|
||||
"target_path": "obj\\JT-DT-YD4N02A_RTT_MRS-4G.hex",
|
||||
"clkSpeed": "High",
|
||||
"debug_interface_mode": "",
|
||||
"debug_interface_mode": "1-wire serial",
|
||||
"erase": true,
|
||||
"program": true,
|
||||
"verify": true,
|
||||
|
|
|
@ -35,7 +35,7 @@ static rt_uint32_t event_flags[kMaxEventcnt] = {0};
|
|||
|
||||
struct rt_event alarm_event;
|
||||
|
||||
rt_bool_t is_event_initialized = RT_FALSE; // 是否初始化完成
|
||||
rt_bool_t is_event_initialized = RT_FALSE; // 是否初始化完成
|
||||
|
||||
TsSysControl SysControl;
|
||||
|
||||
|
@ -43,9 +43,9 @@ struct rt_timer work_cnt_timer;
|
|||
|
||||
rt_timer_t led_state_timer;
|
||||
|
||||
void Send_Laser_Alarm_Event (AlarmEvent event_type);
|
||||
void Send_Laser_Alarm_Event(AlarmEvent event_type);
|
||||
|
||||
static void Set_Event (AlarmEvent event_type)
|
||||
static void Set_Event(AlarmEvent event_type)
|
||||
{
|
||||
if (event_type < kMaxEventcnt)
|
||||
{
|
||||
|
@ -53,28 +53,27 @@ static void Set_Event (AlarmEvent event_type)
|
|||
}
|
||||
}
|
||||
|
||||
void SYS_EventInit (void)
|
||||
void SYS_EventInit(void)
|
||||
{
|
||||
if (!is_event_initialized)
|
||||
{
|
||||
if (rt_event_init (&alarm_event, "alarm_event", RT_IPC_FLAG_PRIO) == RT_EOK)
|
||||
if (rt_event_init(&alarm_event, "alarm_event", RT_IPC_FLAG_PRIO) == RT_EOK)
|
||||
{
|
||||
|
||||
for (AlarmEvent event = kPowerOnEvent; event < kMaxEventcnt; event++)
|
||||
{
|
||||
Set_Event (event);
|
||||
Set_Event(event);
|
||||
}
|
||||
is_event_initialized = RT_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_event_initialized = RT_FALSE;
|
||||
LOG_E ("Alarm event init failed!");
|
||||
LOG_E("Alarm event init failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rt_uint32_t Get_Sys_Event_Flag (AlarmEvent event_type)
|
||||
rt_uint32_t Get_Sys_Event_Flag(AlarmEvent event_type)
|
||||
{
|
||||
if (is_event_initialized == RT_TRUE)
|
||||
{
|
||||
|
@ -86,105 +85,104 @@ rt_uint32_t Get_Sys_Event_Flag (AlarmEvent event_type)
|
|||
return kMaxEventcnt;
|
||||
}
|
||||
|
||||
void Send_Laser_Alarm_Event (AlarmEvent event_type)
|
||||
void Send_Laser_Alarm_Event(AlarmEvent event_type)
|
||||
{
|
||||
|
||||
if (is_event_initialized == RT_TRUE)
|
||||
{
|
||||
if (SysControl.status == kPowerDownEvent)
|
||||
{
|
||||
LOG_D ("掉电模式下不处理其他事件");
|
||||
LOG_D("掉电模式下不处理其他事件");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_I ("Send_Laser_Alarm_Event = %d", event_type);
|
||||
rt_event_send (&alarm_event, Get_Sys_Event_Flag (event_type));
|
||||
LOG_I("Send_Laser_Alarm_Event = %d", event_type);
|
||||
rt_event_send(&alarm_event, Get_Sys_Event_Flag(event_type));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is_event_initialized = RT_FALSE;
|
||||
LOG_E ("Alarm event no init !");
|
||||
LOG_E("Alarm event no init !");
|
||||
}
|
||||
}
|
||||
|
||||
int _Self_Check_Mode (void)
|
||||
int _Self_Check_Mode(void)
|
||||
{
|
||||
LED_STOP (r);
|
||||
LED_STOP (g);
|
||||
LED_STOP (y);
|
||||
rt_thread_mdelay (500);
|
||||
LED_CTRL (g, "500,2500", 1);
|
||||
LED_START (g);
|
||||
rt_thread_mdelay (1000);
|
||||
LED_CTRL (y, "500,2500", 1);
|
||||
LED_START (y);
|
||||
rt_thread_mdelay (1000);
|
||||
LED_CTRL (r, "500,2500", 1);
|
||||
LED_START (r);
|
||||
rt_thread_mdelay (1000);
|
||||
LED_STOP (r);
|
||||
LED_STOP (g);
|
||||
LED_STOP (y);
|
||||
LED_STOP(r);
|
||||
LED_STOP(g);
|
||||
LED_STOP(y);
|
||||
rt_thread_mdelay(500);
|
||||
LED_CTRL(g, "500,2500", 1);
|
||||
LED_START(g);
|
||||
rt_thread_mdelay(1000);
|
||||
LED_CTRL(y, "500,2500", 1);
|
||||
LED_START(y);
|
||||
rt_thread_mdelay(1000);
|
||||
LED_CTRL(r, "500,2500", 1);
|
||||
LED_START(r);
|
||||
rt_thread_mdelay(1000);
|
||||
LED_STOP(r);
|
||||
LED_STOP(g);
|
||||
LED_STOP(y);
|
||||
BEEP_SELF_CHECK;
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
void Preheat_Sensor (rt_uint32_t timeout_counter)
|
||||
void Preheat_Sensor(rt_uint32_t timeout_counter)
|
||||
{
|
||||
// 定义超时时间,单位为毫秒
|
||||
#define TIMEOUT_MS 15000
|
||||
|
||||
timeout_counter += 10; // 每次递归增加10毫秒
|
||||
timeout_counter += 10; // 每次递归增加10毫秒
|
||||
|
||||
if (H308.Data.checksum != 0)
|
||||
{
|
||||
BEEP_PREAT_OK;
|
||||
LED_STOP (r);
|
||||
LED_STOP (g);
|
||||
LED_STOP (y);
|
||||
LOG_D ("预热完成");
|
||||
LED_STOP(r);
|
||||
LED_STOP(g);
|
||||
LED_STOP(y);
|
||||
LOG_D("预热完成");
|
||||
BEEP_PREAT_OK;
|
||||
Send_Laser_Alarm_Event (kNormalDetectionEvents);
|
||||
Send_Laser_Alarm_Event(kNormalDetectionEvents);
|
||||
}
|
||||
else if (IS_H308_EndOfLife()) // 如果寿命到期,预热完成后直接到寿命过期状态
|
||||
else if (IS_H308_EndOfLife()) // 如果寿命到期,预热完成后直接到寿命过期状态
|
||||
{
|
||||
LED_STOP (r);
|
||||
LED_STOP (g);
|
||||
LED_STOP (y);
|
||||
LED_STOP(r);
|
||||
LED_STOP(g);
|
||||
LED_STOP(y);
|
||||
BEEP_PREAT_OK;
|
||||
Send_Laser_Alarm_Event (kSensorFailureEvent);
|
||||
Send_Laser_Alarm_Event(kSensorFailureEvent);
|
||||
}
|
||||
else if ((timeout_counter >= TIMEOUT_MS) && (H308.Data.checksum == 0))
|
||||
{
|
||||
LED_STOP (r);
|
||||
LED_STOP (g);
|
||||
LED_STOP (y);
|
||||
LED_STOP(r);
|
||||
LED_STOP(g);
|
||||
LED_STOP(y);
|
||||
BEEP_PREAT_OK;
|
||||
LOG_D ("预热完成,传感器故障");
|
||||
Send_Laser_Alarm_Event (kFaultEvent); // 传感器故障
|
||||
LOG_D("预热完成,传感器故障");
|
||||
Send_Laser_Alarm_Event(kFaultEvent); // 传感器故障
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_thread_mdelay (10);
|
||||
Preheat_Sensor (timeout_counter);
|
||||
rt_thread_mdelay(10);
|
||||
Preheat_Sensor(timeout_counter);
|
||||
}
|
||||
}
|
||||
|
||||
void Work_Cnt_Timer_Callback (void *parameter)
|
||||
void Work_Cnt_Timer_Callback(void *parameter)
|
||||
{
|
||||
work_duration++;
|
||||
if (IS_H308_EndOfLife() == 1) // 每天检测一下是否过期
|
||||
if (IS_H308_EndOfLife() == 1) // 每天检测一下是否过期
|
||||
{
|
||||
if (Flash_GetNum_Records (kRecordSensoEndOfLife) == 0)
|
||||
if (Flash_GetNum_Records(kRecordSensoEndOfLife) == 0)
|
||||
{
|
||||
Flash_Write_Record (kRecordSensoEndOfLife);
|
||||
Flash_Write_Record(kRecordSensoEndOfLife);
|
||||
}
|
||||
Send_Laser_Alarm_Event (kSensorFailureEvent);
|
||||
Send_Laser_Alarm_Event(kSensorFailureEvent);
|
||||
}
|
||||
}
|
||||
|
||||
int main (void)
|
||||
int main(void)
|
||||
{
|
||||
#define WORK_TIMER_CNT (1000 * 60 * 60 * 24)
|
||||
|
||||
|
@ -200,316 +198,316 @@ int main (void)
|
|||
BSP_SYS_Init();
|
||||
|
||||
work_duration = Flash_Get_WorkDuration();
|
||||
LOG_D ("工作天数:%d", work_duration);
|
||||
LOG_D("工作天数:%d", work_duration);
|
||||
|
||||
TuFlashProductTimeLimitFrame LimitTime;
|
||||
if (Flash_GetProductTimeLimit (&LimitTime, kExpirationTimeId) == READY)
|
||||
if (Flash_GetProductTimeLimit(&LimitTime, kExpirationTimeId) == READY)
|
||||
{
|
||||
// 计算出 到期时间对应的RTC秒数
|
||||
H308.expiration_seconds = DateTime2Seconds (LimitTime.Struct.year,
|
||||
LimitTime.Struct.month, LimitTime.Struct.day, LimitTime.Struct.hour,
|
||||
LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
LOG_D ("h308_expiration_time:%04d-%02d-%02d,%02d:%02d",
|
||||
LimitTime.Struct.year, LimitTime.Struct.month, LimitTime.Struct.day,
|
||||
LimitTime.Struct.hour, LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
H308.expiration_seconds = DateTime2Seconds(LimitTime.Struct.year,
|
||||
LimitTime.Struct.month, LimitTime.Struct.day, LimitTime.Struct.hour,
|
||||
LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
LOG_D("h308_expiration_time:%04d-%02d-%02d,%02d:%02d",
|
||||
LimitTime.Struct.year, LimitTime.Struct.month, LimitTime.Struct.day,
|
||||
LimitTime.Struct.hour, LimitTime.Struct.minute, LimitTime.Struct.second);
|
||||
}
|
||||
if (Flash_GetNum_Records (kRecordSensoEndOfLife) == 1)
|
||||
if (Flash_GetNum_Records(kRecordSensoEndOfLife) == 1)
|
||||
{
|
||||
LOG_W ("寿命已到期");
|
||||
LOG_W("寿命已到期");
|
||||
H308.end_of_life = 1;
|
||||
}
|
||||
rt_timer_init (&work_cnt_timer,
|
||||
"work_cnt_timer",
|
||||
Work_Cnt_Timer_Callback,
|
||||
RT_NULL,
|
||||
WORK_TIMER_CNT,
|
||||
RT_TIMER_FLAG_PERIODIC);
|
||||
rt_timer_start (&work_cnt_timer);
|
||||
rt_timer_init(&work_cnt_timer,
|
||||
"work_cnt_timer",
|
||||
Work_Cnt_Timer_Callback,
|
||||
RT_NULL,
|
||||
WORK_TIMER_CNT,
|
||||
RT_TIMER_FLAG_PERIODIC);
|
||||
rt_timer_start(&work_cnt_timer);
|
||||
// 检测上电/掉电复位标志
|
||||
if (RCC_GetFlagStatus (RCC_FLAG_PORRST) != RESET) // TODO:这块超级电容会造成掉电重启,并且标志是上电复位,只能通过其超级电容造成复位时事件创建失败进行判断,不治本
|
||||
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) // TODO:这块超级电容会造成掉电重启,并且标志是上电复位,只能通过其超级电容造成复位时事件创建失败进行判断,不治本
|
||||
{
|
||||
RCC_ClearFlag();
|
||||
Send_Laser_Alarm_Event (kPowerOnEvent);
|
||||
Send_Laser_Alarm_Event(kPowerOnEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Send_Laser_Alarm_Event (kPreheatingEvent); // 这一句的作用是设备不是掉电重启的情况,直接进入预热模式
|
||||
Send_Laser_Alarm_Event(kPreheatingEvent); // 这一句的作用是设备不是掉电重启的情况,直接进入预热模式
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D ("欠压复位\r\n");
|
||||
LOG_D("欠压复位\r\n");
|
||||
RCC_ClearFlag();
|
||||
NVIC_SystemReset(); // 直接重启系统
|
||||
NVIC_SystemReset(); // 直接重启系统
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
if (is_event_initialized)
|
||||
{
|
||||
result = rt_event_recv (&alarm_event,
|
||||
Get_Sys_Event_Flag (kPowerOnEvent) | // 上电
|
||||
Get_Sys_Event_Flag (kPowerDownEvent) | // 掉电
|
||||
Get_Sys_Event_Flag (kPreheatingEvent) | // 预热
|
||||
Get_Sys_Event_Flag (kNormalDetectionEvents) | // 正常检测
|
||||
Get_Sys_Event_Flag (kAlarmExceptionEvent) | // 报警异常
|
||||
Get_Sys_Event_Flag (kAlarmEvent) | // 报警
|
||||
Get_Sys_Event_Flag (kAlarmRcyEvent) | // 报警恢复
|
||||
Get_Sys_Event_Flag (kSelfCheckEvent) | // 自检
|
||||
Get_Sys_Event_Flag (kFaultEvent) | // 故障模式
|
||||
Get_Sys_Event_Flag (kFaultRcyEvent) | // 故障恢复
|
||||
Get_Sys_Event_Flag (KMuteEvent) | // 消音
|
||||
Get_Sys_Event_Flag (kSensorFailureEvent), // 传感器寿命到期
|
||||
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
|
||||
RT_WAITING_FOREVER, &received_event);
|
||||
result = rt_event_recv(&alarm_event,
|
||||
Get_Sys_Event_Flag(kPowerOnEvent) | // 上电
|
||||
Get_Sys_Event_Flag(kPowerDownEvent) | // 掉电
|
||||
Get_Sys_Event_Flag(kPreheatingEvent) | // 预热
|
||||
Get_Sys_Event_Flag(kNormalDetectionEvents) | // 正常检测
|
||||
Get_Sys_Event_Flag(kAlarmExceptionEvent) | // 报警异常
|
||||
Get_Sys_Event_Flag(kAlarmEvent) | // 报警
|
||||
Get_Sys_Event_Flag(kAlarmRcyEvent) | // 报警恢复
|
||||
Get_Sys_Event_Flag(kSelfCheckEvent) | // 自检
|
||||
Get_Sys_Event_Flag(kFaultEvent) | // 故障模式
|
||||
Get_Sys_Event_Flag(kFaultRcyEvent) | // 故障恢复
|
||||
Get_Sys_Event_Flag(KMuteEvent) | // 消音
|
||||
Get_Sys_Event_Flag(kSensorFailureEvent), // 传感器寿命到期
|
||||
RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR,
|
||||
RT_WAITING_FOREVER, &received_event);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
if (is_event_initialized == RT_TRUE)
|
||||
{
|
||||
if (received_event & Get_Sys_Event_Flag (kPowerOnEvent)) // 上电
|
||||
if (received_event & Get_Sys_Event_Flag(kPowerOnEvent)) // 上电
|
||||
{
|
||||
LOG_D ("上电模式");
|
||||
LOG_D ("is_event_initialized :%d", is_event_initialized);
|
||||
LOG_D("上电模式");
|
||||
LOG_D("is_event_initialized :%d", is_event_initialized);
|
||||
SysControl.status = kPowerOnEvent;
|
||||
|
||||
Flash_Write_Record (kRecordPowerOn);
|
||||
Send_Laser_Alarm_Event (kPreheatingEvent);
|
||||
Flash_Write_Record(kRecordPowerOn);
|
||||
Send_Laser_Alarm_Event(kPreheatingEvent);
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kPreheatingEvent)) // 预热
|
||||
else if (received_event & Get_Sys_Event_Flag(kPreheatingEvent)) // 预热
|
||||
{
|
||||
LOG_D ("预热模式");
|
||||
LOG_D("预热模式");
|
||||
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kPreheatingEvent;
|
||||
SysControl.status = kPreheatingEvent;
|
||||
|
||||
LED_G_PREAT;
|
||||
BEEP_PREAT_OK;
|
||||
Send_Laser_Alarm_Event (kNormalDetectionEvents);
|
||||
Send_Laser_Alarm_Event(kNormalDetectionEvents);
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kNormalDetectionEvents)) // 正常检测
|
||||
else if (received_event & Get_Sys_Event_Flag(kNormalDetectionEvents)) // 正常检测
|
||||
{
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kNormalDetectionEvents;
|
||||
SysControl.status = kNormalDetectionEvents;
|
||||
|
||||
if (SysControl.last_status == kSelfCheckEvent)
|
||||
{
|
||||
rt_thread_mdelay (4000); //1000 * 3 + 4000 = 7000//国标要求7s-30s动作
|
||||
LOG_I ("自检电磁阀动作");
|
||||
rt_thread_mdelay(4000); // 1000 * 3 + 4000 = 7000//国标要求7s-30s动作
|
||||
LOG_I("自检电磁阀动作");
|
||||
EMV_CLOSE_VALVE;
|
||||
LOG_I ("自检风机动作");
|
||||
LOG_I("自检风机动作");
|
||||
relay_state_flag = 1;
|
||||
rt_thread_mdelay (3000);
|
||||
rt_thread_mdelay(3000);
|
||||
relay_state_flag = 0;
|
||||
}
|
||||
if (H308.detection_flag == kH308Alarm)
|
||||
{
|
||||
LED_G_NORMAL;
|
||||
rt_thread_mdelay (500);
|
||||
Send_Laser_Alarm_Event (kAlarmEvent);
|
||||
rt_thread_mdelay(500);
|
||||
Send_Laser_Alarm_Event(kAlarmEvent);
|
||||
}
|
||||
else if (H308.detection_flag == kH308Fault)
|
||||
{
|
||||
LED_G_NORMAL;
|
||||
rt_thread_mdelay (500);
|
||||
Send_Laser_Alarm_Event (kFaultEvent);
|
||||
rt_thread_mdelay(500);
|
||||
Send_Laser_Alarm_Event(kFaultEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D ("正常检测模式");
|
||||
LOG_D("正常检测模式");
|
||||
}
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kAlarmExceptionEvent)) // 浓度异常
|
||||
else if (received_event & Get_Sys_Event_Flag(kAlarmExceptionEvent)) // 浓度异常
|
||||
{
|
||||
LOG_D ("浓度异常模式");
|
||||
LOG_D("浓度异常模式");
|
||||
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kAlarmExceptionEvent;
|
||||
SysControl.status = kAlarmExceptionEvent;
|
||||
|
||||
LED_R_ALARM;
|
||||
LOG_D ("LED_R_ALARM");
|
||||
LOG_D("LED_R_ALARM");
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kAlarmEvent)) // 报警
|
||||
else if (received_event & Get_Sys_Event_Flag(kAlarmEvent)) // 报警
|
||||
{
|
||||
LOG_D ("报警模式");
|
||||
LOG_D("报警模式");
|
||||
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kAlarmEvent;
|
||||
SysControl.status = kAlarmEvent;
|
||||
|
||||
Flash_Write_Record (kRecordAlarm); // 写入flash报警信息
|
||||
Flash_Write_Record(kRecordAlarm); // 写入flash报警信息
|
||||
LED_R_ALARM;
|
||||
BEEP_ALARM;
|
||||
relay_state_flag = 1;
|
||||
EMV_CLOSE_VALVE;
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kAlarmEvent);
|
||||
Nt26k_Send_Event(kNt26kAlarmEvent);
|
||||
#endif
|
||||
rt_thread_mdelay(6000);
|
||||
EMV_CLOSE_VALVE;
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kAlarmRcyEvent)) // 报警恢复
|
||||
else if (received_event & Get_Sys_Event_Flag(kAlarmRcyEvent)) // 报警恢复
|
||||
{
|
||||
LOG_D ("报警恢复模式");
|
||||
LOG_D("报警恢复模式");
|
||||
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kAlarmRcyEvent;
|
||||
SysControl.status = kAlarmRcyEvent;
|
||||
|
||||
Flash_Write_Record (kRecordAlarmRcy);
|
||||
Flash_Write_Record(kRecordAlarmRcy);
|
||||
|
||||
relay_state_flag = 0;
|
||||
BEEP_STOP;
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kAlarmRcyEvent);
|
||||
Nt26k_Send_Event(kNt26kAlarmRcyEvent);
|
||||
#endif
|
||||
|
||||
Send_Laser_Alarm_Event (kNormalDetectionEvents);
|
||||
Send_Laser_Alarm_Event(kNormalDetectionEvents);
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kFaultEvent)) // 故障
|
||||
else if (received_event & Get_Sys_Event_Flag(kFaultEvent)) // 故障
|
||||
{
|
||||
LOG_D ("故障模式");
|
||||
LOG_D("故障模式");
|
||||
|
||||
if (Flash_GetNum_Records (kRecordSensoEndOfLife) != 1) // 当设备失效时,只上报设备失效的故障,其他故障不上报
|
||||
if (Flash_GetNum_Records(kRecordSensoEndOfLife) != 1) // 当设备失效时,只上报设备失效的故障,其他故障不上报
|
||||
{
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kFaultEvent;
|
||||
SysControl.status = kFaultEvent;
|
||||
|
||||
Flash_Write_Record (kRecordFault);
|
||||
Flash_Write_Record(kRecordFault);
|
||||
|
||||
LED_Y_FAULT;
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kFaultEvent);
|
||||
Nt26k_Send_Event(kNt26kFaultEvent);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Send_Laser_Alarm_Event (kSensorFailureEvent);
|
||||
Send_Laser_Alarm_Event(kSensorFailureEvent);
|
||||
}
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kFaultRcyEvent)) // 故障恢复
|
||||
else if (received_event & Get_Sys_Event_Flag(kFaultRcyEvent)) // 故障恢复
|
||||
{
|
||||
LOG_D ("故障恢复模式");
|
||||
LOG_D("故障恢复模式");
|
||||
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kFaultRcyEvent;
|
||||
SysControl.status = kFaultRcyEvent;
|
||||
|
||||
Flash_Write_Record (kRecordFaultRcy);
|
||||
Flash_Write_Record(kRecordFaultRcy);
|
||||
|
||||
Send_Laser_Alarm_Event (kNormalDetectionEvents);
|
||||
Send_Laser_Alarm_Event(kNormalDetectionEvents);
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kFaultRcyEvent);
|
||||
Nt26k_Send_Event(kNt26kFaultRcyEvent);
|
||||
#endif
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (KMuteEvent)) // 消音
|
||||
else if (received_event & Get_Sys_Event_Flag(KMuteEvent)) // 消音
|
||||
{
|
||||
LOG_D ("消音模式");
|
||||
LOG_D("消音模式");
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = KMuteEvent;
|
||||
SysControl.status = KMuteEvent;
|
||||
BEEP_STOP;
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kSilenceEvent);
|
||||
Nt26k_Send_Event(kNt26kSilenceEvent);
|
||||
#endif
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kPowerDownEvent)) // 掉电
|
||||
else if (received_event & Get_Sys_Event_Flag(kPowerDownEvent)) // 掉电
|
||||
{
|
||||
LOG_D ("掉电模式");
|
||||
LOG_D("掉电模式");
|
||||
H308_PWR_OFF;
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kPowerDownEvent;
|
||||
SysControl.status = kPowerDownEvent;
|
||||
|
||||
// 写入掉电记录
|
||||
Flash_Write_Record (kRecordPowerDown);
|
||||
Flash_Write_Record(kRecordPowerDown);
|
||||
|
||||
Flash_Set_WorkDuration (work_duration); // 写入工作时长
|
||||
Flash_Set_WorkDuration(work_duration); // 写入工作时长
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kPowerDownEvent);
|
||||
Nt26k_Send_Event(kNt26kPowerDownEvent);
|
||||
#endif
|
||||
rt_uint8_t cnt = 0;
|
||||
while ((device_power_down_flag == 0)&&(cnt < 10))//等待接收到掉电事件响应
|
||||
while ((device_power_down_flag == 0) && (cnt < 10)) // 等待接收到掉电事件响应
|
||||
{
|
||||
rt_thread_mdelay(500);
|
||||
rt_thread_mdelay(500);
|
||||
LOG_D("cnt1 = %d", cnt);
|
||||
cnt++;
|
||||
}
|
||||
cnt = 0;
|
||||
while ((nt26k_power_down_flag == 0)&&(cnt < 10))//等待接收到物联网模组关机完成
|
||||
while ((nt26k_power_down_flag == 0) && (cnt < 10)) // 等待接收到物联网模组关机完成
|
||||
{
|
||||
rt_thread_mdelay(500);
|
||||
LOG_D("cnt2 = %d", cnt);
|
||||
LOG_D("cnt2 = %d", cnt);
|
||||
cnt++;
|
||||
}
|
||||
NVIC_SystemReset(); // 直接重启系统
|
||||
NVIC_SystemReset(); // 直接重启系统
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kSelfCheckEvent)) // 自检
|
||||
else if (received_event & Get_Sys_Event_Flag(kSelfCheckEvent)) // 自检
|
||||
{
|
||||
LOG_D ("自检模式");
|
||||
LOG_D("自检模式");
|
||||
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kSelfCheckEvent;
|
||||
SysControl.status = kSelfCheckEvent;
|
||||
|
||||
_Self_Check_Mode();
|
||||
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kSelfCheckEvent);
|
||||
Nt26k_Send_Event(kNt26kSelfCheckEvent);
|
||||
#endif
|
||||
Send_Laser_Alarm_Event (kNormalDetectionEvents); // 这里先返回检测模式,然后当事件触发时进入事件模式
|
||||
Send_Laser_Alarm_Event(kNormalDetectionEvents); // 这里先返回检测模式,然后当事件触发时进入事件模式
|
||||
}
|
||||
else if (received_event & Get_Sys_Event_Flag (kSensorFailureEvent)) // 失效
|
||||
else if (received_event & Get_Sys_Event_Flag(kSensorFailureEvent)) // 失效
|
||||
{
|
||||
SysControl.last_status = SysControl.status;
|
||||
SysControl.status = kSensorFailureEvent;
|
||||
LOG_D ("传感器失效模式");
|
||||
SysControl.status = kSensorFailureEvent;
|
||||
LOG_D("传感器失效模式");
|
||||
#if (IOT_MODULE_SWITCH == 1)
|
||||
Nt26k_Send_Event (kNt26kDeviceFailureEvent);
|
||||
Nt26k_Send_Event(kNt26kDeviceFailureEvent);
|
||||
#endif
|
||||
if (Flash_GetNum_Records (kRecordSensoEndOfLife) == 0)
|
||||
if (Flash_GetNum_Records(kRecordSensoEndOfLife) == 0)
|
||||
{
|
||||
Flash_Write_Record (kRecordSensoEndOfLife);
|
||||
Flash_Write_Record(kRecordSensoEndOfLife);
|
||||
}
|
||||
// LED_Y_END_OF_LIFE;
|
||||
Send_Laser_Alarm_Event (kNormalDetectionEvents);
|
||||
Send_Laser_Alarm_Event(kNormalDetectionEvents);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_thread_mdelay (1000);
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_ENABLE
|
||||
static void SYS_Set_RtcProductTime (int argc, char **argv)
|
||||
static void SYS_Set_RtcProductTime(int argc, char **argv)
|
||||
{
|
||||
if (argc == 7)
|
||||
{
|
||||
int year = atoi (argv[1]);
|
||||
int mon = atoi (argv[2]);
|
||||
int day = atoi (argv[3]);
|
||||
int hour = atoi (argv[4]);
|
||||
int min = atoi (argv[5]);
|
||||
int second = atoi (argv[6]);
|
||||
RTC_SetTime (2000 + year, mon, day, hour, min, second);
|
||||
int year = atoi(argv[1]);
|
||||
int mon = atoi(argv[2]);
|
||||
int day = atoi(argv[3]);
|
||||
int hour = atoi(argv[4]);
|
||||
int min = atoi(argv[5]);
|
||||
int second = atoi(argv[6]);
|
||||
RTC_SetTime(2000 + year, mon, day, hour, min, second);
|
||||
RTC_GetTime();
|
||||
LOG_D ("RTC: %4d-%02d-%02d, %02d:%02d:%02d", RtcDateTime.year, RtcDateTime.month, RtcDateTime.day,
|
||||
RtcDateTime.hour, RtcDateTime.minute, RtcDateTime.second);
|
||||
LOG_D("RTC: %4d-%02d-%02d, %02d:%02d:%02d", RtcDateTime.year, RtcDateTime.month, RtcDateTime.day,
|
||||
RtcDateTime.hour, RtcDateTime.minute, RtcDateTime.second);
|
||||
|
||||
// 设置出厂时间
|
||||
Flash_SetProductTimeLimit (2000 + year, mon, day, hour, min, second, kFactoryTimeId);
|
||||
Flash_SetProductTimeLimit(2000 + year, mon, day, hour, min, second, kFactoryTimeId);
|
||||
// 到期时间自动 + 5年30天
|
||||
Set_ExpirationTime (MAX_EXPIRATION_DAYS);
|
||||
Set_ExpirationTime(MAX_EXPIRATION_DAYS);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E ("SYS_Set_RtcProductTime --use _cmd_ [2000 + y] [m] [d] [h] [m] [s]");
|
||||
LOG_E("SYS_Set_RtcProductTime --use _cmd_ [2000 + y] [m] [d] [h] [m] [s]");
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (SYS_Set_RtcProductTime, "SYS_Set_RtcProductTime");
|
||||
MSH_CMD_EXPORT(SYS_Set_RtcProductTime, "SYS_Set_RtcProductTime");
|
||||
|
||||
static void SYS_SW_Version (void)
|
||||
static void SYS_SW_Version(void)
|
||||
{
|
||||
rt_kprintf ("JT-DT-YD4N02A Software version: V%02X\r\n", (uint8_t)Flash_Get_SysCfg (kSwVerId));
|
||||
rt_kprintf("JT-DT-YD4N02A Software version: V%02X\r\n", (uint8_t)Flash_Get_SysCfg(kSwVerId));
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT (SYS_SW_Version, "软件版本");
|
||||
MSH_CMD_EXPORT(SYS_SW_Version, "软件版本");
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "rtdef.h"
|
||||
#include "bsp_flash.h"
|
||||
|
||||
|
||||
#define MAX_EXPIRATION_YEARS (10U)
|
||||
#define MAX_EXPIRATION_DAYS (365 * MAX_EXPIRATION_YEARS + 30 * 3U)
|
||||
|
||||
|
@ -31,7 +30,7 @@
|
|||
#define SYS_IOT_URL ("8.130.117.149")
|
||||
#define SYS_IOT_PORT ("7137")
|
||||
|
||||
typedef enum
|
||||
typedef enum
|
||||
{
|
||||
kPowerOnEvent,
|
||||
kPreheatingEvent,
|
||||
|
|
|
@ -19,6 +19,7 @@ static char button_thread_stack[BUTTON_THREAD_STACK_SIZE];
|
|||
static struct rt_thread button_thread;
|
||||
#else
|
||||
static rt_timer_t button_timer;
|
||||
static struct rt_timer button_timer1;
|
||||
#endif // !BUTTON_USE_THREAD
|
||||
|
||||
typedef enum
|
||||
|
@ -124,18 +125,24 @@ int BSP_BUTTON_Init(void)
|
|||
// return -RT_ERROR;
|
||||
// }
|
||||
#else
|
||||
button_timer = rt_timer_create("button_timer", _BUTTON_Process,
|
||||
// TODO:这里改的静态
|
||||
rt_timer_init(&button_timer1, "button_timer", _BUTTON_Process,
|
||||
RT_NULL, 20,
|
||||
RT_TIMER_FLAG_PERIODIC);
|
||||
if (button_timer != RT_NULL)
|
||||
{
|
||||
rt_timer_start(button_timer);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("create button_timer fail");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
rt_timer_start(&button_timer1);
|
||||
|
||||
// button_timer = rt_timer_create("button_timer", _BUTTON_Process,
|
||||
// RT_NULL, 20,
|
||||
// RT_TIMER_FLAG_PERIODIC);
|
||||
// if (button_timer != RT_NULL)
|
||||
// {
|
||||
// rt_timer_start(button_timer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LOG_E("create button_timer fail");
|
||||
// return -RT_ERROR;
|
||||
// }
|
||||
#endif // !BUTTON_USE_THREAD
|
||||
LOG_I("BSP_BUTTON_Init!");
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ static rt_uint8_t uart4_rx_rb_data[UART4_RX_RB_LENGTH];
|
|||
static rt_sem_t uart4_rx_ok_sem;
|
||||
|
||||
static rt_timer_t uart4_rx_timer;
|
||||
static struct rt_timer uart4_rx_timer1;
|
||||
|
||||
uint8_t sensor_rx_count = 0; // 接收缓冲区中,已经收到的数据包数量
|
||||
|
||||
|
@ -43,7 +44,8 @@ TsH308 H308 = {0};
|
|||
void _UART4_RxTimeout(void *parameter)
|
||||
{
|
||||
rt_sem_release(uart4_rx_ok_sem);
|
||||
rt_timer_stop(uart4_rx_timer);
|
||||
// rt_timer_stop(uart4_rx_timer);
|
||||
rt_timer_stop(&uart4_rx_timer1);
|
||||
}
|
||||
|
||||
static uint8_t H308_XorChecksum(char *str, int len)
|
||||
|
@ -107,7 +109,7 @@ uint8_t H308_GetFrameData(const char *p_src, const rt_uint8_t src_len, TsH308Dat
|
|||
{
|
||||
pData->checksum = (rt_uint8_t)strtol(_H308StrData.checksum, NULL, 16);
|
||||
xor = H308_XorChecksum(p_str, 44); // 对数据进行异或校验
|
||||
if (xor == pData->checksum)
|
||||
if (xor== pData->checksum)
|
||||
{
|
||||
pData->lel = (float)(atof(_H308StrData.vol) * 20);
|
||||
pData->temp = (float)atof(_H308StrData.temp);
|
||||
|
@ -223,9 +225,9 @@ static uint8_t H308_CheckData(void)
|
|||
uint8_t IS_H308_EndOfLife(void)
|
||||
{
|
||||
RTC_GetTime();
|
||||
if (RtcDateTime.year > 2035)//至少大于2035年再检测
|
||||
if (RtcDateTime.year > 2035) // 至少大于2035年再检测
|
||||
{
|
||||
if (RTC_GetCounter() >= H308.expiration_seconds)
|
||||
if (RTC_GetCounter() >= H308.expiration_seconds)
|
||||
{
|
||||
H308.end_of_life = 1;
|
||||
}
|
||||
|
@ -282,11 +284,11 @@ void UART4_Init(void)
|
|||
|
||||
static void h308_thread_entry(void *param)
|
||||
{
|
||||
rt_err_t ret;
|
||||
rt_err_t ret;
|
||||
static uint8_t str[UART4_RX_RB_LENGTH] = {0};
|
||||
static uint8_t h308_rx_timout_cnt = 0;
|
||||
static uint8_t h308_err_cnt = 0;
|
||||
rt_thread_mdelay(1000);
|
||||
rt_thread_mdelay(1000);
|
||||
H308.alarm_value = Flash_Get_SysCfg(kAlarmLValueId); // 获取系统报警阈值
|
||||
LOG_D("报警阈值:%d%LEL", H308.alarm_value);
|
||||
|
||||
|
@ -332,14 +334,14 @@ static void h308_thread_entry(void *param)
|
|||
h308_rx_timout_cnt = 0;
|
||||
}
|
||||
}
|
||||
else if (ret == -RT_ETIMEOUT)//这个主要是考虑传感器未焊接好,或者脱落的情况,国标要求30s内反应 3*5 = 15s,符合国标
|
||||
else if (ret == -RT_ETIMEOUT) // 这个主要是考虑传感器未焊接好,或者脱落的情况,国标要求30s内反应 3*5 = 15s,符合国标
|
||||
{
|
||||
h308_rx_timout_cnt++;
|
||||
if (h308_rx_timout_cnt >= 5)
|
||||
{
|
||||
H308_RST_ON;
|
||||
rt_thread_mdelay(100);
|
||||
H308_RST_OFF;//复位一下
|
||||
H308_RST_OFF; // 复位一下
|
||||
h308_rx_timout_cnt = 0;
|
||||
if (H308.detection_flag != kH308Fault)
|
||||
{
|
||||
|
@ -357,18 +359,21 @@ int BSP_H308_Init(void)
|
|||
rt_pin_mode(H308_RST_PIN, PIN_MODE_OUTPUT);
|
||||
H308_RST_OFF;
|
||||
H308_PWR_ON;
|
||||
|
||||
|
||||
uart4_rx_ok_sem = rt_sem_create("uart4_rx", 0, RT_IPC_FLAG_FIFO);
|
||||
if (uart4_rx_ok_sem == RT_NULL)
|
||||
{
|
||||
LOG_E("uart4_rx_ok_sem create failed");
|
||||
}
|
||||
|
||||
uart4_rx_timer = rt_timer_create("_UART4_RxTimeout", _UART4_RxTimeout, RT_NULL, 200, RT_TIMER_FLAG_PERIODIC);
|
||||
if (uart4_rx_timer == RT_NULL)
|
||||
{
|
||||
LOG_E("uart4_rx_timer create failed");
|
||||
}
|
||||
// TODO:这里改的静态
|
||||
rt_timer_init(&uart4_rx_timer1, "_UART4_RxTimeout", _UART4_RxTimeout, RT_NULL, 200, RT_TIMER_FLAG_PERIODIC);
|
||||
// rt_timer_start(&uart4_rx_timer1);
|
||||
// uart4_rx_timer = rt_timer_create("_UART4_RxTimeout", _UART4_RxTimeout, RT_NULL, 200, RT_TIMER_FLAG_PERIODIC);
|
||||
// if (uart4_rx_timer == RT_NULL)
|
||||
// {
|
||||
// LOG_E("uart4_rx_timer create failed");
|
||||
// }
|
||||
UART4_Init();
|
||||
rt_err_t ret = rt_thread_init(&h308_thread,
|
||||
"h308_thread",
|
||||
|
@ -403,7 +408,8 @@ void UART4_IRQHandler(void)
|
|||
uint8_t temp = USART_ReceiveData(UART4);
|
||||
lwrb_write(&uart4_rx_rb, &temp, 1);
|
||||
// sensor_rx_count++;
|
||||
rt_timer_start(uart4_rx_timer);
|
||||
// rt_timer_start(uart4_rx_timer);
|
||||
rt_timer_start(&uart4_rx_timer1);
|
||||
}
|
||||
|
||||
rt_interrupt_leave();
|
||||
|
|
|
@ -38,11 +38,14 @@ static rt_uint8_t uart5_tx_rb_data[UART5_TX_RB_LENGTH];
|
|||
static rt_sem_t uart5_rx_ok_sem;
|
||||
|
||||
static rt_timer_t uart5_timer;
|
||||
static rt_timer_t uart5_timer1;
|
||||
|
||||
uint8_t hr_rx_flag = 0; // 接收缓冲区中,已经收到的数据包数量
|
||||
void uart5_timeout(void *parameter)
|
||||
{
|
||||
rt_sem_release(uart5_rx_ok_sem);
|
||||
rt_timer_stop(uart5_timer);
|
||||
// rt_timer_stop(uart5_timer);
|
||||
rt_timer_stop(uart5_timer1);
|
||||
hr_rx_flag = 0;
|
||||
}
|
||||
|
||||
|
@ -597,6 +600,9 @@ int BSP_HR_Init(void)
|
|||
{
|
||||
LOG_E("uart5_rx_ok_sem create failed");
|
||||
}
|
||||
|
||||
rt_timer_init(uart5_timer1, "uart5_timeout", uart5_timeout, RT_NULL, 50, RT_TIMER_FLAG_PERIODIC);
|
||||
|
||||
uart5_timer = rt_timer_create("uart5_timeout", uart5_timeout, RT_NULL, 50, RT_TIMER_FLAG_PERIODIC);
|
||||
if (uart5_timer == RT_NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue