drivers: nrf_rtc_timer: Correct initial timeout value

Values to be set to the comparator need to be specified in RTC cycles,
not ticks, so the initial value used in the tickless mode needs to be
MAX_CYCLES, otherwise when CONFIG_SYS_CLOCK_TICKS_PER_SEC is set to
a value less then the RTC frequency, the initially configured timeout
will be unnecessarily shorter.
On the occassion, remove also the call to counter() when setting the
initial timeout value in non-tickless mode. RTC is cleared a few lines
above, so at this point it will most likely be 0, and even if it was
not, compare_set() would properly handle a target time value that had
already passed.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
Andrzej Głąbek 2023-01-04 14:01:36 +01:00 committed by Carles Cufí
commit eb0cbb433c

View file

@ -670,7 +670,7 @@ static int sys_clock_driver_init(const struct device *dev)
}
uint32_t initial_timeout = IS_ENABLED(CONFIG_TICKLESS_KERNEL) ?
MAX_TICKS : (counter() + CYC_PER_TICK);
MAX_CYCLES : CYC_PER_TICK;
compare_set(0, initial_timeout, sys_clock_timeout_handler, NULL);