1.头文件和变量定义

bool g_bFeedWatchdog = true;

#include "driverlib/watchdog.h"

2.初始化

    // Watchdog Init
    SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
    // Enable the watchdog interrupt.
    IntEnable(INT_WATCHDOG);
    // set the watchdog timer frequency
    WatchdogReloadSet(WATCHDOG0_BASE, SysCtlClockGet()/watchdog_freq);
    // watchdog timer reset enable
    WatchdogResetEnable(WATCHDOG0_BASE);
    // watchdog interrupt handler register
    WatchdogIntRegister(WATCHDOG0_BASE, WatchdogIntHandler);
    // enable watchdog timer
    WatchdogEnable(WATCHDOG0_BASE);

3.中断句柄

// watchdog interrupt 
void WatchdogIntHandler(void)
{
    // If the watchdog is not feeded timely, the watchdog timer flag will overflow, and then reset
    if(!g_bFeedWatchdog)  return;
    
    // clear the watchdog interrupt flag
    WatchdogIntClear(WATCHDOG0_BASE);
    
    // When the watchdog is running, the green led will twinkle
       if(GPIOPinRead(GREEN_LED_GPIO, GREEN_LED_PIN))    
    {
        GPIOPinWrite(GREEN_LED_GPIO, GREEN_LED_PIN, 0<<4);
    }
    else
    {
        GPIOPinWrite(GREEN_LED_GPIO, GREEN_LED_PIN, 1<<4);
    }
}

4.使用示例(main函数里面)

 if (Tempvalue>Temp_Threshold_high)
             {
                 g_bFeedWatchdog = false;
             }
             else if(Tempvalue<Temp_Threshold_low)
             {
                 g_bFeedWatchdog = false;
             }
             else
             {
                 g_bFeedWatchdog = true;
             }

 

posted on 2015-12-23 16:07  planet  阅读(1334)  评论(0编辑  收藏  举报