185 lines
4.2 KiB
C
Raw Normal View History

2025-02-19 13:21:11 +08:00
/*******************************************************************************
* the includes
******************************************************************************/
#include "appTask.h"
#include "uart.h"
#include "lin.h"
#include "user_init.h"
#include "sleep.h"
#include "svd.h"
#include "iwdt.h"
#include "rmu.h"
#include "bstim32.h"
2025-02-19 14:20:03 +08:00
#include "hwctrl.h"
/*******************************************************************************
* the defines
******************************************************************************/
2025-02-19 13:21:11 +08:00
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
volatile uint32_t gSystick1msEvent = 0,gSystick1msCnt=0,gSystick1SCnt;
uint8_t Txbuf[8] = {0};
/*******************************************************************************
* the const
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
2025-02-19 16:33:45 +08:00
static void MsgCtrlIO_task(void);
2025-02-19 13:21:11 +08:00
/**
* @brief
* @param
* @retval
*/
static void PowerDownMonitroing(void)
{
/* 确认SVD监测结果是否低于阈值 */
if (true == SVD_Result_Confirmed(SVD_BELOW_THRESHOLD, 1U))
{ /* 防抖处理 */
#if 0
if (true == SVD_Result_Confirmed(SVD_BELOW_THRESHOLD, 2000U/*us*/))
{
/* 电压下降到报警阈值,处理掉电事件 */
/* 用户程序1 */
/* ...... */
/* 注意用户需确保在BOR复位之前执行完毕 */
/* 确认SVD监测结果是否高于阈值如否则持续等待 */
while(false == SVD_Result_Confirmed(SVD_HIGHER_THRESHOLD, 20U/*us*/));
/* 由于电源有下降到报警阈值,软件复位后重新初始化 */
FL_RMU_SetSoftReset(RMU);
}
#endif
}
}
void TimebaseHandle(void)
{
gSystick1msEvent++;
}
void appTaskInit(void)
{
2025-02-19 14:20:03 +08:00
hw_gpio_init();
2025-02-19 13:21:11 +08:00
BSTIM32_Init();
2025-02-19 14:20:03 +08:00
V2_12V_control(V2_12V_OFF);
AP_control(AP_OFF);
2025-02-19 16:33:45 +08:00
for (uint8_t i = 0; i < DCF_NUM; i++)
2025-02-19 14:20:03 +08:00
{
DCF_control(i, DCF_OFF);
}
2025-02-19 13:21:11 +08:00
gSystick1SCnt = 0;
}
void appTask(void)
{
if(gSystick1msEvent > 0u)
{
gSystick1msEvent--;
gSystick1msCnt++;
2025-02-19 16:33:45 +08:00
if (gSystick1msCnt % 5 == 0)
2025-02-19 13:21:11 +08:00
{
2025-02-19 16:33:45 +08:00
MsgCtrlIO_task();
2025-02-19 13:21:11 +08:00
}
if (gSystick1msCnt % 1000 == 0)
{
/* 电源掉电监测处理 */
PowerDownMonitroing();
gSystick1SCnt++;
Txbuf[0] = gSystick1SCnt;
SetSlaveData(Txbuf);
2025-02-19 16:33:45 +08:00
//LED1_TOG();
2025-02-19 13:21:11 +08:00
}
if (gSystick1msCnt % 100 == 0)
{
2025-02-19 16:33:45 +08:00
//LED0_TOG();
2025-02-19 13:21:11 +08:00
/* 清狗 */
IWDT_Clr();
#if (SLEEP_SUPPORT == 1)
if (lin_is_sleep())
{
//sleep();
}
#endif
}
if (gSystick1msCnt >= 1000000)
{
gSystick1msCnt = 0;
}
}
}
2025-02-19 16:33:45 +08:00
uint8_t msgRxBuf[8] = {0};
static void MsgCtrlIO_task(void)
2025-02-19 14:20:03 +08:00
{
2025-02-19 16:33:45 +08:00
GetMasterData(msgRxBuf);
for (uint8_t i = 0; i < 8; i++)
{
if (msgRxBuf[0] & (0x01<<i))
{
DCF_control(i,DCF_ON);
}
else
{
DCF_control(i,DCF_OFF);
}
}
for (uint8_t i = 0; i < 2; i++)
{
if (msgRxBuf[1] & (0x01<<i))
{
DCF_control(i+8,DCF_ON);
}
else
{
DCF_control(i+8,DCF_OFF);
}
}
if (msgRxBuf[1] & 0x80)
{
V2_12V_control(V2_12V_ON);
}
else
{
V2_12V_control(V2_12V_OFF);
}
if (msgRxBuf[1] & 0x40)
{
AP_control(AP_ON);
}
else
{
AP_control(AP_OFF);
}
2025-02-19 14:20:03 +08:00
}