summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-03-11 20:17:21 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-03-11 20:17:21 +0100
commit8625fa013eb7b835215d7089ae8f182e47b04136 (patch)
tree26b566c06a8943848177abd29614c39e52c7e23a
parent5e9d724804b45bbb7f5acc58f8cf7befa33bf141 (diff)
Show timeout message when contact is lost during flashing
-rw-r--r--src/static_patterns.h6
-rw-r--r--src/system.cc25
-rw-r--r--src/system.h2
3 files changed, 33 insertions, 0 deletions
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;