Reactos
1/*
2 * PROJECT: ReactOS HAL
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
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <hal.h>
12#define NDEBUG
13#include <debug.h>
14
15VOID
16FASTCALL
17KeUpdateSystemTime(
18 IN PKTRAP_FRAME TrapFrame,
19 IN ULONG Increment,
20 IN KIRQL OldIrql
21);
22
23/* GLOBALS ********************************************************************/
24
25ULONG HalpCurrentTimeIncrement, HalpNextTimeIncrement, HalpNextIntervalCount;
26
27/* PRIVATE FUNCTIONS **********************************************************/
28
29VOID
30HalpClockInterrupt(VOID)
31{
32 /* Clear the interrupt */
33 ASSERT(KeGetCurrentIrql() == CLOCK2_LEVEL);
34 WRITE_REGISTER_ULONG(TIMER0_INT_CLEAR, 1);
35
36 /* FIXME: Update HAL Perf counters */
37
38 /* FIXME: Check if someone changed the clockrate */
39
40 /* Call the kernel */
41 KeUpdateSystemTime(KeGetCurrentThread()->TrapFrame,
42 HalpCurrentTimeIncrement,
43 CLOCK2_LEVEL);
44}
45
46VOID
47HalpStallInterrupt(VOID)
48{
49 /* Clear the interrupt */
50 WRITE_REGISTER_ULONG(TIMER0_INT_CLEAR, 1);
51}
52
53VOID
54HalpInitializeClock(VOID)
55{
56 PKPCR Pcr = KeGetPcr();
57 ULONG ClockInterval;
58 SP804_CONTROL_REGISTER ControlRegister;
59
60 /* Setup the clock and profile interrupt */
61 Pcr->InterruptRoutine[CLOCK2_LEVEL] = HalpStallInterrupt;
62
63 /*
64 * Configure the interval to 10ms
65 * (INTERVAL (10ms) * TIMCLKfreq (1MHz))
66 * --------------------------------------- == 10^4
67 * (TIMCLKENXdiv (1) * PRESCALEdiv (1))
68 */
69 ClockInterval = 0x2710;
70
71 /* Configure the timer */
72 ControlRegister.AsUlong = 0;
73 ControlRegister.Wide = TRUE;
74 ControlRegister.Periodic = TRUE;
75 ControlRegister.Interrupt = TRUE;
76 ControlRegister.Enabled = TRUE;
77
78 /* Enable the timer */
79 WRITE_REGISTER_ULONG(TIMER0_LOAD, ClockInterval);
80 WRITE_REGISTER_ULONG(TIMER0_CONTROL, ControlRegister.AsUlong);
81}
82
83/* PUBLIC FUNCTIONS ***********************************************************/
84
85/*
86 * @implemented
87 */
88VOID
89NTAPI
90HalCalibratePerformanceCounter(IN volatile PLONG Count,
91 IN ULONGLONG NewCount)
92{
93 UNIMPLEMENTED;
94 while (TRUE);
95}
96
97/*
98 * @implemented
99 */
100ULONG
101NTAPI
102HalSetTimeIncrement(IN ULONG Increment)
103{
104 UNIMPLEMENTED;
105 while (TRUE);
106 return Increment;
107}
108
109/*
110 * @implemented
111 */
112VOID
113NTAPI
114KeStallExecutionProcessor(IN ULONG Microseconds)
115{
116 SP804_CONTROL_REGISTER ControlRegister;
117
118 /* Enable the timer */
119 WRITE_REGISTER_ULONG(TIMER1_LOAD, Microseconds);
120
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);
128
129 /* Now we will loop until the timer reached 0 */
130 while (READ_REGISTER_ULONG(TIMER1_VALUE));
131}
132
133/*
134 * @implemented
135 */
136LARGE_INTEGER
137NTAPI
138KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
139{
140 LARGE_INTEGER Value;
141
142 UNIMPLEMENTED;
143 while (TRUE);
144
145 Value.QuadPart = 0;
146 return Value;
147}
148
149/* EOF */