From 2e73151619c36129f8520d19a30b296a78f479f8 Mon Sep 17 00:00:00 2001 From: FoniksFox Date: Sun, 21 Jun 2026 17:08:07 +0200 Subject: [PATCH 1/4] fix(Diagnostics::Hub): Implement flush throttling to prevent excessive flushes --- Inc/HALAL/Services/Diagnostics/Diagnostics.hpp | 4 ++++ Src/HALAL/Services/Diagnostics/DiagnosticsHub.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp b/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp index 28d5c5dfe..10d003061 100644 --- a/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp +++ b/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp @@ -19,6 +19,8 @@ inline constexpr size_t runtime_message_capacity = 160; inline constexpr size_t function_capacity = 64; inline constexpr size_t file_capacity = 96; inline constexpr size_t formatted_message_capacity = 320; +inline constexpr uint32_t urgent_flush_interval_us = 500; // 500 us +inline constexpr uint32_t normal_flush_interval_us = 1000; // 1000 us } // namespace Config enum class Severity : uint8_t { INFO = 0, WARNING, FAULT }; @@ -245,6 +247,8 @@ class Hub { static size_t history_next_index; static array pending_records; static size_t pending_count; + static uint64_t last_urgent_flush_tick; + static uint64_t last_normal_flush_tick; }; class Runtime { diff --git a/Src/HALAL/Services/Diagnostics/DiagnosticsHub.cpp b/Src/HALAL/Services/Diagnostics/DiagnosticsHub.cpp index 9bad45779..d559f2224 100644 --- a/Src/HALAL/Services/Diagnostics/DiagnosticsHub.cpp +++ b/Src/HALAL/Services/Diagnostics/DiagnosticsHub.cpp @@ -1,5 +1,7 @@ #include "HALAL/Services/Diagnostics/Diagnostics.hpp" +#include "HALAL/Services/Time/Scheduler.hpp" + namespace Diagnostics { array Hub::sink_storage = {}; @@ -10,6 +12,8 @@ size_t Hub::history_count = 0; size_t Hub::history_next_index = 0; array Hub::pending_records = {}; size_t Hub::pending_count = 0; +uint64_t Hub::last_urgent_flush_tick = 0; +uint64_t Hub::last_normal_flush_tick = 0; bool Runtime::defaults_installed = false; namespace { @@ -296,6 +300,16 @@ void Hub::publish_protection_event( } void Hub::flush_pending(bool urgent_only) { + uint64_t& last_flush_tick = urgent_only ? last_urgent_flush_tick : last_normal_flush_tick; + const uint64_t interval_us = urgent_only ? Config::urgent_flush_interval_us + : Config::normal_flush_interval_us; + + const uint64_t now = Scheduler::get_global_tick(); + if (now - last_flush_tick < interval_us) { + return; + } + last_flush_tick = now; + const uint8_t target_mask = sink_count == 0 ? 0 : static_cast((1u << sink_count) - 1u); for (size_t record_index = 0; record_index < pending_count;) { From c4428c6a1881044ccdaea6caf654f8c70a2c6009 Mon Sep 17 00:00:00 2001 From: FoniksFox Date: Sun, 21 Jun 2026 17:11:36 +0200 Subject: [PATCH 2/4] chore: Add flush throttling to DiagnosticsHub --- .changesets/diagnostics-hub-throttling | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changesets/diagnostics-hub-throttling diff --git a/.changesets/diagnostics-hub-throttling b/.changesets/diagnostics-hub-throttling new file mode 100644 index 000000000..e177768dc --- /dev/null +++ b/.changesets/diagnostics-hub-throttling @@ -0,0 +1,2 @@ +release: patch +summary: Add throttling to Diagmostics::Hun:flush \ No newline at end of file From 85ade5e7e39bfec029464fe9458f877fef0757ea Mon Sep 17 00:00:00 2001 From: FoniksFox Date: Sun, 21 Jun 2026 17:59:37 +0200 Subject: [PATCH 3/4] fix(Throttling): Adjust flush intervals --- Inc/HALAL/Services/Diagnostics/Diagnostics.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp b/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp index 10d003061..d31dfda65 100644 --- a/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp +++ b/Inc/HALAL/Services/Diagnostics/Diagnostics.hpp @@ -19,8 +19,8 @@ inline constexpr size_t runtime_message_capacity = 160; inline constexpr size_t function_capacity = 64; inline constexpr size_t file_capacity = 96; inline constexpr size_t formatted_message_capacity = 320; -inline constexpr uint32_t urgent_flush_interval_us = 500; // 500 us -inline constexpr uint32_t normal_flush_interval_us = 1000; // 1000 us +inline constexpr uint32_t urgent_flush_interval_us = 500000; // 500 ms +inline constexpr uint32_t normal_flush_interval_us = 1000000; // 1 s } // namespace Config enum class Severity : uint8_t { INFO = 0, WARNING, FAULT }; From 84dfb8337b3834cbd51dbcc2fb0d052327c67aca Mon Sep 17 00:00:00 2001 From: Boris Mladenov Beslimov Date: Sun, 21 Jun 2026 17:38:33 +0200 Subject: [PATCH 4/4] Fix/hardfaulttrace warning symbols (#663) * fix: Fix a warning about symbols missmatch * chore: Add changeset --- .changesets/fix-hwarfault-warning.md | 2 ++ Inc/HALAL/HardFault/HardfaultTrace.h | 4 ++-- Src/HALAL/HardFault/HardfaultTrace.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .changesets/fix-hwarfault-warning.md diff --git a/.changesets/fix-hwarfault-warning.md b/.changesets/fix-hwarfault-warning.md new file mode 100644 index 000000000..7f25091ea --- /dev/null +++ b/.changesets/fix-hwarfault-warning.md @@ -0,0 +1,2 @@ +release: patch +summary: Fix a warning about symbols in HardfaultTrace (doesn't change any behaviour) diff --git a/Inc/HALAL/HardFault/HardfaultTrace.h b/Inc/HALAL/HardFault/HardfaultTrace.h index 5fe2d7c40..22021cbfc 100644 --- a/Inc/HALAL/HardFault/HardfaultTrace.h +++ b/Inc/HALAL/HardFault/HardfaultTrace.h @@ -9,8 +9,8 @@ #ifdef __cplusplus extern "C" { #endif -extern uint32_t _metadata; -extern uint32_t _hf_log; +extern uint8_t _metadata[]; +extern uint8_t _hf_log[]; #ifdef __cplusplus } #endif diff --git a/Src/HALAL/HardFault/HardfaultTrace.c b/Src/HALAL/HardFault/HardfaultTrace.c index 0aa1d7c18..01f9c3e78 100644 --- a/Src/HALAL/HardFault/HardfaultTrace.c +++ b/Src/HALAL/HardFault/HardfaultTrace.c @@ -18,7 +18,7 @@ extern GPIO_TypeDef* ports_hard_fault[]; extern uint16_t pins_hard_fault[]; extern uint8_t hard_fault_leds_count; -extern uint32_t _hf_log; +extern uint8_t _hf_log[]; static void LED_Blink(); static void LED_init(void);