mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 14:59:24 -05:00
improved m4 m0 communication
This commit is contained in:
parent
2ef9ebd7bd
commit
29b7a5ee56
@ -759,6 +759,9 @@ void SystemView::toggle_overlay() {
|
|||||||
this->add_child(&this->overlay);
|
this->add_child(&this->overlay);
|
||||||
this->set_dirty();
|
this->set_dirty();
|
||||||
shared_memory.request_m4_performance_counter = 1;
|
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;
|
overlay_active = !overlay_active;
|
||||||
|
@ -508,6 +508,8 @@
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System tick event hook.
|
* @brief System tick event hook.
|
||||||
* @details This hook is invoked in the system tick handler immediately
|
* @details This hook is invoked in the system tick handler immediately
|
||||||
@ -516,6 +518,8 @@
|
|||||||
#if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__)
|
#if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__)
|
||||||
#define SYSTEM_TICK_EVENT_HOOK() { \
|
#define SYSTEM_TICK_EVENT_HOOK() { \
|
||||||
/* System tick event code here.*/ \
|
/* System tick event code here.*/ \
|
||||||
|
extern void update_performance_counters(); \
|
||||||
|
update_performance_counters(); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -116,5 +116,35 @@ CH_IRQ_HANDLER(HardFaultVector) {
|
|||||||
#endif
|
#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" */
|
||||||
|
@ -87,10 +87,6 @@ void EventDispatcher::dispatch(const eventmask_t events) {
|
|||||||
if( events & EVT_MASK_SPECTRUM ) {
|
if( events & EVT_MASK_SPECTRUM ) {
|
||||||
handle_spectrum();
|
handle_spectrum();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shared_memory.request_m4_performance_counter == 0x01) {
|
|
||||||
update_performance_counters();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventDispatcher::handle_baseband_queue() {
|
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) {
|
void EventDispatcher::on_message(const Message* const message) {
|
||||||
switch(message->id) {
|
switch(message->id) {
|
||||||
case Message::ID::Shutdown:
|
case Message::ID::Shutdown:
|
||||||
@ -153,3 +121,4 @@ void EventDispatcher::handle_spectrum() {
|
|||||||
const UpdateSpectrumMessage message;
|
const UpdateSpectrumMessage message;
|
||||||
baseband_processor->on_message(&message);
|
baseband_processor->on_message(&message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ private:
|
|||||||
void dispatch(const eventmask_t events);
|
void dispatch(const eventmask_t events);
|
||||||
|
|
||||||
void handle_baseband_queue();
|
void handle_baseband_queue();
|
||||||
void update_performance_counters();
|
|
||||||
|
|
||||||
void on_message(const Message* const message);
|
void on_message(const Message* const message);
|
||||||
void on_message_shutdown(const ShutdownMessage&);
|
void on_message_shutdown(const ShutdownMessage&);
|
||||||
|
@ -45,3 +45,5 @@ int main() {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_performance_counters() {}
|
||||||
|
@ -65,10 +65,10 @@ struct SharedMemory {
|
|||||||
uint8_t data[512];
|
uint8_t data[512];
|
||||||
} bb_data { { { { 0, 0 } }, 0, { 0 } } };
|
} bb_data { { { { 0, 0 } }, 0, { 0 } } };
|
||||||
|
|
||||||
uint8_t request_m4_performance_counter{ 0 };
|
uint8_t volatile request_m4_performance_counter{ 0 };
|
||||||
uint8_t m4_cpu_usage{ 0 };
|
uint8_t volatile m4_cpu_usage{ 0 };
|
||||||
uint16_t m4_stack_usage{ 0 };
|
uint16_t volatile m4_stack_usage{ 0 };
|
||||||
uint16_t m4_heap_usage{ 0 };
|
uint16_t volatile m4_heap_usage{ 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SharedMemory& shared_memory;
|
extern SharedMemory& shared_memory;
|
||||||
|
Loading…
Reference in New Issue
Block a user