185 lines
4.2 KiB
C
185 lines
4.2 KiB
C
/*******************************************************************************
|
||
* 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"
|
||
#include "hwctrl.h"
|
||
|
||
|
||
/*******************************************************************************
|
||
* the defines
|
||
******************************************************************************/
|
||
|
||
|
||
/*******************************************************************************
|
||
* the typedefs
|
||
******************************************************************************/
|
||
|
||
|
||
/*******************************************************************************
|
||
* the globals
|
||
******************************************************************************/
|
||
volatile uint32_t gSystick1msEvent = 0,gSystick1msCnt=0,gSystick1SCnt;
|
||
uint8_t Txbuf[8] = {0};
|
||
|
||
/*******************************************************************************
|
||
* the const
|
||
******************************************************************************/
|
||
|
||
|
||
|
||
/*******************************************************************************
|
||
* the functions
|
||
******************************************************************************/
|
||
static void MsgCtrlIO_task(void);
|
||
|
||
|
||
|
||
|
||
/**
|
||
* @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)
|
||
{
|
||
hw_gpio_init();
|
||
BSTIM32_Init();
|
||
|
||
V2_12V_control(V2_12V_OFF);
|
||
AP_control(AP_OFF);
|
||
|
||
for (uint8_t i = 0; i < DCF_NUM; i++)
|
||
{
|
||
DCF_control(i, DCF_OFF);
|
||
}
|
||
|
||
gSystick1SCnt = 0;
|
||
}
|
||
void appTask(void)
|
||
{
|
||
|
||
if(gSystick1msEvent > 0u)
|
||
{
|
||
gSystick1msEvent--;
|
||
gSystick1msCnt++;
|
||
|
||
if (gSystick1msCnt % 5 == 0)
|
||
{
|
||
MsgCtrlIO_task();
|
||
}
|
||
|
||
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;
|
||
|
||
}
|
||
}
|
||
}
|
||
uint8_t msgRxBuf[8] = {0};
|
||
static void MsgCtrlIO_task(void)
|
||
{
|
||
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);
|
||
}
|
||
|
||
}
|