ReactOS 0.4.15-dev-7958-gcd0bb1a
timer.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for timer.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID FASTCALL KeUpdateSystemTime (IN PKTRAP_FRAME TrapFrame, IN ULONG Increment, IN KIRQL OldIrql)
 
VOID HalpClockInterrupt (VOID)
 
VOID HalpStallInterrupt (VOID)
 
VOID HalpInitializeClock (VOID)
 
VOID NTAPI HalCalibratePerformanceCounter (IN volatile PLONG Count, IN ULONGLONG NewCount)
 
ULONG NTAPI HalSetTimeIncrement (IN ULONG Increment)
 
VOID NTAPI KeStallExecutionProcessor (IN ULONG Microseconds)
 
LARGE_INTEGER NTAPI KeQueryPerformanceCounter (IN PLARGE_INTEGER PerformanceFreq)
 

Variables

ULONG HalpCurrentTimeIncrement
 
ULONG HalpNextTimeIncrement
 
ULONG HalpNextIntervalCount
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file timer.c.

Function Documentation

◆ HalCalibratePerformanceCounter()

VOID NTAPI HalCalibratePerformanceCounter ( IN volatile PLONG  Count,
IN ULONGLONG  NewCount 
)

Definition at line 90 of file timer.c.

92{
94 while (TRUE);
95}
#define UNIMPLEMENTED
Definition: debug.h:115
#define TRUE
Definition: types.h:120

◆ HalpClockInterrupt()

VOID HalpClockInterrupt ( VOID  )

Definition at line 30 of file timer.c.

31{
32 /* Clear the interrupt */
35
36 /* FIXME: Update HAL Perf counters */
37
38 /* FIXME: Check if someone changed the clockrate */
39
40 /* Call the kernel */
44}
#define WRITE_REGISTER_ULONG(r, v)
Definition: arm.h:27
#define CLOCK2_LEVEL
Definition: env_spec_w32.h:700
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
VOID FASTCALL KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame, IN ULONG Increment, IN KIRQL OldIrql)
Definition: time.c:64
ULONG HalpCurrentTimeIncrement
Definition: timer.c:25
#define KeGetCurrentThread
Definition: hal.h:55
#define ASSERT(a)
Definition: mode.c:44
#define TIMER0_INT_CLEAR
Definition: sp804.h:18

Referenced by HalInitSystem(), HalpInitializePICs(), HalpInitPhase0(), and HalpInitPhase1().

◆ HalpInitializeClock()

VOID HalpInitializeClock ( VOID  )

Definition at line 54 of file timer.c.

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);
81}
VOID HalpStallInterrupt(VOID)
Definition: timer.c:47
#define KeGetPcr()
Definition: ketypes.h:81
#define TIMER0_CONTROL
Definition: sp804.h:17
#define TIMER0_LOAD
Definition: sp804.h:15
Definition: ke.h:294
uint32_t ULONG
Definition: typedefs.h:59

Referenced by HalInitSystem().

◆ HalpStallInterrupt()

VOID HalpStallInterrupt ( VOID  )

Definition at line 47 of file timer.c.

48{
49 /* Clear the interrupt */
51}

Referenced by HalpInitializeClock().

◆ HalSetTimeIncrement()

ULONG NTAPI HalSetTimeIncrement ( IN ULONG  Increment)

Definition at line 102 of file timer.c.

103{
105 while (TRUE);
106 return Increment;
107}
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:46

Referenced by ExSetTimerResolution().

◆ KeQueryPerformanceCounter()

◆ KeStallExecutionProcessor()

VOID NTAPI KeStallExecutionProcessor ( IN ULONG  Microseconds)

Definition at line 114 of file timer.c.

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;
128
129 /* Now we will loop until the timer reached 0 */
131}
#define READ_REGISTER_ULONG(r)
Definition: arm.h:26
#define TIMER1_VALUE
Definition: sp804.h:23
#define TIMER1_LOAD
Definition: sp804.h:22
#define TIMER1_CONTROL
Definition: sp804.h:24

◆ KeUpdateSystemTime()

VOID FASTCALL KeUpdateSystemTime ( IN PKTRAP_FRAME  TrapFrame,
IN ULONG  Increment,
IN KIRQL  OldIrql 
)

Definition at line 64 of file time.c.

