zoukankan      html  css  js  c++  java
  • 单片机TM4C123学习(六):看门狗

    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;
                 }
  • 相关阅读:
    mysql 函数在源码中的定义
    mydumper工作原理 :myownstars专家
    drop table big_table 调试
    debugfs恢复文件
    Linux内核里的DebugFS
    在Linux环境中使用Ext3文件系统
    strace
    通过blktrace, debugfs分析磁盘IO
    block_dump观察Linux IO写入的具体文件(mysqld)
    Centos下的IO监控与分析
  • 原文地址:https://www.cnblogs.com/pursuit1996/p/5070256.html
Copyright © 2011-2022 走看看