高精度定时器hrtimer使用示例

时间:2021-04-20 08:54:42

平台:MTK_android_KK_1483M_W503_mt6582

touch_panel_gt9158_hotknot驱动里面添加部分如下:


#include <linux/time.h>

#define GT9158_kthread_hrtimer_zhubing 1
#if GT9158_kthread_hrtimer_zhubing

static struct hrtimer GT9158_kthread_timer;
static unsigned int GT9158_timer_count;

#endif


#if GT9158_kthread_hrtimer_zhubing

enum hrtimer_restart GT9158_kthread_hrtimer_func(struct hrtimer *timer)
{
//bat_thread_wakeup();
unsigned int num;
GT9158_timer_count++;
num=GT9158_timer_count%2;
printk("zhubing_GT9158_timer_count=%d num=%d\n", GT9158_timer_count,num);
if(num)
{
printk("GT9158_suspend_zhubing\n");
//GT9158_suspend();
  }
  else
  {
  printk("GT9158_resume_zhubing\n");
  //GT9158_resume();
  }

return HRTIMER_NORESTART;
}


void GT9158_kthread_hrtimer_init(void)
{
ktime_t ktime;


ktime = ktime_set(1, 0); /* 3s, 10* 1000 ms */       //设置为1秒,0纳秒
hrtimer_init(&GT9158_kthread_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);   //HRTIMER_MODE_REL:相对时间
GT9158_kthread_timer.function = GT9158_kthread_hrtimer_func;    //定时器处理函数
hrtimer_start(&GT9158_kthread_timer, ktime, HRTIMER_MODE_REL);  //开启定时器


printk("GT9158_kthread_hrtimer_init_zhubing : done\n");
}


#endif



#if GT9158_kthread_hrtimer_zhubing
GT9158_kthread_hrtimer_init();
#endif