Skip to content
Merged
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/fix-sched-and-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: patch
summary: Unify get_global_tick behaviour and make format_numeric_value return if value was written in DiagnosticFormatter
48 changes: 23 additions & 25 deletions Src/HALAL/Services/Diagnostics/DiagnosticFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,53 +84,51 @@ 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";
const size_t text_length = value.bool_value ? 4U : 5U;
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<long long>(value.signed_value)) < 0) {
buffer[0] = '\0';
}
return;
bytes_written =
snprintf(buffer, buffer_size, "%lld", static_cast<long long>(value.signed_value));
break;
case Protections::SampleEncoding::UNSIGNED:
if (snprintf(
buffer,
buffer_size,
"%llu",
static_cast<unsigned long long>(value.unsigned_value)
) < 0) {
buffer[0] = '\0';
}
return;
bytes_written = snprintf(
buffer,
buffer_size,
"%llu",
static_cast<unsigned long long>(value.unsigned_value)
);
break;
case Protections::SampleEncoding::FLOAT32:
if (snprintf(buffer, buffer_size, "%.6f", static_cast<double>(value.float32_value)) < 0) {
buffer[0] = '\0';
}
return;
bytes_written =
snprintf(buffer, buffer_size, "%.6f", static_cast<double>(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) {
Expand Down
6 changes: 0 additions & 6 deletions Src/HALAL/Services/Time/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/diagnostics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoMachinePolicy>();
FaultController::start();
Expand Down
Loading