Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / qnx / 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:  QNX
26 *
27 * Description:  QNX specific implementation for the Zen Timer functions.
28 *
29 ****************************************************************************/
30
31 /*----------------------------- Implementation ----------------------------*/
32
33 /****************************************************************************
34 REMARKS:
35 Initialise the Zen Timer module internals.
36 ****************************************************************************/
37 void __ZTimerInit(void)
38 {
39 }
40
41 /****************************************************************************
42 REMARKS:
43 Use the gettimeofday() function to get microsecond precision (probably less
44 though)
45 ****************************************************************************/
46 static ulong __ULZReadTime(void)
47 {
48     struct timespec ts;
49     clock_gettime(CLOCK_REALTIME, &ts);
50     return (ts.tv_nsec / 1000 + ts.tv_sec * 1000000);
51 }
52
53 /****************************************************************************
54 REMARKS:
55 Start the Zen Timer counting.
56 ****************************************************************************/
57 #define __LZTimerOn(tm)     tm->start.low = __ULZReadTime()
58
59 /****************************************************************************
60 REMARKS:
61 Compute the lap time since the timer was started.
62 ****************************************************************************/
63 #define __LZTimerLap(tm)        (__ULZReadTime() - tm->start.low)
64
65 /****************************************************************************
66 REMARKS:
67 Call the assembler Zen Timer functions to do the timing.
68 ****************************************************************************/
69 #define __LZTimerOff(tm)        tm->end.low = __ULZReadTime()
70
71 /****************************************************************************
72 REMARKS:
73 Call the assembler Zen Timer functions to do the timing.
74 ****************************************************************************/
75 #define __LZTimerCount(tm)  (tm->end.low - tm->start.low)
76
77 /****************************************************************************
78 REMARKS:
79 Define the resolution of the long period timer as microseconds per timer tick.
80 ****************************************************************************/
81 #define ULZTIMER_RESOLUTION 1
82
83 /****************************************************************************
84 REMARKS:
85 Compute the elapsed time from the BIOS timer tick. Note that we check to see
86 whether a midnight boundary has passed, and if so adjust the finish time to
87 account for this. We cannot detect if more that one midnight boundary has
88 passed, so if this happens we will be generating erronous results.
89 ****************************************************************************/
90 ulong __ULZElapsedTime(ulong start,ulong finish)
91 { return finish - start; }