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
This commit is contained in:
Sebastian Sumpf 2021-02-25 16:26:43 +01:00 committed by Norman Feske
parent 1826ff8a59
commit d4b58b689c
2 changed files with 4 additions and 6 deletions

View File

@ -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;
}

View File

@ -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;