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 Time-out Interval Period - 
    • 計數 Watchdog Tick,計數的範圍由 2^4 到 2^18  
  • Watchdog Reset Delay Period
    • Watchdog 計數到 Timeout 後,可以選擇再經 3 / 18 / 130 / 1026 個 Watchdog Tick 啟動 Watchdog reset ( MCU cold reset )
  • Watchdog Reset Period
    • Watchdog reset MCU 的時序

Watchdog Timer Coding Flow

  • Enable Watchdog timer module
  • CLK_EnableModuleClock(WDT_MODULE);
    
  • Select Watchdog timer clock source
  • CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDTSEL_LIRC, 0);
  • Enable Watchdog timer interrupt
  • NVIC_EnableIRQ(WDT_IRQn);
    
  • Initialize Watchdog timeout interval periodic (2^14) and 18 Tick for Watchdog reset delay and start watchdog counting
  • /* Unlock protected registers */
    SYS_UnlockReg();
    WDT_Open(WDT_TIMEOUT_2POW14, WDT_RESET_DELAY_18CLK, TRUE, TRUE);
    /* Lock protected registers */
    SYS_LockReg();
    
  • Enable Watchdog interrupt 
  • /* Unlock protected registers */
    SYS_UnlockReg();
    WDT_EnableInt();
    /* Lock protected registers */
    SYS_LockReg();
    
  • Watchdog timer Interrupt Service
  • 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. 


範例程式位於 Github 的 nuvotoon-M451-Sample 的 FreeRTOS-Watchdog-Sample branch

Reference document :
  • nuvoton NuMicro-M451-Series-Training-Material
  • nuvoton TRM_M451_Series_EN_Rev2.08 

留言

這個網誌中的熱門文章

EC 所需知識 - SMBUS

EC 所需知識 - KBC

EC 所需知識 - LPC