Commit 3c7f9903 authored by Piotr Zięcik's avatar Piotr Zięcik Committed by Anas Nashif
Browse files

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: default avatarPiotr Zięcik <piotr.ziecik@nordicsemi.no>
parent 2a26576b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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;