Timer in Linux Device Driver

来源:互联网 发布:java进销存管理系统 编辑:程序博客网 时间:2024/05/16 18:50

Timer in Linux Device Driver

 

    Recently, I am debugging the Audio driver on Atmel AT91SAM9M10 with Linux-2.6.30 kernel version. The detail information as following.

    Hardware: AT91SAM9M10, TLV320AIC3100, interface between them: Atmel SSC (I2S)

    Software: Linux 2.6.30

    Objective: using software to implement the exchange between headset and speaker

 

    As the hardware design, there is no interrupt line can be connect to CPU, so using polling method to solve it. Then, the linux timer (define in include/linux/time.h) is be used.

 

    The following is the example code:

++++++++++++++++++++++++++++

struct timer_list mytimer;

 

init_timer(&mytimer);

mytimer.expires = jiffies + HZ/1000; // jiffies define in include/linux/jiffies.h

mytimer.data = (unsigned long) codec;

mytimer.function = headset_det_task;

add_timer(&mytimer);

++++++++++++++++++++++++++++

 

The "headset_det_task" function as following

++++++++++++++++++++++++++++

int headset_det_task(unsigned long data)

{
   ... ...

   mod_timer(&mytimer, jiffies + HZ); /* re-open the timer */

}

++++++++++++++++++++++++++++

 

 

In my mind, this function also can be implemented by kernel thread function. So this need to be go study.

 

TODO:  

原创粉丝点击