Chinaunix首页 | 论坛 | 博客
  • 博客访问: 790471
  • 博文数量: 118
  • 博客积分: 2067
  • 博客等级: 大尉
  • 技术积分: 1751
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-17 14:27
文章存档

2016年(1)

2013年(1)

2012年(3)

2011年(26)

2010年(47)

2009年(40)

分类: LINUX

2011-04-21 17:13:19

  1. 1
  2.   2 #include <linux/module.h>
  3.   3 #include <linux/kernel.h>
  4.   4 #include <linux/hrtimer.h>
  5.   5 #include <linux/jiffies.h>
  6.   6
  7.   7
  8.   8 static struct hrtimer timer;
  9.   9 ktime_t kt;
  10.  10
  11.  11 static enum hrtimer_restart hrtimer_handler(struct hrtimer *timer)
  12.  12 {
  13.  13 //kt = ktime_set(1, 10);
  14.  14 printk(" ------ I am in hrtimer -----\n");
  15.  15 hrtimer_forward(timer, timer->base->get_time(), kt);
  16.  16 return HRTIMER_RESTART;
  17.  17 }
  18.  18
  19.  19 static int __init test_init(void)
  20.  20 {
  21.  21
  22.  22 pr_info("timer resolution: %lu\n", TICK_NSEC);
  23.  23 kt = ktime_set(1, 10); /* 1 sec, 10 nsec */
  24.  24 hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  25.  25 //hrtimer_set_expires(&timer, kt);
  26.  26 hrtimer_start(&timer, kt, HRTIMER_MODE_REL);
  27.  27 timer.function = hrtimer_handler;
  28.  28
  29.  29 printk("\n-------- test start ---------\n");
  30.  30 return 0;
  31.  31 }
  32.  32
  33.  33 static void __exit test_exit(void)
  34.  34 {
  35.  35 hrtimer_cancel(&timer);
  36.  36 printk("-------- test over ----------\n");
  37.  37 return;
  38.  38 }
  39.  39
  40.  40 MODULE_LICENSE("GPL");
  41.  41
  42.  42 module_init(test_init);
  43.  43 module_exit(test_exit);
  44. ~

编译:

  2 name = test.o
  3 #name ?= jprobe.o
  4 obj-m := $(name)
  5
  6 KERNELDIR := /home/tangyt/tmp/linux-2.6-cloud.p1020/
  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

说明:
1.  40 MODULE_LICENSE("GPL");不可少,否则找不到相应的函数
2. 为了测试需要设置了1秒10纳秒延时,此处完全可以设置纳秒级的延时



阅读(11801) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~