diff options
| author | Selene ToyKeeper | 2019-11-14 01:52:50 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-11-14 01:52:50 -0700 |
| commit | 8b59e880614455bd7bc7d8595de847dd6fe9b5b2 (patch) | |
| tree | a7426296b9fa1471ba2841eba0415bbfaed3e5c7 /spaghetti-monster/fsm-wdt.c | |
| parent | fixed some compile issues related to delay_4ms() (diff) | |
| download | anduril-8b59e880614455bd7bc7d8595de847dd6fe9b5b2.tar.gz anduril-8b59e880614455bd7bc7d8595de847dd6fe9b5b2.tar.bz2 anduril-8b59e880614455bd7bc7d8595de847dd6fe9b5b2.zip | |
refactored how interrupts work...
set a flag and return immediately,
then handle the actual logic later during a less-critical code path
Enables smarter responses to standby wakeups.
Seems to fix missed button presses during standby,
and most of the too-fast sleep ticks.
Also eliminated waits from button state measurement, so it can happen easier during standby.
(also eliminates the chance of an infinite loop on extra-noisy hardware)
Also might improve timing-sensitive interrupts like attiny85 PWM channel 4,
or a PWM-DSM hybrid technique I'd like to try.
BUT this change also appears to break the thermal sensor, so that needs to be fixed.
Diffstat (limited to '')
| -rw-r--r-- | spaghetti-monster/fsm-wdt.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 6e61e87..3cb7d86 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -82,11 +82,23 @@ inline void WDT_off() // clock tick -- this runs every 16ms (62.5 fps) ISR(WDT_vect) { + irq_wdt = 1; // WDT event happened +} + +void WDT_inner() { + irq_wdt = 0; // WDT event handled; reset flag + static uint8_t adc_trigger = 0; - #ifdef TICK_DURING_STANDBY - f_wdt = 1; // WDT event happened + // detect and emit button change events (even during standby) + uint8_t was_pressed = button_last_state; + uint8_t pressed = button_is_pressed(); + if (was_pressed != pressed) { + go_to_standby = 0; + PCINT_inner(pressed); + } + #ifdef TICK_DURING_STANDBY static uint16_t sleep_counter = 0; // handle standby mode specially if (go_to_standby) { @@ -107,11 +119,6 @@ ISR(WDT_vect) { else { sleep_counter = 0; } #endif - // detect and emit button change events - uint8_t was_pressed = button_last_state; - uint8_t pressed = button_is_pressed(); - if (was_pressed != pressed) PCINT_inner(pressed); - // cache this here to reduce ROM size, because it's volatile uint16_t ticks_since_last = ticks_since_last_event; @@ -178,6 +185,7 @@ ISR(WDT_vect) { if (go_to_standby) ADC_on(); #endif ADC_start_measurement(); + irq_adc = 0; adcint_enable = 1; } #endif |
