From b073db4017008ceb638a9c23c8cc93e60a3a7fdb Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 23 Mar 2025 17:53:24 +0100 Subject: fw: app: Move application firmware code here This makes the structure of the `fw` folder more clear and separates application-related code from bootloader- or rtos-related code. --- fw/app/src/heart.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 fw/app/src/heart.c (limited to 'fw/app/src/heart.c') diff --git a/fw/app/src/heart.c b/fw/app/src/heart.c new file mode 100644 index 0000000..6bcced6 --- /dev/null +++ b/fw/app/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 + +#include +#include + +#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); -- cgit v1.2.3-70-g09d2