ReactOS  r75625
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

#define NDEBUG

Definition at line 12 of file timer.c.

Function Documentation

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

Definition at line 90 of file timer.c.

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

Definition at line 30 of file timer.c.

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

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 */
43  CLOCK2_LEVEL);
44 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
VOID FASTCALL KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame, IN ULONG Increment, IN KIRQL OldIrql)
Definition: time.c:64
#define TIMER0_INT_CLEAR
Definition: sp804.h:18
#define CLOCK2_LEVEL
Definition: env_spec_w32.h:700
ULONG HalpCurrentTimeIncrement
Definition: timer.c:25
#define KeGetCurrentThread
Definition: hal.h:44
VOID HalpInitializeClock ( VOID  )

Definition at line 54 of file timer.c.

Referenced by HalInitSystem().

55 {
56  PKIPCR Pcr = (PKIPCR)KeGetPcr();
57  ULONG ClockInterval;
58  SP804_CONTROL_REGISTER ControlRegister;
59 
60  /* Setup the clock and profile interrupt */
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
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
#define TRUE
Definition: types.h:120
#define TIMER0_LOAD
Definition: sp804.h:15
struct _KIPCR * PKIPCR
#define KeGetPcr()
Definition: ke.h:25
#define CLOCK2_LEVEL
Definition: env_spec_w32.h:700
#define TIMER0_CONTROL
Definition: sp804.h:17
unsigned int ULONG
Definition: retypes.h:1
PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR]
Definition: ketypes.h:510
VOID HalpStallInterrupt ( VOID  )

Definition at line 47 of file timer.c.

Referenced by HalpInitializeClock().

48 {
49  /* Clear the interrupt */
51 }
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
#define TIMER0_INT_CLEAR
Definition: sp804.h:18
ULONG NTAPI HalSetTimeIncrement ( IN ULONG  Increment)

Definition at line 102 of file timer.c.

Referenced by ExSetTimerResolution().

103 {
105  while (TRUE);
106  return Increment;
107 }
#define TRUE
Definition: types.h:120
#define UNIMPLEMENTED
Definition: debug.h:114
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
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;
127  WRITE_REGISTER_ULONG(TIMER1_CONTROL, ControlRegister.AsUlong);
128 
129  /* Now we will loop until the timer reached 0 */
131 }
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
#define TRUE
Definition: types.h:120
NTKERNELAPI ULONG NTAPI READ_REGISTER_ULONG(IN PULONG Register)
#define TIMER1_VALUE
Definition: sp804.h:23
#define TIMER1_LOAD
Definition: sp804.h:22
#define TIMER1_CONTROL
Definition: sp804.h:24
VOID FASTCALL KeUpdateSystemTime ( IN PKTRAP_FRAME  TrapFrame,
IN ULONG  Increment,
IN KIRQL  OldIrql 
)

Definition at line 64 of file time.c.

Referenced by HalpClockInterrupt(), and HalpClockInterruptHandler().

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 }
ULONG KeMaximumIncrement
Definition: clock.c:20
FORCEINLINE VOID KiWriteSystemTime(volatile KSYSTEM_TIME *SystemTime, ULARGE_INTEGER NewTime)
Definition: time.c:25
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1054
_Out_ PKIRQL Irql
Definition: csq.h:179
ULONG KeTimeAdjustment
Definition: time.c:18
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
BOOLEAN NTAPI KdPollBreakIn(VOID)
Definition: kdmain.c:337
#define KiEndInterrupt(x, y)
Definition: ke.h:175
UCHAR SkipTick
Definition: ketypes.h:738
BOOLEAN KdDebuggerEnabled
Definition: kdmain.c:16
LONG KiTickOffset
Definition: time.c:17
#define InterlockedExchangeAdd
Definition: interlocked.h:181
ULONG InterruptCount
Definition: ketypes.h:732
FORCEINLINE VOID KiCheckForTimerExpiration(PKPRCB Prcb, PKTRAP_FRAME TrapFrame, ULARGE_INTEGER InterruptTime)
Definition: time.c:40
uint64_t ULONGLONG
Definition: typedefs.h:66
#define SharedUserData
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
VOID NTAPI KeUpdateRunTime(IN PKTRAP_FRAME TrapFrame, IN KIRQL Irql)
Definition: time.c:140
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42

Variable Documentation

ULONG HalpCurrentTimeIncrement

Definition at line 25 of file timer.c.

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

ULONG HalpNextIntervalCount

Definition at line 25 of file timer.c.

Referenced by HalInitSystem().

ULONG HalpNextTimeIncrement

Definition at line 25 of file timer.c.

Referenced by HalInitSystem().