2 chendesheng1988 chendesheng1988 于 2013.07.09 09:36 提问

wince下RTC驱动该如何写?芯片是M41T81

我的板子核心CPU是PXA270,然后我有一个外接的RTC芯片M41T81,用它来实现实时时钟,可是现在关机后,每次重启时间都会归零。
我的IIC总线有两个IC器件在用,一个是摄像头,一个就是这个M41T81。我把我的RTC驱动部分代码贴出来,请大家指教。
BOOL
OEMGetRealTime(LPSYSTEMTIME lpst)
{
unsigned int cur_time;
// Get the RTC value
GetRTCTime (&cur_time);
FormatSystemTime (cur_time, lpst);

//QU_GetRTCTime (lpst);

#if 0
DEBUGMSG(0,(TEXT("OEMGetRealTime: Year: %u, Month: %u, Day: %u, Hour: %u, Minute: %u, second: %u rcnr=%Xh\n"),
lpst->wYear, lpst->wMonth,lpst->wDay, lpst->wHour, lpst->wMinute,lpst->wSecond, cur_time));
#endif

return TRUE;

}

//
//
// Sets the RTC.
// Called by kernel in response to SetSystemTime()
//
//
BOOL OEMSetRealTime(LPSYSTEMTIME lpst)
{
unsigned int cur_time;
ConvertSystemTime (lpst, &cur_time);
SetRTCTime (cur_time);
//QU_SetRTCTime (lpst);

#if 0
DEBUGMSG(0,(TEXT("OEMSetRealTime: Year: %u, Month: %u, Day: %u, Hour: %u, Minute: %u, second: %u rcnr=%Xh\n"),
lpst->wYear, lpst->wMonth,lpst->wDay, lpst->wHour, lpst->wMinute, lpst->wSecond, cur_time));
#endif

return TRUE;

}

//
//
// Set the RTC alarm.
// Ensure synchronization to RTC registers.
//
// Default behavior will allow setting an alarm
// (thereby cancelling any pending one)
//
//
BOOL OEMSetAlarmTime(LPSYSTEMTIME lpst)
{
unsigned int min, day, month, year;
unsigned int *mtbl;
unsigned int alarm_time;

XLLP_RTC_HANDLE_T   XllpRTCHandle;

XllpRTCHandle.pRTCRegs = (XLLP_RTC_T *)RTC_BASE_U_VIRTUAL;
XllpRTCHandle.pINTCRegs = (XLLP_INTC_T *)INTC_BASE_U_VIRTUAL;

day = 0;
for (year=ORIGINYEAR; year<lpst->wYear; year++) {
    day += 365 + isleap(year);
}

mtbl = isleap(year) ? monthtable_leap : monthtable;
for (month=0; month<((unsigned)lpst->wMonth-1); month++) {
    day += mtbl[month];
}

day += lpst->wDay - 1;

min = (day * 24 + lpst->wHour) * 60 + lpst->wMinute;

alarm_time = min * 60 + lpst->wSecond;

// 
// Configure and arm the alarm 
//
XllpRtcConfigureAlarm (&XllpRTCHandle, alarm_time);


return TRUE;

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!