Forum Discussion
Altera_Forum
Honored Contributor
21 years agohi Scott,
Thank you, I tried your advice and it it pretty nice.. But I need timer with interrupt service, which will work as an interval timer and will call interrupt service routine each 20ms. I followed "KURT-Linux User Manual" especially UTIME library. In fact the programming from the user view is the same as for standard linux timer. UTIME library just increases the timer resolution on reasonable value - under 1ms. I suppose that in uClinux must be something similar implemented. I tried interval timer with this code:#include <signal.h># include <sys/time.h># include <stdio.h>
static int i=0;
void timer_handler(int signal)
{
printf("%d\n",i++);
}
void setitimer_test(int delay, int interval, int tries)
{
struct itimerval timer;
sigset_t mask;
struct sigaction action;
int i;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = interval;
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = delay;
sigemptyset(&mask);
action.sa_handler = timer_handler;
action.sa_flags = 0;
sigaction(SIGALRM, &action, 0);
setitimer(ITIMER_REAL, &timer, 0);
for (i = 0; i < tries; i++)
{
sigsuspend(&mask);
}
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 0;
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &timer, 0);
}
int main()
{
setitimer_test(500000,500000,1000);
} it generates interrupt after each 0.5 sec, but when I used my stopwatch and averaged through long time, I found, that the real time interval is about 0.96*0.5 sec, where 0.96 is some magic constant.. And even more it seems, that sometimes time intervals are not the same, sometimes shorter period, sometimes longer.. So, this did not impressed me so much, now I am trying to make timer kernel driver, also described in KURT manual, but it is a hard task for me, so wait a bit.. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif I wish to have direct access to NIOS2 high_res_timer defined in linux_1c20.ptf file. Is it possible?.. with regards jan.