Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changesets/diagnostics-hub-throttling
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: patch
summary: Add throttling to Diagmostics::Hun:flush
2 changes: 2 additions & 0 deletions .changesets/fix-hwarfault-warning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: patch
summary: Fix a warning about symbols in HardfaultTrace (doesn't change any behaviour)
4 changes: 2 additions & 2 deletions Inc/HALAL/HardFault/HardfaultTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Inc/HALAL/Services/Diagnostics/Diagnostics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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 };
Expand Down Expand Up @@ -245,6 +247,8 @@ class Hub {
static size_t history_next_index;
static array<PendingRecord, Config::pending_capacity> pending_records;
static size_t pending_count;
static uint64_t last_urgent_flush_tick;
static uint64_t last_normal_flush_tick;
};

class Runtime {
Expand Down
2 changes: 1 addition & 1 deletion Src/HALAL/HardFault/HardfaultTrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions Src/HALAL/Services/Diagnostics/DiagnosticsHub.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "HALAL/Services/Diagnostics/Diagnostics.hpp"

#include "HALAL/Services/Time/Scheduler.hpp"

namespace Diagnostics {

array<Hub::SinkStorage, Config::max_sinks> Hub::sink_storage = {};
Expand All @@ -10,6 +12,8 @@ size_t Hub::history_count = 0;
size_t Hub::history_next_index = 0;
array<Hub::PendingRecord, Config::pending_capacity> 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 {
Expand Down Expand Up @@ -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<uint8_t>((1u << sink_count) - 1u);

for (size_t record_index = 0; record_index < pending_count;) {
Expand Down
Loading