]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - board/MAI/bios_emulator/scitech/src/pm/ntdrv/ztimer.c
* Code cleanup:
[karo-tx-uboot.git] / board / MAI / bios_emulator / scitech / src / pm / ntdrv / ztimer.c
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:  32-bit Windows VxD
26 *
27 * Description:  OS specific implementation for the Zen Timer functions.
28 *
29 ****************************************************************************/
30
31 /*---------------------------- Global variables ---------------------------*/
32
33 static CPU_largeInteger countFreq;
34 static ulong            start,finish;
35
36 /*----------------------------- Implementation ----------------------------*/
37
38 /****************************************************************************
39 REMARKS:
40 Initialise the Zen Timer module internals.
41 ****************************************************************************/
42 static void __ZTimerInit(void)
43 {
44     KeQueryPerformanceCounter((LARGE_INTEGER*)&countFreq);
45 }
46
47 /****************************************************************************
48 REMARKS:
49 Call the assembler Zen Timer functions to do the timing.
50 ****************************************************************************/
51 static void __LZTimerOn(
52     LZTimerObject *tm)
53 {
54     LARGE_INTEGER lt = KeQueryPerformanceCounter(NULL);
55     tm->start.low = lt.LowPart;
56     tm->start.high = lt.HighPart;
57 }
58
59 /****************************************************************************
60 REMARKS:
61 Call the assembler Zen Timer functions to do the timing.
62 ****************************************************************************/
63 static ulong __LZTimerLap(
64     LZTimerObject *tm)
65 {
66     LARGE_INTEGER       tmLap = KeQueryPerformanceCounter(NULL);
67     CPU_largeInteger    tmCount;
68
69     _CPU_diffTime64(&tm->start,(CPU_largeInteger*)&tmLap,&tmCount);
70     return _CPU_calcMicroSec(&tmCount,countFreq.low);
71 }
72
73 /****************************************************************************
74 REMARKS:
75 Call the assembler Zen Timer functions to do the timing.
76 ****************************************************************************/
77 static void __LZTimerOff(
78     LZTimerObject *tm)
79 {
80     LARGE_INTEGER lt = KeQueryPerformanceCounter(NULL);
81     tm->end.low = lt.LowPart;
82     tm->end.high = lt.HighPart;
83 }
84
85 /****************************************************************************
86 REMARKS:
87 Call the assembler Zen Timer functions to do the timing.
88 ****************************************************************************/
89 static ulong __LZTimerCount(
90     LZTimerObject *tm)
91 {
92     CPU_largeInteger    tmCount;
93
94     _CPU_diffTime64(&tm->start,&tm->end,&tmCount);
95     return _CPU_calcMicroSec(&tmCount,countFreq.low);
96 }
97
98 /****************************************************************************
99 REMARKS:
100 Define the resolution of the long period timer as microseconds per timer tick.
101 ****************************************************************************/
102 #define ULZTIMER_RESOLUTION     1
103
104 /****************************************************************************
105 REMARKS:
106 Read the Long Period timer value from the BIOS timer tick.
107 ****************************************************************************/
108 static ulong __ULZReadTime(void)
109 {
110     LARGE_INTEGER count;
111     KeQuerySystemTime(&count);
112     return (ulong)(*((_int64*)&count) / 10);
113 }
114
115 /****************************************************************************
116 REMARKS:
117 Compute the elapsed time from the BIOS timer tick. Note that we check to see
118 whether a midnight boundary has passed, and if so adjust the finish time to
119 account for this. We cannot detect if more that one midnight boundary has
120 passed, so if this happens we will be generating erronous results.
121 ****************************************************************************/
122 ulong __ULZElapsedTime(ulong start,ulong finish)
123 { return finish - start; }