From 9b8c652ac72736e8f608b78b7cc98a448f0e9826 Mon Sep 17 00:00:00 2001 From: victhor Date: Sat, 9 May 2026 20:18:01 +0200 Subject: [PATCH 1/4] fix: Unify get_global_tick behaviour and make format_numeric_value return if value was written --- .../Diagnostics/DiagnosticFormatter.cpp | 38 +++++++++---------- Src/HALAL/Services/Time/Scheduler.cpp | 6 --- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp b/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp index 22652f480..c5f3d433b 100644 --- a/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp +++ b/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp @@ -84,16 +84,18 @@ const char* rule_edge_label(Protections::RuleEdge edge) { std::unreachable(); } -void format_numeric_value( +/* returns if there was enough size to write the value */ +bool format_numeric_value( Protections::SampleEncoding encoding, Protections::NumericValue value, char* buffer, size_t buffer_size ) { if (buffer_size == 0) { - return; + return false; } + size_t bytes_written = 0; switch (encoding) { case Protections::SampleEncoding::BOOL: { const char* text = value.bool_value ? "true" : "false"; @@ -101,36 +103,30 @@ void format_numeric_value( const size_t length = std::min(text_length, buffer_size - 1); memcpy(buffer, text, length); buffer[length] = '\0'; + return length == text_length; } - return; case Protections::SampleEncoding::SIGNED: - if (snprintf(buffer, buffer_size, "%lld", static_cast(value.signed_value)) < 0) { - buffer[0] = '\0'; - } - return; + bytes_written = snprintf(buffer, buffer_size, "%lld", static_cast(value.signed_value)); + break; case Protections::SampleEncoding::UNSIGNED: - if (snprintf( + bytes_written = snprintf( buffer, buffer_size, "%llu", static_cast(value.unsigned_value) - ) < 0) { - buffer[0] = '\0'; - } - return; + ); + break; case Protections::SampleEncoding::FLOAT32: - if (snprintf(buffer, buffer_size, "%.6f", static_cast(value.float32_value)) < 0) { - buffer[0] = '\0'; - } - return; + bytes_written = snprintf(buffer, buffer_size, "%.6f", static_cast(value.float32_value)); + break; case Protections::SampleEncoding::FLOAT64: - if (snprintf(buffer, buffer_size, "%.6f", value.float64_value) < 0) { - buffer[0] = '\0'; - } - return; + bytes_written = snprintf(buffer, buffer_size, "%.6f", value.float64_value); + break; + default: + std::unreachable(); } - std::unreachable(); + return bytes_written < buffer_size; } void append_timestamp_suffix(const Timestamp& timestamp, DiagnosticStringBuilder& builder) { diff --git a/Src/HALAL/Services/Time/Scheduler.cpp b/Src/HALAL/Services/Time/Scheduler.cpp index 1cc860eae..a01b1da53 100644 --- a/Src/HALAL/Services/Time/Scheduler.cpp +++ b/Src/HALAL/Services/Time/Scheduler.cpp @@ -103,13 +103,7 @@ void Scheduler::update() { uint64_t Scheduler::get_global_tick() { SchedLock(); uint64_t tick = global_tick_us_; -#ifdef SIM_ON - if (Scheduler_global_timer != nullptr) { - tick += Scheduler_global_timer->CNT; - } -#else tick += Scheduler_global_timer->CNT; -#endif SchedUnlock(); return tick; } From e865297b985391bca7e8ebad424f04bdbf3c2268 Mon Sep 17 00:00:00 2001 From: victhor Date: Sat, 9 May 2026 20:40:45 +0200 Subject: [PATCH 2/4] add changeset and formatting --- .changesets/fix-sched-and-format.md | 2 ++ .../Services/Diagnostics/DiagnosticFormatter.cpp | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 .changesets/fix-sched-and-format.md diff --git a/.changesets/fix-sched-and-format.md b/.changesets/fix-sched-and-format.md new file mode 100644 index 000000000..720d413e2 --- /dev/null +++ b/.changesets/fix-sched-and-format.md @@ -0,0 +1,2 @@ +release: patch +summary: Unify get_global_tick behaviour and make format_numeric_value return if value was written in DiagnosticFormatter diff --git a/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp b/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp index c5f3d433b..3baab2471 100644 --- a/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp +++ b/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp @@ -106,18 +106,20 @@ bool format_numeric_value( return length == text_length; } case Protections::SampleEncoding::SIGNED: - bytes_written = snprintf(buffer, buffer_size, "%lld", static_cast(value.signed_value)); + bytes_written = + snprintf(buffer, buffer_size, "%lld", static_cast(value.signed_value)); break; case Protections::SampleEncoding::UNSIGNED: bytes_written = snprintf( - buffer, - buffer_size, - "%llu", - static_cast(value.unsigned_value) - ); + buffer, + buffer_size, + "%llu", + static_cast(value.unsigned_value) + ); break; case Protections::SampleEncoding::FLOAT32: - bytes_written = snprintf(buffer, buffer_size, "%.6f", static_cast(value.float32_value)); + bytes_written = + snprintf(buffer, buffer_size, "%.6f", static_cast(value.float32_value)); break; case Protections::SampleEncoding::FLOAT64: bytes_written = snprintf(buffer, buffer_size, "%.6f", value.float64_value); From dea1038401e42b764442b65a35d1ed034cad094f Mon Sep 17 00:00:00 2001 From: victhor Date: Sat, 9 May 2026 20:45:00 +0200 Subject: [PATCH 3/4] formatting --- CHANGELOG.md | 10 +++++----- Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f37bf6b3..adea158ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,18 +12,18 @@ Historical releases that predate this file remain available in Git tags such as - Redesign fault handling, protections, and Board bootstrap around explicit fault policies This PR changes the public integration contract for applications built on ST-LIB. - + Breaking changes: - + - `Board` now takes the fault policy type as its first template parameter. - The global `FAULT` runtime is owned exclusively by `FaultController`. - User state machines are now nested under the global `OPERATIONAL` state through `FaultPolicy` or `FaultPolicyNoMachine`. - Protections are now compile-time `Board` request objects evaluated through `Board::ProtectionEngine`; the previous `ProtectionManager` and boundary split is no longer the active model. - Runtime reporting is unified under `PANIC(...)`, `FAULT(...)`, `WARNING(...)`, and `INFO(...)`. - The real bootstrap path is `Board::init()`. Legacy `STLIB::start()`, `STLIB::update()`, `STLIB_LOW::start()`, and `STLIB_HIGH::start()` must not be used as the integration path. - + Migration notes: - + - Declare the board as `Board`. - Use `FaultPolicy` when you want an operational state machine nested under the global runtime. - Use `FaultPolicyNoMachine` when you only need a fault-entry callback. @@ -39,7 +39,7 @@ Historical releases that predate this file remain available in Git tags such as timerwrapper: - Add `set_callback(void (*callback)(void*), void* callback_data)` to set the callback and its data instead of needing to call `configurexxbit()` and set the period. - `set_limit_value(uint32_t arr)` to set the arr, this will likely be changed to use a `uint32_t` type only when using a 32 bit timer, for now it is just an alias to `instance->tim->ARR = arr;`. Was not added in this pr but also wasn't mentioned before. - + spi: - Add `transceive` with ptr + data explicitly instead of using a span since it's sometimes a pain in the ass to use. diff --git a/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp b/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp index 3baab2471..3e0036b67 100644 --- a/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp +++ b/Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp @@ -106,7 +106,7 @@ bool format_numeric_value( return length == text_length; } case Protections::SampleEncoding::SIGNED: - bytes_written = + bytes_written = snprintf(buffer, buffer_size, "%lld", static_cast(value.signed_value)); break; case Protections::SampleEncoding::UNSIGNED: @@ -118,7 +118,7 @@ bool format_numeric_value( ); break; case Protections::SampleEncoding::FLOAT32: - bytes_written = + bytes_written = snprintf(buffer, buffer_size, "%.6f", static_cast(value.float32_value)); break; case Protections::SampleEncoding::FLOAT64: From 921688b598d15c186b56cfe8f0076d5ac1395e4b Mon Sep 17 00:00:00 2001 From: victhor Date: Sat, 9 May 2026 21:08:21 +0200 Subject: [PATCH 4/4] fix segfault in tests --- Tests/diagnostics_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/diagnostics_test.cpp b/Tests/diagnostics_test.cpp index f5fad2ba1..f6b99dfa3 100644 --- a/Tests/diagnostics_test.cpp +++ b/Tests/diagnostics_test.cpp @@ -131,7 +131,7 @@ class DiagnosticsHubTest : public ::testing::Test { TestPanicReporter::reset(); fault_enter_calls = 0; Scheduler::global_tick_us_ = 0; - Scheduler_global_timer = nullptr; + Scheduler_global_timer = TIM2_BASE; FaultController::install_runtime(); FaultController::start();