diff options
Diffstat (limited to 'fw/src')
-rw-r--r-- | fw/src/heart.c | 52 | ||||
-rw-r--r-- | fw/src/heart.h | 20 |
2 files changed, 72 insertions, 0 deletions
diff --git a/fw/src/heart.c b/fw/src/heart.c new file mode 100644 index 0000000..6bcced6 --- /dev/null +++ b/fw/src/heart.c @@ -0,0 +1,52 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at https://mozilla.org/MPL/2.0/. + */ + + +#include <stdbool.h> + +#include <zephyr/kernel.h> +#include <zephyr/logging/log.h> + +#include "heart.h" + + +LOG_MODULE_REGISTER(heart); + + +#define HEART_PERIOD K_MSEC(1000) +#define HEART_STACK_SIZE 500 +#define HEART_PRIO K_PRIO_PREEMPT(8) + + +ZBUS_CHAN_DEFINE( + heartbeat_channel, + struct heartbeat, + NULL, + NULL, + ZBUS_OBSERVERS_EMPTY, + ZBUS_MSG_INIT(.ttl_ms = 0) +); + + +static void heart_thread_function(void *ptr1, void *ptr2, void *ptr3) { + LOG_INF("Starting to beat"); + + struct heartbeat heartbeat = {.ttl_ms = 1100}; + + while (true) { + LOG_DBG("Heart beat"); + int ret = zbus_chan_pub(&heartbeat_channel, &heartbeat, K_FOREVER); + if (ret < 0) { + LOG_ERR("Could not publish heartbeat"); + } + k_sleep(HEART_PERIOD); + } +} + + +K_THREAD_DEFINE(heart_thread, HEART_STACK_SIZE, + heart_thread_function, NULL, NULL, NULL, + HEART_PRIO, 0, 0); diff --git a/fw/src/heart.h b/fw/src/heart.h new file mode 100644 index 0000000..cd32c15 --- /dev/null +++ b/fw/src/heart.h @@ -0,0 +1,20 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef SRC_HEART_H +#define SRC_HEART_H + + +#include <zephyr/zbus/zbus.h> + + +struct heartbeat { + uint32_t ttl_ms; +}; + +ZBUS_CHAN_DECLARE(heartbeat_channel); + +#endif // !SRC_HEART_H |