我正在处理一个Linux内核模块,它为来自自定义板的中断注册回调,并将接收到的数据放在char设备接口后面的队列中,由应用程序处理。这个模块需要不断地监控和测量来自板的中断和数据,即使没有来自主板的中断,所以它有另一个根据时间触发的回调。
当前的实现使用RTC中断作为一个固定的定时器源。我禁用内核RTC驱动程序(CONFIG_RTC_DRV_CMOS)并请求IRQ 8,并将计时器回调挂钩作为RTC中断处理程序。每秒钟都会从RTC芯片产生中断。
问题是,我们必须以这种方式失去一些Linux管理时间的能力,因为只有一个rtc-cmos或板模块可以一次加载(显然我们已经选择了板模块)。
目标体系结构是i386 PC机。
我不是一个内核开发人员,所以我对内核模块的开发没有一个全面的了解,但是我正在试图找到我的方法,这些都是我脑海中最接近解决方案的东西:
request_irq(8, rtc_handler, IRQF_SHARED, rtc_handler)?)或者链式加载IRQ处理程序。我想可能有一种简单而标准的方法来做到这一点,如果有人对这两种解决方案中的任何一种提出意见或提出其他解决方案,我会很高兴的。
发布于 2013-11-30 17:51:54
Linux内核高分辨率定时器hrtimer是一种选择。http://lwn.net/Articles/167897/
在这里,我所做的:
#include <linux/interrupt.h>
#include <linux/hrtimer.h>
#include <linux/sched.h>
static struct hrtimer htimer;
static ktime_t kt_periode;
static void timer_init(void)
{
kt_periode = ktime_set(0, 104167); //seconds,nanoseconds
hrtimer_init (& htimer, CLOCK_REALTIME, HRTIMER_MODE_REL);
htimer.function = timer_function;
hrtimer_start(& htimer, kt_periode, HRTIMER_MODE_REL);
}
static void timer_cleanup(void)
{
hrtimer_cancel(& htimer);
}
static enum hrtimer_restart timer_function(struct hrtimer * timer)
{
// @Do your work here.
hrtimer_forward_now(timer, kt_periode);
return HRTIMER_RESTART;
}发布于 2013-11-30 16:14:27
您可能希望使用tasklet,请参阅linux/interrupt.h。
https://stackoverflow.com/questions/20300149
复制相似问题