用
int jiffies_to_msecs(const unsigned long j) 将 jiffies 类型的参数 j 分别转换为对
int jiffies_to_usecs(const unsigned long j) 应的毫秒、 微秒、 纳秒。
u64 jiffies_to_nsecs(const unsigned long j)
将毫秒、 微秒、 纳秒转换为 jiffies 类型。
long msecs_to_jiffies(const unsigned int m)
long usecs_to_jiffies(const unsigned int u)
unsigned long nsecs_to_jiffies(u64 n)
void init_timer(struct timer_list *timer) 初始化定时器
void add_timer(struct timer_list *timer) 向 Linux 内核注册定时器
int del_timer(struct timer_list * timer) 删除一个定时器
int del_timer_sync(struct timer_list
*timer)
等待其他处理器使用完定时器再删除
int mod_timer(struct timer_list *timer,
unsigned long expires)
修改定时值, 如果定时器还没有激活的
话, mod_timer 函数会激活定时器
模板
1 struct timer_list timer; /* 定义定时器 /
2 3
/ 定时器回调函数 /
4 void function(unsigned long arg)
5 {
6 /
7 * 定时器处理代码
8 /
9 1
0 / 如果需要定时器周期性运行的话就使用 mod_timer
11 * 函数重新设置超时值并且启动定时器。
12 /
13 mod_timer(&dev->timertest, jiffies + msecs_to_jiffies(2000));
14 }北京迅为电子有限公司 i.MX6ULL 终结者-开发板使用手册
日期:2020-03-17 1072 www.topeetboard.com
15
16 / 初始化函数 /
17 void init(void)
18 {
19 init_timer(&timer); / 初始化定时器 /
20
21 timer.function = function; / 设置定时处理函数 /
22 timer.expires=jffies + msecs_to_jiffies(2000);/ 超时时间 2 秒 /
23 timer.data = (unsigned long)&dev; / 将设备结构体作为参数 /
24
25 add_timer(&timer); / 启动定时器 /
26 }
27
28 / 退出函数 /
29 void exit(void)
30 {
31 del_timer(&timer); / 删除定时器 /
32 / 或者使用 */
33 del_timer_sync(&timer);
34 }