From ff2054f2cb8a780936d95741e1daa7df789fa246 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 30 Oct 2021 16:49:20 -0400 Subject: [PATCH] fix fault handling; fix LEDs for rev2 --- source/board/board_l4.c | 7 +++++-- source/board/l4/board.h | 6 +++--- source/conversion.cpp | 6 +++--- source/conversion.hpp | 2 +- source/handlers.cpp | 2 +- source/monitor.cpp | 25 +++++++++++++------------ 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/source/board/board_l4.c b/source/board/board_l4.c index 31d1d51..55af697 100644 --- a/source/board/board_l4.c +++ b/source/board/board_l4.c @@ -277,9 +277,12 @@ bool mmc_lld_is_write_protected(MMCDriver *mmcp) { * @note You can add your board-specific code here. */ void boardInit(void) { - palSetLineMode(LINE_LED_GREEN, PAL_MODE_OUTPUT_PUSHPULL); - palSetLineMode(LINE_LED_YELLOW, PAL_MODE_OUTPUT_PUSHPULL); palSetLineMode(LINE_LED_RED, PAL_MODE_OUTPUT_PUSHPULL); + palSetLineMode(LINE_LED_GREEN, PAL_MODE_OUTPUT_PUSHPULL); + palSetLineMode(LINE_LED_BLUE, PAL_MODE_OUTPUT_PUSHPULL); + palClearLine(LINE_LED_RED); + palClearLine(LINE_LED_GREEN); + palClearLine(LINE_LED_BLUE); SCB->CPACR |= 0xF << 20; // Enable FPU diff --git a/source/board/l4/board.h b/source/board/l4/board.h index e4dcf03..4b2642a 100644 --- a/source/board/l4/board.h +++ b/source/board/l4/board.h @@ -1502,8 +1502,8 @@ extern "C" { #endif #endif /* _FROM_ASM_ */ -#define LINE_LED_GREEN PAL_LINE(GPIOC_BASE, 10U) -#define LINE_LED_YELLOW PAL_LINE(GPIOC_BASE, 11U) -#define LINE_LED_RED PAL_LINE(GPIOC_BASE, 12U) +#define LINE_LED_RED PAL_LINE(GPIOC_BASE, 10U) +#define LINE_LED_GREEN PAL_LINE(GPIOC_BASE, 11U) +#define LINE_LED_BLUE PAL_LINE(GPIOC_BASE, 12U) #endif /* BOARD_H */ diff --git a/source/conversion.cpp b/source/conversion.cpp index c9dc0c9..6fdea07 100644 --- a/source/conversion.cpp +++ b/source/conversion.cpp @@ -83,11 +83,11 @@ thread_t *ConversionManager::getMonitorHandle() return m_thread_monitor; } -void ConversionManager::abort() +void ConversionManager::abort(bool fpu_stacked) { ELFManager::unload(); EM.add(Error::ConversionAborted); - run_status = RunStatus::Recovering; + //run_status = RunStatus::Recovering; // Confirm that the exception return thread is the algorithm... uint32_t *psp; @@ -104,7 +104,7 @@ void ConversionManager::abort() // We do this by rebuilding the thread's stacked exception return. auto newpsp = reinterpret_cast(m_thread_runner_stack.data() + m_thread_runner_stack.size() - - 8 * sizeof(uint32_t)); + (fpu_stacked ? 26 : 8) * sizeof(uint32_t)); // Set the LR register to the thread's entry point. newpsp[5] = reinterpret_cast(threadRunner); // Overwrite the instruction we'll return to with "bx lr" (jump to address in LR). diff --git a/source/conversion.hpp b/source/conversion.hpp index 6af4972..a26dd19 100644 --- a/source/conversion.hpp +++ b/source/conversion.hpp @@ -39,7 +39,7 @@ public: static thread_t *getMonitorHandle(); // Internal only: Aborts a running conversion. - static void abort(); + static void abort(bool fpu_stacked = true); private: static void threadMonitor(void *); diff --git a/source/handlers.cpp b/source/handlers.cpp index 2ff948d..43e65c3 100644 --- a/source/handlers.cpp +++ b/source/handlers.cpp @@ -108,7 +108,7 @@ void MemManage_Handler() asm("mov %0, lr" : "=r" (lr)); // 2. Recover from the fault. - ConversionManager::abort(); + ConversionManager::abort((lr & (1 << 4)) ? false : true); // 3. Return. asm("mov lr, %0; bx lr" :: "r" (lr)); diff --git a/source/monitor.cpp b/source/monitor.cpp index 08a62d5..6ef97e9 100644 --- a/source/monitor.cpp +++ b/source/monitor.cpp @@ -39,30 +39,31 @@ void Monitor::threadMonitor(void *) #endif }; - palClearLine(LINE_LED_RED); - palClearLine(LINE_LED_YELLOW); + palSetLine(LINE_LED_RED); + palSetLine(LINE_LED_GREEN); + palSetLine(LINE_LED_BLUE); while (1) { bool isidle = run_status == RunStatus::Idle; - auto led = isidle ? LINE_LED_GREEN : LINE_LED_YELLOW; + auto led = isidle ? LINE_LED_GREEN : LINE_LED_BLUE; auto delay = isidle ? 500 : 250; - palSetLine(led); + palToggleLine(led); chThdSleepMilliseconds(delay); - palClearLine(led); + palToggleLine(led); chThdSleepMilliseconds(delay); - if (run_status == RunStatus::Idle && readButton()) { - palSetLine(LINE_LED_RED); - palSetLine(LINE_LED_YELLOW); + if (isidle && readButton()) { + palClearLine(LINE_LED_GREEN); + palClearLine(LINE_LED_BLUE); chSysLock(); while (readButton()) asm("nop"); while (!readButton()) asm("nop"); chSysUnlock(); - palClearLine(LINE_LED_RED); - palClearLine(LINE_LED_YELLOW); + palSetLine(LINE_LED_GREEN); + palSetLine(LINE_LED_BLUE); chThdSleepMilliseconds(500); } @@ -70,9 +71,9 @@ void Monitor::threadMonitor(void *) if (auto err = EM.hasError(); err ^ erroron) { erroron = err; if (err) - palSetLine(LINE_LED_RED); - else palClearLine(LINE_LED_RED); + else + palSetLine(LINE_LED_RED); } } }