Page 1 of 1

clock_gettime

Posted: Wed Dec 10, 2008 1:15 pm
by hendrixj
I'm using a MOD5270.
I need a high resolution clock (better than 1 millisecond).
It doesn't appear that clock_gettime is defined. (I included time.h, but compiler says 'not declared in this scope.')

Any ideas?

Thanks,
John

Re: clock_gettime

Posted: Wed Dec 10, 2008 2:06 pm
by Ridgeglider
use the PIT or the DMA timer. There are appnotes:
http://www.netburner.com/downloads/mod5 ... 70-PIT.pdf
http://www.netburner.com/downloads/mod5 ... -timer.pdf

Just be aware that PIT ch0 is used by uc/OS

Re: clock_gettime

Posted: Tue Dec 30, 2008 8:02 am
by hendrixj
How about this as clock_gettime where cid is CLOCK_REALTIME:

int clock_gettime(clockid_t cid, struct timespec *ts) {
static const DWORD PIT_CLICKS_PER_SECOND(TICKS_PER_SECOND*sim.pit[0].pmr);
ts->tv_sec = time(NULL);
DWORD pt = GetPreciseTime();
if (ts->tv_sec != time(NULL)) return 0; // error: time may not be coherent
ts->tv_nsec = (pt % PIT_CLICKS_PER_SECOND) * 1000000000ULL / PIT_CLICKS_PER_SECOND;
return 1;
}