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
clock_gettime
-
- Posts: 513
- Joined: Sat Apr 26, 2008 7:14 am
Re: clock_gettime
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
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
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;
}
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;
}