From 9f066595340bfffb8d8eb4f443a1a95125978717 Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 18:56:28 -0400 Subject: [PATCH 1/8] Stub files --- include/f_core/os/tenants/c_timed_tenant.h | 12 ++++++++++++ lib/f_core/os/CMakeLists.txt | 2 +- lib/f_core/os/tenants/c_timed_tenant.cpp | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 include/f_core/os/tenants/c_timed_tenant.h create mode 100644 lib/f_core/os/tenants/c_timed_tenant.cpp diff --git a/include/f_core/os/tenants/c_timed_tenant.h b/include/f_core/os/tenants/c_timed_tenant.h new file mode 100644 index 00000000..86fde009 --- /dev/null +++ b/include/f_core/os/tenants/c_timed_tenant.h @@ -0,0 +1,12 @@ +#ifndef C_TIMED_TENANT_H +#define C_TIMED_TENANT_H + +class CTimedTenant : public CTenant { +public: + +private: + + +}; + +#endif //C_TIMED_TENANT_H \ No newline at end of file diff --git a/lib/f_core/os/CMakeLists.txt b/lib/f_core/os/CMakeLists.txt index 7ef6af7b..4efe8181 100644 --- a/lib/f_core/os/CMakeLists.txt +++ b/lib/f_core/os/CMakeLists.txt @@ -2,6 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() -FILE(GLOB sources *.cpp) +FILE(GLOB sources *.cpp tenants/*.cpp) zephyr_library_sources(${sources}) diff --git a/lib/f_core/os/tenants/c_timed_tenant.cpp b/lib/f_core/os/tenants/c_timed_tenant.cpp new file mode 100644 index 00000000..d6cf64d5 --- /dev/null +++ b/lib/f_core/os/tenants/c_timed_tenant.cpp @@ -0,0 +1,2 @@ +#include "c_timed_tenant.h" + From 4cf97b7fe1d9f109ec03352a421898ea2cf11a36 Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 19:00:19 -0400 Subject: [PATCH 2/8] Implement methods --- app/backplane/sensor_module/src/c_sensor_module.cpp | 1 + include/f_core/os/tenants/c_timed_tenant.h | 10 +++++++++- lib/f_core/os/tenants/c_timed_tenant.cpp | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/backplane/sensor_module/src/c_sensor_module.cpp b/app/backplane/sensor_module/src/c_sensor_module.cpp index 40cb8a7c..86f11e5a 100644 --- a/app/backplane/sensor_module/src/c_sensor_module.cpp +++ b/app/backplane/sensor_module/src/c_sensor_module.cpp @@ -3,6 +3,7 @@ // F-Core Tenant #include #include +#include #include #include LOG_MODULE_REGISTER(sensor_module); diff --git a/include/f_core/os/tenants/c_timed_tenant.h b/include/f_core/os/tenants/c_timed_tenant.h index 86fde009..2b615b33 100644 --- a/include/f_core/os/tenants/c_timed_tenant.h +++ b/include/f_core/os/tenants/c_timed_tenant.h @@ -1,11 +1,19 @@ #ifndef C_TIMED_TENANT_H #define C_TIMED_TENANT_H +#include "f_core/os/c_tenant.h" +#include "f_core/utils/c_soft_timer.h" class CTimedTenant : public CTenant { public: + explicit CTimedTenant(const char* name) + : CTenant(name) {} -private: + void Run() override { + // Should be no behavior + } +private: + CSoftTimer timer; }; diff --git a/lib/f_core/os/tenants/c_timed_tenant.cpp b/lib/f_core/os/tenants/c_timed_tenant.cpp index d6cf64d5..bfa6e91f 100644 --- a/lib/f_core/os/tenants/c_timed_tenant.cpp +++ b/lib/f_core/os/tenants/c_timed_tenant.cpp @@ -1,2 +1,2 @@ -#include "c_timed_tenant.h" +#include "f_core/os/tenants/c_timed_tenant.h" From 3b892900bc11ff6ac612c591ca94dfdc2be2f80e Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 19:00:56 -0400 Subject: [PATCH 3/8] Docs --- include/f_core/os/tenants/c_timed_tenant.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/f_core/os/tenants/c_timed_tenant.h b/include/f_core/os/tenants/c_timed_tenant.h index 2b615b33..b6a07028 100644 --- a/include/f_core/os/tenants/c_timed_tenant.h +++ b/include/f_core/os/tenants/c_timed_tenant.h @@ -1,13 +1,25 @@ #ifndef C_TIMED_TENANT_H #define C_TIMED_TENANT_H + #include "f_core/os/c_tenant.h" #include "f_core/utils/c_soft_timer.h" class CTimedTenant : public CTenant { public: + /** + * @brief Constructor + */ explicit CTimedTenant(const char* name) : CTenant(name) {} + /** + * @brief See parent docs. + */ + void Startup() override; + + /** + * @brief See parent docs. + */ void Run() override { // Should be no behavior } From a8d55329c0625ad79100722c89675e47bfe8f6bc Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 19:06:49 -0400 Subject: [PATCH 4/8] Add ctor for defining timeout for csofttimer --- include/f_core/os/tenants/c_timed_tenant.h | 16 +--------------- include/f_core/utils/c_soft_timer.h | 11 +++++++++++ lib/f_core/os/tenants/c_timed_tenant.cpp | 10 ++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/f_core/os/tenants/c_timed_tenant.h b/include/f_core/os/tenants/c_timed_tenant.h index b6a07028..c65c3d91 100644 --- a/include/f_core/os/tenants/c_timed_tenant.h +++ b/include/f_core/os/tenants/c_timed_tenant.h @@ -9,24 +9,10 @@ class CTimedTenant : public CTenant { /** * @brief Constructor */ - explicit CTimedTenant(const char* name) - : CTenant(name) {} - - /** - * @brief See parent docs. - */ - void Startup() override; - - /** - * @brief See parent docs. - */ - void Run() override { - // Should be no behavior - } + explicit CTimedTenant(const char* name, uint32_t intervalMillis); private: CSoftTimer timer; - }; #endif //C_TIMED_TENANT_H \ No newline at end of file diff --git a/include/f_core/utils/c_soft_timer.h b/include/f_core/utils/c_soft_timer.h index 6cafdc59..a5b0671b 100644 --- a/include/f_core/utils/c_soft_timer.h +++ b/include/f_core/utils/c_soft_timer.h @@ -13,6 +13,17 @@ class CSoftTimer { k_timer_init(&timer, expirationFn, stopFn); } + /** + * Constructor + * @param timeoutMillis Time in milliseconds until the timer expires + * @param expirationFn Function to call when the timer expires + * @param stopFn Function to call when the timer is stopped + */ + CSoftTimer(const int timeoutMillis, k_timer_expiry_t expirationFn = nullptr, k_timer_stop_t stopFn = nullptr) { + k_timer_init(&timer, expirationFn, stopFn); + StartTimer(timeoutMillis); + } + /** * Destructor */ diff --git a/lib/f_core/os/tenants/c_timed_tenant.cpp b/lib/f_core/os/tenants/c_timed_tenant.cpp index bfa6e91f..64d39c75 100644 --- a/lib/f_core/os/tenants/c_timed_tenant.cpp +++ b/lib/f_core/os/tenants/c_timed_tenant.cpp @@ -1,2 +1,12 @@ #include "f_core/os/tenants/c_timed_tenant.h" +static void timerExpirationCallback(struct k_timer *timer) { + +} + +CTimedTenant::CTimedTenant(const char* name, const uint32_t intervalMillis) + : CTenant(name), timer(intervalMillis, timerExpirationCallback) {} + +void CTimedTenant::Startup() { + +} \ No newline at end of file From 84901cc8a1b45a18de78f3bc40005b5d3c711086 Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 19:09:09 -0400 Subject: [PATCH 5/8] Timer expiration callback --- lib/f_core/os/tenants/c_timed_tenant.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/f_core/os/tenants/c_timed_tenant.cpp b/lib/f_core/os/tenants/c_timed_tenant.cpp index 64d39c75..9663ccdb 100644 --- a/lib/f_core/os/tenants/c_timed_tenant.cpp +++ b/lib/f_core/os/tenants/c_timed_tenant.cpp @@ -1,12 +1,20 @@ #include "f_core/os/tenants/c_timed_tenant.h" -static void timerExpirationCallback(struct k_timer *timer) { +#include "f_core/os/n_rtos.h" +#include "zephyr/logging/log.h" +LOG_MODULE_REGISTER(CTimedTenant); + +static void timerExpirationCallback(struct k_timer* timer) { + auto* tenant = static_cast(k_timer_user_data_get(timer)); + if (tenant != nullptr) { + tenant->Run(); + } else { + LOG_ERR("Timed tenant callback with null tenant"); + } } CTimedTenant::CTimedTenant(const char* name, const uint32_t intervalMillis) - : CTenant(name), timer(intervalMillis, timerExpirationCallback) {} - -void CTimedTenant::Startup() { - -} \ No newline at end of file + : CTenant(name), timer(intervalMillis, timerExpirationCallback, timerExpirationCallback) { + timer.SetUserData(this); +} From 4c69d4d39c4c374c51e5792ca235bd0a84b19414 Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 19:13:06 -0400 Subject: [PATCH 6/8] add todo --- app/backplane/sensor_module/src/c_sensor_module.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/backplane/sensor_module/src/c_sensor_module.cpp b/app/backplane/sensor_module/src/c_sensor_module.cpp index 86f11e5a..a9834ca3 100644 --- a/app/backplane/sensor_module/src/c_sensor_module.cpp +++ b/app/backplane/sensor_module/src/c_sensor_module.cpp @@ -3,7 +3,7 @@ // F-Core Tenant #include #include -#include +#include // TODO: Blast once we have CCpuMonitorTenant inherit this #include #include LOG_MODULE_REGISTER(sensor_module); From 91164b19f9816a8417f140e556c02b3f711988c1 Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 19:21:11 -0400 Subject: [PATCH 7/8] Use uint32 instead of int for CSoftTimer --- include/f_core/utils/c_soft_timer.h | 6 +++--- lib/f_core/os/tenants/c_timed_tenant.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/f_core/utils/c_soft_timer.h b/include/f_core/utils/c_soft_timer.h index a5b0671b..e18b8eac 100644 --- a/include/f_core/utils/c_soft_timer.h +++ b/include/f_core/utils/c_soft_timer.h @@ -19,7 +19,7 @@ class CSoftTimer { * @param expirationFn Function to call when the timer expires * @param stopFn Function to call when the timer is stopped */ - CSoftTimer(const int timeoutMillis, k_timer_expiry_t expirationFn = nullptr, k_timer_stop_t stopFn = nullptr) { + CSoftTimer(const uint32_t timeoutMillis, k_timer_expiry_t expirationFn = nullptr, k_timer_stop_t stopFn = nullptr) { k_timer_init(&timer, expirationFn, stopFn); StartTimer(timeoutMillis); } @@ -35,7 +35,7 @@ class CSoftTimer { * Start the timer with the given expiration time * @param millis Time in milliseconds until the timer expires */ - void StartTimer(int millis) { + void StartTimer(uint32_t millis) { // Duration (second arg) is the initial expiration time // Period (third arg) is the time set after each expiration k_timer_start(&timer, K_MSEC(millis), K_MSEC(millis)); @@ -70,7 +70,7 @@ class CSoftTimer { * @param millis Time in milliseconds until the timer expires * @param initialExpirationMillis Time in milliseconds to wait before the first expiration */ - void StartTimer(int millis, int initialExpirationMillis) { + void StartTimer(uint32_t millis, uint32_t initialExpirationMillis) { // Duration (second arg) is the initial expiration time // Period (third arg) is the time set after each expiration k_timer_start(&timer, K_MSEC(initialExpirationMillis), K_MSEC(millis)); diff --git a/lib/f_core/os/tenants/c_timed_tenant.cpp b/lib/f_core/os/tenants/c_timed_tenant.cpp index 9663ccdb..72a097f9 100644 --- a/lib/f_core/os/tenants/c_timed_tenant.cpp +++ b/lib/f_core/os/tenants/c_timed_tenant.cpp @@ -15,6 +15,6 @@ static void timerExpirationCallback(struct k_timer* timer) { } CTimedTenant::CTimedTenant(const char* name, const uint32_t intervalMillis) - : CTenant(name), timer(intervalMillis, timerExpirationCallback, timerExpirationCallback) { + : CTenant(name), timer(intervalMillis, timerExpirationCallback, nullptr) { timer.SetUserData(this); } From c9cf2796641e142d026b06bf09cd781e565c51d1 Mon Sep 17 00:00:00 2001 From: Aaron Chan Date: Mon, 25 Aug 2025 19:21:51 -0400 Subject: [PATCH 8/8] const ctor arg --- include/f_core/os/tenants/c_timed_tenant.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/f_core/os/tenants/c_timed_tenant.h b/include/f_core/os/tenants/c_timed_tenant.h index c65c3d91..b5f2176d 100644 --- a/include/f_core/os/tenants/c_timed_tenant.h +++ b/include/f_core/os/tenants/c_timed_tenant.h @@ -8,8 +8,10 @@ class CTimedTenant : public CTenant { public: /** * @brief Constructor + * @param name Name of the tenant + * @param intervalMillis Interval in milliseconds for the timeout */ - explicit CTimedTenant(const char* name, uint32_t intervalMillis); + explicit CTimedTenant(const char* name, const uint32_t intervalMillis); private: CSoftTimer timer;