namespace XFESystem.NativeKernel; // Pure arithmetic shared by the hardware timer and host checks. A requested // sleep duration cannot be more precise than the actual interrupt period. public static class TimerCalibration { public const ulong DesktopPeriodNanoseconds = 1000000; public static bool TryInitialCount(uint elapsedCounts, ulong elapsedNanoseconds, ulong periodNanoseconds, out uint initialCount) { initialCount = 0; if (elapsedCounts == 0 || elapsedNanoseconds == 0 || periodNanoseconds == 0 || periodNanoseconds > 1000000000) return false; ulong result = (ulong)elapsedCounts * periodNanoseconds / elapsedNanoseconds; if (result == 0 || result > 0xffffffff) return false; initialCount = (uint)result; return true; } }