Commit 86de6b71 authored by Henrik Brix Andersen's avatar Henrik Brix Andersen Committed by Fabio Baltieri
Browse files

sys: util: fix WAIT_FOR() timeout calculation



Use k_us_to_cyc_ceil32() for calculating the number of hardware cycles for
the given timeout value instead of using a custom calculation.

Fixes: #50032

Signed-off-by: default avatarHenrik Brix Andersen <hebad@vestas.com>
parent d41c56c4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -475,7 +475,7 @@ char *utf8_lcpy(char *dst, const char *src, size_t n);
 */
#define WAIT_FOR(expr, timeout, delay_stmt)                                                        \
	({                                                                                         \
		uint32_t cycle_count = (sys_clock_hw_cycles_per_sec() / USEC_PER_SEC) * (timeout); \
		uint32_t cycle_count = k_us_to_cyc_ceil32(timeout); \
		uint32_t start = k_cycle_get_32();                                                 \
		while (!(expr) && (cycle_count > (k_cycle_get_32() - start))) {                    \
			delay_stmt;                                                                \