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-standby.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index 44b047a..4124d92 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -42,13 +42,15 @@ void sleep_until_eswitch_pressed() // make sure switch isn't currently pressed while (button_is_pressed()) {} empty_event_sequence(); // cancel pending input on suspend - //PCINT_since_WDT = 0; // ensure PCINT won't ignore itself PCINT_on(); // wake on e-switch event #ifdef TICK_DURING_STANDBY + // detect which type of event caused a wake-up + irq_adc = 0; + irq_wdt = 0; + irq_pcint = 0; while (go_to_standby) { - f_wdt = 0; // detect if WDT was what caused a wake-up #else go_to_standby = 0; #endif @@ -65,10 +67,19 @@ void sleep_until_eswitch_pressed() sleep_disable(); #ifdef TICK_DURING_STANDBY - // determine what woke us up... WDT or PCINT - if (! f_wdt) { // PCINT went off; wake up + // determine what woke us up... + if (irq_pcint) { // button pressed; wake up go_to_standby = 0; } + if (irq_adc) { // ADC done measuring + adcint_enable = 1; + ADC_inner(); + //ADC_off(); // takes care of itself + //irq_adc = 0; // takes care of itself + } + if (irq_wdt) { // generate a sleep tick + WDT_inner(); + } } #endif -- cgit v1.2.3 From 36b0f74974140093e1b4b9cd6c358ba89f286f48 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 18 Nov 2019 23:59:49 -0700 Subject: fixed issue where button-press-during-sleep could occasionally cause a reboot (by turning off PCINT when the light is awake) --- spaghetti-monster/fsm-standby.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'spaghetti-monster/fsm-standby.c') diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index 4124d92..e4ef92c 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -43,8 +43,6 @@ void sleep_until_eswitch_pressed() while (button_is_pressed()) {} empty_event_sequence(); // cancel pending input on suspend - PCINT_on(); // wake on e-switch event - #ifdef TICK_DURING_STANDBY // detect which type of event caused a wake-up irq_adc = 0; @@ -54,6 +52,9 @@ void sleep_until_eswitch_pressed() #else go_to_standby = 0; #endif + + PCINT_on(); // wake on e-switch event + // configure sleep mode set_sleep_mode(SLEEP_MODE_PWR_DOWN); @@ -89,7 +90,10 @@ void sleep_until_eswitch_pressed() #endif // go back to normal running mode - //PCINT_on(); // should be on already + // PCINT not needed any more, and can cause problems if on + // (occasional reboots on wakeup-by-button-press) + PCINT_off(); + // restore normal awake-mode interrupts ADC_on(); WDT_on(); } -- cgit v1.2.3