aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-events.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-events.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-events.c')
-rw-r--r--spaghetti-monster/fsm-events.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/spaghetti-monster/fsm-events.c b/spaghetti-monster/fsm-events.c
index 3e9a12d..a1b013a 100644
--- a/spaghetti-monster/fsm-events.c
+++ b/spaghetti-monster/fsm-events.c
@@ -110,7 +110,7 @@ uint8_t nice_delay_ms(uint16_t ms) {
/* // delay_zero() implementation
if (ms == 0) {
CLKPR = 1<<CLKPCE; CLKPR = 0; // full speed
- _delay_loop_2(BOGOMIPS*98/100/3);
+ _delay_loop_2(BOGOMIPS*95/100/3);
return 1;
}
*/
@@ -120,15 +120,15 @@ uint8_t nice_delay_ms(uint16_t ms) {
uint8_t level = actual_level; // volatile, avoid repeat access
if (level < QUARTERSPEED_LEVEL) {
clock_prescale_set(clock_div_4);
- _delay_loop_2(BOGOMIPS*98/100/4);
+ _delay_loop_2(BOGOMIPS*95/100/4);
}
//else if (level < HALFSPEED_LEVEL) {
// clock_prescale_set(clock_div_2);
- // _delay_loop_2(BOGOMIPS*98/100/2);
+ // _delay_loop_2(BOGOMIPS*95/100/2);
//}
else {
clock_prescale_set(clock_div_1);
- _delay_loop_2(BOGOMIPS*98/100);
+ _delay_loop_2(BOGOMIPS*95/100);
}
// restore regular clock speed
clock_prescale_set(clock_div_1);
@@ -136,15 +136,18 @@ uint8_t nice_delay_ms(uint16_t ms) {
// underclock MCU to save power
clock_prescale_set(clock_div_4);
// wait
- _delay_loop_2(BOGOMIPS*98/100/4);
+ _delay_loop_2(BOGOMIPS*95/100/4);
// restore regular clock speed
clock_prescale_set(clock_div_1);
#endif // ifdef USE_RAMPING
#else
// wait
- _delay_loop_2(BOGOMIPS*98/100);
+ _delay_loop_2(BOGOMIPS*95/100);
#endif // ifdef USE_DYNAMIC_UNDERCLOCKING
+ // run pending system processes while we wait
+ handle_deferred_interrupts();
+
if ((nice_delay_interrupt) || (old_state != current_state)) {
return 0; // state changed; abort
}