/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
#ifdef VXWORKS_CFG

#include "../h/cdefs.h"
#include "../h/rciConfig.h"
#include "../h/rciTask.h"

extern int rciCpu;
extern int rciClockCount;

int rciTimeInitDone = NO;
double clockRes;
int *clockAddr = NULL; 	/* XXX -- do we need to init this? */

rciTimeInit (addr, res)
int *addr;
double res;
{
	clockRes = res;
	clockAddr = addr;	
	rciTimeInitDone = rciCpu;
	requestFlagInit(&rciTimeInitDone);
}

rciTime ()
{
	if (rciTimeInitDone != rciCpu || clockAddr == NULL)
	 { return (0);
	 }
	else
	 { return ((*clockAddr) * clockRes);
	 }
}

float rciTimeInterval()
{
	return (clockRes);
}

rciGetClock(num)
{
	return (rciClockCount);
}

rciSetClock(num, count)
int num, count;
{
	rciClockCount = count;
}

rciStartClock (incumbent, newRes, oldRes)
int incumbent;
float newRes, oldRes;
{
	int setcount;

	if (incumbent == UNDEF)
	 { setcount = 0;
	 }
	else
	 { setcount = rciClockCount * (oldRes/newRes);
	 }
	rciClockCount = setcount;
	rciTimeInit (&rciClockCount, newRes);
	return (setcount);
}

rciExportClock (targetCpu, code)
int targetCpu, code;
{
	/* not currently implemented */
}

rciImportClock (cpu, res, reInitialize)
int cpu;
double res;
int reInitialize;
{
	rciTimeInit (&rciClockCount, res);
}

#endif
