ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

timer.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS HAL
00003  * LICENSE:         GPL - See COPYING in the top level directory
00004  * FILE:            hal/halx86/generic/timer.c
00005  * PURPOSE:         HAL Timer Routines
00006  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 
00011 #include <hal.h>
00012 #define NDEBUG
00013 #include <debug.h>
00014 
00015 /* GLOBALS *******************************************************************/
00016 
00017 BOOLEAN HalpClockSetMSRate;
00018 ULONG HalpCurrentTimeIncrement;
00019 ULONG HalpCurrentRollOver;
00020 ULONG HalpNextMSRate = 14;
00021 ULONG HalpLargestClockMS = 15;
00022 
00023 LARGE_INTEGER HalpRolloverTable[15] =
00024 {
00025     {{1197, 10032}},
00026     {{2394, 20064}},
00027     {{3591, 30096}},
00028     {{4767, 39952}},
00029     {{5964, 49984}},
00030     {{7161, 60016}},
00031     {{8358, 70048}},
00032     {{9555, 80080}},
00033     {{10731, 89936}},
00034     {{11949, 100144}},
00035     {{13125, 110000}},
00036     {{14322, 120032}},
00037     {{15519, 130064}},
00038     {{16695, 139920}},
00039     {{17892, 149952}}
00040 };
00041 
00042 /* PRIVATE FUNCTIONS *********************************************************/
00043 
00044 VOID
00045 NTAPI
00046 HalpInitializeClock(VOID)
00047 {
00048     //PKPRCB Prcb = KeGetCurrentPrcb();
00049     ULONG Increment;
00050     USHORT RollOver;
00051     ULONG Flags = 0;
00052 
00053     /* Get increment and rollover for the largest time clock ms possible */
00054     Increment = HalpRolloverTable[HalpLargestClockMS - 1].HighPart;
00055     RollOver = (USHORT)HalpRolloverTable[HalpLargestClockMS - 1].LowPart;
00056 
00057     /* Set the maximum and minimum increment with the kernel */
00058     HalpCurrentTimeIncrement = Increment;
00059     KeSetTimeIncrement(Increment, HalpRolloverTable[0].HighPart);
00060 
00061     /* Disable interrupts */
00062     Flags = __readmsr();
00063     _disable();
00064 
00065     /* Set the rollover */
00066     __outbyte(TIMER_CONTROL_PORT, TIMER_SC0 | TIMER_BOTH | TIMER_MD2);
00067     __outbyte(TIMER_DATA_PORT0, RollOver & 0xFF);
00068     __outbyte(TIMER_DATA_PORT0, RollOver >> 8);
00069 
00070     /* Restore interrupts if they were previously enabled */
00071     __writemsr(Flags);
00072 
00073     /* Save rollover and return */
00074     HalpCurrentRollOver = RollOver;
00075 }
00076 
00077 /* PUBLIC FUNCTIONS ***********************************************************/
00078 
00079 /*
00080  * @implemented
00081  */
00082 VOID
00083 NTAPI
00084 HalCalibratePerformanceCounter(IN volatile PLONG Count,
00085                                IN ULONGLONG NewCount)
00086 {
00087     ULONG Flags = 0;
00088 
00089     /* Disable interrupts */
00090     Flags = __readmsr();
00091     _disable();
00092 
00093     /* Do a decrement for this CPU */
00094     _InterlockedDecrement(Count);
00095 
00096     /* Wait for other CPUs */
00097     while (*Count);
00098 
00099     /* Restore interrupts if they were previously enabled */
00100     __writemsr(Flags);
00101 }
00102 
00103 /*
00104  * @implemented
00105  */
00106 ULONG
00107 NTAPI
00108 HalSetTimeIncrement(IN ULONG Increment)
00109 {
00110     /* Round increment to ms */
00111     Increment /= 10000;
00112 
00113     /* Normalize between our minimum (1 ms) and maximum (variable) setting */
00114     if (Increment > HalpLargestClockMS) Increment = HalpLargestClockMS;
00115     if (Increment <= 0) Increment = 1;
00116 
00117     /* Set the rate and tell HAL we want to change it */
00118     HalpNextMSRate = Increment;
00119     HalpClockSetMSRate = TRUE;
00120 
00121     /* Return the increment */
00122     return HalpRolloverTable[Increment - 1].HighPart;
00123 }
00124 
00125 VOID
00126 NTHALAPI
00127 KeStallExecutionProcessor(ULONG USec)
00128 {
00129     LARGE_INTEGER Freq, Start = KeQueryPerformanceCounter(&Freq), End;
00130     LARGE_INTEGER Timebase, Remainder;
00131     Timebase.QuadPart = 1000000;
00132     Freq.QuadPart *= USec;
00133     End = RtlLargeIntegerDivide(Freq, Timebase, &Remainder);
00134     End.QuadPart += Start.QuadPart;
00135     while(End.QuadPart > __rdtsc());
00136 }
00137 
00138 /* EOF */

Generated on Sun May 27 2012 04:18:16 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.