|
From: <jmk...@us...> - 2003-08-24 09:38:28
|
Update of /cvsroot/emc/rtapi/examples/watchdog
In directory sc8-pr-cvs1:/tmp/cvs-serv3121/examples/watchdog
Modified Files:
watchdog.c
Log Message:
Added module ID, now rtapi_exit() should remove all items allocated by the module. Added a mutex to protect RTAPI internal data from simultaneous access. Basic testing complete, needs more detailed testing.
Index: watchdog.c
===================================================================
RCS file: /cvsroot/emc/rtapi/examples/watchdog/watchdog.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** watchdog.c 16 Aug 2003 20:29:39 -0000 1.2
--- watchdog.c 24 Aug 2003 09:38:25 -0000 1.3
***************
*** 63,66 ****
--- 63,67 ----
#endif
+ static int module;
static int hi_task; /* the high priority task ID */
static int lo_task; /* the low priority task ID */
***************
*** 111,142 ****
int retval;
int prio;
rtapi_print_msg(RTAPI_MSG_INFO, "WATCHDOG: Installing watchdog\n");
! if (rtapi_init() != RTAPI_SUCCESS ) {
return -1;
}
! /* set the base timer period */
! retval = rtapi_clock_set_period(TIMER_PERIOD_NSEC);
! if ( retval < 0 ) {
! /* See rtapi.h for the error codes returned */
! rtapi_print_msg( RTAPI_MSG_ERR,
! "watchdog init: rtapi_clock_set_period returned %d\n", retval );
return -1;
}
/* low priority task first */
prio = rtapi_prio_lowest();
! lo_task = rtapi_task_new(lo_code, 0 /* arg */, prio, STACKSIZE, RTAPI_NO_FP );
if ( lo_task < 0 ) {
/* See rtapi.h for the error codes returned */
rtapi_print_msg( RTAPI_MSG_ERR,
"watchdog init: rtapi_task_new(lo) returned %d\n", lo_task );
return -1;
}
/* now the high priority task */
prio = rtapi_prio_highest();
! hi_task = rtapi_task_new(hi_code, 0 /* arg */, prio, STACKSIZE, RTAPI_NO_FP );
if ( hi_task < 0 ) {
rtapi_print_msg( RTAPI_MSG_ERR,
"watchdog init: rtapi_task_new(hi) returned %d\n", hi_task );
return -1;
}
--- 112,164 ----
int retval;
int prio;
+ long int period;
rtapi_print_msg(RTAPI_MSG_INFO, "WATCHDOG: Installing watchdog\n");
! module = rtapi_init("WATCHDOG");
! if ( module < 0 ) {
! rtapi_print( "watchdog init: rtapi_init returned %d\n", module );
return -1;
}
! /* is timer started? if so, what period? */
! period = rtapi_clock_set_period(0);
! if ( period == 0 ) {
! /* not running, start it */
! rtapi_print("watchdog init: starting timer with period %ld\n", TIMER_PERIOD_NSEC);
! period = rtapi_clock_set_period(TIMER_PERIOD_NSEC);
! if (period < 0) {
! rtapi_print("watchdog init: rtapi_clock_set_period failed with %ld\n",
! period);
! rtapi_exit(module);
! return -1;
! }
! }
! /* make sure period <= desired period (allow 1% roundoff error) */
! if ( period > (TIMER_PERIOD_NSEC+(TIMER_PERIOD_NSEC/100))) {
! /* timer period too long */
! rtapi_print("watchdog init: clock period too long: %ld\n", period );
! rtapi_exit(module);
return -1;
}
+ rtapi_print("watchdog init: desired clock %ld, actual %ld\n",
+ TIMER_PERIOD_NSEC, period );
/* low priority task first */
prio = rtapi_prio_lowest();
! lo_task = rtapi_task_new(lo_code, 0 /* arg */, prio, module,
! STACKSIZE, RTAPI_NO_FP );
if ( lo_task < 0 ) {
/* See rtapi.h for the error codes returned */
rtapi_print_msg( RTAPI_MSG_ERR,
"watchdog init: rtapi_task_new(lo) returned %d\n", lo_task );
+ rtapi_exit(module);
return -1;
}
/* now the high priority task */
prio = rtapi_prio_highest();
! hi_task = rtapi_task_new(hi_code, 0 /* arg */, prio, module,
! STACKSIZE, RTAPI_NO_FP );
if ( hi_task < 0 ) {
rtapi_print_msg( RTAPI_MSG_ERR,
"watchdog init: rtapi_task_new(hi) returned %d\n", hi_task );
+ rtapi_exit(module);
return -1;
}
***************
*** 146,149 ****
--- 168,172 ----
rtapi_print_msg( RTAPI_MSG_ERR,
"watchdog init: rtapi_task_start(lo) returned %d\n", retval );
+ rtapi_exit(module);
return -1;
}
***************
*** 152,155 ****
--- 175,179 ----
rtapi_print_msg( RTAPI_MSG_ERR,
"watchdog init: rtapi_task_start(hi) returned %d\n", retval );
+ rtapi_exit(module);
return -1;
}
***************
*** 186,190 ****
"watchdog exit: rtapi_task_delete(lo) returned %d\n", retval );
}
! rtapi_exit();
rtapi_print_msg(RTAPI_MSG_INFO, "WATCHDOG: Watchdog removed.\n");
}
--- 210,214 ----
"watchdog exit: rtapi_task_delete(lo) returned %d\n", retval );
}
! rtapi_exit(module);
rtapi_print_msg(RTAPI_MSG_INFO, "WATCHDOG: Watchdog removed.\n");
}
|