【发布时间】:2014-11-03 18:58:21
【问题描述】:
我编写了一个简单的应用程序来启用 rtc 中断。
#include <stdio.h>
#include <fcntl.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
int main() {
int fd = open("/dev/rtc0",O_RDONLY);
int hz = 64;
if (ioctl(fd, RTC_IRQP_SET, hz) == -1){
printf("ioctl(RTC_IRQP_SET) failed");
return 1;
}
if (ioctl(fd, RTC_PIE_ON) == -1){
printf("ioctl(RTC_PIE_ON) failed");
return 1;
}
}
运行后,我预计中断会显示在 IRQ8 下的 /proc/interrupts 中。
来自https://www.kernel.org/doc/Documentation/rtc.txt:
不过,它也可用于生成从 2Hz 到 2Hz 的慢速信号 相对较快的 8192Hz,以 2 的幂为增量。这些信号 由中断号 8 报告。(哦!所以那就是 IRQ 8 for...) 它也可以用作 24 小时警报,当 闹钟响了。
但没有任何变化。
8: 0 1 IO-APIC-edge rtc0
保持被动。我在这里错过了什么?
【问题讨论】:
-
好问题!有趣的是,如果您输入
char buf[8]; for (int i = 0; i < 64; ++i) read(fd, buf, sizeof(buf)),程序会按预期花费 1 秒。所以它正在工作,但仍然不计算中断。 -
你读过time(7)。您不需要 RTC 来获得时间!
-
显示整个
/proc/interrupts。
标签: linux timer linux-kernel real-time