From eac4cf678a489f75b64e320eb6ff22b452c9a487 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 27 Feb 2016 12:10:39 -0800 Subject: [PATCH] Capture M4 chDbgPanic msg, show in application. --- firmware/application/event_m0.cpp | 37 +++++++++++++++++++++ firmware/application/event_m0.hpp | 1 + firmware/common/debug.cpp | 12 +++++++ firmware/common/portapack_shared_memory.hpp | 2 ++ 4 files changed, 52 insertions(+) diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 96df09a4..3acdb4f6 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -40,6 +40,8 @@ using namespace lpc43xx; #include +#include "ui_font_fixed_8x16.hpp" + extern "C" { CH_IRQ_HANDLER(M4Core_IRQHandler) { @@ -133,6 +135,40 @@ eventmask_t EventDispatcher::wait() { } void EventDispatcher::dispatch(const eventmask_t events) { + if( shared_memory.m4_panic_msg[0] != 0 ) { + halt = true; + } + + if( halt ) { + if( shared_memory.m4_panic_msg[0] != 0 ) { + painter.fill_rectangle( + { 0, 0, portapack::display.width(), portapack::display.height() }, + ui::Color::red() + ); + + constexpr int border = 8; + painter.fill_rectangle( + { border, border, portapack::display.width() - (border * 2), portapack::display.height() - (border * 2) }, + ui::Color::black() + ); + + painter.draw_string({ 48, 24 }, top_widget->style(), "M4 Guru Meditation"); + + shared_memory.m4_panic_msg[sizeof(shared_memory.m4_panic_msg) - 1] = 0; + const std::string message = shared_memory.m4_panic_msg; + const int x_offset = (portapack::display.width() - (message.size() * 8)) / 2; + constexpr int y_offset = (portapack::display.height() - 16) / 2; + painter.draw_string( + { x_offset, y_offset }, + top_widget->style(), + message + ); + + shared_memory.m4_panic_msg[0] = 0; + } + return; + } + if( events & EVT_MASK_APPLICATION ) { handle_application_queue(); } @@ -291,6 +327,7 @@ void EventDispatcher::init_message_queues() { new (&shared_memory.app_local_queue) MessageQueue( shared_memory.app_local_queue_data, SharedMemory::app_local_queue_k ); + shared_memory.m4_panic_msg[0] = 0; } MessageHandlerRegistration::MessageHandlerRegistration( diff --git a/firmware/application/event_m0.hpp b/firmware/application/event_m0.hpp index 35de0e4d..d08ce78a 100644 --- a/firmware/application/event_m0.hpp +++ b/firmware/application/event_m0.hpp @@ -102,6 +102,7 @@ private: bool is_running = true; bool sd_card_present = false; bool display_sleep = false; + bool halt = false; eventmask_t wait(); void dispatch(const eventmask_t events); diff --git a/firmware/common/debug.cpp b/firmware/common/debug.cpp index 886abeaf..218bf236 100644 --- a/firmware/common/debug.cpp +++ b/firmware/common/debug.cpp @@ -24,6 +24,8 @@ #include #include +#include "portapack_shared_memory.hpp" + #if defined(LPC43XX_M0) static void debug_indicate_error_init() { // TODO: Get knowledge of LED GPIO port/bit from shared place. @@ -75,6 +77,16 @@ void __early_init(void) { } void port_halt(void) { + // Copy debug panic message to M0 region. + const auto* p = dbg_panic_msg; + for(size_t i=0; i