From a42314459905b9532f584aa086b19687b1195a08 Mon Sep 17 00:00:00 2001 From: Leon Krieg Date: Fri, 20 Sep 2024 23:51:44 +0200 Subject: [PATCH] Fix possible race condition and ensure proper reset flag detection --- src/common/memory.c | 5 ++++- src/common/watchdog.c | 2 +- src/main.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/memory.c b/src/common/memory.c index 1519d37..d8f76f9 100644 --- a/src/common/memory.c +++ b/src/common/memory.c @@ -192,6 +192,8 @@ static void WriteRaw(int addr, byte data) static byte ReadRaw(int addr) { + byte data; + // The EEPROM Read Enable Signal EERE is the read // strobe to the EEPROM. When the correct address // is set up in the EEAR Register, the EERE bit @@ -214,7 +216,8 @@ static byte ReadRaw(int addr) // Read from address EECR |= BIT(EERE); + data = EEDR; } - return EEDR; + return data; } diff --git a/src/common/watchdog.c b/src/common/watchdog.c index f15b5cc..45fcbe8 100644 --- a/src/common/watchdog.c +++ b/src/common/watchdog.c @@ -75,7 +75,7 @@ bool WDT_HasTriggered(void) // JTD ISC2 – JTRF WDRF BORF EXTRF PORF // Is watchdog reset flag set? - isreset = ((MCUCSR & BIT(3)) == 1); + isreset = ((MCUCSR & BIT(WDRF)) != 0); // XXX: Reset flag detection should be a separate // module to handle the different types. diff --git a/src/main.c b/src/main.c index 2df9a28..e6c01df 100644 --- a/src/main.c +++ b/src/main.c @@ -89,7 +89,7 @@ static int Init(void) PWM_Init(); MOS_Enable(MOS03); // Lights - //MOS_Enable(MOS01); // Peltier + // MOS_Enable(MOS01); // Peltier // MOS_Disable(MOS02); // Heating // Only FAN01 and FAN02 are receiving the correct