Posts

Showing posts from July, 2009

Using Timers in Linux kernel module

Image
Linux kernel timer tutorial
This is a tutorial for using timer in linux kernel module. we all need one function to be called periodically say 500ms,1s to do so some task periodically(like GPIO polling, sending some message to user space etc)

As any system/OS, we need to initialize the timer module before we can use it. We need to give a name for the timer(for us to configure and restart the timer), timer function handler(ie.when timer expires this function will be called). One important thing to be noted is after timer expires it wont restart the timer automatically, it has to be restarted manually to get the next timer expiry.

The timer implementation resides in and kernel/timer.c

The timer study program is as shown below. In the module init we are initializing the timer with the the timer expiry routine(timer1_routine), data to be passed when the routing is called(in my example 1) , the timer expiry in jiffies. these are the minimum initialization we need to do with the timer stru…