最近在基于linux4的版本开发驱动,使用到timer模块,遂到网上找参考的使用例子。
发现几乎都是基于2.x版本的内核的使用例子,而linux4上的timer结构体已经和原来完全不同了,无法直接使用。
新版本的timer_list结构体如下所示:
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
* same cacheline
*/
struct hlist_node entry;
unsigned long expires;
void (*function)(struct timer_list *);
u32 flags;
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
具体的使用方法如下:
定义:
static void timer_function(struct timer_list * tl)
{
(void)tl;
//add yourself codes here
mod_timer(&jpeg_timer, jiffies + msecs_to_jiffies(10));
}
static DEFINE_TIMER(timer, timer_function);
初始化:
timer_setup(&timer, timer_function, 0);
去初始化:
del_timer(&timer);