Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Timers in vxworks

551 views
Skip to first unread message

Anuradha Pani

unread,
Jul 2, 2001, 12:19:44 PM7/2/01
to
hi,

i am new to vxworks and am trying to implement basic
timer routines. i'm not able to find any example code
which tells me how to handle any signal upon timer
expiry.

i'm able to create timers but am not able to proceed
further.

could anyone give me any pointers?

thanks in advance
anuradha

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Michel Hendriks

unread,
Jul 3, 2001, 8:51:10 AM7/3/01
to
Try this, it should work without modifications...
/*--------------------------------------------------------------------------
-
[TITLE] Demo
[FILE]
[VSN]
[CREATED]
[LASTCHNGD]
[COPYRIGHT] Copyright 2001 (C) CPS Europe B.V.
[AUTHOR] Michel Hendriks
[PURPOSE]
[NOTE]
---------------------------------------------------------------------------
-
[VERSION HISTORY]
[DATE] [WHO] [COMMENT]
---------------------------------------------------------------------------
-*/
/* Include
files ------------------------------------------------------------*/

#include <vxWorks.h> /* our OS */
#include <taskLib.h> /* task control */
#include <signal.h> /* signals */
#include <stdio.h> /* printf */
#include <sysLib.h> /* sysClkRateGet */
#include <timers.h> /* timers */
#include <logLib.h> /* logMsg */
#include <wdLib.h> /* watchdog routines */

/*
Constants ----------------------------------------------------------------*/

/* Type
Definitions ---------------------------------------------------------*/

/* External
data ------------------------------------------------------------*/

/* Public
data --------------------------------------------------------------*/

/* Private
vars -------------------------------------------------------------*/
static BOOL wait;
static WDOG_ID wdogId;

/* Compile time
checks ------------------------------------------------------*/

/* Prototyping for private
routines -----------------------------------------*/

/*
Implementation -----------------------------------------------------------*/

/*--------------------------------------------------------------------------
---
Description : WatchDog ISR handler
Parameters :
Globals Changed:
Returns :
----------------------------------------------------------------------------
-*/
static void watchDogISR(void)
{
logMsg( "timedemo: WatchDogISR called\n", 1, 2, 3, 4, 5, 6 );
}

/*--------------------------------------------------------------------------
---
Description : Signal handler for SIGALRM (Timer Handler)
Parameters :
Globals Changed:
Returns :
----------------------------------------------------------------------------
-*/
static void timerHandler
(
timer_t timerid, /* expired timer ID */
int arg /* user argument */
)
{
logMsg( "timedemo: Timer 0x%x expired (arg = 0x%x)\n", (int)timerid,
arg, 3, 4, 5, 6 );

wait = FALSE;
}

/*--------------------------------------------------------------------------
---
Description : Main entry for this demo
Parameters :
Globals Changed:
Returns : OK
----------------------------------------------------------------------------
-*/
STATUS timedemo( void )
{
timer_t timerId ; /* id for the posix timer */
struct itimerspec timeToSet ; /* time to be set */
STATUS retval = OK;

wait = TRUE;

/*
* Start POSIX timer demo
*/

/* Set the time to the desired value */
timeToSet.it_value.tv_sec = 5 ; /* initial (one shot) value
*/
timeToSet.it_value.tv_nsec = 0 ;
timeToSet.it_interval.tv_sec = 0 ; /* reload (repetitive) value
*/
timeToSet.it_interval.tv_nsec = 0 ;

if( timer_create( CLOCK_REALTIME, NULL, &timerId ) == ERROR )
{
perror( "timedemo: Error in creating the timer\n" );
retval = ERROR;
}

if( timer_connect( timerId, &timerHandler, 2) == ERROR )
{
perror( "timedemo: Error in connecting the timer\n" );
retval = ERROR;
}
else if( timer_settime( timerId, CLOCK_REALTIME, &timeToSet, NULL ) ==
ERROR )
{
perror( "timedemo: Error in setting the timer\n" );
retval = ERROR;
}
else
{
if ( taskDelay(sysClkRateGet() * 20) == ERROR )
{
perror( "timedemo: taskDelay expired early\n" );
retval = ERROR;
}

{
struct timespec time_delay;
struct timespec time_remaining;

time_delay.tv_sec = 2;
time_delay.tv_nsec = 500000000L;
if ( nanosleep( &time_delay, &time_remaining ) == ERROR )
{
perror( "timedemo: nanosleep expired early\n" );
retval = ERROR;
}
else
{
logMsg( "timedemo: nanosleep expired normally\n", 1, 2, 3,
4, 5, 6 );
}
}
/*
while ( wait )
{
}
*/
}
/* Cleanup */
if (timer_delete (timerId) == ERROR)
{
perror( "timedemo: Error in deleting the timer\n" );
retval = ERROR;
}

/*
* Start watchdog timer demo
*/

wdogId = wdCreate();
if ( wdogId == NULL )
{
perror( "timedemo: couldn't create watchdog\n" );
retval = ERROR;
}
else if ( wdStart( wdogId, sysClkRateGet() * 5, (FUNCPTR)watchDogISR,
0 ) == ERROR )
{
perror( "timedemo: couldn't start watchdog\n" );
retval = ERROR;
}
else
{
if ( taskDelay(sysClkRateGet() * 20) == ERROR )
{
perror( "timedemo: taskDelay expired early\n" );
retval = ERROR;
}
}
/* Cleanup */
if ( wdDelete( wdogId ) == ERROR )
{
perror( "timedemo: couldn't delete watchdog\n" );
retval = ERROR;
}
return( retval );
}

Anuradha Pani <buis...@yahoo.com> wrote in message
news:9hqa6u$ge6$1...@overload.lbl.gov...

0 new messages