void buttonsHandleColdBootButtonPresses(void) { uint8_t secondsRemaining = 10; bool bothButtonsHeld; do { bothButtonsHeld = !digitalIn(BUTTON_A_PORT, BUTTON_A_PIN) && !digitalIn(BUTTON_B_PORT, BUTTON_B_PIN); if (bothButtonsHeld) { if (--secondsRemaining == 0) { resetEEPROM(); systemReset(); } if (secondsRemaining > 5) { delay(1000); } else { // flash quicker after a few seconds delay(500); LED0_TOGGLE; delay(500); } LED0_TOGGLE; } } while (bothButtonsHeld); // buttons released between 5 and 10 seconds if (secondsRemaining < 5) { usbGenerateDisconnectPulse(); flashLedsAndBeep(); systemResetToBootloader(); } }
void evaluateOtherData(serialPort_t *serialPort, uint8_t receivedChar) { if (receivedChar == '#') { cliEnter(serialPort); } else if (receivedChar == serialConfig->reboot_character) { systemResetToBootloader(); } }
void evaluateOtherData(serialPort_t *serialPort, uint8_t receivedChar) { #ifndef USE_CLI UNUSED(serialPort); #else if (receivedChar == '#') { cliEnter(serialPort); } #endif if (receivedChar == serialConfig->reboot_character) { systemResetToBootloader(); } }
// FIXME replace mode with an enum so usage can be tracked, currently mode is a magic number void failureMode(uint8_t mode) { uint8_t flashesRemaining = 10; LED1_ON; LED0_OFF; while (flashesRemaining--) { LED1_TOGGLE; LED0_TOGGLE; delay(475 * mode - 2); BEEP_ON; delay(25); BEEP_OFF; } systemResetToBootloader(); }
void failureMode(failureMode_e mode) { int codeRepeatsRemaining = 10; int codeFlashesRemaining; int shortFlashesRemaining; while (codeRepeatsRemaining--) { LED1_ON; LED0_OFF; shortFlashesRemaining = 5; codeFlashesRemaining = mode + 1; uint8_t flashDuration = SHORT_FLASH_DURATION; while (shortFlashesRemaining || codeFlashesRemaining) { LED1_TOGGLE; LED0_TOGGLE; BEEP_ON; delay(flashDuration); LED1_TOGGLE; LED0_TOGGLE; BEEP_OFF; delay(flashDuration); if (shortFlashesRemaining) { shortFlashesRemaining--; if (shortFlashesRemaining == 0) { delay(500); flashDuration = CODE_FLASH_DURATION; } } else { codeFlashesRemaining--; } } delay(1000); } #ifdef DEBUG systemReset(); #else systemResetToBootloader(); #endif }
static void mspProcessPendingRequest(mspPort_t * mspPort) { // If no request is pending or 100ms guard time has not elapsed - do nothing if ((mspPort->pendingRequest == MSP_PENDING_NONE) || (millis() - mspPort->lastActivityMs < 100)) { return; } switch(mspPort->pendingRequest) { case MSP_PENDING_BOOTLOADER: systemResetToBootloader(); break; #ifdef USE_CLI case MSP_PENDING_CLI: cliEnter(mspPort->port); break; #endif default: break; } }
void serialEvaluateNonMspData(serialPort_t *serialPort, uint8_t receivedChar) { #ifndef USE_CLI UNUSED(serialPort); #else if (receivedChar == '#') { cliEnter(serialPort); } #endif if (receivedChar == serialConfig()->reboot_character) { // A 100ms guard delay to make sure reboot_character is followed by silence // If anything is received during the guard period - reboot_character is ignored for (int i = 0; i < 10; i++) { delay(10); if (serialRxBytesWaiting(serialPort)) { return; } } systemResetToBootloader(); } }
int main(void) { //spiInit(SPIDEV_1); // start fpu SCB->CPACR = (0x3 << (10*2)) | (0x3 << (11*2)); SetSysClock(); systemInit(); timerInit(); // timer must be initialized before any channel is allocated serial0 = serial0_open(); dmaInit(); setup(); while (true) { #ifndef EXTERNAL_DEBUG static uint32_t dbg_start_msec; // support reboot from host computer if (millis()-dbg_start_msec > 100) { dbg_start_msec = millis(); while (serialRxBytesWaiting(serial0)) { uint8_t c = serialRead(serial0); if (c == 'R') systemResetToBootloader(); } } #endif loop(); } } // main
void resetToBootloader(void) { systemResetToBootloader(); }