improved m4 m0 communication

This commit is contained in:
Bernd Herzog 2023-04-23 23:48:20 +02:00
parent 2ef9ebd7bd
commit 29b7a5ee56
7 changed files with 44 additions and 37 deletions

View File

@ -759,6 +759,9 @@ void SystemView::toggle_overlay() {
this->add_child(&this->overlay);
this->set_dirty();
shared_memory.request_m4_performance_counter = 1;
shared_memory.m4_cpu_usage = 0;
shared_memory.m4_heap_usage = 0;
shared_memory.m4_stack_usage = 0;
}
overlay_active = !overlay_active;

View File

@ -508,6 +508,8 @@
}
#endif
/**
* @brief System tick event hook.
* @details This hook is invoked in the system tick handler immediately
@ -516,6 +518,8 @@
#if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__)
#define SYSTEM_TICK_EVENT_HOOK() { \
/* System tick event code here.*/ \
extern void update_performance_counters(); \
update_performance_counters(); \
}
#endif

View File

@ -116,5 +116,35 @@ CH_IRQ_HANDLER(HardFaultVector) {
#endif
}
void update_performance_counters() {
auto performance_counter_active = shared_memory.request_m4_performance_counter;
if (performance_counter_active == 0x00)
return;
static bool last_paint_state = false;
if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state)
return;
last_paint_state = !last_paint_state;
auto now = chTimeNow();
auto idle_ticks = chThdGetTicks(chSysGetIdleThread());
static systime_t last_time;
static systime_t last_last_time;
auto time_elapsed = now - last_time;
auto idle_elapsed = idle_ticks - last_last_time;
last_time = now;
last_last_time = idle_ticks;
auto cpu_usage = (time_elapsed - idle_elapsed) / 10;
auto free_stack = (uint32_t)get_free_stack_space();
auto free_heap = chCoreStatus();
shared_memory.m4_cpu_usage = cpu_usage;
shared_memory.m4_stack_usage = free_stack;
shared_memory.m4_heap_usage = free_heap;
}
} /* extern "C" */

View File

@ -87,10 +87,6 @@ void EventDispatcher::dispatch(const eventmask_t events) {
if( events & EVT_MASK_SPECTRUM ) {
handle_spectrum();
}
if (shared_memory.request_m4_performance_counter == 0x01) {
update_performance_counters();
}
}
void EventDispatcher::handle_baseband_queue() {
@ -100,34 +96,6 @@ void EventDispatcher::handle_baseband_queue() {
}
}
void EventDispatcher::update_performance_counters() {
static bool last_paint_state = false;
if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state)
return;
last_paint_state = !last_paint_state;
auto now = chTimeNow();
auto idle_ticks = chThdGetTicks(chSysGetIdleThread());
static systime_t last_time;
static systime_t last_last_time;
auto time_elapsed = now - last_time;
auto idle_elapsed = idle_ticks - last_last_time;
last_time = now;
last_last_time = idle_ticks;
auto cpu_usage = (time_elapsed - idle_elapsed) / 10;
auto free_stack = (uint32_t)get_free_stack_space();
auto free_heap = chCoreStatus();
shared_memory.m4_cpu_usage = cpu_usage;
shared_memory.m4_stack_usage = free_stack;
shared_memory.m4_heap_usage = free_heap;
}
void EventDispatcher::on_message(const Message* const message) {
switch(message->id) {
case Message::ID::Shutdown:
@ -153,3 +121,4 @@ void EventDispatcher::handle_spectrum() {
const UpdateSpectrumMessage message;
baseband_processor->on_message(&message);
}

View File

@ -61,7 +61,6 @@ private:
void dispatch(const eventmask_t events);
void handle_baseband_queue();
void update_performance_counters();
void on_message(const Message* const message);
void on_message_shutdown(const ShutdownMessage&);

View File

@ -45,3 +45,5 @@ int main() {
return 0;
}
void update_performance_counters() {}

View File

@ -65,10 +65,10 @@ struct SharedMemory {
uint8_t data[512];
} bb_data { { { { 0, 0 } }, 0, { 0 } } };
uint8_t request_m4_performance_counter{ 0 };
uint8_t m4_cpu_usage{ 0 };
uint16_t m4_stack_usage{ 0 };
uint16_t m4_heap_usage{ 0 };
uint8_t volatile request_m4_performance_counter{ 0 };
uint8_t volatile m4_cpu_usage{ 0 };
uint16_t volatile m4_stack_usage{ 0 };
uint16_t volatile m4_heap_usage{ 0 };
};
extern SharedMemory& shared_memory;