OEMSetRealTime (Compact 2013)

10/16/2014

This function sets the real-time clock (RTC) to local time.

Syntax

BOOL OEMSetRealTime( 
  LPSYSTEMTIME lpst 
);

Parameters

  • lpst
    [in] Long pointer to the buffer containing the current time in SYSTEMTIME format.

Return Value

TRUE indicates success. FALSE indicates failure.

Remarks

This function must be reentrant and, thus, must protect the hardware from being accessed multiple times. The kernel calls this function.

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.

For more information, see Rtc.c in the %_WINCEROOT%\platform\common\src\x86\common\rtc directory.

Note

In Windows Embedded Compact, the system behaves as if the real-time clock were maintained in Universal Coordinated Time (UTC). However, for backward compatibility, the underlying hardware clock is maintained in local time.

Example

The following code example shows how to make this function re-entrant and use two digits to hold the value for the year.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

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

See Also

Reference

Required OAL Functions
OEMGetRealTime
OEMSetAlarmTime