Partager via


Implementing the Real-Time Clock and System Timer (Windows Embedded CE 6.0)

1/5/2010

Windows Embedded CE provides a variety of functions that your OAL can use to manage time. These functions fall into two categories: real-time clock functions and system-timer functions.

Implementing Real-Time Clock Functions

Real-time clock functions manage time-of-day information. The file Rtc.c, located in %_WINCEROOT%\Platform\Common\Src\Common\RTC\Timer, defines the interfaces that Windows Embedded CE uses to communicate with the kernel and the real-time clock.

The following table shows the functions that you must implement on hardware platforms that provide the time of day to the user.

Function Description

OEMGetRealTime

Gets the system time.

OEMSetRealTime

Sets the system time.

OEMSetAlarmTime

Sets the alarm time.

You can also use the IOCTL_HAL_INIT_RTC I/O control code in a call to KernelIoControl to force real-time clock initialization. For more information about how to set the real-time clock, see Setting the Real-Time Clock.

OEMGetRealTime is called by GetSystemTime when the clock is running in hardware mode. In hardware mode, OEMGetRealTime queries the RTC. Alternatively, you can run the clock in software mode by setting a registry key. In software mode, a clock is simulated in software based on GetTickCount, which tracks clock ticks using the timer. To specify software mode for the clock, set HKEY_LOCAL_MACHINE\Platform\"SoftRTC" = 1. This registry key must be set at boot time to have any effect.

Implementing the System-Timer Functions

To query the system timer, Windows Embedded CE provides the Win32 GetTickCount function. Windows Embedded CE also provides a prototype implementation of the system-timer interrupt service routine (ISR).

The OAL system-timer function, SC_GetTickCount, returns the current number of milliseconds since boot. Windows Embedded CE calls SC_GetTickCount in your OAL when the GetTickCount function is called. You must register the system-timer interrupts in OEMInit to ensure the system timer is updated appropriately.

Each sample OAL provides a sample implementation of the system-timer ISR. Each time the interrupt goes off, the ISR should reset the hardware and increment the variable CurMSec by one millisecond.

See Also

Tasks

How to Develop an OEM Adaptation Layer