127 lines
3.2 KiB
C
Raw Normal View History

2025-02-19 13:21:11 +08:00
/*******************************************************************************
* the includes
******************************************************************************/
/*******************************************************************************
* the defines
******************************************************************************/
#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"
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
volatile uint32_t gSystick1msEvent = 0,gSystick1msCnt=0,gSystick1SCnt;
uint8_t Txbuf[8] = {0};
/*******************************************************************************
* the const
******************************************************************************/
/*******************************************************************************
* the functions
******************************************************************************/
/**
* @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)
{
BSTIM32_Init();
gSystick1SCnt = 0;
}
void appTask(void)
{
if(gSystick1msEvent > 0u)
{
gSystick1msEvent--;
gSystick1msCnt++;
if (gSystick1msCnt % 2 == 0)
{
}
if (gSystick1msCnt % 1000 == 0)
{
/* 电源掉电监测处理 */
PowerDownMonitroing();
gSystick1SCnt++;
Txbuf[0] = gSystick1SCnt;
SetSlaveData(Txbuf);
LED1_TOG();
}
if (gSystick1msCnt % 100 == 0)
{
LED0_TOG();
/* 清狗 */
IWDT_Clr();
#if (SLEEP_SUPPORT == 1)
if (lin_is_sleep())
{
//sleep();
}
#endif
}
if (gSystick1msCnt >= 1000000)
{
gSystick1msCnt = 0;
}
}
}