- 5 #include <linux/module.h>
-
6 #include <linux/kernel.h>
-
7 #include <linux/delay.h>
-
8 #include <linux/jiffies.h>
-
9
-
10 struct timer_list timer;
-
11
-
12 static void timer_handle(unsigned long arg)
-
13 {
-
14 mod_timer(&timer, jiffies + HZ);
-
15 printk(" I am in timer\n");
-
16 }
-
17
-
18 static int __init test_init(void)
-
19 {
-
20
-
21 init_timer(&timer);
-
22 timer.function = &timer_handle;
-
23 timer.expires = jiffies + HZ;
-
24 add_timer(&timer);
-
25
-
26 printk("-------- test start ----------\n");
-
27 return 0;
-
28 }
-
29
-
30 static void __exit test_exit(void)
-
31 {
-
32 del_timer(&timer);
-
33 printk("-------- test over ----------\n");
-
34 return;
-
35 }
-
36
-
37 MODULE_LICENSE("GPL");
-
38
-
39 module_init(test_init);
-
40 module_exit(test_exit);
-
~
说明:
因为是以jiffies为计时单位,所以最低精度为1/HZ秒。如HZ=250,则精度为4ms.
Makefile内容:
1
2 name = test.o
3 #name ?= jprobe.o
4 obj-m := $(name)
5
6 KERNELDIR := /home/tangyt/tmp/linux-2.6-cloud/
7
8 ARCH = powerpc
9 CROSS_COMPILE = /home/tangyt/toolchain/powerpc-linux-gnu-
10 export ARCH CROSS_COMPILE
11 #export CC
12
13 default:
14 make -C $(KERNELDIR) M=$(shell pwd) modules
15
16
17 clean:
18 make -C $(KERNELDIR) M=$(shell pwd) clean
阅读(1257) | 评论(0) | 转发(0) |