Files
test/interface_boot.c
2025-07-05 20:11:15 +08:00

131 lines
3.2 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.

#include <udelay/udelay.h>
#include <reset_ip.h>
#include <debug.h>
#include <sdrv_gpio.h>
#include <armv7-r/cache.h>
#include "sdrv_rstgen.h"
#include "interface_config.h"
uint16_t FrameHeader = 0;//帧头
bool boot_can_flag = false;//帧头
bool boot_eth_flag = false;//帧头
SystemDataRecord g_systemDataRecord = {0,0,0,0};
bool WDTReFresh_flag = false;//
Timer boot_timer_interface;
void bootmian(void *signal_id)
{
static uint16_t bootmianSTT = 0;
// uint32_t time_boot = getCurrentTime();//记录当前时间
//------------------------------------------------------------------------------
(void)signal_id; // 标记变量为已使用,避免编译器警告
if( (true == boot_can_flag) || (true == boot_eth_flag) )//重启标志在中断中接收后置1
{
boot_can_flag = false;
boot_eth_flag = false;
if(EXCUTE_APP == FrameHeader)//写标志0重启进入APP
{
printf("go to app!\r\n");
wrbyte_24c02(Update_Flg_E2adr,NORMAL_ON); //写标志位为0重启下一次程序直接进入app
// udelay(3000);//延时3ms
g_systemDataRecord.canBootloaderUpgrade = rdbyte_24c02(Update_Flg_E2adr); //更新数据方便喂狗
// sdrv_rstgen_global_reset(&rstctl_glb);
for(;;)
{
printf("Restart!\r\n");
}
}
else if(ENTER_UPDATE_MODE == FrameHeader)//写标志1重启进入boot
{
ssdk_printf(SSDK_INFO, "go to boot!\r\n");
wrbyte_24c02(Update_Flg_E2adr,CAN_BOOTLOADER_UPGRADE); //写标志重启
// udelay(3000);//延时3ms
// sdrv_rstgen_global_reset(&rstctl_glb);
for(;;)
{
printf("Restart!\r\n");
}
}
}
//判断从e2读取boot标志后决定是否由APP定时喂狗
if( CAN_BOOTLOADER_UPGRADE == (g_systemDataRecord.canBootloaderUpgrade) )//boot标志
{
//boot标志为1上电进boot由上位机喂狗
if(true == WDTReFresh_flag)//接收到ID才更新WDT 接收到标志才喂狗
{
feedWatchdog();//喂狗
WDTReFresh_flag = false;
}
}
else//APP自己喂狗
{
bootmianSTT ++;
if(bootmianSTT >= 5)//5*1000*100us = 500ms
{
bootmianSTT = 0;
feedWatchdog();//喂狗
}
}
timerStart(&boot_timer_interface, 100,0);
// printf("bootAPP spend time:%d\n",getCurrentTime() - time_boot);//检查app用了多长时间
}
static uint32_t time_wdt = 0;
// 喂狗
void feedWatchdog(void)
{
sdrv_gpio_toggle_pin_output_level(WDTGPIO); //外部wdt喂狗
printf("WDT:%d \n",getCurrentTime() - time_wdt);
time_wdt = getCurrentTime();
}
// APP模块的初始化
void bootInterfaceInit(void)
{
// 初始化定时器
timerInit(&boot_timer_interface);
// 订阅定时器信号,用于定时采集
subscribe(&boot_timer_interface, bootmian);
timerStart(&boot_timer_interface, 100,0); //100ms
feedWatchdog();//喂狗,初始化完毕先喂一次
printf("bootInterface: initial OK %d\n",getCurrentTime());
}