Skip to content

Commit

Permalink
timepoints: minimal compatibility with CONFIG_SYS_CLOCK_EXISTS=n
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nicolas Pitre authored and Umar Nisar committed Aug 15, 2023
1 parent fffaf73 commit a663f37
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions include/zephyr/sys_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a663f37

Please sign in to comment.