watchdog.c

来自「IT projecotr reference design.」· C语言 代码 · 共 83 行

C
83
字号
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      All Rights Reserved.                                                */
/*                                                                          */
/*  Property of Texas Instruments Incorporated. Restricted Rights -         */
/*  Use, duplication, or disclosure is subject to restrictions set          */
/*  forth in TI's program license agreement and associated documentation.   */
/****************************************************************************/

/****************************************************************************/
/* watchdog.c                                                               */
/*                                                                          */
/* Watchdog monitor.                                                        */
/****************************************************************************/

#include "common.h"
#include "gpio.h"
#include "tmr.h"

#include "global.h"
#include "watchdog.h"
#include "dbmessage.h"



/****************************************************************************/
/*Local data.                                                               */
/****************************************************************************/

static BOOL isEnabled;                          /* watchdog-is-enabled flag */



/****************************************************************************/
/* Watchdog enable/disable.                                                 */
/****************************************************************************/

BOOL watchdog_enable( BOOL enable )
{
    if( TRUE == ( isEnabled = ( enable && gpConfiguration -> System.EnableWatchdog )))
        return PASS == TMR_SetWatchdog( gpConfiguration -> System.WatchdogInterval );

    TMR_SetWatchdog( 0 );                               /* disable watchdog */
    
    return TRUE;
}



/****************************************************************************/
/* Module reset function.                                                   */
/*                                                                          */
/* id:   reset type.                                                        */
/*                                                                          */
/* The API does not allow the watchdog timer to be allocated but disabled - */
/* Disabling the timer (setting its period to zero) frees the timer. Thus,  */
/* the watchdog timer cannot be allocated here, and the application must    */
/* ensure that the watchdog timer is not allocated as an interval timer.    */
/****************************************************************************/

EXEC_CC_ENUM watchdog_init( void )
{
    isEnabled = FALSE;                         /* indicates watchdog is off */

    return EXEC_CC_PASS;
}



/****************************************************************************/
/* Periodic polling callback function.                                      */
/****************************************************************************/

int16 watchdog_poll( uint16 tick )
{
    if( isEnabled )
        TMR_ServiceWatchdog();                         /* ping the watchdog */
        
    return 100 / RTOS_MS_PER_TICK;
}

⌨️ 快捷键说明

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