]>
Commit | Line | Data |
---|---|---|
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: OS/2 | |
26 | * | |
27 | * Description: OS specific implementation for the Zen Timer functions. | |
28 | * | |
29 | ****************************************************************************/ | |
30 | ||
31 | /*---------------------------- Global variables ---------------------------*/ | |
32 | ||
33 | static ulong frequency; | |
34 | ||
35 | /*----------------------------- Implementation ----------------------------*/ | |
36 | ||
37 | /**************************************************************************** | |
38 | REMARKS: | |
39 | Initialise the Zen Timer module internals. | |
40 | ****************************************************************************/ | |
41 | void __ZTimerInit(void) | |
42 | { | |
43 | DosTmrQueryFreq(&frequency); | |
44 | } | |
45 | ||
46 | /**************************************************************************** | |
47 | REMARKS: | |
48 | Start the Zen Timer counting. | |
49 | ****************************************************************************/ | |
50 | #define __LZTimerOn(tm) DosTmrQueryTime((QWORD*)&tm->start) | |
51 | ||
52 | /**************************************************************************** | |
53 | REMARKS: | |
54 | Compute the lap time since the timer was started. | |
55 | ****************************************************************************/ | |
56 | static ulong __LZTimerLap( | |
57 | LZTimerObject *tm) | |
58 | { | |
59 | CPU_largeInteger tmLap,tmCount; | |
60 | ||
61 | DosTmrQueryTime((QWORD*)&tmLap); | |
62 | _CPU_diffTime64(&tm->start,&tmLap,&tmCount); | |
63 | return _CPU_calcMicroSec(&tmCount,frequency); | |
64 | } | |
65 | ||
66 | /**************************************************************************** | |
67 | REMARKS: | |
68 | Call the assembler Zen Timer functions to do the timing. | |
69 | ****************************************************************************/ | |
70 | #define __LZTimerOff(tm) DosTmrQueryTime((QWORD*)&tm->end) | |
71 | ||
72 | /**************************************************************************** | |
73 | REMARKS: | |
74 | Call the assembler Zen Timer functions to do the timing. | |
75 | ****************************************************************************/ | |
76 | static ulong __LZTimerCount( | |
77 | LZTimerObject *tm) | |
78 | { | |
79 | CPU_largeInteger tmCount; | |
80 | ||
81 | _CPU_diffTime64(&tm->start,&tm->end,&tmCount); | |
82 | return _CPU_calcMicroSec(&tmCount,frequency); | |
83 | } | |
84 | ||
85 | /**************************************************************************** | |
86 | REMARKS: | |
87 | Define the resolution of the long period timer as microseconds per timer tick. | |
88 | ****************************************************************************/ | |
89 | #define ULZTIMER_RESOLUTION 1000 | |
90 | ||
91 | /**************************************************************************** | |
92 | REMARKS: | |
93 | Read the Long Period timer value from the BIOS timer tick. | |
94 | ****************************************************************************/ | |
95 | static ulong __ULZReadTime(void) | |
96 | { | |
97 | ULONG count; | |
98 | DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &count, sizeof(ULONG) ); | |
99 | return count; | |
100 | } | |
101 | ||
102 | /**************************************************************************** | |
103 | REMARKS: | |
104 | Compute the elapsed time from the BIOS timer tick. Note that we check to see | |
105 | whether a midnight boundary has passed, and if so adjust the finish time to | |
106 | account for this. We cannot detect if more that one midnight boundary has | |
107 | passed, so if this happens we will be generating erronous results. | |
108 | ****************************************************************************/ | |
109 | ulong __ULZElapsedTime(ulong start,ulong finish) | |
110 | { return finish - start; } |