CMOS_WRITE 无法工作的可能原因是什么?
我已经被 RTC 问题困扰了好几天:我无法写入 RTC 寄存器。
以下是代码片段,我从 reg(最后一行)读取的值始终与我刚刚写入 reg 的值不同。任何人都可以帮助我理解这一点吗?
val = CMOS_READ(RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", val);
val &= 0xf0;
val |= 2;
printk(KERN_INFO "writing val=%d to RTC_FREQ_SELECT.\n", val);
CMOS_WRITE(val, RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", CMOS_READ(RTC_FREQ_SELECT));
我使用的是 linux 2.6 内核,我尝试的平台是 PPC 和 x86。
更新:每个 Amardeep 的评论有更多代码片段...
/* disable periodic interrupts */
tmp_control = CMOS_READ(RTC_CONTROL);
tmp_control &= ~RTC_PIE;
CMOS_WRITE(tmp_control, RTC_CONTROL);
CMOS_READ(RTC_INTR_FLAGS);
val = CMOS_READ(RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", val);
val &= 0xf0;
/* ...... */
val |= 2;
printk(KERN_INFO "writing val=%d to RTC_FREQ_SELECT.\n", val);
CMOS_WRITE(val, RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", CMOS_READ(RTC_FREQ_SELECT));
/* Enable periodic interrupts */
tmp_control = CMOS_READ(RTC_CONTROL);
tmp_control |= RTC_PIE;
CMOS_WRITE(tmp_control, RTC_CONTROL);
/* read the flags register to start interrupts */
CMOS_READ(RTC_INTR_FLAGS);
I've been puzzled by a RTC problem for several days: i couldn't write to the RTC register.
Following is the code snippet and the value I read from the reg(last line) is always different from what i just wrote to the reg. Anyone can help me understand this ?
val = CMOS_READ(RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", val);
val &= 0xf0;
val |= 2;
printk(KERN_INFO "writing val=%d to RTC_FREQ_SELECT.\n", val);
CMOS_WRITE(val, RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", CMOS_READ(RTC_FREQ_SELECT));
I am using linux 2.6 kernel and the platforms i tried were PPC and x86.
UPDATE: more code snippets per Amardeep's comment...
/* disable periodic interrupts */
tmp_control = CMOS_READ(RTC_CONTROL);
tmp_control &= ~RTC_PIE;
CMOS_WRITE(tmp_control, RTC_CONTROL);
CMOS_READ(RTC_INTR_FLAGS);
val = CMOS_READ(RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", val);
val &= 0xf0;
/* ...... */
val |= 2;
printk(KERN_INFO "writing val=%d to RTC_FREQ_SELECT.\n", val);
CMOS_WRITE(val, RTC_FREQ_SELECT);
printk(KERN_INFO "reading val=%d from RTC_FREQ_SELECT.\n", CMOS_READ(RTC_FREQ_SELECT));
/* Enable periodic interrupts */
tmp_control = CMOS_READ(RTC_CONTROL);
tmp_control |= RTC_PIE;
CMOS_WRITE(tmp_control, RTC_CONTROL);
/* read the flags register to start interrupts */
CMOS_READ(RTC_INTR_FLAGS);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
具体的RTC芯片是什么?大多数 RTC,在读/写其寄存器组时必须翻转一点以“暂停”它,然后在完成后“取消暂停”它。通常,您希望尽快完成此操作。
您是否还检查了芯片文档以确保允许写入您尝试写入的特定寄存器?
What's the specific RTC chip? Most RTC's, you have to flip a bit to "pause" it while you read/write its register banks, then "unpause" it when done. Usually, you want to do this as fast as possible.
Did you also check the chip docs to make sure the specific register you're trying to write to is allowed to be written to?