38
Programming Watchdog Timer
Embedded and Industrial Computing
Appendix D
// Clear case open state
int mCaseOpen_Clear (int argc, char* argv[])
{
CHECK_ARGC (2) ;
CaseOpen_Clear () ;
BOOL bOpen = CaseOpen () ;
printf (“CaseOpen state %s”, bOpen ? “not cleared”
: “cleared”) ;
return bOpen ;
}
// Get DIO_IN state
int
mDIO_IN
(int
argc,
char*
argv[])
{
CHECK_ARGC (3) ;
CheckNumeric (argv[2]) ;
int nPort = atoi (argv[2]) ;
BOOL ret = Read_DIO (nPort) ;
printf (“DIO_IN #%d = %d\n”, nPort, ret) ;
return
ret
;
}
// Milli-second delay
int mSleep (int argc, char *argv[])
{
CHECK_ARGC (3) ;
CheckNumeric (argv[2]) ;
Sleep (atoi (argv[2]) ) ;
return 0 ;
}
// Watchdog
int mWatchDog (int argc, char *argv[])
{
if (argc != 3 && argc != 2)
RETMSG (-1, PARAMETER_HELP) ;
if (argc == 3)
{
CheckNumeric (argv[2]) ;
int nValue = atoi (argv[2]) ;
WatchDog_Enable (nValue) ;
}
int nLeft = WatchDog_GetLeft () ;
printf (“Watchdog timer left %d seconds\n”, nLeft)
;
return nLeft ;
}
// Argument - function mapping
typedef struct
{
char *szCmd ;
int (*function) (int argc, char *argv[]) ;
} CMD2FUN ;