67{
68 PKPRCB Prcb = KeGetCurrentPrcb();
69 ULARGE_INTEGER CurrentTime, InterruptTime;
70 LONG OldTickOffset;
71
72 /* Check if this tick is being skipped */
73 if (Prcb->SkipTick)
74 {
75 /* Handle it next time */
76 Prcb->SkipTick = FALSE;
77
78 /* Increase interrupt count and end the interrupt */
79 Prcb->InterruptCount++;
80 KiEndInterrupt(Irql, TrapFrame);
81
82 /* Note: non-x86 return back to the caller! */
83 return;
84 }
85
86 /* Add the increment time to the shared data */
87 InterruptTime.QuadPart = *(ULONGLONG*)&SharedUserData->InterruptTime;
88 InterruptTime.QuadPart += Increment;
89 KiWriteSystemTime(&SharedUserData->InterruptTime, InterruptTime);
90
91 /* Check for timer expiration */
92 KiCheckForTimerExpiration(Prcb, TrapFrame, InterruptTime);
93
94 /* Update the tick offset */
96
97 /* If the debugger is enabled, check for break-in request */
99 {
100 /* Break-in requested! */
102 }
103
104 /* Check for full tick */
105 if (OldTickOffset <= (LONG)Increment)
106 {
107 /* Update the system time */
108 CurrentTime.QuadPart = *(ULONGLONG*)&SharedUserData->SystemTime;
109 CurrentTime.QuadPart += KeTimeAdjustment;
110 KiWriteSystemTime(&SharedUserData->SystemTime, CurrentTime);
111
112 /* Update the tick count */
113 CurrentTime.QuadPart = (*(ULONGLONG*)&KeTickCount) + 1;
114 KiWriteSystemTime(&KeTickCount, CurrentTime);
115
116 /* Update it in the shared user data */
117 KiWriteSystemTime(&SharedUserData->TickCount, CurrentTime);
118
119 /* Check for expiration with the new tick count as well */
120 KiCheckForTimerExpiration(Prcb, TrapFrame, InterruptTime);
121
122 /* Reset the tick offset */
124
125 /* Update processor/thread runtime */
126 KeUpdateRunTime(TrapFrame, Irql);
127 }
128 else
129 {
130 /* Increase interrupt count only */
131 Prcb->InterruptCount++;
132 }
133
134 /* Disable interrupts and end the interrupt */
135 KiEndInterrupt(Irql, TrapFrame);
136}
_Out_ PKIRQL Irql
Definition: csq.h:179
#define FALSE
Definition: types.h:117
#define InterlockedExchangeAdd
Definition: interlocked.h:181
BOOLEAN KdDebuggerEnabled
Definition: kddata.c:82
BOOLEAN NTAPI KdPollBreakIn(VOID)
Definition: kdlock.c:75
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
#define KiEndInterrupt(x, y)
Definition: ke.h:175
ULONG KeMaximumIncrement
Definition: clock.c:20
LONG KiTickOffset
Definition: time.c:17
ULONG KeTimeAdjustment
Definition: time.c:18
FORCEINLINE VOID KiCheckForTimerExpiration(PKPRCB Prcb, PKTRAP_FRAME TrapFrame, ULARGE_INTEGER InterruptTime)
Definition: time.c:40
FORCEINLINE VOID KiWriteSystemTime(volatile KSYSTEM_TIME *SystemTime, ULARGE_INTEGER NewTime)
Definition: time.c:25
VOID NTAPI KeUpdateRunTime(IN PKTRAP_FRAME TrapFrame, IN KIRQL Irql)
Definition: time.c:140
long LONG
Definition: pedump.c:60
#define SharedUserData
ULONG InterruptCount
Definition: ketypes.h:816
UCHAR SkipTick
Definition: ketypes.h:822
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
uint64_t ULONGLONG
Definition: typedefs.h:67
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)

Referenced by HalpClockInterrupt(), and HalpClockInterruptHandler().

Variable Documentation

◆ HalpCurrentTimeIncrement

ULONG HalpCurrentTimeIncrement

Definition at line 25 of file timer.c.

Referenced by HalInitSystem(), HalpClockInterrupt(), and HalpInitializeClock().

◆ HalpNextIntervalCount

ULONG HalpNextIntervalCount

Definition at line 25 of file timer.c.

Referenced by HalInitSystem().

◆ HalpNextTimeIncrement

ULONG HalpNextTimeIncrement

Definition at line 25 of file timer.c.

Referenced by HalInitSystem().