How to analyze the time accuracy of Wince
How to analyze the time accuracy of Wince, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
GetSystemTime () or GetLocalTime () is accurate to seconds at most in wince, because in embedded systems, the time of the system is maintained by RTC (usually a hardware logic within CPU), which is measured in seconds and is timed by adding 1 per second. So its exact range can only be up to seconds. You can see the implementation of the OEMGetRealTime () function in many BSP KERNEL. When you call API:GetSystemTime () or GetLocalTime (), KERNEL will call the OEMGetRealTime () function to return the result. In OEMGetRealTime (), for the above reasons, ms=0. So you can only get second-level accuracy.
I don't know how this function is implemented on PC, but it must be hardware-related.
A CPU will also have a logic function called OSTimer, which can provide timing similar to RTC, but with millisecond precision. In WINCE, KERNEL has a CurMSec variable that saves how long the system has been running since it was started in milliseconds. In fact, the variable CurMSec is calculated by OSTIMER. When you call GetTickCount (), the system will return the value of CurMSec to you. You can get a time difference by calling GetTickCount () before and after doing an action, that is, the time it takes you to perform this action, which is millisecond precision.
WINCE microsecond and millisecond delay function
/ / WINCE microsecond delay function
Void delay_us (int n) {
LARGE_INTEGER litmp
LONGLONG QPart1,QPart2
Double dfMinus, dfFreq, dfTim
If (QueryPerformanceFrequency (& litmp) = = FALSE)
{
MessageBox (NULL,TEXT ("Error:QueryPerformanceFrequency"), TEXT ("Error"), MB_OK)
Return
}
DfFreq = (double) litmp.QuadPart
QueryPerformanceCounter & litmp)
QPart1 = litmp.QuadPart
Do
{
QueryPerformanceCounter & litmp)
QPart2=litmp.QuadPart
DfMinus= (double) (QPart2-QPart1)
DfTim=dfMinus/dfFreq
} while (dfTim