Zephyr API 3.6.99
|
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. | |
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. | |
Zbus API .
#define ZBUS_CHAN_ADD_OBS | ( | _chan, | |
_obs, | |||
_prio ) |
#include <zephyr/zbus/zbus.h>
Add a static channel observervation.
This macro initializes a channel observation by receiving the channel and the observer.
_chan | Channel instance. |
_obs | Observer instance. |
_prio | Observer notification sequence priority. |
#define ZBUS_CHAN_ADD_OBS_WITH_MASK | ( | _chan, | |
_obs, | |||
_masked, | |||
_prio ) |
#include <zephyr/zbus/zbus.h>
Add a static channel observervation.
This macro initializes a channel observation by receiving the channel and the observer.
_chan | Channel instance. |
_obs | Observer instance. |
_masked | Observation state. |
_prio | Observer notification sequence priority. |
#define ZBUS_CHAN_DECLARE | ( | ... | ) |
#include <zephyr/zbus/zbus.h>
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.
#define ZBUS_CHAN_DEFINE | ( | _name, | |
_type, | |||
_validator, | |||
_user_data, | |||
_observers, | |||
_init_val ) |
#include <zephyr/zbus/zbus.h>
Zbus channel definition.
This macro defines a channel.
_name | The channel's name. |
_type | The Message type. It must be a struct or union. |
_validator | The validator function. |
_user_data | A pointer to the user data. |
_observers | The observers list. The sequence indicates the priority of the observer. The first the highest priority. |
_init_val | The message initialization. |
#define ZBUS_LISTENER_DEFINE | ( | _name, | |
_cb ) |
#include <zephyr/zbus/zbus.h>
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.
[in] | _name | The listener's name. |
[in] | _cb | The callback function. |
#define ZBUS_LISTENER_DEFINE_WITH_ENABLE | ( | _name, | |
_cb, | |||
_enable ) |
#include <zephyr/zbus/zbus.h>
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.
[in] | _name | The listener's name. |
[in] | _cb | The callback function. |
[in] | _enable | The listener initial enable state. |
#define ZBUS_MSG_INIT | ( | _val, | |
... ) |
#include <zephyr/zbus/zbus.h>
Initialize a message.
This macro initializes a message by passing the values to initialize the message struct or union.
[in] | _val | Variadic with the initial values. ZBUS_INIT(0) means {0} , as ZBUS_INIT(.a=10, .b=30) means {.a=10, .b=30} . |
#define ZBUS_MSG_SUBSCRIBER_DEFINE | ( | _name | ) |
#include <zephyr/zbus/zbus.h>
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.
[in] | _name | The subscriber's name. |
#define ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE | ( | _name, | |
_enable ) |
#include <zephyr/zbus/zbus.h>
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.
[in] | _name | The subscriber's name. |
[in] | _enable | The subscriber's initial state. |
#define ZBUS_OBS_DECLARE | ( | ... | ) |
#include <zephyr/zbus/zbus.h>
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.
#define ZBUS_OBSERVERS | ( | ... | ) |
#include <zephyr/zbus/zbus.h>
This macro indicates the channel has listed observers.
Note the sequence of observer notification will follow the same as listed.
#define ZBUS_OBSERVERS_EMPTY |
#include <zephyr/zbus/zbus.h>
This macro indicates the channel has no observers.
#define ZBUS_SUBSCRIBER_DEFINE | ( | _name, | |
_queue_size ) |
#include <zephyr/zbus/zbus.h>
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.
[in] | _name | The subscriber's name. |
[in] | _queue_size | The notification queue's size. |
#define ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE | ( | _name, | |
_queue_size, | |||
_enable ) |
#include <zephyr/zbus/zbus.h>
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.
[in] | _name | The subscriber's name. |
[in] | _queue_size | The notification queue's size. |
[in] | _enable | The subscriber initial enable state. |
enum 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 |
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.
chan | The channel's reference. |
obs | The observer's reference to be added. |
timeout | Waiting period to add an observer, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Observer added to the channel. |
-EALREADY | The observer is already present in the channel's runtime observers list. |
-ENOMEM | Returned without waiting. |
-EAGAIN | Waiting period timed out. |
-EINVAL | Some parameter is invalid. |
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.
[in] | chan | The channel's reference. |
[in] | timeout | Waiting period to claim the channel, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Channel claimed. |
-EBUSY | The channel is busy. |
-EAGAIN | Waiting period timed out. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |
|
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.
chan | The channel's constant reference. |
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.
chan | The channel's reference. |
0 | Channel finished. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |
|
inlinestatic |
#include <zephyr/zbus/zbus.h>
Get the reference for a channel message directly.
This routine returns the reference of a channel message.
chan | The channel's reference. |
|
inlinestatic |
#include <zephyr/zbus/zbus.h>
Get the channel's message size.
This routine returns the channel's message size.
chan | The channel's reference. |
|
inlinestatic |
#include <zephyr/zbus/zbus.h>
Get the channel's name.
This routine returns the channel's name reference.
chan | The channel's reference. |
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.
chan | The channel's reference. |
timeout | Waiting period to notify the channel, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Channel notified. |
-EBUSY | The channel's semaphore returned without waiting. |
-EAGAIN | Timeout to take the channel's semaphore. |
-ENOMEM | There is not more buffer on the messgage buffers pool. |
-EFAULT | A 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_MOCKis enabled. |
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.
chan | The channel's reference. |
msg | Reference to the message where the publish function copies the channel's message data from. |
timeout | Waiting period to publish the channel, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Channel published. |
-ENOMSG | The message is invalid based on the validator function or some of the observers could not receive the notification. |
-EBUSY | The channel is busy. |
-EAGAIN | Waiting period timed out. |
-EFAULT | A 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_MOCKis enabled. |
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.
[in] | chan | The channel's reference. |
[out] | msg | Reference to the message where the read function copies the channel's message data to. |
[in] | timeout | Waiting period to read the channel, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Channel read. |
-EBUSY | The channel is busy. |
-EAGAIN | Waiting period timed out. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |
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.
chan | The channel's reference. |
obs | The observer's reference to be removed. |
timeout | Waiting period to remove an observer, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Observer removed to the channel. |
-EINVAL | Invalid data supplied. |
-EBUSY | Returned without waiting. |
-EAGAIN | Waiting period timed out. |
-ENODATA | no observer found in channel's runtime observer list. |
-ENOMEM | Returned without waiting. |
|
inlinestatic |
#include <zephyr/zbus/zbus.h>
Set the channel's msg subscriber net_buf
pool.
chan | The channel's reference. |
pool | The reference to the net_buf memory pool. |
|
inlinestatic |
#include <zephyr/zbus/zbus.h>
Get the channel's user data.
This routine returns the channel's user data.
chan | The channel's reference. |
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.
[in] | iterator_func | The function that will be execute on each iteration. |
true | Iterator executed for all channels. |
false | Iterator could not be executed. Some iterate returned false. |
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.
[in] | iterator_func | The function that will be execute on each iteration. |
[in] | user_data | The user data that can be passed in the function. |
true | Iterator executed for all channels. |
false | Iterator could not be executed. Some iterate returned false. |
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.
[in] | iterator_func | The function that will be execute on each iteration. |
true | Iterator executed for all channels. |
false | Iterator could not be executed. Some iterate returned false. |
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.
[in] | iterator_func | The function that will be execute on each iteration. |
[in] | user_data | The user data that can be passed in the function. |
true | Iterator executed for all channels. |
false | Iterator could not be executed. Some iterate returned false. |
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.
[in] | obs | The observer's reference. |
0 | Observer detached from the thread. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |
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.
[in] | obs | The observer's reference. |
0 | Observer detached from the thread. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |
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.
obs | The observer's reference to be added. | |
chan | The channel's reference. | |
[out] | masked | The mask state. When the mask is true, the observer will not receive notifications from the channel. |
0 | Retrieved the masked state. |
-ESRCH | No observation found for the related pair chan/obs. |
-EINVAL | Some parameter is invalid. |
|
inlinestatic |
#include <zephyr/zbus/zbus.h>
Get the observer state.
This routine retrieves the observer state.
[in] | obs | The observer's reference. |
[out] | enable | The boolean output's reference. |
|
inlinestatic |
#include <zephyr/zbus/zbus.h>
Get the observer's name.
This routine returns the observer's name reference.
obs | The observer's reference. |
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.
obs | The observer's reference to be added. |
chan | The channel's reference. |
masked | The mask state. When the mask is true, the observer will not receive notifications from the channel. |
0 | Channel notifications masked to the observer. |
-ESRCH | No observation found for the related pair chan/obs. |
-EINVAL | Some parameter is invalid. |
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.
[in] | obs | The observer's reference. |
[in] | enabled | State to be. When false the observer stops to receive notifications. |
0 | Observer set enable. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |
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.
[in] | sub | The subscriber's reference. |
[out] | chan | The notification channel's reference. |
[in] | timeout | Waiting period for a notification arrival, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Notification received. |
-ENOMSG | Returned without waiting. |
-EAGAIN | Waiting period timed out. |
-EINVAL | The observer is not a subscriber. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |
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.
[in] | sub | The subscriber's reference. |
[out] | chan | The notification channel's reference. |
[out] | msg | A reference to a copy of the published message. |
[in] | timeout | Waiting period for a notification arrival, or one of the special values, K_NO_WAIT and K_FOREVER. |
0 | Message received. |
-EINVAL | The observer is not a subscriber. |
-ENOMSG | Could not retrieve the net_buf from the subscriber FIFO. |
-EILSEQ | Received an invalid channel reference. |
-EFAULT | A parameter is incorrect, or the function context is invalid (inside an ISR). The function only returns this value when the CONFIG_ZBUS_ASSERT_MOCKis enabled. |