Beispiel #1
0
//------------------------------------------------------------------------------
//
//  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;
    SYSTEMTIME *pTime = (SYSTEMTIME*)pInpBuffer;

    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;
    }

    // Add static mapping for RTC alarm
    OALIntrStaticTranslate(SYSINTR_RTC_ALARM, IRQ_RTC);

    // Set time
    rc = OEMSetRealTime(pTime);
    
cleanUp:
    OALMSG(OAL_IOCTL&&OAL_FUNC, (L"-OALIoCtlHalInitRTC(rc = %d)\r\n", rc));
    return rc;
}
Beispiel #2
0
//------------------------------------------------------------------------------
//
//  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;
}