现在的位置: 首页 > 综合 > 正文

Timer in Linux Device Driver

2013年07月25日 ⁄ 综合 ⁄ 共 1040字 ⁄ 字号 评论关闭

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:  

抱歉!评论已关闭.