linux内核定时器使用

来源:互联网 发布:淘宝还没收货怎么评价 编辑:程序博客网 时间:2024/03/29 20:52

//加入头文件

#include <linux/hrtimer.h>

//init owen.wei modify time


struct hrtimer timer_ptt;


//初始化定时器

hrtimer_init(&timer_ptt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
timer_ptt.function = timer_ptt_interrupt;
//


//定义定时中断函数
static enum hrtimer_restart timer_ptt_interrupt(struct hrtimer *timer)
{
       static unsigned int c=0;
      c++;
       printk("%s,%d,c=%d\n",__func__,__LINE__,c);
       hrtimer_start(&timer_ptt, ktime_set(1, 0), HRTIMER_MODE_REL);
      return HRTIMER_NORESTART;
}

//开始起动定时器

hrtimer_start(&timer_ptt, ktime_set(1, 0), HRTIMER_MODE_REL);



0 0