From 31af206a8c2fdd340b9b9e8fda29316ce047a482 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Mon, 7 Aug 2017 14:27:55 +0200 Subject: [PATCH] hw rpi: fix bug that caused bad timer precision The kernel timer on RPI is able to measure time microseconds-precise. Howeer, due to a bug, we dropped precision during the ticks-to-time translation and return only milliseconds-precise time. Ref #2400 --- repos/base-hw/src/core/spec/rpi/timer.cc | 4 ++-- repos/base-hw/src/core/spec/rpi/timer_driver.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/repos/base-hw/src/core/spec/rpi/timer.cc b/repos/base-hw/src/core/spec/rpi/timer.cc index 68e18a4c21..d3066e4698 100644 --- a/repos/base-hw/src/core/spec/rpi/timer.cc +++ b/repos/base-hw/src/core/spec/rpi/timer.cc @@ -35,11 +35,11 @@ void Timer::_start_one_shot(time_t const ticks) time_t Timer::_ticks_to_us(time_t const ticks) const { - return (ticks / Driver::TICS_PER_MS) * 1000; } + return ticks / Driver::TICS_PER_US; } time_t Timer::us_to_ticks(time_t const us) const { - return (us / 1000) * Driver::TICS_PER_MS; } + return us * Driver::TICS_PER_US; } time_t Timer::_max_value() const { diff --git a/repos/base-hw/src/core/spec/rpi/timer_driver.h b/repos/base-hw/src/core/spec/rpi/timer_driver.h index daa703a4c1..9ad4a9f709 100644 --- a/repos/base-hw/src/core/spec/rpi/timer_driver.h +++ b/repos/base-hw/src/core/spec/rpi/timer_driver.h @@ -29,7 +29,7 @@ namespace Kernel { class Timer_driver; } */ struct Kernel::Timer_driver : Genode::Mmio { - enum { TICS_PER_MS = Board::SYSTEM_TIMER_CLOCK / 1000 }; + enum { TICS_PER_US = Board::SYSTEM_TIMER_CLOCK / 1000 / 1000 }; struct Cs : Register<0x0, 32> { struct M1 : Bitfield<1, 1> { }; }; struct Clo : Register<0x4, 32> { };