rtc.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 79 行

C
79
字号
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-1998  Microsoft Corporation

Module Name:

   rtc.c

Abstract:

   This file implements the NK kernel interfaces for the real time clock.

Notes:


--*/


#include <windows.h>
#include <nkintr.h>
#include <altoona.h>

__int64 RealTimeBias;

unsigned long AlarmTime[2];

unsigned long volatile CurMSecHigh = 0;

extern volatile DWORD *PtrCurMSec;      /* current millisecond counter */

__int64 ReadRTC(void)
{
    return (((__int64)CurMSecHigh << 32) | *PtrCurMSec) * 10000;
}


BOOL OEMGetRealTime(LPSYSTEMTIME lpst)
{
    __int64 realTime;
    FILETIME ft;

    realTime = ReadRTC() + RealTimeBias;
    ft.dwLowDateTime = (DWORD)realTime;
    ft.dwHighDateTime = (DWORD)(realTime >> 32);

    return KFileTimeToSystemTime(&ft, lpst);
}

BOOL OEMSetRealTime(LPSYSTEMTIME lpst)
{
    FILETIME ft;
    BOOL bRet;

    if (bRet = KSystemTimeToFileTime(lpst, &ft)) {
        RealTimeBias = ((__int64)ft.dwHighDateTime << 32 | ft.dwLowDateTime) - ReadRTC();
    }

    return bRet;
}

BOOL OEMSetAlarmTime(LPSYSTEMTIME lpst)
{
    FILETIME ft;
    __int64 aTime;
    BOOL bRet;

    if (bRet = KSystemTimeToFileTime(lpst, &ft)) {
        aTime = ((__int64)ft.dwHighDateTime << 32 | ft.dwLowDateTime) / 10000 - RealTimeBias;
        INTERRUPTS_OFF();
        AlarmTime[1] = (unsigned long)(aTime >> 32);
        AlarmTime[0] = (unsigned long)aTime;
        INTERRUPTS_ON();
    }
    return bRet;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?