在linux设备驱动编程中,可以利用linux内核中提供的一组函数和数据结构来完成定时触发工作或者完成某周期性的事物。
struct time_list{
struct list_head entry;
unsigned long expires;
void (*function)(unsigned long);
unsigned long data;
struct timer_base_s *base;
...
}
内核在时钟中断发生后执行检测各定时器是否到期,到期后的定时器处理函数将作为软中断在底半部执行。
当定时器期满后,function()成员将被执行,expires是定时器到期的时间。
1.初始化定时器
void init_timer(struct timer_list *timer);
初始化timer_list的entry的next为NULL,并给base指针赋值。
TIMER_INITIALIZER(_function,_expires,_data)宏用于赋值定时器结构体的function,expires,data和base成员。
2.增加定时器
void add_timer(struct timer_list *timer);
将定时器加到内核动态定时器链表中。
3.删除定时器
int del_timer(struct timer_list *timer);
int del_timer_sync(struct timer_list *timer);del_timer的同步版,不能发生在中断上下文中。
4.修改定时器的expires
int mod_timer(struct timer_list *timer,unsigned long expires);
用于修改定时器的到期时间。
2158

被折叠的 条评论
为什么被折叠?



