clock_gettime

Discussion to talk about software related topics only.
Post Reply
hendrixj
Posts: 33
Joined: Thu Oct 23, 2008 11:39 am

clock_gettime

Post 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
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: clock_gettime

Post 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
hendrixj
Posts: 33
Joined: Thu Oct 23, 2008 11:39 am

Re: clock_gettime

Post 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;
}
Post Reply