linux - 了解 rtc_interrupt 中的代码

标签 linux linux-kernel interrupt

我需要了解“实时时钟”函数 rtc_interrupt 中的代码。代码是

rtc_irq_data += 0x100; 
rtc_irq_data &= ~0xff; 
rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0);

我无法理解为什么它是 += 0x100 以及其余代码。

最佳答案

摘自 Robert Love 的“Linux 内核开发”一书,该代码片段具有以下注释:

/*
 * Can be an alarm interrupt, update complete interrupt,
 * or a periodic interrupt. We store the status in the
 * low byte and the number of interrupts received since
 * the last read in the remainder of rtc_irq_data.
 */

至于rtc_irq_data += 0x100; 所以,我们知道在高字节有一个接收中断的计数器。因此 0x100。如果用16位的16进制数表示,这里最高字节被加+1(计数器上加1个中断)。

至于第二行,rtc_irq_data &= ~0xff; rtc_irq_data 在逻辑上与 0xff 的否定进行逻辑与运算,例如,可能为 0xff00。整数的高位部分被保留,低位部分被丢弃。因此,假设这是第一次被调用,现在该值将保证为 0x0100。

最后一部分 rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); 正在对低字节(现在是 0/0x00)进行逻辑或 |= ) 作为 RTC 当前状态。因此评论“我们将状态存储在低字节”。

至于在 (CMOS_READ(RTC_INTR_FLAGS) & 0xF0) 中与 0xF0 进行逻辑与,查阅原始 AT 兼容 RTC 数据表,INTR_FLAGS 是 REGISTER C,一个寄存器字节,其中只有 4 个向上位被使用。 b7 = IRQF, b6 = FP, b5 = AF, b4 = UF,

b3 到 b0

The unused bits of Status Register 1 are read as "0s". They cannot be writen.

来自 RTC datasheet

因此,作为一个良好的标准编码实践,确保 AND 逻辑 0xF0 忽略低 4 位。

关于linux - 了解 rtc_interrupt 中的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54867627/

相关文章:

linux命令合并两个tar.gz文件

linux - 如何通过 Bus、Device、Function 和 Offset 获取物理地址

c - 如何在 Linux 2.6.29 中解码 ioctl() 系统调用中的 arg 指针?

linux - 使用 sed 从给定文件中删除单词

python - 在 Python 中开发 Linux 内核模块

c++ - 在 boost::asio::io_service 下获取 boost::process::child 的退出代码?

linux - 使用 Linux 审计系统追踪 Web shell 攻击

c - 中断是由于中断使能之前发生的变化而发生的

operating-system - 轮询与中断

c - MSP430 UART TX 中断启用/禁用