diff options
| -rw-r--r-- | fw/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | fw/prj.conf | 7 | ||||
| -rw-r--r-- | fw/src/heart.c | 52 | ||||
| -rw-r--r-- | fw/src/heart.h | 20 | 
4 files changed, 79 insertions, 1 deletions
diff --git a/fw/CMakeLists.txt b/fw/CMakeLists.txt index cffb6a1..b7a3783 100644 --- a/fw/CMakeLists.txt +++ b/fw/CMakeLists.txt @@ -23,6 +23,7 @@ target_sources(app  		"${CMAKE_CURRENT_SOURCE_DIR}/src/syslog.c"  		"${CMAKE_CURRENT_SOURCE_DIR}/src/mac.c"  		"${CMAKE_CURRENT_SOURCE_DIR}/src/http.c" +		"${CMAKE_CURRENT_SOURCE_DIR}/src/heart.c"  )  zephyr_linker_sources(SECTIONS sections-rom.ld) diff --git a/fw/prj.conf b/fw/prj.conf index bd761fc..7984caa 100644 --- a/fw/prj.conf +++ b/fw/prj.conf @@ -20,10 +20,15 @@ CONFIG_LOG_MODE_DEFERRED=y  CONFIG_POSIX_C_LANG_SUPPORT_R=y -CONFIG_HTTP_SERVER=y  CONFIG_HTTP_PARSER=y  CONFIG_HTTP_PARSER_URL=y +CONFIG_HTTP_SERVER=y +  CONFIG_FILE_SYSTEM=y  CONFIG_EVENTFD=y + +CONFIG_ZBUS=y +CONFIG_ZBUS_MSG_SUBSCRIBER=y +CONFIG_HEAP_MEM_POOL_SIZE=2048 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  | 
