From 8625fa013eb7b835215d7089ae8f182e47b04136 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 11 Mar 2016 20:17:21 +0100 Subject: Show timeout message when contact is lost during flashing --- src/static_patterns.h | 6 ++++++ src/system.cc | 25 +++++++++++++++++++++++++ src/system.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/src/static_patterns.h b/src/static_patterns.h index b1147a9..155c68e 100644 --- a/src/static_patterns.h +++ b/src/static_patterns.h @@ -41,4 +41,10 @@ const uint8_t PROGMEM emptyPattern[] = { 'e', ' ', 'i', 's', ' ', 'e', 'm', 'p', 't', 'y' }; +const uint8_t PROGMEM timeoutPattern[] = { + 0x10, 0x0a, + 0x20, 0x00, + ' ', 2, ' ', 'T', 'i', 'm', 'e', 'o', 'u', 't' +}; + #endif /* STATIC_PATTERNS_H_ */ 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(); +} diff --git a/src/system.h b/src/system.h index 3cb74b0..870ec35 100644 --- a/src/system.h +++ b/src/system.h @@ -75,6 +75,8 @@ class System { * whenever the system is woken up by an interrupt. */ void loop(void); + + void handleTimeout(void); }; extern System rocket; -- cgit v1.2.3