base-hw: preserve usec accuracy in us_to_ticks

The kernel timer used to truncated timeouts to the next lower
millisecond, which not only limits the wakeup accuracy but also results
in situations where a user-level timeout is triggered earlier than
expected. The latter effect results in the observation of a spurious
timeouts and the subsequent programming of another timeout.

The patch solves the problem by preserving the sub-milliseconds bits
in the 'us_to_ticks' implementation(s).

Issue #5142
This commit is contained in:
Norman Feske 2024-03-12 13:44:54 +01:00 committed by Christian Helmuth
parent 7ae7b8481a
commit a0290f8c51
4 changed files with 4 additions and 4 deletions

View File

@ -102,7 +102,7 @@ unsigned Timer::interrupt_id() const {
time_t Timer::us_to_ticks(time_t const us) const {
return (us / 1000) * TICS_PER_MS; }
return (us * TICS_PER_MS) / 1000; }
time_t Timer::_duration() const {

View File

@ -58,7 +58,7 @@ time_t Timer::ticks_to_us(time_t const ticks) const {
time_t Timer::us_to_ticks(time_t const us) const {
return (us / 1000) * _device.ticks_per_ms; }
return (us * _device.ticks_per_ms) / 1000; }
time_t Timer::_max_value() const {

View File

@ -84,7 +84,7 @@ time_t Timer::ticks_to_us(time_t const ticks) const {
time_t Timer::us_to_ticks(time_t const us) const {
return (us / 1000UL) * Board::Timer::TICS_PER_MS; }
return (us * Board::Timer::TICS_PER_MS) / 1000; }
time_t Timer::_max_value() const {

View File

@ -109,7 +109,7 @@ time_t Timer::ticks_to_us(time_t const ticks) const {
time_t Timer::us_to_ticks(time_t const us) const {
return (us / 1000) * _device.ticks_per_ms; }
return (us * _device.ticks_per_ms) / 1000; }
time_t Timer::_max_value() const {