diff --git a/ArmPkg/Drivers/TimerDxe/TimerDxe.c b/ArmPkg/Drivers/TimerDxe/TimerDxe.c index 633876bea6..ccdb38c79b 100644 --- a/ArmPkg/Drivers/TimerDxe/TimerDxe.c +++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.c @@ -141,12 +141,13 @@ TimerDriverSetTimerPeriod ( ArmArchTimerDisableTimer (); if (TimerPeriod != 0) { - // Convert TimerPeriod to micro sec units - TimerTicks = DivU64x32 (TimerPeriod, 10); + // TimerTicks = TimerPeriod in 1ms unit x Frequency.10^-3 + // = TimerPeriod.10^-4 x Frequency.10^-3 + // = (TimerPeriod x Frequency) x 10^-7 + TimerTicks = MultU64x32 (TimerPeriod, FixedPcdGet32 (PcdArmArchTimerFreqInHz)); + TimerTicks = DivU64x32 (TimerTicks, 10000000U); - TimerTicks = MultU64x32 (TimerTicks, (PcdGet32(PcdArmArchTimerFreqInHz)/1000000)); - - ArmArchTimerSetTimerVal((UINTN)TimerTicks); + ArmArchTimerSetTimerVal ((UINTN)TimerTicks); // Enable the timer ArmArchTimerEnableTimer (); diff --git a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c index d1cd0c8e6e..4fe7cb8d64 100644 --- a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c +++ b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c @@ -82,8 +82,10 @@ MicroSecondDelay ( UINT64 TimerTicks64; UINT64 SystemCounterVal; - // Calculate counter ticks that can represent requested delay - TimerTicks64 = MultU64x32 (MicroSeconds, TICKS_PER_MICRO_SEC); + // Calculate counter ticks that can represent requested delay: + // = MicroSeconds x TICKS_PER_MICRO_SEC + // = MicroSeconds x Frequency.10^-6 + TimerTicks64 = (MicroSeconds * PcdGet32 (PcdArmArchTimerFreqInHz)) / 1000000U; // Read System Counter value SystemCounterVal = ArmArchTimerGetSystemCount ();