diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-03-11 20:17:21 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-03-11 20:17:21 +0100 |
commit | 8625fa013eb7b835215d7089ae8f182e47b04136 (patch) | |
tree | 26b566c06a8943848177abd29614c39e52c7e23a /src/system.cc | |
parent | 5e9d724804b45bbb7f5acc58f8cf7befa33bf141 (diff) |
Show timeout message when contact is lost during flashing
Diffstat (limited to 'src/system.cc')
-rw-r--r-- | src/system.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/system.cc b/src/system.cc index d7d0f71..759c58e 100644 --- a/src/system.cc +++ b/src/system.cc @@ -140,6 +140,12 @@ void System::receive(void) rxExpect = PATTERN1; storage.reset(); loadPattern_P(flashingPattern); + MCUSR &= ~_BV(WDRF); + cli(); + // watchdog interrupt after 4 seconds + WDTCSR = _BV(WDCE) | _BV(WDE); + WDTCSR = _BV(WDIE) | _BV(WDP3); + sei(); } else { rxExpect = NEXT_BLOCK; } @@ -154,6 +160,7 @@ void System::receive(void) current_anim_no = 0; loadPattern(0); rxExpect = START1; + wdt_disable(); } break; case PATTERN1: @@ -176,6 +183,7 @@ void System::receive(void) case HEADER2: rxExpect = META1; remaining_bytes += rx_byte; + wdt_reset(); break; case META1: rxExpect = META2; @@ -314,7 +322,24 @@ void System::shutdown() rxExpect = START1; } +void System::handleTimeout() +{ + rxExpect = START1; + current_anim_no = 0; + loadPattern_P(timeoutPattern); +} + ISR(PCINT1_vect) { // we use PCINT1 for wakeup, so we need an (in this case empty) ISR for it } + +ISR(WDT_vect) +{ + /* + * Modem transmission was interrupted without END byte. Reset state + * machine and show timeout message. + */ + wdt_disable(); + rocket.handleTimeout(); +} |