⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 watchdog.c

📁 powerpc下watchdog驱动,支持tornado2.2
💻 C
字号:
/****************************************************************************
    File : watchdog.c

    实现了看门狗功能
****************************************************************************/

#include <vxworks.h>
#if ( CPU == PPC860 )
#include "ads852.h"
#include "m852reg.h"
#include "m852mask.h"
#else
#include "ads8260.h"
#include "m8260reg.h"
#include "m8260mask.h"
#endif
#include "base.h"
#include "watchdog.h"


int allow_feed_dog  ;
//   Function : init_watchdog
//Description : initial watchdog module ,config the pin type 
void init_watchdog   (void)
{        
    int immrVal = vxImmrGet();

    allow_feed_dog = 1 ;
#if ( HARDWARE_VERSION == 2 )  
    *PBPAR(immrVal) &= ~WATCHDOG_PIN; 
    *PBODR(immrVal) &= ~WATCHDOG_PIN;
    *PBDIR(immrVal) |=  WATCHDOG_PIN;
#elif ( HARDWARE_VERSION == 8 )  
    *M8260_PCPAR(immrVal) &= ~WATCHDOG_PIN; 
    *M8260_PCODR(immrVal) &= ~WATCHDOG_PIN;
    *M8260_PCDIR(immrVal) |=  WATCHDOG_PIN;
#elif ( HARDWARE_VERSION == 16 )  
    *M8260_PBPAR(immrVal) &= ~WATCHDOG_PIN; 
    *M8260_PBODR(immrVal) &= ~WATCHDOG_PIN;
    *M8260_PBDIR(immrVal) |=  WATCHDOG_PIN;
#endif
    /*先清一下狗*/
    feed_watchdog( ) ;
  
}

//  Functiion : reset_board
//Description : reset the system 
void reset_board     (void)
{
    allow_feed_dog = 0 ;
    enable_watchdog( ) ;
}

//  Functiion : enable_watchdog
//Description : enable watchdog 
void enable_watchdog (void)
{
    /*feed dog first , prevent once we enable it , borad is reset automatically*/
    feed_watchdog( );
    *EPLD_WATCHDOG_REG = WATCHDOG_ENABLE_MASK;
}

//  Functiion : disable_watchdog
//Description : disable watchdog
void disable_watchdog(void)
{
    *EPLD_WATCHDOG_REG = WATCHDOG_DISABLE_MASK;
}

//  Functiion : feed_watchdog
//Description : feed the watchdog , must be called every 0.8 second
void feed_watchdog   (void)
{
    int immrVal = vxImmrGet();

    if ( allow_feed_dog == 1 )
    {    
        /* 电平拉低拉高各一次 */
#if ( HARDWARE_VERSION == 2 )  
        *PBDAT(immrVal) &= ~WATCHDOG_PIN;
        *PBDAT(immrVal) |=  WATCHDOG_PIN;
#elif ( HARDWARE_VERSION == 8 )  
        *M8260_PCDAT(immrVal) &= ~WATCHDOG_PIN;
        *M8260_PCDAT(immrVal) |=  WATCHDOG_PIN;
#elif ( HARDWARE_VERSION == 16 )  
        *M8260_PBDAT(immrVal) &= ~WATCHDOG_PIN;
        *M8260_PBDAT(immrVal) |=  WATCHDOG_PIN;
#endif
    }    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -