Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Zbus API . More...

Data Structures

struct  zbus_channel_data
 Type used to represent a channel mutable data. More...
 
struct  zbus_channel
 Type used to represent a channel. More...
 
struct  zbus_observer_data
 
struct  zbus_observer
 Type used to represent an observer. More...
 

Macros

#define ZBUS_CHAN_ADD_OBS_WITH_MASK(_chan, _obs, _masked, _prio)
 Add a static channel observervation.
 
#define ZBUS_CHAN_ADD_OBS(_chan, _obs, _prio)
 Add a static channel observervation.
 
#define ZBUS_OBS_DECLARE(...)
 This macro list the observers to be used in a file.
 
#define ZBUS_CHAN_DECLARE(...)
 This macro list the channels to be used in a file.
 
#define ZBUS_OBSERVERS_EMPTY
 This macro indicates the channel has no observers.
 
#define ZBUS_OBSERVERS(...)
 This macro indicates the channel has listed observers.
 
#define ZBUS_CHAN_DEFINE(_name, _type, _validator, _user_data, _observers, _init_val)
 Zbus channel definition.
 
#define ZBUS_MSG_INIT(_val, ...)
 Initialize a message.
 
#define ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _queue_size, _enable)
 Define and initialize a subscriber.
 
#define ZBUS_SUBSCRIBER_DEFINE(_name, _queue_size)
 Define and initialize a subscriber.
 
#define ZBUS_LISTENER_DEFINE_WITH_ENABLE(_name, _cb, _enable)
 Define and initialize a listener.
 
#define ZBUS_LISTENER_DEFINE(_name, _cb)
 Define and initialize a listener.
 
#define ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _enable)
 Define and initialize a message subscriber.
 
#define ZBUS_MSG_SUBSCRIBER_DEFINE(_name)
 Define and initialize an enabled message subscriber.
 

Enumerations

enum  zbus_observer_type { ZBUS_OBSERVER_LISTENER_TYPE , ZBUS_OBSERVER_SUBSCRIBER_TYPE , ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE }
 Type used to represent an observer type. More...
 

Functions

int zbus_chan_pub (const struct zbus_channel *chan, const void *msg, k_timeout_t timeout)
 Publish to a channel.
 
int zbus_chan_read (const struct zbus_channel *chan, void *msg, k_timeout_t timeout)
 Read a channel.
 
int zbus_chan_claim (const struct zbus_channel *chan, k_timeout_t timeout)
 Claim a channel.
 
int zbus_chan_finish (const struct zbus_channel *chan)
 Finish a channel claim.
 
int zbus_chan_notify (const struct zbus_channel *chan, k_timeout_t timeout)
 Force a channel notification.
 
static const char * zbus_chan_name (const struct zbus_channel *chan)
 Get the channel's name.
 
static void * zbus_chan_msg (const struct zbus_channel *chan)
 Get the reference for a channel message directly.
 
static const void * zbus_chan_const_msg (const struct zbus_channel *chan)
 Get a constant reference for a channel message directly.
 
static uint16_t zbus_chan_msg_size (const struct zbus_channel *chan)
 Get the channel's message size.
 
static void * zbus_chan_user_data (const struct zbus_channel *chan)
 Get the channel's user data.
 
static void zbus_chan_set_msg_sub_pool (const struct zbus_channel *chan, struct net_buf_pool *pool)
 Set the channel's msg subscriber net_buf pool.
 
static void zbus_chan_pub_stats_update (const struct zbus_channel *chan)
 Update the publishing statistics for a channel.
 
static k_ticks_t zbus_chan_pub_stats_last_time (const struct zbus_channel *chan)
 Get the time a channel was last published to.
 
static uint32_t zbus_chan_pub_stats_count (const struct zbus_channel *chan)
 Get the number of times a channel has been published to.
 
static uint32_t zbus_chan_pub_stats_avg_period (const struct zbus_channel *chan)
 Get the average period between publishes to a channel.
 
int zbus_chan_add_obs (const struct zbus_channel *chan, const struct zbus_observer *obs, k_timeout_t timeout)
 Add an observer to a channel.
 
int zbus_chan_rm_obs (const struct zbus_channel *chan, const struct zbus_observer *obs, k_timeout_t timeout)
 Remove an observer from a channel.
 
int zbus_obs_set_enable (const struct zbus_observer *obs, bool enabled)
 Change the observer state.
 
static int zbus_obs_is_enabled (const struct zbus_observer *obs, bool *enable)
 Get the observer state.
 
int zbus_obs_set_chan_notification_mask (const struct zbus_observer *obs, const struct zbus_channel *chan, bool masked)
 Mask notifications from a channel to an observer.
 
int zbus_obs_is_chan_notification_masked (const struct zbus_observer *obs, const struct zbus_channel *chan, bool *masked)
 Get the notifications masking state from a channel to an observer.
 
static const char * zbus_obs_name (const struct zbus_observer *obs)
 Get the observer's name.
 
int zbus_obs_attach_to_thread (const struct zbus_observer *obs)
 Set the observer thread priority by attaching it to a thread.
 
int zbus_obs_detach_from_thread (const struct zbus_observer *obs)
 Clear the observer thread priority by detaching it from a thread.
 
int zbus_sub_wait (const struct zbus_observer *sub, const struct zbus_channel **chan, k_timeout_t timeout)
 Wait for a channel notification.
 
int zbus_sub_wait_msg (const struct zbus_observer *sub, const struct zbus_channel **chan, void *msg, k_timeout_t timeout)
 Wait for a channel message.
 
bool zbus_iterate_over_channels (bool(*iterator_func)(const struct zbus_channel *chan))
 Iterate over channels.
 
bool zbus_iterate_over_channels_with_user_data (bool(*iterator_func)(const struct zbus_channel *chan, void *user_data), void *user_data)
 Iterate over channels with user data.
 
bool zbus_iterate_over_observers (bool(*iterator_func)(const struct zbus_observer *obs))
 Iterate over observers.
 
bool zbus_iterate_over_observers_with_user_data (bool(*iterator_func)(const struct zbus_observer *obs, void *user_data), void *user_data)
 Iterate over observers with user data.
 

Detailed Description

Zbus API .

Macro Definition Documentation

◆ ZBUS_CHAN_ADD_OBS

#define ZBUS_CHAN_ADD_OBS ( _chan,
_obs,
_prio )

#include <zephyr/zbus/zbus.h>

Value:
ZBUS_CHAN_ADD_OBS_WITH_MASK(_chan, _obs, false, _prio)
#define ZBUS_CHAN_ADD_OBS_WITH_MASK(_chan, _obs, _masked, _prio)
Add a static channel observervation.
Definition zbus.h:281

Add a static channel observervation.

This macro initializes a channel observation by receiving the channel and the observer.

Parameters
_chanChannel instance.
_obsObserver instance.
_prioObserver notification sequence priority.

◆ ZBUS_CHAN_ADD_OBS_WITH_MASK

#define ZBUS_CHAN_ADD_OBS_WITH_MASK ( _chan,
_obs,
_masked,
_prio )

#include <zephyr/zbus/zbus.h>

Value:
const STRUCT_SECTION_ITERABLE(zbus_channel_observation, \
_CONCAT(_CONCAT(_chan, zz), _CONCAT(_prio, _obs))) = { \
.chan = &_chan, \
.obs = &_obs, \
}; \
STRUCT_SECTION_ITERABLE(zbus_channel_observation_mask, \
_CONCAT(_CONCAT(_CONCAT(_chan, zz), _CONCAT(_prio, _obs)), \
_mask)) = {.enabled = _masked}
#define STRUCT_SECTION_ITERABLE(struct_type, varname)
Defines a new element for an iterable section.
Definition iterable_sections.h:216

Add a static channel observervation.

This macro initializes a channel observation by receiving the channel and the observer.

Parameters
_chanChannel instance.
_obsObserver instance.
_maskedObservation state.
_prioObserver notification sequence priority.

◆ ZBUS_CHAN_DECLARE

#define ZBUS_CHAN_DECLARE ( ...)

#include <zephyr/zbus/zbus.h>

Value:
FOR_EACH(_ZBUS_CHAN_EXTERN, (;), __VA_ARGS__)
#define FOR_EACH(F, sep,...)
Call a macro F on each provided argument with a given separator between each call.
Definition util_macro.h:481

This macro list the channels to be used in a file.

Internally, it declares the channels with the extern statement. Note it is only necessary when the channels are declared outside the file.

◆ ZBUS_CHAN_DEFINE

#define ZBUS_CHAN_DEFINE ( _name,
_type,
_validator,
_user_data,
_observers,
_init_val )

#include <zephyr/zbus/zbus.h>

Value:
static _type _CONCAT(_zbus_message_, _name) = _init_val; \
static struct zbus_channel_data _CONCAT(_zbus_chan_data_, _name) = { \
.observers_start_idx = -1, \
.observers_end_idx = -1, \
.sem = Z_SEM_INITIALIZER(_CONCAT(_zbus_chan_data_, _name).sem, 1, 1), \
IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
.highest_observer_priority = ZBUS_MIN_THREAD_PRIORITY, \
)) \
IF_ENABLED(CONFIG_ZBUS_RUNTIME_OBSERVERS, ( \
&_CONCAT(_zbus_chan_data_, _name).observers), \
)) \
}; \
static K_MUTEX_DEFINE(_CONCAT(_zbus_mutex_, _name)); \
_ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_channel, _name) = { \
ZBUS_CHANNEL_NAME_INIT(_name) /* Maybe removed */ \
.message = &_CONCAT(_zbus_message_, _name), \
.message_size = sizeof(_type), \
.user_data = _user_data, \
.validator = _validator, \
.data = &_CONCAT(_zbus_chan_data_, _name), \
IF_ENABLED(ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_ISOLATION, ( \
.msg_subscriber_pool = &_zbus_msg_subscribers_pool, \
)) \
}; \
/* Extern declaration of observers */ \
ZBUS_OBS_DECLARE(_observers); \
/* Create all channel observations from observers list */ \
FOR_EACH_FIXED_ARG_NONEMPTY_TERM(_ZBUS_CHAN_OBSERVATION, (;), _name, _observers)
#define K_MUTEX_DEFINE(name)
Statically define and initialize a mutex.
Definition kernel.h:3037
#define SYS_SLIST_STATIC_INIT(ptr_to_list)
Statically initialize a single-linked list.
Definition slist.h:209
Type used to represent a channel mutable data.
Definition zbus.h:30
struct net_buf_pool * msg_subscriber_pool
Net buf pool for message subscribers.
Definition zbus.h:63
struct k_sem sem
Access control semaphore.
Definition zbus.h:44
sys_slist_t observers
Channel observer list.
Definition zbus.h:57
Type used to represent a channel.
Definition zbus.h:80

Zbus channel definition.

This macro defines a channel.

Parameters
_nameThe channel's name.
_typeThe Message type. It must be a struct or union.
_validatorThe validator function.
_user_dataA pointer to the user data.
See also
struct zbus_channel
Parameters
_observersThe observers list. The sequence indicates the priority of the observer. The first the highest priority.
_init_valThe message initialization.

◆ ZBUS_LISTENER_DEFINE

#define ZBUS_LISTENER_DEFINE ( _name,
_cb )

#include <zephyr/zbus/zbus.h>

Value:
#define ZBUS_LISTENER_DEFINE_WITH_ENABLE(_name, _cb, _enable)
Define and initialize a listener.
Definition zbus.h:453

Define and initialize a listener.

This macro defines an observer of listener type. This macro establishes the callback where the listener will be notified synchronously and initialize the struct zbus_observer defining the listener. The listeners are defined in the enabled state with this macro.

Parameters
[in]_nameThe listener's name.
[in]_cbThe callback function.

◆ ZBUS_LISTENER_DEFINE_WITH_ENABLE

#define ZBUS_LISTENER_DEFINE_WITH_ENABLE ( _name,
_cb,
_enable )

#include <zephyr/zbus/zbus.h>

Value:
static struct zbus_observer_data _CONCAT(_zbus_obs_data_, _name) = { \
.enabled = _enable, \
IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
.priority = ZBUS_MIN_THREAD_PRIORITY, \
)) \
}; \
_ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \
ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \
.data = &_CONCAT(_zbus_obs_data_, _name), \
.callback = (_cb) \
}
@ ZBUS_OBSERVER_LISTENER_TYPE
Definition zbus.h:114
Definition zbus.h:119
Type used to represent an observer.
Definition zbus.h:144

Define and initialize a listener.

This macro defines an observer of listener type. This macro establishes the callback where the listener will be notified synchronously, and initialize the struct zbus_observer defining the listener.

Parameters
[in]_nameThe listener's name.
[in]_cbThe callback function.
[in]_enableThe listener initial enable state.

◆ ZBUS_MSG_INIT

#define ZBUS_MSG_INIT ( _val,
... )

#include <zephyr/zbus/zbus.h>

Value:
{ \
_val, ##__VA_ARGS__ \
}

Initialize a message.

This macro initializes a message by passing the values to initialize the message struct or union.

Parameters
[in]_valVariadic with the initial values. ZBUS_INIT(0) means {0}, as ZBUS_INIT(.a=10, .b=30) means {.a=10, .b=30}.

◆ ZBUS_MSG_SUBSCRIBER_DEFINE

#define ZBUS_MSG_SUBSCRIBER_DEFINE ( _name)

#include <zephyr/zbus/zbus.h>

Value:
#define ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _enable)
Define and initialize a message subscriber.
Definition zbus.h:492

Define and initialize an enabled message subscriber.

This macro defines an observer of message subscriber type. It defines a FIFO where the subscriber will receive the message asynchronously and initialize the zbus_observer defining the subscriber. The message subscribers are defined in the enabled state with this macro.

Parameters
[in]_nameThe subscriber's name.

◆ ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE

#define ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE ( _name,
_enable )

#include <zephyr/zbus/zbus.h>

Value:
static K_FIFO_DEFINE(_zbus_observer_fifo_##_name); \
static struct zbus_observer_data _CONCAT(_zbus_obs_data_, _name) = { \
.enabled = _enable, \
IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
.priority = ZBUS_MIN_THREAD_PRIORITY, \
)) \
}; \
_ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \
ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \
.data = &_CONCAT(_zbus_obs_data_, _name), \
.message_fifo = &_zbus_observer_fifo_##_name, \
}
#define K_FIFO_DEFINE(name)
Statically define and initialize a FIFO queue.
Definition kernel.h:2701
@ ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE
Definition zbus.h:116

Define and initialize a message subscriber.

This macro defines an observer of ZBUS_OBSERVER_SUBSCRIBER_TYPE type. It defines a FIFO where the subscriber will receive the message asynchronously and initialize the zbus_observer defining the subscriber.

Parameters
[in]_nameThe subscriber's name.
[in]_enableThe subscriber's initial state.

◆ ZBUS_OBS_DECLARE

#define ZBUS_OBS_DECLARE ( ...)

#include <zephyr/zbus/zbus.h>

Value:
FOR_EACH_NONEMPTY_TERM(_ZBUS_OBS_EXTERN, (;), __VA_ARGS__)
#define FOR_EACH_NONEMPTY_TERM(F, term,...)
Like FOR_EACH(), but with a terminator instead of a separator, and drops empty elements from the argu...
Definition util_macro.h:536

This macro list the observers to be used in a file.

Internally, it declares the observers with the extern statement. Note it is only necessary when the observers are declared outside the file.

◆ ZBUS_OBSERVERS

#define ZBUS_OBSERVERS ( ...)

#include <zephyr/zbus/zbus.h>

