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.
*/
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

@ -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 */

@ -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<uint32_t *>(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<uint32_t>(threadRunner);
// Overwrite the instruction we'll return to with "bx lr" (jump to address in LR).

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

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

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

Loading…
Cancel
Save