Last active
September 19, 2023 02:48
-
-
Save yashi/3f3e4774ddd39015ef7361d87e20e979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int _zbus_message_acc_data_chan = { 42 }; | |
static struct zbus_channel_data _zbus_chan_data_acc_data_chan = { | |
.observers_start_idx = -1, | |
.observers_end_idx = -1 | |
}; | |
static struct k_mutex _zbus_mutex_acc_data_chan = { | |
.wait_q = { { {(&(&_zbus_mutex_acc_data_chan.wait_q)->waitq)}, {(&(&_zbus_mutex_acc_data_chan.wait_q)->waitq)} } }, | |
.owner = NULL, | |
.lock_count = 0, | |
.owner_orig_prio = (15 - 1), | |
}; | |
const struct zbus_channel acc_data_chan = { | |
.name = "acc_data_chan", | |
.message = &_zbus_message_acc_data_chan, | |
.message_size = sizeof(int), | |
.user_data = NULL, | |
.validator = NULL), | |
.data = &_zbus_chan_data_acc_data_chan | |
}; | |
extern struct zbus_observer my_listener; | |
extern struct zbus_observer my_subscriber; | |
const struct zbus_channel_observation acc_data_chan00 = { | |
.chan = &acc_data_chan, | |
.obs = &my_listener | |
}; | |
struct zbus_channel_observation_mask acc_data_chan00_mask = { | |
.enabled = 0 | |
}; | |
const struct zbus_channel_observation acc_data_chan01 = { | |
.chan = &acc_data_chan, | |
.obs = &my_subscriber | |
}; | |
struct zbus_channel_observation_mask acc_data_chan01_mask = { | |
.enabled = 0 | |
}; | |
static void listener_cb(const struct zbus_channel *chan) | |
{ | |
const int *msg = zbus_chan_const_msg(chan); | |
const char *name = k_thread_name_get(k_current_get()); | |
} | |
struct zbus_observer my_listener = { | |
.name = "my_listener", | |
.type = ZBUS_OBSERVER_LISTENER_TYPE, | |
.enabled = 1, | |
.callback = (listener_cb) | |
}; | |
static char _k_fifo_buf__zbus_observer_queue_my_subscriber[(4) * (sizeof(const struct zbus_channel *))]; | |
struct k_msgq _zbus_observer_queue_my_subscriber = { | |
.wait_q = { { {(&(&_zbus_observer_queue_my_subscriber.wait_q)->waitq)}, {(&(&_zbus_observer_queue_my_subscriber.wait_q)->waitq)} } }, | |
.msg_size = (sizeof(const struct zbus_channel *)), | |
.max_msgs = (4), | |
.buffer_start = _k_fifo_buf__zbus_observer_queue_my_subscriber, | |
.buffer_end = _k_fifo_buf__zbus_observer_queue_my_subscriber + ((4) * (sizeof(const struct zbus_channel *))), | |
.read_ptr = _k_fifo_buf__zbus_observer_queue_my_subscriber, | |
.write_ptr = _k_fifo_buf__zbus_observer_queue_my_subscriber, | |
.used_msgs = 0, | |
}; | |
struct zbus_observer my_subscriber = { | |
.name = "my_subscriber", | |
.type = ZBUS_OBSERVER_SUBSCRIBER_TYPE, | |
.enabled = 1, | |
.queue = &_zbus_observer_queue_my_subscriber | |
}; | |
static void subscriber_func(void) | |
{ | |
const struct zbus_channel *chan; | |
const char *name = k_thread_name_get(k_current_get()); | |
while (!zbus_sub_wait(&my_subscriber, &chan, K_FOREVER)) { | |
int val; | |
if (&acc_data_chan == chan) { | |
zbus_chan_read(&acc_data_chan, &val, K_MSEC(500)); | |
} | |
} | |
} | |
struct z_thread_stack_element _k_thread_stack_subscriber[(((((unsigned long)(1024) + ((unsigned long)(8) - 1)) / (unsigned long)(8)) * (unsigned long)(8)) + ((size_t)0x40))]; | |
struct k_thread _k_thread_obj_subscriber; | |
struct _static_thread_data _k_thread_data_subscriber = { | |
.init_thread = (&_k_thread_obj_subscriber), | |
.init_stack = (_k_thread_stack_subscriber), | |
.init_stack_size = (1024), | |
.init_entry = (k_thread_entry_t)subscriber_func, | |
.init_p1 = (void *)((void *)0), | |
.init_p2 = (void *)((void *)0), | |
.init_p3 = (void *)((void *)0), | |
.init_prio = (3), | |
.init_options = (0), | |
.init_delay = (0), | |
.init_name = "subscriber", | |
}; | |
const k_tid_t subscriber = (k_tid_t)&_k_thread_obj_subscriber; | |
int main(void) | |
{ | |
int val = {100}; | |
while (1) { | |
zbus_chan_pub(&acc_data_chan, &val, K_SECONDS(1)); | |
val += 1; | |
k_sleep(K_SECONDS(1)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/yashi/e9a3955d83682eec279742dda398dd77 become (almost) the above.