mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-28 00:39:44 -05:00
Add tick tracking for all baseband threads.
This commit is contained in:
parent
aa733b1b61
commit
7f46f0d071
@ -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<typename Callback>
|
||||
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 };
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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 };
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user