kernel: Do not use sys_clock_ticks_per_sec in _ms_to_ticks()
The value of sys_clock_ticks_per_sec is obtained using simple integer division with rounding toward zero. As result using this variable in _ms_to_ticks() introduces some error. This commit eliminates sys_clock_ticks_per_sec from equation used in _ms_to_ticks() removing introduced error. Also, this commit fixes #8895. Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
This commit is contained in:
parent
2a26576b03
commit
3c7f990367
1 changed files with 3 additions and 3 deletions
|
@ -1357,9 +1357,9 @@ static ALWAYS_INLINE s32_t _ms_to_ticks(s32_t ms)
|
|||
|
||||
#ifdef _NEED_PRECISE_TICK_MS_CONVERSION
|
||||
/* use 64-bit math to keep precision */
|
||||
s64_t ms_ticks_per_sec = (s64_t)ms * sys_clock_ticks_per_sec;
|
||||
|
||||
return (s32_t)ceiling_fraction(ms_ticks_per_sec, MSEC_PER_SEC);
|
||||
return (s32_t)ceiling_fraction(
|
||||
(s64_t)ms * sys_clock_hw_cycles_per_sec,
|
||||
(s64_t)MSEC_PER_SEC * sys_clock_hw_cycles_per_tick);
|
||||
#else
|
||||
/* simple division keeps precision */
|
||||
s32_t ms_per_tick = MSEC_PER_SEC / sys_clock_ticks_per_sec;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue