Guys,
I have setup an interrupt that would fire every 20ms, but is acting very random, below is my code:
I call interruptInit() from Main to run it, and is just acting very random.
/********************************************************/
/* Function: interruptInit(void) */
/* Interrupt 20ms. INTERVAL_TIME_RESOLUTION sets the */
/* time. The variable comes from rs485.c */
/********************************************************/
void interruptInit(void) {
struct sigaction sa;
struct itimerval timer;
timerStatus = TRUE;
memset (&sa, 0, sizeof (sa));
sa.sa_handler = &timer_handler;
//sigaction (SIGALRM, &sa, NULL);
sigaction (SIGPROF, &sa, NULL);
//Mutiply by 1,000 to make it 20ms
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = INTERVAL_TIME_RESOLUTION * 1000;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = INTERVAL_TIME_RESOLUTION * 1000;
//setitimer (ITIMER_REAL, &timer, NULL);
setitimer (ITIMER_PROF, &timer, NULL);
}
/********************************************************/
/* Function: timer_handler (int sinum) */
/* Handles the interrupt */
/* */
/********************************************************/
void timer_handler (int sinum) {
if (timerStatus == TRUE) {
onInterval();
}
}