3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: hal/halx86/generic/timer.c
5 * PURPOSE: HAL Timer Routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
15 /* GLOBALS *******************************************************************/
17 BOOLEAN HalpClockSetMSRate
;
18 ULONG HalpCurrentTimeIncrement
;
19 ULONG HalpCurrentRollOver
;
20 ULONG HalpNextMSRate
= 14;
21 ULONG HalpLargestClockMS
= 15;
23 LARGE_INTEGER HalpRolloverTable
[15] =
42 /* PRIVATE FUNCTIONS *********************************************************/
46 HalpInitializeClock(VOID
)
48 PKPRCB Prcb
= KeGetCurrentPrcb();
53 /* Check the CPU Type */
54 if (Prcb
->CpuType
<= 4)
56 /* 486's or equal can't go higher then 10ms */
57 HalpLargestClockMS
= 10;
61 /* Get increment and rollover for the largest time clock ms possible */
62 Increment
= HalpRolloverTable
[HalpLargestClockMS
- 1].HighPart
;
63 RollOver
= (USHORT
)HalpRolloverTable
[HalpLargestClockMS
- 1].LowPart
;
65 /* Set the maximum and minimum increment with the kernel */
66 HalpCurrentTimeIncrement
= Increment
;
67 KeSetTimeIncrement(Increment
, HalpRolloverTable
[0].HighPart
);
69 /* Disable interrupts */
70 Ke386SaveFlags(Flags
);
73 /* Set the rollover */
74 __outbyte(TIMER_CONTROL_PORT
, TIMER_SC0
| TIMER_BOTH
| TIMER_MD2
);
75 __outbyte(TIMER_DATA_PORT0
, RollOver
& 0xFF);
76 __outbyte(TIMER_DATA_PORT0
, RollOver
>> 8);
78 /* Restore interrupts if they were previously enabled */
79 Ke386RestoreFlags(Flags
);
81 /* Save rollover and return */
82 HalpCurrentRollOver
= RollOver
;
85 /* PUBLIC FUNCTIONS ***********************************************************/
92 HalCalibratePerformanceCounter(IN
volatile PLONG Count
,
93 IN ULONGLONG NewCount
)
97 /* Disable interrupts */
98 Ke386SaveFlags(Flags
);
101 /* Do a decrement for this CPU */
102 _InterlockedDecrement(Count
);
104 /* Wait for other CPUs */
107 /* Restore interrupts if they were previously enabled */
108 Ke386RestoreFlags(Flags
);
116 HalSetTimeIncrement(IN ULONG Increment
)
118 /* Round increment to ms */
121 /* Normalize between our minimum (1 ms) and maximum (variable) setting */
122 if (Increment
> HalpLargestClockMS
) Increment
= HalpLargestClockMS
;
123 if (Increment
<= 0) Increment
= 1;
125 /* Set the rate and tell HAL we want to change it */
126 HalpNextMSRate
= Increment
;
127 HalpClockSetMSRate
= TRUE
;
129 /* Return the increment */
130 return HalpRolloverTable
[Increment
- 1].HighPart
;