Value:
__VA_ARGS__

This macro indicates the channel has listed observers.

Note the sequence of observer notification will follow the same as listed.

◆ ZBUS_OBSERVERS_EMPTY

#define ZBUS_OBSERVERS_EMPTY

#include <zephyr/zbus/zbus.h>

This macro indicates the channel has no observers.

◆ ZBUS_SUBSCRIBER_DEFINE

#define ZBUS_SUBSCRIBER_DEFINE ( _name,
_queue_size )

#include <zephyr/zbus/zbus.h>

Value:
ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _queue_size, true)
#define ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _queue_size, _enable)
Define and initialize a subscriber.
Definition zbus.h:407

Define and initialize a subscriber.

This macro defines an observer of subscriber type. It defines a message queue where the subscriber will receive the notification asynchronously, and initialize the struct zbus_observer defining the subscriber. The subscribers are defined in the enabled state with this macro.

Parameters
[in]_nameThe subscriber's name.
[in]_queue_sizeThe notification queue's size.

◆ ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE

#define ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE ( _name,
_queue_size,
_enable )

#include <zephyr/zbus/zbus.h>

Value:
K_MSGQ_DEFINE(_zbus_observer_queue_##_name, \
sizeof(struct zbus_channel *), \
_queue_size, sizeof(struct zbus_channel *) \
); \
static struct zbus_observer_data _CONCAT(_zbus_obs_data_, _name) = { \
.enabled = _enable, \
IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
.priority = ZBUS_MIN_THREAD_PRIORITY, \
)) \
}; \
_ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \
ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \
.data = &_CONCAT(_zbus_obs_data_, _name), \
.queue = &_zbus_observer_queue_##_name, \
}
#define K_MSGQ_DEFINE(q_name, q_msg_size, q_max_msgs, q_align)
Statically define and initialize a message queue.
Definition kernel.h:4590
@ ZBUS_OBSERVER_SUBSCRIBER_TYPE
Definition zbus.h:115

Define and initialize a subscriber.

This macro defines an observer of subscriber type. It defines a message queue where the subscriber will receive the notification asynchronously, and initialize the struct zbus_observer defining the subscriber.

Parameters
[in]_nameThe subscriber's name.
[in]_queue_sizeThe notification queue's size.
[in]_enableThe subscriber initial enable state.

Enumeration Type Documentation

◆ zbus_observer_type

#include <zephyr/zbus/zbus.h>

Type used to represent an observer type.

A observer can be a listener or a subscriber.

Enumerator
ZBUS_OBSERVER_LISTENER_TYPE 
ZBUS_OBSERVER_SUBSCRIBER_TYPE 
ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE 

Function Documentation

◆ zbus_chan_add_obs()

