Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / dos / 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:  MSDOS
26 *
27 * Description:  OS specific implementation for the Zen Timer functions.
28 *
29 ****************************************************************************/
30
31
32 /*---------------------------- Global variables ---------------------------*/
33
34 uchar * _VARAPI _ZTimerBIOSPtr;
35
36 /*----------------------------- Implementation ----------------------------*/
37
38 /* External assembler functions */
39
40 void    _ASMAPI LZ_timerOn(void);
41 ulong   _ASMAPI LZ_timerLap(void);
42 void    _ASMAPI LZ_timerOff(void);
43 ulong   _ASMAPI LZ_timerCount(void);
44 void    _ASMAPI LZ_disable(void);
45 void    _ASMAPI LZ_enable(void);
46
47 /****************************************************************************
48 REMARKS:
49 Initialise the Zen Timer module internals.
50 ****************************************************************************/
51 void __ZTimerInit(void)
52 {
53     _ZTimerBIOSPtr = PM_getBIOSPointer();
54 }
55
56 /****************************************************************************
57 REMARKS:
58 Call the assembler Zen Timer functions to do the timing.
59 ****************************************************************************/
60 #define __LZTimerOn(tm)     LZ_timerOn()
61
62 /****************************************************************************
63 REMARKS:
64 Call the assembler Zen Timer functions to do the timing.
65 ****************************************************************************/
66 #define __LZTimerLap(tm)        LZ_timerLap()
67
68 /****************************************************************************
69 REMARKS:
70 Call the assembler Zen Timer functions to do the timing.
71 ****************************************************************************/
72 #define __LZTimerOff(tm)        LZ_timerOff()
73
74 /****************************************************************************
75 REMARKS:
76 Call the assembler Zen Timer functions to do the timing.
77 ****************************************************************************/
78 #define __LZTimerCount(tm)  LZ_timerCount()
79
80 /****************************************************************************
81 REMARKS:
82 Define the resolution of the long period timer as microseconds per timer tick.
83 ****************************************************************************/
84 #define ULZTIMER_RESOLUTION     54925
85
86 /****************************************************************************
87 REMARKS:
88 Read the Long Period timer value from the BIOS timer tick.
89 ****************************************************************************/
90 static ulong __ULZReadTime(void)
91 {
92     ulong   ticks;
93     LZ_disable();            /* Turn of interrupts               */
94     ticks = PM_getLong(_ZTimerBIOSPtr+0x6C);
95     LZ_enable();             /* Turn on interrupts again         */
96     return ticks;
97 }
98
99 /****************************************************************************
100 REMARKS:
101 Compute the elapsed time from the BIOS timer tick. Note that we check to see
102 whether a midnight boundary has passed, and if so adjust the finish time to
103 account for this. We cannot detect if more that one midnight boundary has
104 passed, so if this happens we will be generating erronous results.
105 ****************************************************************************/
106 ulong __ULZElapsedTime(ulong start,ulong finish)
107 {
108     if (finish < start)
109         finish += 1573040L;         /* Number of ticks in 24 hours      */
110     return finish - start;
111 }