ReactOS  0.4.14-dev-323-g6fe6a88
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)
 
VOID RtcSetClockRate (UCHAR ClockRate)
 
INIT_FUNCTION 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 = 6
 
static UCHAR RtcMaximumClockRate = 10
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file rtctimer.c.

Function Documentation

◆ HalpClockInterruptHandler()

VOID FASTCALL HalpClockInterruptHandler ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 107 of file rtctimer.c.

108 {
109  ULONG LastIncrement;
110  KIRQL Irql;
111 
112  /* Enter trap */
113  KiEnterInterruptTrap(TrapFrame);
114 #ifdef _M_AMD64
115  /* This is for debugging */
116  TrapFrame->ErrorCode = 0xc10c4;
117 #endif
118 
119  /* Start the interrupt */
121  {
122  /* Spurious, just end the interrupt */
123  KiEoiHelper(TrapFrame);
124  }
125 
126  /* Read register C, so that the next interrupt can happen */
128 
129  /* Save increment */
130  LastIncrement = HalpCurrentTimeIncrement;
131 
132  /* Check if someone changed the time rate */
133  if (HalpClockSetMSRate)
134  {
135  /* Set new clock rate */
137 
138  /* We're done */
140  }
141 
142  /* Update the system time -- on x86 the kernel will exit this trap */
143  KeUpdateSystemTime(TrapFrame, LastIncrement, Irql);
144 }
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:23
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
VOID RtcSetClockRate(UCHAR ClockRate)
Definition: rtctimer.c:40
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define CLOCK_LEVEL
UCHAR FORCEINLINE HalpReadCmos(IN UCHAR Reg)
Definition: cmos.c:24
UCHAR HalpNextMSRate
Definition: rtctimer.c:24
const UCHAR HalpClockVector
Definition: rtctimer.c:22
#define RTC_REGISTER_C
Definition: halp.h:56
FORCEINLINE VOID KiEnterInterruptTrap(IN PKTRAP_FRAME TrapFrame)
Definition: trap_x.h:369
ULONG HalpCurrentTimeIncrement
Definition: rtctimer.c:26
unsigned int ULONG
Definition: retypes.h:1

◆ HalpInitializeClock()

INIT_FUNCTION VOID NTAPI HalpInitializeClock ( VOID  )

Definition at line 70 of file rtctimer.c.

