/* @func DWORD | OEMEthGetSecs | Returns a free-running seconds count. @rdesc Number of elapsed seconds since last roll-over. @comm @xref */ DWORD OEMEthGetSecs(void) { SYSTEMTIME sTime; OEMGetRealTime(&sTime); return((60UL * (60UL * (24UL * (31UL * sTime.wMonth + sTime.wDay) + sTime.wHour) + sTime.wMinute)) + sTime.wSecond); }
DWORD OEMKitlGetSecs() { SYSTEMTIME st; DWORD dwRet; static DWORD dwLastTime; // For making sure we aren't running backward static DWORD dwBias; // after post-init, it's possible that someone is holding the RTC CS, and we cannot safely call OEMGetRealTime while in KITL. // So we use CurMSec directly after post init. // NOTE: if this function is called while interrupts are off, the time will not advance. // if (!IsAfterPostInit()) { OEMGetRealTime( &st ); dwRet = ((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond); dwBias = dwRet; } else { dwRet = (CurMSec/1000) + dwBias; } if (dwRet < dwLastTime) { KITLOutputDebugString ("! Time went backwards (or wrapped): cur: %u, last %u\n", dwRet,dwLastTime); } dwLastTime = dwRet; return (dwRet); }
//------------------------------------------------------------------------------ // // Function: OALIoCtlHalInitRTC // // This function is called by WinCE OS to initialize the time after boot. // Input buffer contains SYSTEMTIME structure with default time value. // If hardware has persistent real time clock it will ignore this value // (or all call). // BOOL OALIoCtlHalInitRTC( UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer, UINT32 outSize, UINT32 *pOutSize) { BOOL rc = FALSE; BOOL bResetRTC = FALSE; SYSTEMTIME SysTime; OALMSG(OAL_IOCTL&&OAL_FUNC, (L"+OALIoCtlHalInitRTC(...)\r\n")); // Validate inputs if (pInpBuffer == NULL || inpSize < sizeof(SYSTEMTIME)) { NKSetLastError(ERROR_INVALID_PARAMETER); OALMSG(OAL_ERROR, ( L"ERROR: OALIoCtlHalInitRTC: Invalid parameter\r\n" )); goto cleanUp; } // Initialize critical section for RTC functions. InitializeCriticalSection(&g_oalRTCcs); g_oalRTCcsInit = 1; // Add static mapping for RTC alarm OALIntrStaticTranslate(SYSINTR_RTC_ALARM, IRQ_RTC_ALARM); OEMGetRealTime(&SysTime); /* RTC Time validity check */ bResetRTC = (SysTime.wYear < RTC_YEAR_DATUM || (SysTime.wYear - RTC_YEAR_DATUM) > 99) ? TRUE : bResetRTC; bResetRTC = (SysTime.wMonth > 12 || SysTime.wMonth < 1) ? TRUE : bResetRTC; bResetRTC = (SysTime.wDay > 31 || SysTime.wDay < 1) ? TRUE : bResetRTC; bResetRTC = (SysTime.wDayOfWeek > 6 || SysTime.wDayOfWeek < 0) ? TRUE : bResetRTC; bResetRTC = (SysTime.wHour > 23 || SysTime.wHour < 0) ? TRUE : bResetRTC; bResetRTC = (SysTime.wMinute > 59 || SysTime.wMinute < 0) ? TRUE : bResetRTC; bResetRTC = (SysTime.wSecond > 59 || SysTime.wSecond < 0) ? TRUE : bResetRTC; if(bResetRTC) { OALMSG(OAL_RTC&&OAL_ERROR,(L"Invalid RTC Time (%d.%d.%d, %d:%d:%d, (%d th day of week)\r\n", \ SysTime.wYear, SysTime.wMonth, SysTime.wDay, \ SysTime.wHour, SysTime.wMinute, SysTime.wSecond, \ SysTime.wDayOfWeek )); } // Set time if(bResetRTC) { rc = OEMSetRealTime(&g_oalRtcResetTime); } cleanUp: OALMSG(OAL_IOCTL&&OAL_FUNC, (L"-OALIoCtlHalInitRTC(rc = %d)\r\n", rc)); return rc; }
DWORD OEMKitlGetSecs (void) { SYSTEMTIME st; DWORD dwRet; static DWORD dwBias; static DWORD dwLastTime; OEMGetRealTime( &st ); dwRet = ((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond); dwBias = dwRet; if (dwRet < dwLastTime) { KITLOutputDebugString("[KITL] Time went backwards (or wrapped): cur: %u, last %u\n", dwRet,dwLastTime); } dwLastTime = dwRet; return (dwRet); }