?? watchdog.c
字號:
/*
* Copyright (c) 2004, 2005 Koninklijke Philips Electronics N V. Includes code
* copyright (c) 2004 by VCom Electronics Inc; copyright transferred by verbal
* agreement between Tim Meakin and Jonathan Coxhead, November 2004. All rights
* reserved.
*
* This source code and any compilation or derivative thereof is the proprietary
* information of Koninklijke Philips Electronics N V and is confidential in
* nature. Under no circumstances is this software to be exposed to or placed
* under an Open Source License of any type without the express written
* permission of Koninklijke Philips Electronics N V.
*
* #############################################################################
*
* Module: %name: watchdog.c % %version: 1 %
*
* %date_created: Fri Mar 11 11:55:33 2005 % %created_by: jcoxhead %
*
* %date_modified: Fri Jun 14 11:31:56 2002 %
*
* #############################################################################
*/
/* --------------------------------------------------------------------------
*
* DESCRIPTION: Controls the Watchdog timer
*
* ------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include <tmNxCompId.h>
#include <tmosal.h>
#include <tmbslCore.h>
#include <tsaClock.h>
#include <tmArith.h>
#include <tmMainStreaming.h>
#include <tmDbg.h>
#include <tmdlWatchdog.h>
#include "tmalDemuxMpegTS.h"
#include "watchdog.h"
//---------------------------------------------------------------------------
// Defines and Macros
//---------------------------------------------------------------------------
#define TASK_SMALL_SLEEP_MS 10
//---------------------------------------------------------------------------
// Global Data
//---------------------------------------------------------------------------
#ifdef USE_WATCHDOG_TIMER
static tmInstance_t watchdogInst = 0;
#endif // USE_WATCHDOG_TIMER
#ifdef PRINT_RUNNING_TIME
static Int gClock = 0;
#endif // PRINT_RUNNING_TIME
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
tmErrorCode_t
initWatchdog(
Int clock )
{
tmErrorCode_t rval = TM_OK;
#ifdef USE_WATCHDOG_TIMER
tmSWVersion_t SWVersion;
const tmdlWatchdog_Capabilities_t *pCaps;
tmdlWatchdog_InstanceSetup_t *pSetup;
Bool isRunning = False;
#endif // USE_WATCHDOG_TIMER
DBG_ISR_PRINT( (dbgTsDemux, DBG_INTERNAL_ENTER, "initWatchdog") )
#ifdef USE_WATCHDOG_TIMER
ERRCHK( tmdlWatchdog_GetSWVersion( &SWVersion ) )
ERRCHK( tmdlWatchdog_GetCapabilities( &pCaps ) )
ERRCHK( tmdlWatchdog_Open( &watchdogInst ) )
ERRCHK( tmdlWatchdog_GetInstanceSetup( watchdogInst, &pSetup ) )
// Watchdog will reset board in 5 seconds if not fed
pSetup->mode = tmdlWatchdog_Noninterrupt;
pSetup->setup.noninterrupt.ticksToReset = pCaps->tickFreq * 10;
ERRCHK( tmdlWatchdog_InstanceSetup( watchdogInst, pSetup ) )
ERRCHK( tmdlWatchdog_SetEventMask( watchdogInst, TMDL_WATCHDOG_EVENT_ALL ) )
ERRCHK( tmdlWatchdog_Start( watchdogInst ) )
ERRCHK( tmdlWatchdog_QueryRunning( watchdogInst, &isRunning ) )
if ( !isRunning )
{
rval = TM_ERR_NOT_STARTED;
goto _return;
}
#endif // USE_WATCHDOG_TIMER
#ifdef PRINT_RUNNING_TIME
gClock = clock;
#else
// Remove compiler warning about unused parameters
clock = clock;
#endif // PRINT_RUNNING_TIME
_return:
DBG_ISR_PRINT( (dbgTsDemux, DBG_INTERNAL_LEAVE, "initWatchdog") )
return( rval );
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void
watchdogTask(
pVoid pArgs )
{
DBG_ISR_PRINT( (dbgTsDemux, DBG_INTERNAL_ENTER, "watchdogTask") )
// Remove compiler warning about unused parameters
pArgs = pArgs;
for ( ;; )
{
#ifdef USE_WATCHDOG_TIMER
// Feed the Watchdog (reset the timer before it expires and resets the board)
ERRCHK( tmdlWatchdog_Feed( watchdogInst ) )
#endif // USE_WATCHDOG_TIMER
// Check if we have been ordered to kill ourself
if ( bKillWatchDogTask )
{
#ifdef USE_WATCHDOG_TIMER
ERRCHK( tmdlWatchdog_Close( watchdogInst ) )
#endif // USE_WATCHDOG_TIMER
DBG_ISR_PRINT( (dbgTsDemux, DBG_LEVEL_1,
"watchdogTask: Received kill signal, exiting") )
tmosalTaskExit();
}
#ifdef PRINT_RUNNING_TIME
dbgPrintRunningTime( gClock, DBG_LEVEL_4, 60 );
#endif // PRINT_RUNNING_TIME
tmosalTaskSleep( TASK_SMALL_SLEEP_MS );
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
/*
* Function : print out how long the video has been running for
* Parameters : clock: instance of the tsaClock
* dbgLevel: which debug level the running time should
* be displayed at.
* refreshRate: how often, in seconds, the clock is displayed
* Function Result : In dpDump, the current running time is displayed in
* hours, minutes, seconds, and days.
*/
void
dbgPrintRunningTime(
Int clock,
UInt32 dbgLevel,
Int refreshRate )
{
tmTimeStamp_t time;
UInt32 lo_ticks = 0;
UInt32 maxIntSize = 0xFFFFFFFF;
static Float partOfaSecond = 0.0;
static UInt32 seconds = 0;
static UInt32 minutes = 0;
static UInt32 hours = 0;
static UInt32 days = 0;
static UInt32 prevTime = 0;
static UInt32 refreshSeconds = 0;
tsaClockGetTime( clock, &time );
lo_ticks = U64LOCASTU32( time );
#if 0
if ( prevTime == 0 )
{
prevTime = lo_ticks;
return;
}
#endif
partOfaSecond += (lo_ticks > prevTime) ?
(((Float)lo_ticks - (Float)prevTime) / 90000.0) :
((((Float)maxIntSize - (Float)prevTime) +
(Float)lo_ticks) / 90000.0);
if ( lo_ticks < prevTime )
{
DBG_ISR_PRINT( (dbgTsDemux, dbgLevel,
"*****************************CLOCK*******WRAPPED*******"
"***************************************************") )
DBG_ISR_PRINT( (dbgTsDemux, dbgLevel,
"*****************************CLOCK*******WRAPPED*******"
"***************************************************") )
}
while ( partOfaSecond >= 1.0 )
{
seconds++;
refreshSeconds++;
partOfaSecond -= 1.0;
}
while ( seconds >= 60 )
{
minutes++;
seconds -= 60;
}
while ( minutes >= 60 )
{
hours++;
minutes -= 60;
}
while ( hours >= 24 )
{
days++;
hours -= 24;
}
if ( refreshSeconds >= refreshRate )
{
DBG_ISR_PRINT( (dbgTsDemux, dbgLevel,
"Current Running Time (dd:hh:mm:ss) is %02d:%02d:%02d:%02d",
days, hours, minutes, seconds) )
refreshSeconds = 0;
}
prevTime = lo_ticks;
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -