系统在移植到wince5下,突然出现了这么一个bug,更改日期(在控制面板中)只能在1到7之间。例如选择了24日,应用之后,自动又是4日获得了焦点。
      查看了MS的相应处理代码(在wince500\public\wceshellfe\ctlpnl\cplmain\datetime.cpp中)。代码如下:
void Update(void)
{
    SYSTEMTIME cpltime, tmptime;
    // to allow the user to get good feedback about the current timezone
    // daylight savings time etc, we actually update the system on the fly
    // for these items the changes will be reflected in the time of each date
    // control
    // load the 'clock'
    DateTime_GetSystemtime(M_DI(IDC_TIME_TIME),(LPARAM)&cpltime);
    // load the 'date'
    MonthCal_GetCurSel(M_DI(IDC_TIME_DATE), (LPARAM)&tmptime);
    // copy the dates into cpltime
    cpltime.wYear = tmptime.wYear;
    cpltime.wDayOfWeek = tmptime.wDayOfWeek;
    cpltime.wDay = tmptime.wDay;
    cpltime.wMonth = tmptime.wMonth;
    if ( !UpdateTimeZone(&cpltime) && m_fTimeChanged)
    {
        // Need to change system time but didn't do it in UpdateTimeZone
        SetLocalTime(&cpltime);
    }
    // Update the clock & calendar display, since things may have changed
    GetLocalTime(&cpltime);
    DateTime_SetSystemtime(M_DI(IDC_TIME_TIME), GDT_VALID, &cpltime);
    MonthCal_SetToday(M_DI(IDC_TIME_DATE), &cpltime);
    MonthCal_SetCurSel(M_DI(IDC_TIME_DATE), &cpltime);
    m_fTimeChanged = FALSE;
}
 
      很明显是在从日期时间对话框中读到了日期和时间去SetLocalTime,这个函数是MS的(所以没有看到函数的实现)最终要调用OEMSetRealTime来设置RTC。接下来GetLocalTime读出刚设置的值来显示,这个函数最终要调用OEMGetRealTime从RTC中读取相关值。MS是牛X的,就不要怀疑它了,问题应该出在了OEM的两个函数中。这两个函数都在wince500\platform\common\src\arm\samsung\s3c2440a\rtc\rtc.c中。分别在这两个函数中打印串口消息。奇怪了,只要一设置完pRTCReg->BCDDAY寄存器再读出来就不是那回事了。
OEMSetRealTime中的部分代码如下:
OUTPORT32(&pRTCReg->BCDSEC,  TO_BCD(pTime->wSecond));
OUTPORT32(&pRTCReg->BCDMIN,  TO_BCD(pTime->wMinute));
OUTPORT32(&pRTCReg->BCDHOUR, TO_BCD(pTime->wHour));
OUTPORT32(&pRTCReg->BCDDATE, pTime->wDayOfWeek + 1);
OUTPORT32(&pRTCReg->BCDDAY,  TO_BCD(pTime->wDay));
OUTPORT32(&pRTCReg->BCDMON,  TO_BCD(pTime->wMonth));
OUTPORT32(&pRTCReg->BCDYEAR, TO_BCD(pTime->wYear - RTC_YEAR_DATUM));
 
     难道又是RTC的问题,昨天真是让它给搞惨了。不过这个应该不会吧,因为别的值都是好的,只有这day一个是不行的。还好2440的用户手册已经打开了,于是随手翻一下吧。
BCDDAY   Bit   Description                          Initial State
Reserved [7:3] –                                   –
DAYDATA  [2:0] BCD value for a day of the week.     –
               1 ~ 7
BCDDATE  Bit   Description                          Initial State
Reserved [7:6] –                                   –
DATEDATA [5:4] BCD value for date.
               0 ~ 3                                –
         [3:0] 0 ~ 9                                –
     
     真是不看不知道,一看吓一跳。明明是BCDDATE表示日期,BCDDAY表示星期的吗。MD,真想抽丫的!调换一下,果然OK了。