timepoints: minimal compatibility with CONFIG_SYS_CLOCK_EXISTS=n

When timers are configured out, timepoint-based timeouts are reduced to
"no wait" or "wait forever" only.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2023-08-02 18:08:41 -04:00 committed by Carles Cufí
commit 90eac6e4bc

View file

@ -190,6 +190,8 @@ int64_t sys_clock_tick_get(void);
#define sys_clock_tick_get_32() (0) #define sys_clock_tick_get_32() (0)
#endif #endif
#ifdef CONFIG_SYS_CLOCK_EXISTS
/** /**
* @brief Kernel timepoint type * @brief Kernel timepoint type
* *
@ -235,19 +237,6 @@ k_timepoint_t sys_timepoint_calc(k_timeout_t timeout);
*/ */
k_timeout_t sys_timepoint_timeout(k_timepoint_t timepoint); k_timeout_t sys_timepoint_timeout(k_timepoint_t timepoint);
/**
* @brief Indicates if timepoint is expired
*
* @param timepoint Timepoint to evaluate
* @retval true if the timepoint is in the past, false otherwise
*
* @see sys_timepoint_calc()
*/
static inline bool sys_timepoint_expired(k_timepoint_t timepoint)
{
return K_TIMEOUT_EQ(sys_timepoint_timeout(timepoint), Z_TIMEOUT_NO_WAIT);
}
/** /**
* @brief Provided for backward compatibility. * @brief Provided for backward compatibility.
* *
@ -263,6 +252,43 @@ static inline uint64_t sys_clock_timeout_end_calc(k_timeout_t timeout)
return tp.tick; 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 Indicates if timepoint is expired
*
* @param timepoint Timepoint to evaluate
* @retval true if the timepoint is in the past, false otherwise
*
* @see sys_timepoint_calc()
*/
static inline bool sys_timepoint_expired(k_timepoint_t timepoint)
{
return K_TIMEOUT_EQ(sys_timepoint_timeout(timepoint), Z_TIMEOUT_NO_WAIT);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif