Capture M4 chDbgPanic msg, show in application.

This commit is contained in:
Jared Boone 2016-02-27 12:10:39 -08:00
parent 97ba19af24
commit eac4cf678a
4 changed files with 52 additions and 0 deletions

View File

@ -40,6 +40,8 @@ using namespace lpc43xx;
#include <array>
#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(

View File

@ -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);

View File

@ -24,6 +24,8 @@
#include <ch.h>
#include <hal.h>
#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<sizeof(shared_memory.m4_panic_msg); i++) {
if( *p == 0 ) {
shared_memory.m4_panic_msg[i] = 0;
} else {
shared_memory.m4_panic_msg[i] = *(p++);
}
}
port_disable();
runtime_error();
}

View File

@ -45,6 +45,8 @@ struct SharedMemory {
// TODO: M0 should directly configure and control DMA channel that is
// acquiring ADC samples.
TouchADCFrame touch_adc_frame;
char m4_panic_msg[32];
};
extern SharedMemory& shared_memory;