23
Programming Watchdog Timer
Embedded and Industrial Computing
Appendix A
“ F81865_test Sleep
milliseconds\n”\
“\n”\
“Argement:\n”\
“ DIO_IN Read state from DIO
In.\n”\
“ DIO_OUT Set DIO Out state.\n”\
“ PIO Set PIO LED state.\n”\
“ RunLED Set RUN LED state.\n”\
“ AlarmLED Set Alarm LED state.\n”\
“ GPS_LED Set GPS LED state.\n”\
“ WirelessLED Set Wireless LED state.\n”\
“ Watchdog
Set
Watchdog timer.\n”\
“ CaseOpen Check case opened state.\n”\
“ CaseOpen_Clear Clear case open state.\n”\
“ port_number The port number.\n”\
“ value 1 for on and 0 for off.\n”\
“ seconds
The
watchdog count down seconds. 0 for disable.\n”\
“ milliseconds Milliseconds to
delay\n”
#define RETMSG(a,b) {printf (b) ; return a;}
#define
CHECK_ARGC(a)
{if
(argc
!=
a)
throw
PARAMETER_HELP
;}
// Translate
Hex
string
to
a
long
value
LONG
Hex2Long
(char
*str)
{
LONG
nLong
;
if
(scanf
(str, “%x”,
&nLong)
!=
1)
throw “Error parsing parameter\n” ;
return
nLong
;
}
//
Make
sure
the
argument
is
numeric
void
CheckNumeric
(char
*szBuf)
{
int
nLen
=
strlen
(szBuf)
;
for (int i = 0 ; i < nLen ; i++)
if (!strchr (“01234567890ABCDEFabcdef”, szBuf[i]) )
throw “Wrong argument\n” ;
}
// Common GPIO output function definition
#define GPIO_OUT(a,b,c)
\
int a (int argc, char *argv[])
\
{
\
CHECK_ARGC (4) ;
\
CheckNumeric (argv[2]) ;
\
CheckNumeric (argv[3]) ;
\
\
int nPort = atoi (argv[2]) ; \
int nValue = atoi (argv[3]) ;
\
\
c (nPort, nValue) ;
\
\
printf (b “ #%d = %d\n”, nPort, nValue) ;
\
\
return
0
;
\
}
// Function generate by common function definition
GPIO_OUT
(mDIO_
OUT
, “DIO_OUT”
, Write_DIO)
G
P
I
O
_
O
U
T
(mPIO
, “DIO_OUT”
, PIO)
G
P
I
O
_
O
U
T
(mRunLED
, “RunLED”
, RunLED)
G
P
I
O
_
O
U
T
(mAlarmLED
, “AlarmLED”
, AlarmLED)
GPIO_OUT
(mGPS_
LED
, “GPS_LED”
,
GPS_LED)