HC32F460独立看门狗的使用

使用背景

为了防止程序跑飞,MCU特意引入了看门狗,看门狗分为窗口看门狗和独立看门狗,窗口看门狗采用中断实现,其时间更加的精确,独立看门狗大约会在附近1S左右没有喂狗就产生看门狗复位。

具体代码实现

#include “bsp_wdt.h”
#include “hc32_ddl.h”

// pclk = system_clock/div4 = 50M
// max cycle = 65536
// max feed interval = 65536 / (50000000/8192) = 10.7s
void bsp_wdt_init(void)
{
stc_wdt_init_t stcWdtInit;

/* configure structure initialization */
MEM_ZERO_STRUCT(stcWdtInit);

stcWdtInit.enClkDiv = WdtPclk3Div8192;
stcWdtInit.enCountCycle = WdtCountCycle65536;
stcWdtInit.enRefreshRange = WdtRefresh100Pct;
stcWdtInit.enSleepModeCountEn = Disable;
stcWdtInit.enRequestType = WdtTriggerResetRequest;
WDT_Init(&stcWdtInit);

}

void bsp_wdt_refresh(void)
{
en_result_t enRet = Error;
enRet = WDT_RefreshCounter();

if(enRet != Ok) {
    printf("Failed at function: %s, line: %d\n", __FUNCTION__, __LINE__);
}

}

上一篇:uboot的WATCHDOG_RESET()执行路径


下一篇:ltp-ddt wdt_test