From 7f46f0d071f63d59c45d7bfd0c29df156c7b4b9c Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 14 Oct 2015 10:44:20 -0700 Subject: [PATCH] Add tick tracking for all baseband threads. --- .../baseband/baseband_stats_collector.hpp | 30 +++++++++++++++++-- firmware/baseband/main.cpp | 20 +++++++++---- firmware/common/message.hpp | 2 ++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/firmware/baseband/baseband_stats_collector.hpp b/firmware/baseband/baseband_stats_collector.hpp index 6fc5439b..fe5c7fe9 100644 --- a/firmware/baseband/baseband_stats_collector.hpp +++ b/firmware/baseband/baseband_stats_collector.hpp @@ -33,6 +33,18 @@ class BasebandStatsCollector { public: + BasebandStatsCollector( + const Thread* const thread_idle, + const Thread* const thread_main, + const Thread* const thread_rssi, + const Thread* const thread_baseband + ) : thread_idle { thread_idle }, + thread_main { thread_main }, + thread_rssi { thread_rssi }, + thread_baseband { thread_baseband } + { + } + template void process(buffer_c8_t buffer, Callback callback) { samples += buffer.count; @@ -40,11 +52,19 @@ public: const size_t report_samples = buffer.sampling_rate * report_interval; const auto report_delta = samples - samples_last_report; if( report_delta >= report_samples ) { - const auto idle_ticks = chSysGetIdleThread()->total_ticks; + const auto idle_ticks = thread_idle->total_ticks; statistics.idle_ticks = (idle_ticks - last_idle_ticks); last_idle_ticks = idle_ticks; - const auto baseband_ticks = chThdSelf()->total_ticks; + const auto main_ticks = thread_main->total_ticks; + statistics.main_ticks = (main_ticks - last_main_ticks); + last_main_ticks = main_ticks; + + const auto rssi_ticks = thread_rssi->total_ticks; + statistics.rssi_ticks = (rssi_ticks - last_rssi_ticks); + last_rssi_ticks = rssi_ticks; + + const auto baseband_ticks = thread_baseband->total_ticks; statistics.baseband_ticks = (baseband_ticks - last_baseband_ticks); last_baseband_ticks = baseband_ticks; @@ -62,7 +82,13 @@ private: BasebandStatistics statistics; size_t samples { 0 }; size_t samples_last_report { 0 }; + const Thread* const thread_idle; uint32_t last_idle_ticks { 0 }; + const Thread* const thread_main; + uint32_t last_main_ticks { 0 }; + const Thread* const thread_rssi; + uint32_t last_rssi_ticks { 0 }; + const Thread* const thread_baseband; uint32_t last_baseband_ticks { 0 }; }; diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index 3f041070..71fc37ea 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -82,6 +82,9 @@ constexpr auto baseband_thread_priority = NORMALPRIO + 20; constexpr auto rssi_thread_priority = NORMALPRIO + 10; +const Thread* thread_main; +const Thread* thread_rssi; + static BasebandProcessor* baseband_processor { nullptr }; static BasebandConfiguration baseband_configuration; @@ -90,7 +93,12 @@ static __attribute__((noreturn)) msg_t baseband_fn(void *arg) { (void)arg; chRegSetThreadName("baseband"); - BasebandStatsCollector stats; + BasebandStatsCollector stats { + chSysGetIdleThread(), + thread_main, + thread_rssi, + chThdSelf() + }; while(true) { // TODO: Place correct sampling rate into buffer returned here: @@ -182,13 +190,15 @@ static void init() { rf::rssi::init(); touch::dma::init(); - chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa), - baseband_thread_priority, baseband_fn, + thread_main = chThdSelf(); + + thread_rssi = chThdCreateStatic(rssi_thread_wa, sizeof(rssi_thread_wa), + rssi_thread_priority, rssi_fn, nullptr ); - chThdCreateStatic(rssi_thread_wa, sizeof(rssi_thread_wa), - rssi_thread_priority, rssi_fn, + chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa), + baseband_thread_priority, baseband_fn, nullptr ); } diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index fa06c703..8d028ea9 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -76,6 +76,8 @@ public: struct BasebandStatistics { uint32_t idle_ticks { 0 }; + uint32_t main_ticks { 0 }; + uint32_t rssi_ticks { 0 }; uint32_t baseband_ticks { 0 }; bool saturation { false }; };