int zbus_chan_add_obs ( const struct zbus_channel * chan,
const struct zbus_observer * obs,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Add an observer to a channel.

This routine adds an observer to the channel.

Parameters
chanThe channel's reference.
obsThe observer's reference to be added.
timeoutWaiting period to add an observer, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Observer added to the channel.
-EALREADYThe observer is already present in the channel's runtime observers list.
-ENOMEMReturned without waiting.
-EAGAINWaiting period timed out.
-EINVALSome parameter is invalid.

◆ zbus_chan_claim()

int zbus_chan_claim ( const struct zbus_channel * chan,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Claim a channel.

This routine claims a channel. During the claiming period the channel is blocked for publishing, reading, notifying or claiming again. Finishing is the only available action.

Warning
After calling this routine, the channel cannot be used by other thread until the zbus_chan_finish routine is performed.
This routine should only be called once before a zbus_chan_finish.
Parameters
[in]chanThe channel's reference.
[in]timeoutWaiting period to claim the channel, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Channel claimed.
-EBUSYThe channel is busy.
-EAGAINWaiting period timed out.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_chan_const_msg()

static const void * zbus_chan_const_msg ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get a constant reference for a channel message directly.

This routine returns a constant reference of a channel message. This should be used inside listeners to access the message directly. In this way zbus prevents the listener of changing the notifying channel's message during the notification process.

Warning
This function must only be used directly for already locked channels. This can be done inside a listener for the receiving channel or after claim a channel.
Parameters
chanThe channel's constant reference.
Returns
A constant channel's message reference.

◆ zbus_chan_finish()

int zbus_chan_finish ( const struct zbus_channel * chan)

#include <zephyr/zbus/zbus.h>

Finish a channel claim.

This routine finishes a channel claim. After calling this routine with success, the channel will be able to be used by other thread.

Warning
This routine must only be used after a zbus_chan_claim.
Parameters
chanThe channel's reference.
Return values
0Channel finished.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_chan_msg()

static void * zbus_chan_msg ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the reference for a channel message directly.

This routine returns the reference of a channel message.

Warning
This function must only be used directly for already locked channels. This can be done inside a listener for the receiving channel or after claim a channel.
Parameters
chanThe channel's reference.
Returns
Channel's message reference.

◆ zbus_chan_msg_size()

static uint16_t zbus_chan_msg_size ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the channel's message size.

This routine returns the channel's message size.

Parameters
chanThe channel's reference.
Returns
Channel's message size.

◆ zbus_chan_name()

static const char * zbus_chan_name ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the channel's name.

This routine returns the channel's name reference.

Parameters
chanThe channel's reference.
Returns
Channel's name reference.

◆ zbus_chan_notify()

int zbus_chan_notify ( const struct zbus_channel * chan,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Force a channel notification.

This routine forces the event dispatcher to notify the channel's observers even if the message has no changes. Note this function could be useful after claiming/finishing actions.

Parameters
chanThe channel's reference.
timeoutWaiting period to notify the channel, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Channel notified.
-EBUSYThe channel's semaphore returned without waiting.
-EAGAINTimeout to take the channel's semaphore.
-ENOMEMThere is not more buffer on the messgage buffers pool.
-EFAULTA parameter is incorrect, the notification could not be sent to one or more observer, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_chan_pub()

int zbus_chan_pub ( const struct zbus_channel * chan,
const void * msg,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Publish to a channel.

This routine publishes a message to a channel.

Parameters
chanThe channel's reference.
msgReference to the message where the publish function copies the channel's message data from.
timeoutWaiting period to publish the channel, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Channel published.
-ENOMSGThe message is invalid based on the validator function or some of the observers could not receive the notification.
-EBUSYThe channel is busy.
-EAGAINWaiting period timed out.
-EFAULTA parameter is incorrect, the notification could not be sent to one or more observer, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_chan_pub_stats_avg_period()

static uint32_t zbus_chan_pub_stats_avg_period ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the average period between publishes to a channel.

Note
Will return 0 if channel has not yet been published to.
Parameters
chanThe channel's reference.
Returns
Average duration in milliseconds between publishes.

◆ zbus_chan_pub_stats_count()

static uint32_t zbus_chan_pub_stats_count ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the number of times a channel has been published to.

Note
Will return 0 if channel has not yet been published to.
Parameters
chanThe channel's reference.
Returns
The number of times a channel has been published to.

◆ zbus_chan_pub_stats_last_time()

static k_ticks_t zbus_chan_pub_stats_last_time ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the time a channel was last published to.

Note
Will return 0 if channel has not yet been published to.
Parameters
chanThe channel's reference.
Returns
The kernel timestamp of the last publishing action.

◆ zbus_chan_pub_stats_update()

static void zbus_chan_pub_stats_update ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Update the publishing statistics for a channel.

This function updates the publishing statistics for the zbus_chan_claim -> zbus_chan_finish workflow, which cannot automatically determine whether new data has been published or not.

Warning
This function must only be used directly for already locked channels.
Parameters
chanThe channel's reference.

◆ zbus_chan_read()

int zbus_chan_read ( const struct zbus_channel * chan,
void * msg,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Read a channel.

This routine reads a message from a channel.

Parameters
[in]chanThe channel's reference.
[out]msgReference to the message where the read function copies the channel's message data to.
[in]timeoutWaiting period to read the channel, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Channel read.
-EBUSYThe channel is busy.
-EAGAINWaiting period timed out.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_chan_rm_obs()

int zbus_chan_rm_obs ( const struct zbus_channel * chan,
const struct zbus_observer * obs,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Remove an observer from a channel.

This routine removes an observer to the channel.

Parameters
chanThe channel's reference.
obsThe observer's reference to be removed.
timeoutWaiting period to remove an observer, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Observer removed to the channel.
-EINVALInvalid data supplied.
-EBUSYReturned without waiting.
-EAGAINWaiting period timed out.
-ENODATAno observer found in channel's runtime observer list.
-ENOMEMReturned without waiting.

◆ zbus_chan_set_msg_sub_pool()

static void zbus_chan_set_msg_sub_pool ( const struct zbus_channel * chan,
struct net_buf_pool * pool )
inlinestatic

#include <zephyr/zbus/zbus.h>

Set the channel's msg subscriber net_buf pool.

Parameters
chanThe channel's reference.
poolThe reference to the net_buf memory pool.

◆ zbus_chan_user_data()

static void * zbus_chan_user_data ( const struct zbus_channel * chan)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the channel's user data.

This routine returns the channel's user data.

Parameters
chanThe channel's reference.
Returns
Channel's user data.

◆ zbus_iterate_over_channels()

bool zbus_iterate_over_channels ( bool(* iterator_func )(const struct zbus_channel *chan))

#include <zephyr/zbus/zbus.h>

Iterate over channels.

Enables the developer to iterate over the channels giving to this function an iterator_func which is called for each channel. If the iterator_func returns false all the iteration stops.

Parameters
[in]iterator_funcThe function that will be execute on each iteration.
Return values
trueIterator executed for all channels.
falseIterator could not be executed. Some iterate returned false.

◆ zbus_iterate_over_channels_with_user_data()

bool zbus_iterate_over_channels_with_user_data ( bool(* iterator_func )(const struct zbus_channel *chan, void *user_data),
void * user_data )

#include <zephyr/zbus/zbus.h>

Iterate over channels with user data.

Enables the developer to iterate over the channels giving to this function an iterator_func which is called for each channel. If the iterator_func returns false all the iteration stops.

Parameters
[in]iterator_funcThe function that will be execute on each iteration.
[in]user_dataThe user data that can be passed in the function.
Return values
trueIterator executed for all channels.
falseIterator could not be executed. Some iterate returned false.

◆ zbus_iterate_over_observers()

bool zbus_iterate_over_observers ( bool(* iterator_func )(const struct zbus_observer *obs))

#include <zephyr/zbus/zbus.h>

Iterate over observers.

Enables the developer to iterate over the observers giving to this function an iterator_func which is called for each observer. If the iterator_func returns false all the iteration stops.

Parameters
[in]iterator_funcThe function that will be execute on each iteration.
Return values
trueIterator executed for all channels.
falseIterator could not be executed. Some iterate returned false.

◆ zbus_iterate_over_observers_with_user_data()

bool zbus_iterate_over_observers_with_user_data ( bool(* iterator_func )(const struct zbus_observer *obs, void *user_data),
void * user_data )

#include <zephyr/zbus/zbus.h>

Iterate over observers with user data.

Enables the developer to iterate over the observers giving to this function an iterator_func which is called for each observer. If the iterator_func returns false all the iteration stops.

Parameters
[in]iterator_funcThe function that will be execute on each iteration.
[in]user_dataThe user data that can be passed in the function.
Return values
trueIterator executed for all channels.
falseIterator could not be executed. Some iterate returned false.

◆ zbus_obs_attach_to_thread()

int zbus_obs_attach_to_thread ( const struct zbus_observer * obs)

#include <zephyr/zbus/zbus.h>

Set the observer thread priority by attaching it to a thread.

Parameters
[in]obsThe observer's reference.
Return values
0Observer detached from the thread.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_obs_detach_from_thread()

int zbus_obs_detach_from_thread ( const struct zbus_observer * obs)

#include <zephyr/zbus/zbus.h>

Clear the observer thread priority by detaching it from a thread.

Parameters
[in]obsThe observer's reference.
Return values
0Observer detached from the thread.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_obs_is_chan_notification_masked()

int zbus_obs_is_chan_notification_masked ( const struct zbus_observer * obs,
const struct zbus_channel * chan,
bool * masked )

#include <zephyr/zbus/zbus.h>

Get the notifications masking state from a channel to an observer.

Parameters
obsThe observer's reference to be added.
chanThe channel's reference.
[out]maskedThe mask state. When the mask is true, the observer will not receive notifications from the channel.
Return values
0Retrieved the masked state.
-ESRCHNo observation found for the related pair chan/obs.
-EINVALSome parameter is invalid.

◆ zbus_obs_is_enabled()

static int zbus_obs_is_enabled ( const struct zbus_observer * obs,
bool * enable )
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the observer state.

This routine retrieves the observer state.

Parameters
[in]obsThe observer's reference.
[out]enableThe boolean output's reference.
Returns
Observer state.

◆ zbus_obs_name()

static const char * zbus_obs_name ( const struct zbus_observer * obs)
inlinestatic

#include <zephyr/zbus/zbus.h>

Get the observer's name.

This routine returns the observer's name reference.

Parameters
obsThe observer's reference.
Returns
The observer's name reference.

◆ zbus_obs_set_chan_notification_mask()

int zbus_obs_set_chan_notification_mask ( const struct zbus_observer * obs,
const struct zbus_channel * chan,
bool masked )

#include <zephyr/zbus/zbus.h>

Mask notifications from a channel to an observer.

The observer can mask notifications from a specific observing channel by calling this function.

Parameters
obsThe observer's reference to be added.
chanThe channel's reference.
maskedThe mask state. When the mask is true, the observer will not receive notifications from the channel.
Return values
0Channel notifications masked to the observer.
-ESRCHNo observation found for the related pair chan/obs.
-EINVALSome parameter is invalid.

◆ zbus_obs_set_enable()

int zbus_obs_set_enable ( const struct zbus_observer * obs,
bool enabled )

#include <zephyr/zbus/zbus.h>

Change the observer state.

This routine changes the observer state. A channel when disabled will not receive notifications from the event dispatcher.

Parameters
[in]obsThe observer's reference.
[in]enabledState to be. When false the observer stops to receive notifications.
Return values
0Observer set enable.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_sub_wait()

int zbus_sub_wait ( const struct zbus_observer * sub,
const struct zbus_channel ** chan,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Wait for a channel notification.

This routine makes the subscriber to wait a notification. The notification comes as a channel reference.

Parameters
[in]subThe subscriber's reference.
[out]chanThe notification channel's reference.
[in]timeoutWaiting period for a notification arrival, or one of the special values K_NO_WAIT and K_FOREVER.
Return values
0Notification received.
-ENOMSGReturned without waiting.
-EAGAINWaiting period timed out.
-EINVALThe observer is not a subscriber.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.

◆ zbus_sub_wait_msg()

int zbus_sub_wait_msg ( const struct zbus_observer * sub,
const struct zbus_channel ** chan,
void * msg,
k_timeout_t timeout )

#include <zephyr/zbus/zbus.h>

Wait for a channel message.

This routine makes the subscriber wait for the new message in case of channel publication.

Parameters
[in]subThe subscriber's reference.
[out]chanThe notification channel's reference.
[out]msgA reference to a copy of the published message.
[in]timeoutWaiting period for a notification arrival, or one of the special values, K_NO_WAIT and K_FOREVER.
Return values
0Message received.
-EINVALThe observer is not a subscriber.
-ENOMSGCould not retrieve the net_buf from the subscriber FIFO.
-EILSEQReceived an invalid channel reference.
-EFAULTA parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the
CONFIG_ZBUS_ASSERT_MOCK 
is enabled.