OEMSetRealTime (Windows Embedded CE 6.0)
1/5/2010
This function is called by the kernel to set the real-time clock.
Syntax
BOOL OEMSetRealTime(
LPSYSTEMTIME lpst
);
Parameters
- lpst
[in] Long pointer to the buffer containing the current time in SYSTEMTIME format.
Return Value
If this function succeeds, it returns TRUE.
If this function fails, it returns FALSE.
Remarks
If your hardware provides two digits to hold the value for the year, you must add additional code to avoid issues similar to the year 2000 issue.
This function must be reentrant and, thus, must protect the hardware from being accessed multiple times.
For more details, see Rtc.c in the %_WINCEROOT%\Platform\common\src\x86\common\rtc directory.
Code Example
Description
The following code example shows how to make this function re-entrant and use two digits to hold the value for the year.
Code
BOOL OEMSetRealTime( __in LPSYSTEMTIME lpst )
{
BOOL RetVal;
EnterCriticalSection(&RTC_critsect);
RetVal = Bare_SetRealTime(lpst);
LeaveCriticalSection(&RTC_critsect);
return RetVal;
}
BOOL Bare_SetRealTime( __in const SYSTEMTIME* const lpst )
{
BYTE cStatusRegA, cStatusRegB, Year;
Year = lpst->wYear % 100;
// Read the update in progress bit, wait for it to be clear.
// This bit will be set once per second for about
// 2us (Undoc. PC, page 897)
do
{
cStatusRegA = CMOS_Read( RTC_STATUS_A);
}
while ( cStatusRegA & RTC_SRA_UIP );
// Disable updates while we change the values
cStatusRegB = CMOS_Read( RTC_STATUS_B );
cStatusRegB |= RTC_SRB_UPDT;
CMOS_Write( RTC_STATUS_B, cStatusRegB );
if ( !(cStatusRegB & RTC_SRB_DM) )
{
// BCD Mode
CMOS_Write( RTC_YEAR, (BYTE)(CREATE_BCD(Year)));
CMOS_Write( RTC_MONTH, (BYTE)(CREATE_BCD(lpst->wMonth)));
// RTC clock stores DO_WEEK 1-7, SYSTEMTIME uses 0-6
CMOS_Write( RTC_DO_WEEK, (BYTE)(CREATE_BCD(lpst-wDayOfWeek+1)));
CMOS_Write( RTC_DO_MONTH, (BYTE)(CREATE_BCD(lpst->wDay)));
CMOS_Write( RTC_HOUR, (BYTE)(CREATE_BCD(lpst->wHour)));
CMOS_Write( RTC_MINUTE, (BYTE)(CREATE_BCD(lpst->wMinute)));
CMOS_Write( RTC_SECOND, (BYTE)(CREATE_BCD(lpst->wSecond)));
// Not sure how we can do lpst->wMilliseconds;
}
else
{
// Binary mode
CMOS_Write( RTC_YEAR, (UCHAR)Year);
CMOS_Write( RTC_MONTH, (UCHAR)lpst->wMonth);
// RTC clock stores DO_WEEK 1-7, SYSTEMTIME uses 0-6
CMOS_Write( RTC_DO_WEEK, (UCHAR)(lpst->wDayOfWeek+1));
CMOS_Write( RTC_DO_MONTH, (UCHAR)lpst->wDay);
CMOS_Write( RTC_HOUR, (UCHAR)lpst->wHour);
CMOS_Write( RTC_MINUTE, (UCHAR)lpst->wMinute);
CMOS_Write( RTC_SECOND, (UCHAR)lpst->wSecond);
}
// Reenable updates
cStatusRegB &= ~RTC_SRB_UPDT;
CMOS_Write( RTC_STATUS_B, cStatusRegB );
return TRUE;
}
Requirements
Header | nkintr.h |
Library | OEMMain.lib or OEMMain_StaticKITL.lib |
Windows Embedded CE | Windows CE 2.10 and later |
See Also
Reference
Required OAL Functions
OEMGetRealTime
OEMSetAlarmTime