subsys/zbus: move to timepoint API

Remove sys_clock_timeout_end_calc() usage as well as custom
_zbus_timeout_remainder().

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2023-07-07 22:29:32 -04:00 committed by Carles Cufí
parent 531aa5786d
commit a7b3584745
3 changed files with 11 additions and 19 deletions

View file

@ -148,7 +148,6 @@ struct zbus_observer {
#define ZBUS_REF(_value) &(_value)
k_timeout_t _zbus_timeout_remainder(uint64_t end_ticks);
/** @endcond */
/**

View file

@ -9,13 +9,6 @@
#include <zephyr/zbus/zbus.h>
LOG_MODULE_REGISTER(zbus, CONFIG_ZBUS_LOG_LEVEL);
k_timeout_t _zbus_timeout_remainder(uint64_t end_ticks)
{
int64_t now_ticks = sys_clock_tick_get();
return K_TICKS((k_ticks_t)MAX(end_ticks - now_ticks, 0));
}
#if (CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE > 0)
static inline void _zbus_notify_runtime_listeners(const struct zbus_channel *chan)
{
@ -34,7 +27,7 @@ static inline void _zbus_notify_runtime_listeners(const struct zbus_channel *cha
}
static inline int _zbus_notify_runtime_subscribers(const struct zbus_channel *chan,
uint64_t end_ticks)
k_timepoint_t end_time)
{
__ASSERT(chan != NULL, "chan is required");
@ -47,7 +40,7 @@ static inline int _zbus_notify_runtime_subscribers(const struct zbus_channel *ch
if (obs_nd->obs->enabled && (obs_nd->obs->queue != NULL)) {
err = k_msgq_put(obs_nd->obs->queue, &chan,
_zbus_timeout_remainder(end_ticks));
sys_timepoint_timeout(end_time));
_ZBUS_ASSERT(err == 0,
"could not deliver notification to observer %s. Error code %d",
@ -63,7 +56,7 @@ static inline int _zbus_notify_runtime_subscribers(const struct zbus_channel *ch
}
#endif /* CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE */
static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_ticks)
static int _zbus_notify_observers(const struct zbus_channel *chan, k_timepoint_t end_time)
{
int last_error = 0, err;
/* Notify static listeners */
@ -80,7 +73,7 @@ static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_
/* Notify static subscribers */
for (const struct zbus_observer *const *obs = chan->observers; *obs != NULL; ++obs) {
if ((*obs)->enabled && ((*obs)->queue != NULL)) {
err = k_msgq_put((*obs)->queue, &chan, _zbus_timeout_remainder(end_ticks));
err = k_msgq_put((*obs)->queue, &chan, sys_timepoint_timeout(end_time));
_ZBUS_ASSERT(err == 0, "could not deliver notification to observer %s.",
_ZBUS_OBS_NAME(*obs));
if (err) {
@ -92,7 +85,7 @@ static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_
}
#if CONFIG_ZBUS_RUNTIME_OBSERVERS_POOL_SIZE > 0
err = _zbus_notify_runtime_subscribers(chan, end_ticks);
err = _zbus_notify_runtime_subscribers(chan, end_time);
if (err) {
last_error = err;
}
@ -103,7 +96,7 @@ static int _zbus_notify_observers(const struct zbus_channel *chan, uint64_t end_
int zbus_chan_pub(const struct zbus_channel *chan, const void *msg, k_timeout_t timeout)
{
int err;
uint64_t end_ticks = sys_clock_timeout_end_calc(timeout);
k_timepoint_t end_time = sys_timepoint_calc(timeout);
_ZBUS_ASSERT(!k_is_in_isr(), "zbus cannot be used inside ISRs");
_ZBUS_ASSERT(chan != NULL, "chan is required");
@ -120,7 +113,7 @@ int zbus_chan_pub(const struct zbus_channel *chan, const void *msg, k_timeout_t
memcpy(chan->message, msg, chan->message_size);
err = _zbus_notify_observers(chan, end_ticks);
err = _zbus_notify_observers(chan, end_time);
k_mutex_unlock(chan->mutex);
@ -148,7 +141,7 @@ int zbus_chan_read(const struct zbus_channel *chan, void *msg, k_timeout_t timeo
int zbus_chan_notify(const struct zbus_channel *chan, k_timeout_t timeout)
{
int err;
uint64_t end_ticks = sys_clock_timeout_end_calc(timeout);
k_timepoint_t end_time = sys_timepoint_calc(timeout);
_ZBUS_ASSERT(!k_is_in_isr(), "zbus cannot be used inside ISRs");
_ZBUS_ASSERT(chan != NULL, "chan is required");
@ -158,7 +151,7 @@ int zbus_chan_notify(const struct zbus_channel *chan, k_timeout_t timeout)
return err;
}
err = _zbus_notify_observers(chan, end_ticks);
err = _zbus_notify_observers(chan, end_time);
k_mutex_unlock(chan->mutex);

View file

@ -21,7 +21,7 @@ int zbus_chan_add_obs(const struct zbus_channel *chan, const struct zbus_observe
{
int err;
struct zbus_observer_node *obs_nd, *tmp;
uint64_t end_ticks = sys_clock_timeout_end_calc(timeout);
k_timepoint_t end_time = sys_timepoint_calc(timeout);
_ZBUS_ASSERT(!k_is_in_isr(), "ISR blocked");
_ZBUS_ASSERT(chan != NULL, "chan is required");
@ -50,7 +50,7 @@ int zbus_chan_add_obs(const struct zbus_channel *chan, const struct zbus_observe
}
err = k_mem_slab_alloc(&_zbus_runtime_obs_pool, (void **)&obs_nd,
_zbus_timeout_remainder(end_ticks));
sys_timepoint_timeout(end_time));
if (err) {
LOG_ERR("Could not allocate memory on runtime observers pool\n");