根据别人的模块改的,不管怎么样,贴出来,大家指正。
//timer.c
#include
#include
#include
#include
#include
#define MODULE_NAME "MODULE_TIMER .. Maomao 's timer"
#define SUCCESS 0
#define CHECK_INTERVAL 2*HZ
struct timer_list mm_timer;
void mm_runtimer(void);
void mm_timeout(unsigned long ptr);
static int counter=0;
static __init int timer_init(void);
static __exit void timer_exit(void);
void mm_runtimer(void)
{
init_timer(&mm_timer);
mm_timer.function = mm_timeout;
mm_timer.data = counter++;
mm_timer.expires = jiffies+CHECK_INTERVAL;
add_timer(&mm_timer);
return;
}
void mm_timeout(unsigned long ptr)
{
printk("<0>,timer reach,jiffies=%lu,ptr=%lu\n",jiffies,ptr);
if(counter<5){
del_timer(&mm_timer);
mm_runtimer();
}
else{
printk("<0>%d times reach return\n",counter);
del_timer(&mm_timer);
return;
}
}
static __init int timer_init(void)
{
mm_runtimer();
return 0;
}
static __exit void timer_exit(void)
{
return ;
}
module_init(timer_init);
module_exit(timer_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("mm");
阅读(725) | 评论(0) | 转发(0) |