1 /****************************************************************************
3 * Ultra Long Period Timer
5 * ========================================================================
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
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.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
25 * Environment: RTTarget-32
27 * Description: OS specific implementation for the Zen Timer functions.
29 ****************************************************************************/
31 /*---------------------------- Global variables ---------------------------*/
33 static CPU_largeInteger countFreq;
34 static ibool havePerformanceCounter;
35 static ulong start,finish;
37 /*----------------------------- Implementation ----------------------------*/
39 /****************************************************************************
41 Initialise the Zen Timer module internals.
42 ****************************************************************************/
43 void __ZTimerInit(void)
46 havePerformanceCounter = false;
48 havePerformanceCounter = QueryPerformanceFrequency((LARGE_INTEGER*)&countFreq);
52 /****************************************************************************
54 Start the Zen Timer counting.
55 ****************************************************************************/
56 static void __LZTimerOn(
59 if (havePerformanceCounter)
60 QueryPerformanceCounter((LARGE_INTEGER*)&tm->start);
62 tm->start.low = timeGetTime();
65 /****************************************************************************
67 Compute the lap time since the timer was started.
68 ****************************************************************************/
69 static ulong __LZTimerLap(
72 CPU_largeInteger tmLap,tmCount;
74 if (havePerformanceCounter) {
75 QueryPerformanceCounter((LARGE_INTEGER*)&tmLap);
76 _CPU_diffTime64(&tm->start,&tmLap,&tmCount);
77 return _CPU_calcMicroSec(&tmCount,countFreq.low);
80 tmLap.low = timeGetTime();
81 return (tmLap.low - tm->start.low) * 1000L;
85 /****************************************************************************
87 Stop the Zen Timer counting.
88 ****************************************************************************/
89 static void __LZTimerOff(
92 if (havePerformanceCounter)
93 QueryPerformanceCounter((LARGE_INTEGER*)&tm->end);
95 tm->end.low = timeGetTime();
98 /****************************************************************************
100 Compute the elapsed time in microseconds between start and end timings.
101 ****************************************************************************/
102 static ulong __LZTimerCount(
105 CPU_largeInteger tmCount;
107 if (havePerformanceCounter) {
108 _CPU_diffTime64(&tm->start,&tm->end,&tmCount);
109 return _CPU_calcMicroSec(&tmCount,countFreq.low);
112 return (tm->end.low - tm->start.low) * 1000L;
115 /****************************************************************************
117 Define the resolution of the long period timer as microseconds per timer tick.
118 ****************************************************************************/
119 #define ULZTIMER_RESOLUTION 1000
121 /****************************************************************************
123 Read the Long Period timer from the OS
124 ****************************************************************************/
125 static ulong __ULZReadTime(void)
126 { return timeGetTime(); }
128 /****************************************************************************
130 Compute the elapsed time from the BIOS timer tick. Note that we check to see
131 whether a midnight boundary has passed, and if so adjust the finish time to
132 account for this. We cannot detect if more that one midnight boundary has
133 passed, so if this happens we will be generating erronous results.
134 ****************************************************************************/
135 ulong __ULZElapsedTime(ulong start,ulong finish)
136 { return finish - start; }