Linux内核驱动定时微秒级别实现
Posted panda_w
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux内核驱动定时微秒级别实现相关的知识,希望对你有一定的参考价值。
Linux内核驱动定时微秒级别实现
#include <linux/module.h> #include <linux/kthread.h> #define TIMEOUT_HR 1000000 /* 1us */ static struct hrtimer etx_hr_timer; ktime_t ktime; enum hrtimer_restart hrtimer_callback(struct hrtimer *timer) { static int count; printk(KERN_INFO "hrtimer callback is running count:%d ", count++); hrtimer_forward_now(timer, ktime_set(0, TIMEOUT_HR)); return HRTIMER_RESTART; } static int __init lkm_init(void) { printk(KERN_INFO "init lkm module. "); /* 设置高精度时钟 */ ktime = ktime_set(0, TIMEOUT_HR); hrtimer_init(&etx_hr_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); etx_hr_timer.function = &hrtimer_callback; hrtimer_start(&etx_hr_timer, ktime, HRTIMER_MODE_REL); return 0; } static void __exit lkm_exit(void) { hrtimer_cancel(&etx_hr_timer); printk(KERN_INFO "exit lkm module. "); } module_init(lkm_init); module_exit(lkm_exit); MODULE_VERSION("0.0"); MODULE_DESCRIPTION("sample kernel module"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("panda_w");
优质博客:
https://blog.csdn.net/qq_37858386/article/details/85784994
以上是关于Linux内核驱动定时微秒级别实现的主要内容,如果未能解决你的问题,请参考以下文章