fix fault handling; fix LEDs for rev2

master
Clyne 3 years ago
parent 6f1c5203f1
commit ff2054f2cb

@ -277,9 +277,12 @@ bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
* @note You can add your board-specific code here. * @note You can add your board-specific code here.
*/ */
void boardInit(void) { 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_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 SCB->CPACR |= 0xF << 20; // Enable FPU

@ -1502,8 +1502,8 @@ extern "C" {
#endif #endif
#endif /* _FROM_ASM_ */ #endif /* _FROM_ASM_ */
#define LINE_LED_GREEN PAL_LINE(GPIOC_BASE, 10U) #define LINE_LED_RED PAL_LINE(GPIOC_BASE, 10U)
#define LINE_LED_YELLOW PAL_LINE(GPIOC_BASE, 11U) #define LINE_LED_GREEN PAL_LINE(GPIOC_BASE, 11U)
#define LINE_LED_RED PAL_LINE(GPIOC_BASE, 12U) #define LINE_LED_BLUE PAL_LINE(GPIOC_BASE, 12U)
#endif /* BOARD_H */ #endif /* BOARD_H */

@ -83,11 +83,11 @@ thread_t *ConversionManager::getMonitorHandle()
return m_thread_monitor; return m_thread_monitor;
} }
void ConversionManager::abort() void ConversionManager::abort(bool fpu_stacked)
{ {
ELFManager::unload(); ELFManager::unload();
EM.add(Error::ConversionAborted); EM.add(Error::ConversionAborted);
run_status = RunStatus::Recovering; //run_status = RunStatus::Recovering;
// Confirm that the exception return thread is the algorithm... // Confirm that the exception return thread is the algorithm...
uint32_t *psp; uint32_t *psp;
@ -104,7 +104,7 @@ void ConversionManager::abort()
// We do this by rebuilding the thread's stacked exception return. // We do this by rebuilding the thread's stacked exception return.
auto newpsp = reinterpret_cast<uint32_t *>(m_thread_runner_stack.data() + auto newpsp = reinterpret_cast<uint32_t *>(m_thread_runner_stack.data() +
m_thread_runner_stack.size() - 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. // Set the LR register to the thread's entry point.
newpsp[5] = reinterpret_cast<uint32_t>(threadRunner); newpsp[5] = reinterpret_cast<uint32_t>(threadRunner);
// Overwrite the instruction we'll return to with "bx lr" (jump to address in LR). // Overwrite the instruction we'll return to with "bx lr" (jump to address in LR).

@ -39,7 +39,7 @@ public:
static thread_t *getMonitorHandle(); static thread_t *getMonitorHandle();
// Internal only: Aborts a running conversion. // Internal only: Aborts a running conversion.
static void abort(); static void abort(bool fpu_stacked = true);
private: private:
static void threadMonitor(void *); static void threadMonitor(void *);

@ -108,7 +108,7 @@ void MemManage_Handler()
asm("mov %0, lr" : "=r" (lr)); asm("mov %0, lr" : "=r" (lr));
// 2. Recover from the fault. // 2. Recover from the fault.
ConversionManager::abort(); ConversionManager::abort((lr & (1 << 4)) ? false : true);
// 3. Return. // 3. Return.
asm("mov lr, %0; bx lr" :: "r" (lr)); asm("mov lr, %0; bx lr" :: "r" (lr));

@ -39,30 +39,31 @@ void Monitor::threadMonitor(void *)
#endif #endif
}; };
palClearLine(LINE_LED_RED); palSetLine(LINE_LED_RED);
palClearLine(LINE_LED_YELLOW); palSetLine(LINE_LED_GREEN);
palSetLine(LINE_LED_BLUE);
while (1) { while (1) {
bool isidle = run_status == RunStatus::Idle; 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; auto delay = isidle ? 500 : 250;
palSetLine(led); palToggleLine(led);
chThdSleepMilliseconds(delay); chThdSleepMilliseconds(delay);
palClearLine(led); palToggleLine(led);
chThdSleepMilliseconds(delay); chThdSleepMilliseconds(delay);
if (run_status == RunStatus::Idle && readButton()) { if (isidle && readButton()) {
palSetLine(LINE_LED_RED); palClearLine(LINE_LED_GREEN);
palSetLine(LINE_LED_YELLOW); palClearLine(LINE_LED_BLUE);
chSysLock(); chSysLock();
while (readButton()) while (readButton())
asm("nop"); asm("nop");
while (!readButton()) while (!readButton())
asm("nop"); asm("nop");
chSysUnlock(); chSysUnlock();
palClearLine(LINE_LED_RED); palSetLine(LINE_LED_GREEN);
palClearLine(LINE_LED_YELLOW); palSetLine(LINE_LED_BLUE);
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
} }
@ -70,9 +71,9 @@ void Monitor::threadMonitor(void *)
if (auto err = EM.hasError(); err ^ erroron) { if (auto err = EM.hasError(); err ^ erroron) {
erroron = err; erroron = err;
if (err) if (err)
palSetLine(LINE_LED_RED);
else
palClearLine(LINE_LED_RED); palClearLine(LINE_LED_RED);
else
palSetLine(LINE_LED_RED);
} }
} }
} }

Loading…
Cancel
Save