nuvoton - M451 Watchdog Timer
Watchdog Timer 特性
- 18 bits 上數的計數器
- 8 selections of timeout interval
- 2^(4 - 18)
- 4 selections of Watchdog reset delay period
- 3 / 18 / 130 / 1026 * TWDT
- 支援 watchdog timer interrupt
- 支援 watchdog timer reset
- 支援 watchdog wake-up
Watchdog Timer Clock Source
- LXT (32.768 KHz)
- PCLK0 / 2048
- LIRC (10 KHz)
Watchdog Timer Block Diagram
- WDT Time-out interrupt
- WDTEN(WDT_CTL[7]) = 0, enable WDT and start WDT counter.
- 8 Timeout interval selected by TOUTSEL(WDT_CTL[10:8]).
- WDT time-out set IF(WDT_CTL[3]) = 1, occur the WDT time-out interrupt.
- WDT Wake-up
- Clock source selected to LIRC or LXT
- WKEN(WDT_CTL[4]) enable
- WDT time-out interrupt to wake-up power-down system and WKF (WDT_CTL[5]) = 1
- WDT Reset Delay Period and Reset System
- RSTF (WDT_CTL[2]) keep 1 after WDT time-out reset
- RSTCNT (WDT_CTL[0]) to reset 18-bit WDT
- RSTDSEL (WDT_ALTCTL[1:0]) select reset delay
- RSTEN (WDT_CTL[1]) enable WDT reset
- RSTF (WDT_CTL[2]) =1 when WDT reset delay timeout.
Watchdog Timeout Interval and Reset Timing
Watchdog Timer Coding Flow
- Enable Watchdog timer module
CLK_EnableModuleClock(WDT_MODULE);
CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDTSEL_LIRC, 0);
NVIC_EnableIRQ(WDT_IRQn);
/* Unlock protected registers */
SYS_UnlockReg();
WDT_Open(WDT_TIMEOUT_2POW14, WDT_RESET_DELAY_18CLK, TRUE, TRUE);
/* Lock protected registers */
SYS_LockReg();
/* Unlock protected registers */
SYS_UnlockReg();
WDT_EnableInt();
/* Lock protected registers */
SYS_LockReg();
void WDT_IRQHandler(void)
{
if(g_u32WDTINTCounts < 10)
WDT_RESET_COUNTER();
if(WDT_GET_TIMEOUT_INT_FLAG() == 1)
{
/* Clear WDT time-out interrupt flag */
WDT_CLEAR_TIMEOUT_INT_FLAG();
g_u32WDTINTCounts++;
}
}
範例程式 :
在 FreeRTOS 中,加入一個 Task 來完成 Watchdog 中斷沒有立即完成的工作,平常 Task 位於 Suspend 的狀態,等 Watchdog 計算完成,叫醒 Task 再經數個 Watchdog Clock (N*0.1 second),就會啟動 Watchdog reset MCU.
Reference document :
- nuvoton NuMicro-M451-Series-Training-Material
- nuvoton TRM_M451_Series_EN_Rev2.08
留言
張貼留言