diff --git a/include/zephyr/sys_clock.h b/include/zephyr/sys_clock.h index 66c767a24e1d7fb..34dffc62f70bf57 100644 --- a/include/zephyr/sys_clock.h +++ b/include/zephyr/sys_clock.h @@ -190,6 +190,8 @@ int64_t sys_clock_tick_get(void); #define sys_clock_tick_get_32() (0) #endif +#ifdef CONFIG_SYS_CLOCK_EXISTS + /** * @brief Kernel timepoint type * @@ -236,31 +238,55 @@ k_timepoint_t sys_timepoint_calc(k_timeout_t timeout); k_timeout_t sys_timepoint_timeout(k_timepoint_t timepoint); /** - * @brief Indicates if timepoint is expired + * @brief Provided for backward compatibility. * - * @param timepoint Timepoint to evaluate - * @retval true if the timepoint is in the past, false otherwise + * This is deprecated. Consider `sys_timepoint_calc()` instead. * * @see sys_timepoint_calc() */ -static inline bool sys_timepoint_expired(k_timepoint_t timepoint) +__deprecated +static inline uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout) { - return K_TIMEOUT_EQ(sys_timepoint_timeout(timepoint), Z_TIMEOUT_NO_WAIT); + k_timepoint_t tp = sys_timepoint_calc(timeout); + + return tp.tick; +} + +#else + +/* + * When timers are configured out, timepoints can't relate to anything. + * The best we can do is to preserve whether or not they are derived from + * K_NO_WAIT. Anything else will translate back to K_FOREVER. + */ +typedef struct { bool wait; } k_timepoint_t; + +static inline k_timepoint_t sys_timepoint_calc(k_timeout_t timeout) +{ + k_timepoint_t timepoint; + + timepoint.wait = !K_TIMEOUT_EQ(timeout, Z_TIMEOUT_NO_WAIT); + return timepoint; +} + +static inline k_timeout_t sys_timepoint_timeout(k_timepoint_t timepoint) +{ + return timepoint.wait ? Z_FOREVER : Z_TIMEOUT_NO_WAIT; } +#endif + /** - * @brief Provided for backward compatibility. + * @brief Indicates if timepoint is expired * - * This is deprecated. Consider `sys_timepoint_calc()` instead. + * @param timepoint Timepoint to evaluate + * @retval true if the timepoint is in the past, false otherwise * * @see sys_timepoint_calc() */ -__deprecated -static inline uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout) +static inline bool sys_timepoint_expired(k_timepoint_t timepoint) { - k_timepoint_t tp = sys_timepoint_calc(timeout); - - return tp.tick; + return K_TIMEOUT_EQ(sys_timepoint_timeout(timepoint), Z_TIMEOUT_NO_WAIT); } #ifdef __cplusplus