]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/MAI/bios_emulator/scitech/src/pm/win32/ztimer.c
* Code cleanup:
[people/ms/u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / win32 / ztimer.c
CommitLineData
c7de829c
WD
1/****************************************************************************
2*
3* Ultra Long Period Timer
4*
5* ========================================================================
6*
7* The contents of this file are subject to the SciTech MGL Public
8* License Version 1.0 (the "License"); you may not use this file
9* except in compliance with the License. You may obtain a copy of
10* the License at http://www.scitechsoft.com/mgl-license.txt
11*
12* Software distributed under the License is distributed on an
13* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14* implied. See the License for the specific language governing
15* rights and limitations under the License.
16*
17* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18*
19* The Initial Developer of the Original Code is SciTech Software, Inc.
20* All Rights Reserved.
21*
22* ========================================================================
23*
24* Language: ANSI C
25* Environment: Win32
26*
27* Description: OS specific implementation for the Zen Timer functions.
28*
29****************************************************************************/
30
31/*---------------------------- Global variables ---------------------------*/
32
33static CPU_largeInteger countFreq;
34static ibool havePerformanceCounter;
35static ulong start,finish;
36
37/*----------------------------- Implementation ----------------------------*/
38
39/****************************************************************************
40REMARKS:
41Initialise the Zen Timer module internals.
42****************************************************************************/
43void __ZTimerInit(void)
44{
45#ifdef NO_ASSEMBLER
46 havePerformanceCounter = false;
47#else
48 havePerformanceCounter = QueryPerformanceFrequency((LARGE_INTEGER*)&countFreq);
49#endif
50}
51
52/****************************************************************************
53REMARKS:
54Start the Zen Timer counting.
55****************************************************************************/
56static void __LZTimerOn(
57 LZTimerObject *tm)
58{
59 if (havePerformanceCounter)
8bde7f77 60 QueryPerformanceCounter((LARGE_INTEGER*)&tm->start);
c7de829c 61 else
8bde7f77 62 tm->start.low = timeGetTime();
c7de829c
WD
63}
64
65/****************************************************************************
66REMARKS:
67Compute the lap time since the timer was started.
68****************************************************************************/
69static ulong __LZTimerLap(
70 LZTimerObject *tm)
71{
72 CPU_largeInteger tmLap,tmCount;
73
74 if (havePerformanceCounter) {
8bde7f77
WD
75 QueryPerformanceCounter((LARGE_INTEGER*)&tmLap);
76 _CPU_diffTime64(&tm->start,&tmLap,&tmCount);
77 return _CPU_calcMicroSec(&tmCount,countFreq.low);
78 }
c7de829c 79 else {
8bde7f77
WD
80 tmLap.low = timeGetTime();
81 return (tmLap.low - tm->start.low) * 1000L;
82 }
c7de829c
WD
83}
84
85/****************************************************************************
86REMARKS:
87Stop the Zen Timer counting.
88****************************************************************************/
89static void __LZTimerOff(
90 LZTimerObject *tm)
91{
92 if (havePerformanceCounter)
8bde7f77 93 QueryPerformanceCounter((LARGE_INTEGER*)&tm->end);
c7de829c 94 else
8bde7f77 95 tm->end.low = timeGetTime();
c7de829c
WD
96}
97
98/****************************************************************************
99REMARKS:
100Compute the elapsed time in microseconds between start and end timings.
101****************************************************************************/
102static ulong __LZTimerCount(
103 LZTimerObject *tm)
104{
105 CPU_largeInteger tmCount;
106
107 if (havePerformanceCounter) {
8bde7f77
WD
108 _CPU_diffTime64(&tm->start,&tm->end,&tmCount);
109 return _CPU_calcMicroSec(&tmCount,countFreq.low);
110 }
c7de829c 111 else
8bde7f77 112 return (tm->end.low - tm->start.low) * 1000L;
c7de829c
WD
113}
114
115/****************************************************************************
116REMARKS:
117Define the resolution of the long period timer as microseconds per timer tick.
118****************************************************************************/
119#define ULZTIMER_RESOLUTION 1000
120
121/****************************************************************************
122REMARKS:
123Read the Long Period timer from the OS
124****************************************************************************/
125static ulong __ULZReadTime(void)
126{ return timeGetTime(); }
127
128/****************************************************************************
129REMARKS:
130Compute the elapsed time from the BIOS timer tick. Note that we check to see
131whether a midnight boundary has passed, and if so adjust the finish time to
132account for this. We cannot detect if more that one midnight boundary has
133passed, so if this happens we will be generating erronous results.
134****************************************************************************/
135ulong __ULZElapsedTime(ulong start,ulong finish)
136{ return finish - start; }