[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Timer Interrupt


I'm not sure if this is as accurate as you might want but it worked for a 
I was working on.  This function which I found on the Internet is the 
version of the alarm function.  It might be supported on some of the later 
glibc versions
of the dev board, but I cannot confirm this... you will definately need it 
in the
older uClibc versions of the devboard.

unsigned int ualarm(unsigned int value, unsigned int interval)
  struct itimerval oldtv, newtv;
  newtv.it_interval.tv_usec = (long int)interval;
  newtv.it_interval.tv_sec = 0;
  newtv.it_value.tv_usec = (long int)value;;
  newtv.it_value.tv_sec = 0;
  if (setitimer (ITIMER_REAL, &newtv, &oldtv) < 0)
    return 0;
    return oldtv.it_value.tv_sec; 

To use this, you will need to catch the SIGALRM signal.

e.g. To set up a 5 millisecond timer to call the function "alarm_handler", 
place this
code somewhere in your main code.

  struct sigaction new_alrm_action, old_alrm_action;
  new_alrm_action.sa_handler = alarm_handler;
  sigemptyset (&new_alrm_action.sa_mask);
  new_alrm_action.sa_flags = 0;
  sigaction (SIGALRM, NULL, &old_alrm_action);
  if (old_alrm_action.sa_handler != SIG_IGN)
      sigaction (SIGALRM, &new_alrm_action, NULL);
  ualarm(5000, 5000);  // set up 5 millisecond timer

I hope this works for you.


Matt Hook

Claudius Moor <Claudius.Moor@xxxxxxx.de>
Sent by: owner-dev-etrax@xxxxxxx.com
09/08/01 12:43 AM

        To:     dev-etrax <dev-etrax@xxxxxxx.com>
        Subject:        Timer Interrupt


I have to execute a function every 10 ms and tried to register the
function for the timer interrupt. I added the code below to the
gpio-driver, but my counter does not increase and the debug message is
not written out to COM2.

Does anyone know, what I am doing wrong? Is it the right way to call a
function every 10 ms on the Dev.Board or is there a better solution?

Thanks for your help


(I am still using kernel-2.4.3, Cris compiler 1.11 and Devboard_lx


static int TimerIntrpt = 0;

static void spi_intrpt(void *);

static struct tq_struct Task = {

static void spi_intrpt(void *irrelevant)

// sampled_value = read_a_d(...);
   if (TimerIntrpt = 100)
      printk("**** couter = 100 ****\n");
   queue_task(&Task, &tq_timer);

static int
gpio_open(struct inode *inode, struct file *filp)

   /* registering function */
   queue_task(&Task, &tq_timer);

   return 0;