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