Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
zbus.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Rodrigo Peixoto <rodrigopex@gmail.com>
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#ifndef ZEPHYR_INCLUDE_ZBUS_H_
7#define ZEPHYR_INCLUDE_ZBUS_H_
8
9#include <string.h>
10
11#include <zephyr/kernel.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
35
40
44 struct k_sem sem;
45
46#if defined(CONFIG_ZBUS_PRIORITY_BOOST)
50 int highest_observer_priority;
51#endif /* CONFIG_ZBUS_PRIORITY_BOOST */
52
53#if defined(CONFIG_ZBUS_RUNTIME_OBSERVERS) || defined(__DOXYGEN__)
58#endif /* CONFIG_ZBUS_RUNTIME_OBSERVERS */
59
60#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_ISOLATION) || defined(__DOXYGEN__)
64#endif /* ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_ISOLATION */
65
66#if defined(CONFIG_ZBUS_CHANNEL_PUBLISH_STATS) || defined(__DOXYGEN__)
71#endif /* CONFIG_ZBUS_CHANNEL_PUBLISH_STATS */
72};
73
81#if defined(CONFIG_ZBUS_CHANNEL_NAME) || defined(__DOXYGEN__)
83 const char *name;
84#endif
88 void *message;
89
92
96 void *user_data;
97
102 bool (*validator)(const void *msg, size_t msg_size);
103
106};
107
118
122
123#if defined(CONFIG_ZBUS_PRIORITY_BOOST)
125 int priority;
126#endif /* CONFIG_ZBUS_PRIORITY_BOOST */
127};
128
145#if defined(CONFIG_ZBUS_OBSERVER_NAME) || defined(__DOXYGEN__)
147 const char *name;
148#endif
151
154
155 union {
157 struct k_msgq *queue;
158
160 void (*callback)(const struct zbus_channel *chan);
161
162#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) || defined(__DOXYGEN__)
167#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */
168 };
169};
170
172struct zbus_channel_observation_mask {
173 bool enabled;
174};
175
176struct zbus_channel_observation {
177 const struct zbus_channel *chan;
178 const struct zbus_observer *obs;
179};
180
181#ifdef __cplusplus
182#define _ZBUS_CPP_EXTERN extern
183#else
184#define _ZBUS_CPP_EXTERN
185#endif /* __cplusplus */
186
187#define ZBUS_MIN_THREAD_PRIORITY (CONFIG_NUM_PREEMPT_PRIORITIES - 1)
188
189#if defined(CONFIG_ZBUS_ASSERT_MOCK)
190#define _ZBUS_ASSERT(_cond, _fmt, ...) \
191 do { \
192 if (!(_cond)) { \
193 printk("ZBUS ASSERT: "); \
194 printk(_fmt, ##__VA_ARGS__); \
195 printk("\n"); \
196 return -EFAULT; \
197 } \
198 } while (0)
199#else
200#define _ZBUS_ASSERT(_cond, _fmt, ...) __ASSERT(_cond, _fmt, ##__VA_ARGS__)
201#endif
202
203#if defined(CONFIG_ZBUS_CHANNEL_NAME)
204#define ZBUS_CHANNEL_NAME_INIT(_name) .name = #_name,
205#define _ZBUS_CHAN_NAME(_chan) (_chan)->name
206#else
207#define ZBUS_CHANNEL_NAME_INIT(_name)
208#define _ZBUS_CHAN_NAME(_chan) ""
209#endif
210
211#if defined(CONFIG_ZBUS_OBSERVER_NAME)
212#define ZBUS_OBSERVER_NAME_INIT(_name) .name = #_name,
213#define _ZBUS_OBS_NAME(_obs) (_obs)->name
214#else
215#define ZBUS_OBSERVER_NAME_INIT(_name)
216#define _ZBUS_OBS_NAME(_obs) ""
217#endif
218
219#if defined(CONFIG_ZBUS_RUNTIME_OBSERVERS)
220#define ZBUS_RUNTIME_OBSERVERS_LIST_DECL(_slist_name) static sys_slist_t _slist_name
221#define ZBUS_RUNTIME_OBSERVERS_LIST_INIT(_slist_name) .runtime_observers = &_slist_name,
222#else
223#define ZBUS_RUNTIME_OBSERVERS_LIST_DECL(_slist_name)
224#define ZBUS_RUNTIME_OBSERVERS_LIST_INIT(_slist_name) /* No runtime observers */
225#endif
226
227#define _ZBUS_OBS_EXTERN(_name) extern const struct zbus_observer _name
228
229#define _ZBUS_CHAN_EXTERN(_name) extern const struct zbus_channel _name
230
231#define ZBUS_REF(_value) &(_value)
232
233#define FOR_EACH_FIXED_ARG_NONEMPTY_TERM(F, sep, fixed_arg, ...) \
234 COND_CODE_0(/* are there zero non-empty arguments ? */ \
235 NUM_VA_ARGS_LESS_1( \
236 LIST_DROP_EMPTY(__VA_ARGS__, _)), /* if so, expand to nothing */ \
237 (), /* otherwise, expand to: */ \
238 (FOR_EACH_IDX_FIXED_ARG( \
239 F, sep, fixed_arg, \
240 LIST_DROP_EMPTY(__VA_ARGS__)) /* plus a final terminator */ \
241 __DEBRACKET sep))
242
243#define _ZBUS_OBSERVATION_PREFIX(_idx) \
244 GET_ARG_N(_idx, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, \
245 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, \
246 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, \
247 58, 59, 60, 61, 62, 63)
248
249#define _ZBUS_CHAN_OBSERVATION(_idx, _obs, _chan) \
250 const STRUCT_SECTION_ITERABLE( \
251 zbus_channel_observation, \
252 _CONCAT(_chan, _ZBUS_OBSERVATION_PREFIX(UTIL_INC(_idx)))) = {.chan = &_chan, \
253 .obs = &_obs}; \
254 STRUCT_SECTION_ITERABLE(zbus_channel_observation_mask, \
255 _CONCAT(_CONCAT(_chan, _ZBUS_OBSERVATION_PREFIX(UTIL_INC(_idx))), \
256 _mask)) = {.enabled = false};
257
258#if defined(CONFIG_ZBUS_RUNTIME_OBSERVERS) || defined(__DOXYGEN__)
259#define _ZBUS_RUNTIME_OBSERVERS(_name) .observers = &(_CONCAT(_observers_, _name)),
260#define _ZBUS_RUNTIME_OBSERVERS_DECL(_name) static sys_slist_t _CONCAT(_observers_, _name);
261#else
262#define _ZBUS_RUNTIME_OBSERVERS(_name)
263#define _ZBUS_RUNTIME_OBSERVERS_DECL(_name)
264#endif /* CONFIG_ZBUS_RUNTIME_OBSERVERS */
265
268/* clang-format off */
269
281#define ZBUS_CHAN_ADD_OBS_WITH_MASK(_chan, _obs, _masked, _prio) \
282 const STRUCT_SECTION_ITERABLE(zbus_channel_observation, \
283 _CONCAT(_CONCAT(_chan, zz), _CONCAT(_prio, _obs))) = { \
284 .chan = &_chan, \
285 .obs = &_obs, \
286 }; \
287 STRUCT_SECTION_ITERABLE(zbus_channel_observation_mask, \
288 _CONCAT(_CONCAT(_CONCAT(_chan, zz), _CONCAT(_prio, _obs)), \
289 _mask)) = {.enabled = _masked}
290/* clang-format on */
291
302#define ZBUS_CHAN_ADD_OBS(_chan, _obs, _prio) ZBUS_CHAN_ADD_OBS_WITH_MASK(_chan, _obs, false, _prio)
303
309#define ZBUS_OBS_DECLARE(...) FOR_EACH_NONEMPTY_TERM(_ZBUS_OBS_EXTERN, (;), __VA_ARGS__)
310
316#define ZBUS_CHAN_DECLARE(...) FOR_EACH(_ZBUS_CHAN_EXTERN, (;), __VA_ARGS__)
317
322#define ZBUS_OBSERVERS_EMPTY
323
329#define ZBUS_OBSERVERS(...) __VA_ARGS__
330
331/* clang-format off */
332
348#define ZBUS_CHAN_DEFINE(_name, _type, _validator, _user_data, _observers, _init_val) \
349 static _type _CONCAT(_zbus_message_, _name) = _init_val; \
350 static struct zbus_channel_data _CONCAT(_zbus_chan_data_, _name) = { \
351 .observers_start_idx = -1, \
352 .observers_end_idx = -1, \
353 .sem = Z_SEM_INITIALIZER(_CONCAT(_zbus_chan_data_, _name).sem, 1, 1), \
354 IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
355 .highest_observer_priority = ZBUS_MIN_THREAD_PRIORITY, \
356 )) \
357 IF_ENABLED(CONFIG_ZBUS_RUNTIME_OBSERVERS, ( \
358 .observers = SYS_SLIST_STATIC_INIT( \
359 &_CONCAT(_zbus_chan_data_, _name).observers), \
360 )) \
361 }; \
362 static K_MUTEX_DEFINE(_CONCAT(_zbus_mutex_, _name)); \
363 _ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_channel, _name) = { \
364 ZBUS_CHANNEL_NAME_INIT(_name) /* Maybe removed */ \
365 .message = &_CONCAT(_zbus_message_, _name), \
366 .message_size = sizeof(_type), \
367 .user_data = _user_data, \
368 .validator = _validator, \
369 .data = &_CONCAT(_zbus_chan_data_, _name), \
370 IF_ENABLED(ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_ISOLATION, ( \
371 .msg_subscriber_pool = &_zbus_msg_subscribers_pool, \
372 )) \
373 }; \
374 /* Extern declaration of observers */ \
375 ZBUS_OBS_DECLARE(_observers); \
376 /* Create all channel observations from observers list */ \
377 FOR_EACH_FIXED_ARG_NONEMPTY_TERM(_ZBUS_CHAN_OBSERVATION, (;), _name, _observers)
378/* clang-format on */
379
389#define ZBUS_MSG_INIT(_val, ...) \
390 { \
391 _val, ##__VA_ARGS__ \
392 }
393
394/* clang-format off */
395
407#define ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _queue_size, _enable) \
408 K_MSGQ_DEFINE(_zbus_observer_queue_##_name, \
409 sizeof(struct zbus_channel *), \
410 _queue_size, sizeof(struct zbus_channel *) \
411 ); \
412 static struct zbus_observer_data _CONCAT(_zbus_obs_data_, _name) = { \
413 .enabled = _enable, \
414 IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
415 .priority = ZBUS_MIN_THREAD_PRIORITY, \
416 )) \
417 }; \
418 _ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \
419 ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \
420 .type = ZBUS_OBSERVER_SUBSCRIBER_TYPE, \
421 .data = &_CONCAT(_zbus_obs_data_, _name), \
422 .queue = &_zbus_observer_queue_##_name, \
423 }
424/* clang-format on */
425
437#define ZBUS_SUBSCRIBER_DEFINE(_name, _queue_size) \
438 ZBUS_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _queue_size, true)
439
440/* clang-format off */
441
453#define ZBUS_LISTENER_DEFINE_WITH_ENABLE(_name, _cb, _enable) \
454 static struct zbus_observer_data _CONCAT(_zbus_obs_data_, _name) = { \
455 .enabled = _enable, \
456 IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
457 .priority = ZBUS_MIN_THREAD_PRIORITY, \
458 )) \
459 }; \
460 _ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \
461 ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \
462 .type = ZBUS_OBSERVER_LISTENER_TYPE, \
463 .data = &_CONCAT(_zbus_obs_data_, _name), \
464 .callback = (_cb) \
465 }
466/* clang-format on */
467
478#define ZBUS_LISTENER_DEFINE(_name, _cb) ZBUS_LISTENER_DEFINE_WITH_ENABLE(_name, _cb, true)
479
480/* clang-format off */
481
492#define ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, _enable) \
493 static K_FIFO_DEFINE(_zbus_observer_fifo_##_name); \
494 static struct zbus_observer_data _CONCAT(_zbus_obs_data_, _name) = { \
495 .enabled = _enable, \
496 IF_ENABLED(CONFIG_ZBUS_PRIORITY_BOOST, ( \
497 .priority = ZBUS_MIN_THREAD_PRIORITY, \
498 )) \
499 }; \
500 _ZBUS_CPP_EXTERN const STRUCT_SECTION_ITERABLE(zbus_observer, _name) = { \
501 ZBUS_OBSERVER_NAME_INIT(_name) /* Name field */ \
502 .type = ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE, \
503 .data = &_CONCAT(_zbus_obs_data_, _name), \
504 .message_fifo = &_zbus_observer_fifo_##_name, \
505 }
506/* clang-format on */
507
519#define ZBUS_MSG_SUBSCRIBER_DEFINE(_name) ZBUS_MSG_SUBSCRIBER_DEFINE_WITH_ENABLE(_name, true)
541int zbus_chan_pub(const struct zbus_channel *chan, const void *msg, k_timeout_t timeout);
542
560int zbus_chan_read(const struct zbus_channel *chan, void *msg, k_timeout_t timeout);
561
583int zbus_chan_claim(const struct zbus_channel *chan, k_timeout_t timeout);
584
599int zbus_chan_finish(const struct zbus_channel *chan);
600
619int zbus_chan_notify(const struct zbus_channel *chan, k_timeout_t timeout);
620
621#if defined(CONFIG_ZBUS_CHANNEL_NAME) || defined(__DOXYGEN__)
622
632static inline const char *zbus_chan_name(const struct zbus_channel *chan)
633{
634 __ASSERT(chan != NULL, "chan is required");
635
636 return chan->name;
637}
638
639#endif
640
653static inline void *zbus_chan_msg(const struct zbus_channel *chan)
654{
655 __ASSERT(chan != NULL, "chan is required");
656
657 return chan->message;
658}
659
674static inline const void *zbus_chan_const_msg(const struct zbus_channel *chan)
675{
676 __ASSERT(chan != NULL, "chan is required");
677
678 return chan->message;
679}
680
690static inline uint16_t zbus_chan_msg_size(const struct zbus_channel *chan)
691{
692 __ASSERT(chan != NULL, "chan is required");
693
694 return chan->message_size;
695}
696
706static inline void *zbus_chan_user_data(const struct zbus_channel *chan)
707{
708 __ASSERT(chan != NULL, "chan is required");
709
710 return chan->user_data;
711}
712
713#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_ISOLATION) || defined(__DOXYGEN__)
714
721static inline void zbus_chan_set_msg_sub_pool(const struct zbus_channel *chan,
722 struct net_buf_pool *pool)
723{
724 __ASSERT(chan != NULL, "chan is required");
725 __ASSERT(pool != NULL, "pool is required");
726
727 chan->data->msg_subscriber_pool = pool;
728}
729
730#endif /* ZBUS_MSG_SUBSCRIBER_NET_BUF_POOL_ISOLATION */
731
732#if defined(CONFIG_ZBUS_CHANNEL_PUBLISH_STATS) || defined(__DOXYGEN__)
733
745static inline void zbus_chan_pub_stats_update(const struct zbus_channel *chan)
746{
747 __ASSERT(chan != NULL, "chan is required");
748
750 chan->data->publish_count += 1;
751}
752
762static inline k_ticks_t zbus_chan_pub_stats_last_time(const struct zbus_channel *chan)
763{
764 __ASSERT(chan != NULL, "chan is required");
765
766 return chan->data->publish_timestamp;
767}
768
778static inline uint32_t zbus_chan_pub_stats_count(const struct zbus_channel *chan)
779{
780 __ASSERT(chan != NULL, "chan is required");
781
782 return chan->data->publish_count;
783}
784
794static inline uint32_t zbus_chan_pub_stats_avg_period(const struct zbus_channel *chan)
795{
796 __ASSERT(chan != NULL, "chan is required");
797
798 /* Not yet published, period = 0ms */
799 if (chan->data->publish_count == 0) {
800 return 0;
801 }
802 /* Average period across application runtime */
803 return k_uptime_get() / chan->data->publish_count;
804}
805
806#else
807
808static inline void zbus_chan_pub_stats_update(const struct zbus_channel *chan)
809{
810 (void)chan;
811}
812
813#endif /* CONFIG_ZBUS_CHANNEL_PUBLISH_STATS */
814
815#if defined(CONFIG_ZBUS_RUNTIME_OBSERVERS) || defined(__DOXYGEN__)
816
833int zbus_chan_add_obs(const struct zbus_channel *chan, const struct zbus_observer *obs,
834 k_timeout_t timeout);
835
853int zbus_chan_rm_obs(const struct zbus_channel *chan, const struct zbus_observer *obs,
854 k_timeout_t timeout);
855
858struct zbus_observer_node {
859 sys_snode_t node;
860 const struct zbus_observer *obs;
861};
862
865#endif /* CONFIG_ZBUS_RUNTIME_OBSERVERS */
866
880int zbus_obs_set_enable(const struct zbus_observer *obs, bool enabled);
881
892static inline int zbus_obs_is_enabled(const struct zbus_observer *obs, bool *enable)
893{
894 _ZBUS_ASSERT(obs != NULL, "obs is required");
895 _ZBUS_ASSERT(enable != NULL, "enable is required");
896
897 *enable = obs->data->enabled;
898
899 return 0;
900}
901
917 const struct zbus_channel *chan, bool masked);
918
932 const struct zbus_channel *chan, bool *masked);
933
934#if defined(CONFIG_ZBUS_OBSERVER_NAME) || defined(__DOXYGEN__)
935
945static inline const char *zbus_obs_name(const struct zbus_observer *obs)
946{
947 __ASSERT(obs != NULL, "obs is required");
948
949 return obs->name;
950}
951
952#endif
953
954#if defined(CONFIG_ZBUS_PRIORITY_BOOST) || defined(__DOXYGEN__)
955
966
977
978#endif /* CONFIG_ZBUS_PRIORITY_BOOST */
979
998int zbus_sub_wait(const struct zbus_observer *sub, const struct zbus_channel **chan,
999 k_timeout_t timeout);
1000
1001#if defined(CONFIG_ZBUS_MSG_SUBSCRIBER) || defined(__DOXYGEN__)
1002
1021int zbus_sub_wait_msg(const struct zbus_observer *sub, const struct zbus_channel **chan, void *msg,
1022 k_timeout_t timeout);
1023
1024#endif /* CONFIG_ZBUS_MSG_SUBSCRIBER */
1025
1039bool zbus_iterate_over_channels(bool (*iterator_func)(const struct zbus_channel *chan));
1055 bool (*iterator_func)(const struct zbus_channel *chan, void *user_data), void *user_data);
1056
1070bool zbus_iterate_over_observers(bool (*iterator_func)(const struct zbus_observer *obs));
1086 bool (*iterator_func)(const struct zbus_observer *obs, void *user_data), void *user_data);
1087
1092#ifdef __cplusplus
1093}
1094#endif
1095
1096#endif /* ZEPHYR_INCLUDE_ZBUS_H_ */
int64_t k_uptime_ticks(void)
Get system uptime, in system ticks.
uint32_t k_ticks_t
Tick precision used in timeout APIs.
Definition sys_clock.h:48
static int64_t k_uptime_get(void)
Get system uptime.
Definition kernel.h:1828
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
int zbus_chan_claim(const struct zbus_channel *chan, k_timeout_t timeout)
Claim a channel.
static const char * zbus_chan_name(const struct zbus_channel *chan)
Get the channel's name.
Definition zbus.h:632
static uint32_t zbus_chan_pub_stats_avg_period(const struct zbus_channel *chan)
Get the average period between publishes to a channel.
Definition zbus.h:794
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.
bool zbus_iterate_over_observers(bool(*iterator_func)(const struct zbus_observer *obs))
Iterate over observers.
static int zbus_obs_is_enabled(const struct zbus_observer *obs, bool *enable)
Get the observer state.
Definition zbus.h:892
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.
Definition zbus.h:721
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.
int zbus_obs_detach_from_thread(const struct zbus_observer *obs)
Clear the observer thread priority by detaching it from a thread.
static uint32_t zbus_chan_pub_stats_count(const struct zbus_channel *chan)
Get the number of times a channel has been published to.
Definition zbus.h:778
static const char * zbus_obs_name(const struct zbus_observer *obs)
Get the observer's name.
Definition zbus.h:945
bool zbus_iterate_over_channels(bool(*iterator_func)(const struct zbus_channel *chan))
Iterate over channels.
int zbus_chan_notify(const struct zbus_channel *chan, k_timeout_t timeout)
Force a channel notification.
int zbus_chan_finish(const struct zbus_channel *chan)
Finish a channel claim.
int zbus_chan_read(const struct zbus_channel *chan, void *msg, k_timeout_t timeout)
Read a channel.
int zbus_sub_wait(const struct zbus_observer *sub, const struct zbus_channel **chan, k_timeout_t timeout)
Wait for a channel notification.
zbus_observer_type
Type used to represent an observer type.
Definition zbus.h:113
static uint16_t zbus_chan_msg_size(const struct zbus_channel *chan)
Get the channel's message size.
Definition zbus.h:690
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_set_enable(const struct zbus_observer *obs, bool enabled)
Change the observer state.
static void * zbus_chan_msg(const struct zbus_channel *chan)
Get the reference for a channel message directly.
Definition zbus.h:653
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.
int zbus_obs_attach_to_thread(const struct zbus_observer *obs)
Set the observer thread priority by attaching it to a thread.
static void * zbus_chan_user_data(const struct zbus_channel *chan)
Get the channel's user data.
Definition zbus.h:706
static k_ticks_t zbus_chan_pub_stats_last_time(const struct zbus_channel *chan)
Get the time a channel was last published to.
Definition zbus.h:762
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_pub(const struct zbus_channel *chan, const void *msg, k_timeout_t timeout)
Publish 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.
static void zbus_chan_pub_stats_update(const struct zbus_channel *chan)
Update the publishing statistics for a channel.
Definition zbus.h:745
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.
static const void * zbus_chan_const_msg(const struct zbus_channel *chan)
Get a constant reference for a channel message directly.
Definition zbus.h:674
@ ZBUS_OBSERVER_LISTENER_TYPE
Definition zbus.h:114
@ ZBUS_OBSERVER_SUBSCRIBER_TYPE
Definition zbus.h:115
@ ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE
Definition zbus.h:116
Public kernel APIs.
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT16_TYPE__ int16_t
Definition stdint.h:73
Definition kernel.h:2468
Message Queue Structure.
Definition kernel.h:4503
Kernel timeout type.
Definition sys_clock.h:65
Network buffer pool representation.
Definition net_buf.h:1078
Type used to represent a channel mutable data.
Definition zbus.h:30
k_ticks_t publish_timestamp
Kernel timestamp of the last publish action on this channel.
Definition zbus.h:68
struct net_buf_pool * msg_subscriber_pool
Net buf pool for message subscribers.
Definition zbus.h:63
uint32_t publish_count
Number of times data has been published to this channel.
Definition zbus.h:70
int16_t observers_end_idx
Static channel observer list end index.
Definition zbus.h:39
int16_t observers_start_idx
Static channel observer list start index.
Definition zbus.h:34
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
void * user_data
User data available to extend zbus features.
Definition zbus.h:96
struct zbus_channel_data * data
Mutable channel data struct.
Definition zbus.h:105
bool(* validator)(const void *msg, size_t msg_size)
Message validator.
Definition zbus.h:102
size_t message_size
Message size.
Definition zbus.h:91
const char * name
Channel name.
Definition zbus.h:83
void * message
Message reference.
Definition zbus.h:88
Definition zbus.h:119
bool enabled
Enabled flag.
Definition zbus.h:121
Type used to represent an observer.
Definition zbus.h:144
enum zbus_observer_type type
Type indication.
Definition zbus.h:150
struct k_fifo * message_fifo
Observer message FIFO.
Definition zbus.h:166
struct zbus_observer_data * data
Mutable observer data struct.
Definition zbus.h:153
struct k_msgq * queue
Observer message queue.
Definition zbus.h:157
const char * name
Observer name.
Definition zbus.h:147