71 {
72  ULONG_PTR EFlags;
73  UCHAR RegisterB;
74 
75  /* Save EFlags and disable interrupts */
76  EFlags = __readeflags();
77  _disable();
78 
79  // TODO: disable NMI
80 
81  /* Acquire CMOS lock */
83 
84  /* Enable the periodic interrupt in the CMOS */
85  RegisterB = HalpReadCmos(RTC_REGISTER_B);
87 
88  /* Release CMOS lock */
90 
91  /* Set initial rate */
93 
94  /* Restore interrupt state */
95  __writeeflags(EFlags);
96 
97  /* Notify the kernel about the maximum and minimum increment */
100 
101 
102  DPRINT1("Clock initialized\n");
103 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
#define RTC_REG_B_PI
Definition: halp.h:55
VOID NTAPI KeSetTimeIncrement(IN ULONG MaxIncrement, IN ULONG MinIncrement)
Definition: ntoskrnl.c:46
static UCHAR RtcMaximumClockRate
Definition: rtctimer.c:28
VOID RtcSetClockRate(UCHAR ClockRate)
Definition: rtctimer.c:40
uint32_t ULONG_PTR
Definition: typedefs.h:63
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1555
UCHAR HalpCurrentRate
Definition: rtctimer.c:25
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:1550
static UCHAR RtcMinimumClockRate
Definition: rtctimer.c:27
FORCEINLINE ULONG RtcClockRateToIncrement(UCHAR Rate)
Definition: rtctimer.c:33
#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 148 of file rtctimer.c.

149 {
150  __debugbreak();
151 }
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698

◆ HalSetTimeIncrement()

ULONG NTAPI HalSetTimeIncrement ( IN ULONG  Increment)

Definition at line 155 of file rtctimer.c.

156 {
157  UCHAR Rate;
158 
159  /* Lookup largest value below given Increment */
160  for (Rate = RtcMinimumClockRate; Rate <= RtcMaximumClockRate; Rate++)
161  {
162  /* Check if this is the largest rate possible */
163  if (RtcClockRateToIncrement(Rate + 1) > Increment) break;
164  }
165 
166  /* Set the rate and tell HAL we want to change it */
167  HalpNextMSRate = Rate;
169 
170  /* Return the real increment */
171  return RtcClockRateToIncrement(Rate);
172 }
#define TRUE
Definition: types.h:120
static UCHAR RtcMaximumClockRate
Definition: rtctimer.c:28
BOOLEAN HalpClockSetMSRate
Definition: rtctimer.c:23
UCHAR HalpNextMSRate
Definition: rtctimer.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
static UCHAR RtcMinimumClockRate
Definition: rtctimer.c:27
FORCEINLINE ULONG RtcClockRateToIncrement(UCHAR Rate)
Definition: rtctimer.c:33
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42

◆ RtcClockRateToIncrement()

FORCEINLINE ULONG RtcClockRateToIncrement ( UCHAR  Rate)

Definition at line 33 of file rtctimer.c.

34 {
35  ULONG Freqency = ((32768 << 1) >> Rate);
36  return (1000000 + (Freqency/2)) / Freqency;
37 }
unsigned int ULONG
Definition: retypes.h:1

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

◆ RtcSetClockRate()

VOID RtcSetClockRate ( UCHAR  ClockRate)

Definition at line 40 of file rtctimer.c.

41 {
42  UCHAR RegisterA;
43 
44  /* Update the global values */
45  HalpCurrentRate = ClockRate;
47 
48  /* Acquire CMOS lock */
50 
51  // TODO: disable NMI
52 
53  /* Read value of register A */
54  RegisterA = HalpReadCmos(RTC_REGISTER_A);
55 
56  /* Change lower 4 bits to new rate */
57  RegisterA &= 0xF0;
58  RegisterA |= ClockRate;
59 
60  /* Write the new value */
61  HalpWriteCmos(RTC_REGISTER_A, RegisterA);
62 
63  /* Release CMOS lock */
65 }
VOID FORCEINLINE HalpWriteCmos(IN UCHAR Reg, IN UCHAR Value)
Definition: cmos.c:35
UCHAR HalpCurrentRate
Definition: rtctimer.c:25
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)
Definition: rtctimer.c:33
#define RTC_REGISTER_A
Definition: xboxrtc.c:21
ULONG HalpCurrentTimeIncrement
Definition: rtctimer.c:26

Referenced by HalpClockInterruptHandler(), and HalpInitializeClock().

Variable Documentation

◆ HalpClockSetMSRate

BOOLEAN HalpClockSetMSRate

Definition at line 23 of file rtctimer.c.

Referenced by HalpClockInterruptHandler(), and HalSetTimeIncrement().

◆ HalpClockVector

const UCHAR HalpClockVector = 0xD1

Definition at line 22 of file rtctimer.c.

Referenced by HalpClockInterruptHandler().

◆ HalpCurrentRate

UCHAR HalpCurrentRate = 9

Definition at line 25 of file rtctimer.c.

Referenced by HalpInitializeClock(), and RtcSetClockRate().

◆ HalpCurrentTimeIncrement

ULONG HalpCurrentTimeIncrement

Definition at line 26 of file rtctimer.c.

Referenced by HalpClockInterruptHandler(), and RtcSetClockRate().

◆ HalpNextMSRate

UCHAR HalpNextMSRate

Definition at line 24 of file rtctimer.c.

Referenced by HalpClockInterruptHandler(), and HalSetTimeIncrement().

◆ RtcMaximumClockRate

UCHAR RtcMaximumClockRate = 10
static

Definition at line 28 of file rtctimer.c.

Referenced by HalpInitializeClock(), and HalSetTimeIncrement().

◆ RtcMinimumClockRate

UCHAR RtcMinimumClockRate = 6
static

Definition at line 27 of file rtctimer.c.

Referenced by HalpInitializeClock(), and HalSetTimeIncrement().