From: <jmk...@us...> - 2003-07-23 01:22:52
|
Update of /cvsroot/emc/rtapi/examples/timertask In directory sc8-pr-cvs1:/tmp/cvs-serv23441/examples/timertask Modified Files: timertask.c Log Message: changed examples to use new api - fifo not working yet Index: timertask.c =================================================================== RCS file: /cvsroot/emc/rtapi/examples/timertask/timertask.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** timertask.c 22 Jul 2003 17:20:22 -0000 1.2 --- timertask.c 23 Jul 2003 01:22:49 -0000 1.3 *************** *** 9,19 **** #include "rtapi_app.h" /* rtapi_app_main,exit() */ ! static void *timer_task = 0; /* pointer to the task structure */ static int timer_count = 0; /* the output variable */ enum { TIMER_PERIOD_NSEC = 1000000 }; /* timer period, in nanoseconds */ enum { TIMER_STACKSIZE = 1024 }; /* how big the stack is */ ! /* task code, executed each timer interrupt */ ! static void timer_code(int t) { while (1) { --- 9,18 ---- #include "rtapi_app.h" /* rtapi_app_main,exit() */ ! static rtapi_task_handle timer_task; /* the task */ static int timer_count = 0; /* the output variable */ enum { TIMER_PERIOD_NSEC = 1000000 }; /* timer period, in nanoseconds */ enum { TIMER_STACKSIZE = 1024 }; /* how big the stack is */ ! static void timer_code( int arg ) { while (1) { *************** *** 28,65 **** int rtapi_app_main(void) { int timer_prio; - int ret_val; if (0 != rtapi_app_init()) { return -1; } /* set the base timer period */ ! rtapi_clock_set_period(TIMER_PERIOD_NSEC); /* set the task priority to lowest, since we only have one task */ timer_prio = rtapi_prio_lowest(); ! /* launch the timer task */ ! // timer_task = rtapi_task_new(); ! ret_val = rtapi_task_new(&timer_task); ! if (0 != ret_val) { ! rtapi_print("timertask: can't allocate timer task %d\n", ret_val); ! return -1; ! } ! ! if (timer_task == NULL) { ! rtapi_print("timertask: Pointer returned is NULL\n"); return -1; } ! ret_val = rtapi_task_start(timer_task, timer_code, 0, timer_prio, TIMER_STACKSIZE, TIMER_PERIOD_NSEC, 0); ! ! if (0 != ret_val ) { ! rtapi_print("timertask: can't start timer task %d\n", ret_val); return -1; } ! rtapi_print("timertask: started timer task\n"); return 0; --- 27,66 ---- int rtapi_app_main(void) { + int retval; int timer_prio; + /* init is still in a state of change - right now this isn't needed if (0 != rtapi_app_init()) { return -1; } + */ /* set the base timer period */ ! retval = rtapi_clock_set_period(TIMER_PERIOD_NSEC); ! if ( retval != RTAPI_SUCCESS ) { ! rtapi_print( "timertask init: rtapi_clock_set_period returned %d\n", retval ); ! return -1; ! } /* set the task priority to lowest, since we only have one task */ timer_prio = rtapi_prio_lowest(); ! /* create the timer task */ ! retval = rtapi_task_new( &timer_task ); ! if ( retval != RTAPI_SUCCESS ) { ! rtapi_print( "timertask init: rtapi_task_new returned %d\n", retval ); return -1; } ! retval = rtapi_task_start( timer_task, timer_code, ! 0, timer_prio, ! TIMER_STACKSIZE, ! TIMER_PERIOD_NSEC, RTAPI_NO_FP ); ! if ( retval != RTAPI_SUCCESS ) { ! rtapi_print("timertask init: rtapi_task_start returned %d\n", retval ); return -1; } ! rtapi_print( "timertask init: started timer task\n" ); return 0; *************** *** 69,83 **** void rtapi_app_exit(void) { ! if (0 != timer_task) { ! if (0 != rtapi_task_stop(timer_task)) { ! rtapi_print("timertask: can't stop timer task\n"); ! } ! if (0 != rtapi_task_delete(timer_task)) { ! rtapi_print("timertask: can't delete timer task\n"); ! } ! timer_task = 0; } ! rtapi_print("timertask: timer count is %d\n", timer_count); rtapi_app_return(); --- 70,87 ---- void rtapi_app_exit(void) { ! int retval; ! ! retval = rtapi_task_stop(timer_task); ! if ( retval != RTAPI_SUCCESS ) { ! rtapi_print("timertask exit: rtapi_task_stop returned %d\n", retval ); ! return; ! } ! retval = rtapi_task_delete( timer_task ); ! if ( retval != RTAPI_SUCCESS ) { ! rtapi_print("timertask exit: rtapi_task_delete returned %d\n", retval ); ! return; } ! rtapi_print("timertask exit: timer count is %d\n", timer_count); rtapi_app_return(); |