ReactOS  0.4.15-dev-1374-g8d3e80e
rtctimer.c File Reference
#include <hal.h>
#include <debug.h>
Include dependency graph for rtctimer.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

FORCEINLINE ULONG RtcClockRateToIncrement (UCHAR Rate)
 Converts the CMOS RTC rate into the time increment in 100ns intervals. More...
 
VOID RtcSetClockRate (UCHAR ClockRate)
 
VOID NTAPI HalpInitializeClock (VOID)
 
VOID FASTCALL HalpClockInterruptHandler (IN PKTRAP_FRAME TrapFrame)
 
VOID FASTCALL HalpProfileInterruptHandler (IN PKTRAP_FRAME TrapFrame)
 
ULONG NTAPI HalSetTimeIncrement (IN ULONG Increment)
 

Variables

const UCHAR HalpClockVector = 0xD1
 
BOOLEAN HalpClockSetMSRate
 
UCHAR HalpNextMSRate
 
UCHAR HalpCurrentRate = 9
 
ULONG HalpCurrentTimeIncrement
 
static UCHAR RtcMinimumClockRate = 8
 
static UCHAR RtcMaximumClockRate = 12
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file rtctimer.c.

Function Documentation

◆ HalpClockInterruptHandler()

VOID FASTCALL HalpClockInterruptHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 131 of file rtctimer.c.

