From 06d189e08c01e6edcbbc933e7f16101f1154fb0d Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sat, 11 May 2024 19:32:45 +0200 Subject: [PATCH] average tick interrupt interval --- kw11-l.cpp | 9 ++++++++- kw11-l.h | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/kw11-l.cpp b/kw11-l.cpp index 97480d8..f94e4f3 100644 --- a/kw11-l.cpp +++ b/kw11-l.cpp @@ -45,6 +45,9 @@ kw11_l::~kw11_l() void kw11_l::show_state(console *const cnsl) const { cnsl->put_string_lf(format("CSR: %06o", lf_csr)); + + if (n_t_diff) + cnsl->put_string_lf(format("Average tick interrupt interval: %.3f ms", double(t_diff_sum) / n_t_diff)); } void kw11_l::begin(console *const cnsl) @@ -96,11 +99,15 @@ void kw11_l::operator()() // - 50 Hz depending on instrution count // - nothing executed in interval // - 10 Hz minimum - if (took_ms >= 1000 / 50 || current_cycle_count - interval_prev_cycle_count == 0 || now - prev_tick >= 100) { + auto t_diff = now - prev_tick; + if (took_ms >= 1000 / 50 || current_cycle_count - interval_prev_cycle_count == 0 || t_diff >= 100) { do_interrupt(); prev_cycle_count = current_cycle_count; + t_diff_sum += t_diff; + n_t_diff++; + prev_tick = now; } diff --git a/kw11-l.h b/kw11-l.h index 75b28cf..9861d8d 100644 --- a/kw11-l.h +++ b/kw11-l.h @@ -24,6 +24,9 @@ private: #endif uint16_t lf_csr { 0 }; + int64_t t_diff_sum { 0 }; + uint64_t n_t_diff { 0 }; + std::atomic_bool stop_flag { false }; uint8_t get_lf_crs();