/*****************************************************************************/
/* Copyright 1995 to 1996 MBARI                                              */
/*****************************************************************************/
/* Summary  : Wrapper functions for VxWorks timers                           */
/* Filename : timers.c                                                       */
/* Author   : Andrew Pearce                                                  */
/* Project  : Tiburon                                                        */
/* Version  : Version 1.0                                                    */
/* Created  : 02/08/96                                                       */
/* Modified : 02/08/96                                                       */
/* Archived :                                                                */
/*****************************************************************************/
/* Modification History:                                                     */
/* $Header:$
 * $Log:$
  */
/*****************************************************************************/

#include <vxWorks.h>                /* vxWorks system declarations           */
#include <systime.h>                /* vxWorks time and date functions       */
#include <timers.h>                 /* vxWorks timer library                 */

#include <mbariTypes.h>             /* MBARI style guide type declarations   */
#include <mbariConst.h>             /* Miscellaneous constants               */
#include <timerWrap.h>              /* Wrapper functions for vxWorks timers  */

#define TIMER_RELTIME   ~TIMER_ABSTIME

/*****************************************************************************/
/* Function    : startIntervalTimer                                          */
/* Purpose     : Start a vxWorks POSIX timer in one-shot timer mode          */
/* Inputs      : timer data structure                                        */
/* Outputs     : NONE                                                        */
/*****************************************************************************/
    Void
startIntervalTimer( timer_t timer, long secs, long nsec )
{
    struct itimerspec  timerSpec;

    timerSpec.it_value.tv_sec     = secs;
    timerSpec.it_value.tv_nsec    = nsec;
    timerSpec.it_interval.tv_sec  = 0;
    timerSpec.it_interval.tv_nsec = 0;

    timer_settime( timer, TIMER_RELTIME, &timerSpec, NULL);
} /* startIntervalTimer() */

/*****************************************************************************/
/* Function    : startPeriodiclTimer                                         */
/* Purpose     : Start a vxWorks POSIX timer for peroidic mode               */
/* Inputs      : timer data structure                                        */
/* Outputs     : NONE                                                        */
/*****************************************************************************/
    Void
startPeriodicTimer( timer_t timer, long secs, long nsec )
{
    struct itimerspec  timerSpec;

    timerSpec.it_value.tv_sec     = 1;
    timerSpec.it_value.tv_nsec    = 0;
    timerSpec.it_interval.tv_sec  = secs;
    timerSpec.it_interval.tv_nsec = nsec;

    timer_settime( timer, TIMER_RELTIME, &timerSpec, NULL);
} /* startPeriodicTimer() */

/****************************************************************************/

#if 0
/************************************************************************/
/* Function    : gettimeofday                                           */
/* Purpose     : Unix-compatible function to get time in usecs          */
/* Inputs      : Ptr to struct timeval, ptr to struct timezone          */
/* Outputs     : 0                                                      */
/************************************************************************/
    int
gettimeofday( struct timeval *tp, struct timezone *tzp )
{
    if ( tp != (struct timeval *)0 )
    {
        tp->tv_sec = 0;
        tp->tv_usec = 0;
    }

    if ( tzp != (struct timezone *)0 )
    {
        tzp->tz_minuteswest = 0;
        tzp->tz_dsttime = 0;
    }
    return( 0 );
} /* gettimeofday() */

#endif






