commit 77defa182fb07e5e5decf6da9965760cc05a79aa
parent d98a7cc40bbdc37d61d883b29c5af44e3e0c9ee5
Author: Kevin Pulo <kev@pulo.com.au>
Date: Wed, 18 May 2022 08:37:05 +1000
keyboard-fw: interrupts must be disabled while WDT parameters are set
Diffstat:
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/reform2-keyboard-fw/powersave.c b/reform2-keyboard-fw/powersave.c
@@ -49,6 +49,10 @@ void keyboard_power_off(void)
// We can use the Watchdog timer to do this.
do {
+ // Setting WDT parameters must be done within 4 cycles of setting WDCE, so interrupts
+ // must be disabled.
+ cli();
+
wdt_reset();
WDTCSR = (1<<WDCE) | (1<<WDE); // Enable writes to watchdog
WDTCSR = (1<<WDIE) | (1<<WDE) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (0<<WDP0); // Interrupt mode, 1s timeout