From 8b59e880614455bd7bc7d8595de847dd6fe9b5b2 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 14 Nov 2019 01:52:50 -0700 Subject: 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. --- spaghetti-monster/fsm-main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spaghetti-monster/fsm-main.c') diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c index e537a9e..a898f41 100644 --- a/spaghetti-monster/fsm-main.c +++ b/spaghetti-monster/fsm-main.c @@ -160,6 +160,9 @@ int main() { standby_mode(); } + // catch up on interrupts + handle_deferred_interrupts(); + // give the recipe some time slices loop(); @@ -168,4 +171,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 -- cgit v1.2.3 From 81ed77d88c999f9c2368718047d0969fef44e534 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 14 Nov 2019 18:28:52 -0700 Subject: fixed factory reset (wasn't running interrupt logic since it's deferred now) (also fixed issue where nice_delay_ms() was aborted during setup()) (and adjusted the timing to make factory reset similar to the speed it was before this change) --- spaghetti-monster/fsm-main.c | 1 - 1 file changed, 1 deletion(-) (limited to 'spaghetti-monster/fsm-main.c') diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c index a898f41..c9ab69b 100644 --- a/spaghetti-monster/fsm-main.c +++ b/spaghetti-monster/fsm-main.c @@ -123,7 +123,6 @@ int main() { #else delay_4ms(1); #endif - empty_event_sequence(); // fallback for handling a few things #ifndef DONT_USE_DEFAULT_STATE -- cgit v1.2.3