aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-main.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-11-19 00:44:14 -0700
committerSelene ToyKeeper2019-11-19 00:44:14 -0700
commitd6d40c54707bd840bff3e919e99f7a8bf03ee526 (patch)
tree90086acbcabd0ce5a34fef5298f780cf8e8b13b4 /spaghetti-monster/fsm-main.c
parentadded SOS mode to the BLF LT1 Lantern build, because people wanted it (diff)
parentMateminco MF01S can fit muggle mode again, barely (diff)
downloadanduril-d6d40c54707bd840bff3e919e99f7a8bf03ee526.tar.gz
anduril-d6d40c54707bd840bff3e919e99f7a8bf03ee526.tar.bz2
anduril-d6d40c54707bd840bff3e919e99f7a8bf03ee526.zip
merged irq-refactor branch, which fixes some small but long-standing issues:
- fixed occasional short/aborted frames in aux LED sleep animation - fixed rare case of bogus voltage and/or temperature values - fixed issue where nice_delay_ms() didn't work in setup() - fixed theoretical possibility of extra-noisy buttons causing a hang - fixed reboot loop which happened after any crashes - fixed issue where button press in sleep mode could occasionally crash (but the issue may have been created by this branch before being fixed by it) - reduced occasional missed button events while asleep (still seems to happen but not nearly as much) Also does some other things: - cleans up the ADC code significantly - cleans up the WDT code - adds a voltage stabilizer/lowpass option (enabled on t1634 builds) - greatly reduces time spent per interrupt, which might make a future PWM-DSM technique possible - moves most interrupt-handling logic to a non-critical code path, deferring that code until timing doesn't matter as much - sped up button state measurements - very slightly reduces power used in sleep mode
Diffstat (limited to 'spaghetti-monster/fsm-main.c')
-rw-r--r--spaghetti-monster/fsm-main.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c
index e537a9e..4ad1e16 100644
--- a/spaghetti-monster/fsm-main.c
+++ b/spaghetti-monster/fsm-main.c
@@ -37,7 +37,7 @@ ISR(TIMER1_COMPA_vect) {
#endif
#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
-inline void hw_setup() {
+static inline void hw_setup() {
// configure PWM channels
#if PWM_CHANNELS >= 1
DDRB |= (1 << PWM1_PIN);
@@ -69,7 +69,7 @@ inline void hw_setup() {
PCMSK = (1 << SWITCH_PIN); // pin change interrupt uses this pin
}
#elif (ATTINY == 1634)
-inline void hw_setup() {
+static inline void hw_setup() {
// this gets tricky with so many pins...
// ... so punt it to the hwdef file
hwdef_setup();
@@ -79,22 +79,24 @@ inline void hw_setup() {
#endif
-#ifdef USE_REBOOT
-void prevent_reboot_loop() {
+//#ifdef USE_REBOOT
+static inline void prevent_reboot_loop() {
// prevent WDT from rebooting MCU again
MCUSR &= ~(1<<WDRF); // reset status flag
wdt_disable();
}
-#endif
+//#endif
int main() {
// Don't allow interrupts while booting
cli();
- #ifdef USE_REBOOT
+ //#ifdef USE_REBOOT
+ // prevents cycling after a crash,
+ // whether intentional (like factory reset) or not (bugs)
prevent_reboot_loop();
- #endif
+ //#endif
hw_setup();
@@ -123,7 +125,6 @@ int main() {
#else
delay_4ms(1);
#endif
- empty_event_sequence();
// fallback for handling a few things
#ifndef DONT_USE_DEFAULT_STATE
@@ -160,6 +161,9 @@ int main() {
standby_mode();
}
+ // catch up on interrupts
+ handle_deferred_interrupts();
+
// give the recipe some time slices
loop();
@@ -168,4 +172,22 @@ int main() {
}
}
+
+void handle_deferred_interrupts() {
+ /*
+ if (irq_pcint) { // button pressed or released
+ // nothing to do here
+ // (PCINT only matters during standby)
+ }
+ */
+ if (irq_adc) { // ADC done measuring
+ ADC_inner();
+ // irq_adc = 0; // takes care of itself
+ }
+ if (irq_wdt) { // the clock ticked
+ WDT_inner();
+ // irq_wdt = 0; // takes care of itself
+ }
+}
+
#endif