132 {
133  ULONG LastIncrement;
134  KIRQL Irql;
135 
136  /* Enter trap */
137  KiEnterInterruptTrap(TrapFrame);
138 #ifdef _M_AMD64
139  /* This is for debugging */
140  TrapFrame->ErrorCode = 0xc10c4;
141 #endif
142 
143  /* Start the interrupt */
145  {
146  /* Spurious, just end the interrupt */
147  KiEoiHelper(TrapFrame);
148  }
149 
150  /* Read register C, so that the next interrupt can happen */
152 
153  /* Save increment */
154  LastIncrement = HalpCurrentTimeIncrement;
155 
156  /* Check if someone changed the time rate */
157  if (HalpClockSetMSRate)
158  {
159  /* Set new clock rate */
161 
162  /* We're done */
164  }
165 
166  /* Update the system time -- on x86 the kernel will exit this trap */
167  KeUpdateSystemTime(TrapFrame, LastIncrement, Irql);
168 }
VOID FASTCALL KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame, IN ULONG Increment, IN KIRQL OldIrql)
Definition: time.c:64
BOOLEAN NTAPI HalBeginSystemInterrupt(IN KIRQL Irql, IN ULONG Vector, OUT PKIRQL OldIrql)
Definition: pic.c:321
_Out_ PKIRQL Irql
Definition: csq.h:179
BOOLEAN HalpClockSetMSRate
Definition: rtctimer.c:21
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
VOID RtcSetClockRate(UCHAR ClockRate)
Definition: rtctimer.c:64
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define CLOCK_LEVEL
#define FALSE
Definition: types.h:117
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
UCHAR HalpNextMSRate
Definition: rtctimer.c:22
const UCHAR HalpClockVector
Definition: rtctimer.c:20
#define RTC_REGISTER_C
Definition: halhw.h:17
FORCEINLINE VOID KiEnterInterruptTrap(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:368
ULONG HalpCurrentTimeIncrement
Definition: rtctimer.c:24
unsigned int ULONG
Definition: retypes.h:1

◆ HalpInitializeClock()

VOID NTAPI HalpInitializeClock ( VOID  )

Definition at line 94 of file rtctimer.c.

95 {
96  ULONG_PTR EFlags;
97  UCHAR RegisterB;
98 
99  /* Save EFlags and disable interrupts */
100  EFlags = __readeflags();
101  _disable();
102 
103  // TODO: disable NMI
104 
105  /* Acquire CMOS lock */
107 
108  /* Enable the periodic interrupt in the CMOS */
109  RegisterB = HalpReadCmos(RTC_REGISTER_B);
111 
112  /* Release CMOS lock */
114 
115  /* Set initial rate */
117 
118  /* Restore interrupt state */
119  __writeeflags(EFlags);
120 
121  /* Notify the kernel about the maximum and minimum increment */
124 
125 
126  DPRINT1("Clock initialized\n");
127 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
VOID NTAPI KeSetTimeIncrement(IN ULONG MaxIncrement, IN ULONG MinIncrement)
Definition: ntoskrnl.c:42
static UCHAR RtcMaximumClockRate
Definition: rtctimer.c:26
VOID RtcSetClockRate(UCHAR ClockRate)
Definition: rtctimer.c:64
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RTC_REG_B_PI
Definition: halhw.h:16
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1603
UCHAR HalpCurrentRate
Definition: rtctimer.c:23
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
#define RTC_REGISTER_B
Definition: halp.h:17
unsigned char UCHAR
Definition: xmlstorage.h:181
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1598
static UCHAR RtcMinimumClockRate
Definition: rtctimer.c:25
FORCEINLINE ULONG RtcClockRateToIncrement(UCHAR Rate)
Converts the CMOS RTC rate into the time increment in 100ns intervals.
Definition: rtctimer.c:53
#define DPRINT1
Definition: precomp.h:8
void __cdecl _disable(void)
Definition: intrin_arm.h:365

◆ HalpProfileInterruptHandler()

VOID FASTCALL HalpProfileInterruptHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 172 of file rtctimer.c.

173 {
174  __debugbreak();
175 }
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698

◆ HalSetTimeIncrement()

ULONG NTAPI HalSetTimeIncrement ( IN ULONG  Increment)

Definition at line 179 of file rtctimer.c.

180 {
181  UCHAR Rate;
182 
183  /* Lookup largest value below given Increment */
184  for (Rate = RtcMinimumClockRate; Rate <= RtcMaximumClockRate; Rate++)
185  {
186  /* Check if this is the largest rate possible */
187  if (RtcClockRateToIncrement(Rate + 1) > Increment) break;
188  }
189 
190  /* Set the rate and tell HAL we want to change it */
191  HalpNextMSRate = Rate;
193 
194  /* Return the real increment */
195  return RtcClockRateToIncrement(Rate);
196 }
#define TRUE
Definition: types.h:120
static UCHAR RtcMaximumClockRate
Definition: rtctimer.c:26
BOOLEAN HalpClockSetMSRate
Definition: rtctimer.c:21
UCHAR HalpNextMSRate
Definition: rtctimer.c:22
unsigned char UCHAR
Definition: xmlstorage.h:181
static UCHAR RtcMinimumClockRate
Definition: rtctimer.c:25
FORCEINLINE ULONG RtcClockRateToIncrement(UCHAR Rate)
Converts the CMOS RTC rate into the time increment in 100ns intervals.
Definition: rtctimer.c:53
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42

◆ RtcClockRateToIncrement()

FORCEINLINE ULONG RtcClockRateToIncrement ( UCHAR  Rate)

Converts the CMOS RTC rate into the time increment in 100ns intervals.

Rate Freqency Interval (ms) Result

0 disabled 1 32768 0.03052 305 2 16384 0.06103 610 3 8192 0.12207 1221 4 4096 0.24414 2441 5 2048 0.48828 4883 6 1024 0.97656 9766 7 512 1.95313 19531 8 256 3.90625 39063 9 128 7.8125 78125 10 64 15.6250 156250 11 32 31.25 312500 12 16 62.5 625000 13 8 125 1250000 14 4 250 2500000 15 2 500 5000000

Definition at line 53 of file rtctimer.c.

54 {
55  /* Calculate frequency */
56  ULONG Freqency = 32768 >> (Rate - 1);
57 
58  /* Calculate interval in 100ns interval: Interval = (1 / Frequency) * 10000000
59  This formula will round properly, instead of truncating. */
60  return (10000000 + (Freqency/2)) / Freqency;
61 }
unsigned int ULONG
Definition: retypes.h:1

Referenced by HalpInitializeClock(), HalSetTimeIncrement(), and RtcSetClockRate().

◆ RtcSetClockRate()

VOID RtcSetClockRate ( UCHAR  ClockRate)

Definition at line 64 of file rtctimer.c.

65 {
66  UCHAR RegisterA;
67 
68  /* Update the global values */
69  HalpCurrentRate = ClockRate;
71 
72  /* Acquire CMOS lock */
74 
75  // TODO: disable NMI
76 
77  /* Read value of register A */
78  RegisterA = HalpReadCmos(RTC_REGISTER_A);
79 
80  /* Change lower 4 bits to new rate */
81  RegisterA &= 0xF0;
82  RegisterA |= ClockRate;
83 
84  /* Write the new value */
85  HalpWriteCmos(RTC_REGISTER_A, RegisterA);
86 
87  /* Release CMOS lock */
89 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
UCHAR HalpCurrentRate
Definition: rtctimer.c:23
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:244
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:227
unsigned char UCHAR
Definition: xmlstorage.h:181
FORCEINLINE ULONG RtcClockRateToIncrement(UCHAR Rate)
Converts the CMOS RTC rate into the time increment in 100ns intervals.
Definition: rtctimer.c:53
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
ULONG HalpCurrentTimeIncrement
Definition: rtctimer.c:24

Referenced by HalpClockInterruptHandler(), and HalpInitializeClock().

Variable Documentation

◆ HalpClockSetMSRate

BOOLEAN HalpClockSetMSRate

Definition at line 21 of file rtctimer.c.

Referenced by HalpClockInterruptHandler(), and HalSetTimeIncrement().

◆ HalpClockVector

const UCHAR HalpClockVector = 0xD1

Definition at line 20 of file rtctimer.c.

Referenced by HalpClockInterruptHandler().

◆ HalpCurrentRate

UCHAR HalpCurrentRate = 9

Definition at line 23 of file rtctimer.c.

Referenced by HalpInitializeClock(), and RtcSetClockRate().

◆ HalpCurrentTimeIncrement

ULONG HalpCurrentTimeIncrement

Definition at line 24 of file rtctimer.c.

Referenced by HalpClockInterruptHandler(), and RtcSetClockRate().

◆ HalpNextMSRate

UCHAR HalpNextMSRate

Definition at line 22 of file rtctimer.c.

Referenced by HalpClockInterruptHandler(), and HalSetTimeIncrement().

◆ RtcMaximumClockRate

UCHAR RtcMaximumClockRate = 12
static

Definition at line 26 of file rtctimer.c.

Referenced by HalpInitializeClock(), and HalSetTimeIncrement().

◆ RtcMinimumClockRate

UCHAR RtcMinimumClockRate = 8
static

Definition at line 25 of file rtctimer.c.

Referenced by HalpInitializeClock(), and HalSetTimeIncrement().