From d4b58b689c01c08ce1031ad940265d0ec0956ca6 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Thu, 25 Feb 2021 16:26:43 +0100 Subject: [PATCH] base-hw: fix RISC-V duration calculation Simplify calculation of Timer::_duration, the old implementation caused the time running backwards sometimes. This makes 'nic_router_dhcp_*' and 'event_filter' run scripts succeed. issue #4021 --- repos/base-hw/src/core/spec/riscv/timer.cc | 8 +++----- repos/base-hw/src/core/spec/riscv/timer.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/repos/base-hw/src/core/spec/riscv/timer.cc b/repos/base-hw/src/core/spec/riscv/timer.cc index b222712a6e..dd1297b1b7 100644 --- a/repos/base-hw/src/core/spec/riscv/timer.cc +++ b/repos/base-hw/src/core/spec/riscv/timer.cc @@ -39,8 +39,8 @@ time_t Board::Timer::stime() const void Timer::_start_one_shot(time_t const ticks) { - _device.timeout = _device.stime() + ticks; - Sbi::set_timer(_device.timeout); + _device.last_time = _device.stime(); + Sbi::set_timer(_device.last_time + ticks); } @@ -58,9 +58,7 @@ time_t Timer::_max_value() const { time_t Timer::_duration() const { - addr_t time = _device.stime(); - return time < _device.timeout ? _device.timeout - time - : _last_timeout_duration + (time - _device.timeout); + return _device.stime() - _device.last_time; } diff --git a/repos/base-hw/src/core/spec/riscv/timer.h b/repos/base-hw/src/core/spec/riscv/timer.h index 8ded8dffd9..d5032409a6 100644 --- a/repos/base-hw/src/core/spec/riscv/timer.h +++ b/repos/base-hw/src/core/spec/riscv/timer.h @@ -31,7 +31,7 @@ struct Board::Timer TICKS_PER_US = TICKS_PER_MS / 1000, }; - Kernel::time_t timeout = 0; + Kernel::time_t last_time { 0 }; Kernel::time_t stime() const;