⼀种的STM32的应⽤喂狗⽅法喂狗结构体:
typedef struct
{
uint32 last_update; /**< Time of the last system monitor update */
uint32 longest_permitted_delay; /**< Longest permitted delay between checkins with the system monitor */ } wdg_feed_t;
函数接⼝:
//初始化函数
void wdgFeed_start(void)
{
wdg_feed.last_update = Tick_Get();
wdg_feed.longest_permitted_delay = WDG_FEED_MS;
WDG_Refresh();
}
//喂狗时间更新,在滴答定时中断⾥调⽤
void wdgFeed_update(uint32 permitted_delay)
{
uint32 cur_time = Tick_Get();
/* Update the system monitor if it hasn't already pasd it's permitted delay */
if(cur_time < (wdg_feed.last_update + MS2TICK(wdg_feed.longest_permitted_delay)))
{
wdg_feed.last_update = cur_time;
wdg_feed.longest_permitted_delay = permitted_delay;
}
}
//定时喂狗, 在应⽤程序中调⽤
void wdgFeed(void)
{
static uint32 refresh_time = 0;
uint32 cur_time = Tick_Get();
//每隔500ms喂狗⼀次
if(cur_time >= (refresh_time + MS2TICK(500)))
{
WDG_Refresh(); //喂狗
refresh_time = cur_time;
}
if(cur_time >= (wdg_feed.last_update + MS2TICK(wdg_feed.longest_permitted_delay)))
{
/* A system monitor update period has been misd */
while(1);
}
}
wdgFeed_update()和wdgFeed()有关联性,⽆论哪个函数定期未执⾏,都会导致程序复位