3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: hal/halarm/generic/timer.c
5 * PURPOSE: Timer Routines
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
18 IN PKTRAP_FRAME TrapFrame
,
23 /* GLOBALS ********************************************************************/
25 ULONG HalpCurrentTimeIncrement
, HalpNextTimeIncrement
, HalpNextIntervalCount
;
27 /* PRIVATE FUNCTIONS **********************************************************/
30 HalpClockInterrupt(VOID
)
32 /* Clear the interrupt */
33 ASSERT(KeGetCurrentIrql() == CLOCK2_LEVEL
);
34 WRITE_REGISTER_ULONG(TIMER0_INT_CLEAR
, 1);
36 /* FIXME: Update HAL Perf counters */
38 /* FIXME: Check if someone changed the clockrate */
41 KeUpdateSystemTime(KeGetCurrentThread()->TrapFrame
,
42 HalpCurrentTimeIncrement
,
47 HalpStallInterrupt(VOID
)
49 /* Clear the interrupt */
50 WRITE_REGISTER_ULONG(TIMER0_INT_CLEAR
, 1);
54 HalpInitializeClock(VOID
)
56 PKIPCR Pcr
= (PKIPCR
)KeGetPcr();
58 SP804_CONTROL_REGISTER ControlRegister
;
60 /* Setup the clock and profile interrupt */
61 Pcr
->InterruptRoutine
[CLOCK2_LEVEL
] = HalpStallInterrupt
;
64 * Configure the interval to 10ms
65 * (INTERVAL (10ms) * TIMCLKfreq (1MHz))
66 * --------------------------------------- == 10^4
67 * (TIMCLKENXdiv (1) * PRESCALEdiv (1))
69 ClockInterval
= 0x2710;
71 /* Configure the timer */
72 ControlRegister
.AsUlong
= 0;
73 ControlRegister
.Wide
= TRUE
;
74 ControlRegister
.Periodic
= TRUE
;
75 ControlRegister
.Interrupt
= TRUE
;
76 ControlRegister
.Enabled
= TRUE
;
78 /* Enable the timer */
79 WRITE_REGISTER_ULONG(TIMER0_LOAD
, ClockInterval
);
80 WRITE_REGISTER_ULONG(TIMER0_CONTROL
, ControlRegister
.AsUlong
);
83 /* PUBLIC FUNCTIONS ***********************************************************/
90 HalCalibratePerformanceCounter(IN
volatile PLONG Count
,
91 IN ULONGLONG NewCount
)
102 HalSetTimeIncrement(IN ULONG Increment
)
114 KeStallExecutionProcessor(IN ULONG Microseconds
)
116 SP804_CONTROL_REGISTER ControlRegister
;
118 /* Enable the timer */
119 WRITE_REGISTER_ULONG(TIMER1_LOAD
, Microseconds
);
121 /* Configure the timer */
122 ControlRegister
.AsUlong
= 0;
123 ControlRegister
.OneShot
= TRUE
;
124 ControlRegister
.Wide
= TRUE
;
125 ControlRegister
.Periodic
= TRUE
;
126 ControlRegister
.Enabled
= TRUE
;
127 WRITE_REGISTER_ULONG(TIMER1_CONTROL
, ControlRegister
.AsUlong
);
129 /* Now we will loop until the timer reached 0 */
130 while (READ_REGISTER_ULONG(TIMER1_VALUE
));
138 KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq
)