diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index a7a474081e27ea..b2a5ccad9d8219 100644 --- a/include/zephyr/kernel.h +++ b/include/zephyr/kernel.h @@ -755,7 +755,7 @@ struct _static_thread_data { #define Z_THREAD_INIT_DELAY_INITIALIZER(ms) .init_delay_ms = (ms) #define Z_THREAD_INIT_DELAY(thread) SYS_TIMEOUT_MS((thread)->init_delay_ms) #else -#define Z_THREAD_INIT_DELAY_INITIALIZER(ms) .init_delay = SYS_TIMEOUT_MS(ms) +#define Z_THREAD_INIT_DELAY_INITIALIZER(ms) .init_delay = SYS_TIMEOUT_MS_INIT(ms) #define Z_THREAD_INIT_DELAY(thread) (thread)->init_delay #endif diff --git a/include/zephyr/sys/time_units.h b/include/zephyr/sys/time_units.h index c02fd01288726e..46679fc33acf75 100644 --- a/include/zephyr/sys/time_units.h +++ b/include/zephyr/sys/time_units.h @@ -38,10 +38,16 @@ extern "C" { */ #define SYS_FOREVER_US (-1) +/** @brief System-wide macro to initialize #k_timeout_t with a number of ticks + * converted from milliseconds. + */ +#define SYS_TIMEOUT_MS_INIT(ms) \ + Z_TIMEOUT_TICKS_INIT((ms) == SYS_FOREVER_MS ? \ + K_TICKS_FOREVER : Z_TIMEOUT_MS_TICKS(ms)) + /** @brief System-wide macro to convert milliseconds to kernel timeouts */ -#define SYS_TIMEOUT_MS(ms) Z_TIMEOUT_TICKS((ms) == SYS_FOREVER_MS ? \ - K_TICKS_FOREVER : Z_TIMEOUT_MS_TICKS(ms)) +#define SYS_TIMEOUT_MS(ms) ((k_timeout_t) SYS_TIMEOUT_MS_INIT(ms)) /* Exhaustively enumerated, highly optimized time unit conversion API */ diff --git a/include/zephyr/sys_clock.h b/include/zephyr/sys_clock.h index 36abcff9f874c1..105d91a1545afe 100644 --- a/include/zephyr/sys_clock.h +++ b/include/zephyr/sys_clock.h @@ -115,12 +115,14 @@ typedef struct { /** @} */ /** @cond INTERNAL_HIDDEN */ -#define Z_TIMEOUT_NO_WAIT ((k_timeout_t) {0}) +#define Z_TIMEOUT_NO_WAIT_INIT {0} +#define Z_TIMEOUT_NO_WAIT ((k_timeout_t) Z_TIMEOUT_NO_WAIT_INIT) #if defined(__cplusplus) && ((__cplusplus - 0) < 202002L) -#define Z_TIMEOUT_TICKS(t) ((k_timeout_t) { (t) }) +#define Z_TIMEOUT_TICKS_INIT(t) { (t) } #else -#define Z_TIMEOUT_TICKS(t) ((k_timeout_t) { .ticks = (t) }) +#define Z_TIMEOUT_TICKS_INIT(t) { .ticks = (t) } #endif +#define Z_TIMEOUT_TICKS(t) ((k_timeout_t) Z_TIMEOUT_TICKS_INIT(t)) #define Z_FOREVER Z_TIMEOUT_TICKS(K_TICKS_FOREVER) #ifdef CONFIG_TIMEOUT_64BIT