Share via


Setting the Real-Time Clock (Windows Embedded CE 6.0)

1/5/2010

Some target devices cannot detect whether the real-time clock is initialized, and therefore cannot determine when to reset it. For example, a computer-based target device that has a clock with a battery backup may be unable to detect real-time clock initialization.

You change this behavior by implementing the I/O control code IOCTL_HAL_INIT_RTC in OEMIoControl. The Windows Embedded CEā€“based file system passes IOCTL_HAL_INIT_RTC to KernelIoControl during initialization for a cold boot sequence.

The following code example shows the SYSTEMTIME structure that the file system passes.

const SYSTEMTIME st = {2003,1,0,1,12,0,0,0};
DWORD bytesUsed;
KernelIoControl(IOCTL_HAL_INIT_RTC, (UCHAR *)&st, sizeof(SYSTEMTIME), NULL, 0, &bytesUsed);

To set the real-time clock in OAL code

  1. Validate the clock during the OEM boot process in your OAL code.

  2. Set the real-time clock to the value stored in SYSTEMTIME, if the boot process did not return a valid time.

  3. Call OEMSetRealTime in OEMIoControl to set the real-time clock of the target device.

The following code example shows one implementation of setting the real-time clock.

case IOCTL_HAL_INIT_RTC:
    // The kernel has detected a cold boot. 
    // The real-time clock probably needs to be reset.
    if( nInBufSize >= sizeof(SYSTEMTIME) )
      return OEMSetRealTime( (LPSYSTEMTIME)lpInBuf );
    else
      return FALSE;
     break;

See Also

Tasks

How to Develop an OEM Adaptation Layer

Concepts

Implementing the OEMIoControl Function