#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/init.h>
#include <linux/timer.h>
static void test_1s_timer_fn(struct timer_list *data); // define timer function
// static void test_1s_timer_fn(unsigned long data); // define timer function,内部版本不同。function 不同。
static DEFINE_TIMER(test_1s_timer,test_1s_timer_fn); // init timer
// static DEFINE_TIMER(test_1s_timer,test_1s_timer_fn, 0, 0); // init timer,内核版本不同,对应的宏定义不同。
static void test_1s_timer_fn(struct timer_list *data)
{
printk("test_1s is ok\n");
printk("receive data from timer:%ld,\n", data->expires);
}
static int __init timer_init (void)
{
printk("start timer1 \n");
mod_timer(&test_1s_timer, jiffies+1*HZ); // 1*HZ=1s, 3HZ=3s
printk("start timer1_1 \n");
return 0;
}
static void __exit timer_exit (void)
{
del_timer_sync(&test_1s_timer);//stop timer
printk("timer exit\n");
}
module_init(timer_init);
module_exit(timer_exit);
MODULE_AUTHOR("tjg");
MODULE_LICENSE("GPL");
test timer测试
最新推荐文章于 2023-02-13 16:00:36 发布