2010-06-21 76 views
3

幾天來我一直困擾於RTC問題:我無法寫入RTC寄存器。CMOS_WRITE無法正常工作的原因是什麼?

以下是代碼片段,我從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。

UPDATE:每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); 

回答

0

有什麼具體的RTC芯片?大多數RTC,當你讀/寫它的寄存器組時,你必須翻轉一下「暫停」它,然後在完成時「解除暫停」。通常,你想盡可能快地做到這一點。

您是否還檢查了芯片文檔以確保您試圖寫入的特定寄存器被允許寫入?

相關問題