Meanwhile, I wrote a simple application to test resolution timers in my system, using fuction "clock_getres" and the results are:
CLOCK_REALTIME: 0 s, 10000000 ns
CLOCK_MONOTONIC: 0 s, 10000000 ns
CLOCK_PROCESS_CPUTIME_ID: 0 s, 1 ns
CLOCK_THREAD_CPUTIME_ID: 0 s, 1 ns
Then, I wrote another simple application using "CLOCK_PROCESS_CPUTIME_ID" because I thought I could use the high resolution of this timer. You can see the code:
#define NSEC_PER_SEC 1000000000L
#define timerdiff(a,b) ((float)((a)->tv_sec - (b)->tv_sec) + \
((float)((a)->tv_nsec - (b)->tv_nsec))/NSEC_PER_SEC)
static struct timespec prev = {.tv_sec=0,.tv_nsec=0};
static int count = 5;
void handler( signo )
{
struct timespec now;
if(count >= 0)
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now);
printf("[%d]Diff time:%lf\n", count, timerdiff(&now, &prev));
prev = now;
count--;
}
else
{
exit(0);
}
}
int main(int argc, char **argv)
{
timer_t t_id;
struct itimerspec tim_spec;
tim_spec.it_value.tv_sec = 0;
tim_spec.it_value.tv_nsec = 1000000; //1ms
tim_spec.it_interval.tv_sec = 0;
tim_spec.it_interval.tv_nsec = 1000000; //1ms
if (timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &t_id))
perror("timer_create");
if (timer_settime(t_id, 0, &tim_spec, NULL))
perror("timer_settime");
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &prev);
signal(SIGALRM, handler);
while(1)
{
}
return 0;
}
But, when I execute the application, the result is 10ms, as you can see:
# ./TestTimers.flt
[5]Diff time:0.010000
[4]Diff time:0.010000
[3]Diff time:0.010000
[2]Diff time:0.010000
[1]Diff time:0.010000
[0]Diff time:0.010000
So, I don't know if I can obtain 1ms of resolution with this hardware (Coldfire MCF53017). Do I have to change the Kernel?
Thanks,
Patricia