Update watchdog feeding to prevent some deadlocks
authorNathael Pajani <nathael.pajani@ed3l.fr>
Mon, 16 Sep 2024 18:00:10 +0000 (20:00 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Mon, 16 Sep 2024 18:00:10 +0000 (20:00 +0200)
v10/main.c

index 8d5e66f..421d2fe 100644 (file)
@@ -636,8 +636,32 @@ int main(void)
        status_led(green_only);
 
        while (1) {
-               /* Feed the dog */
-               if ((solar_prod_value != 0) && (home_conso_value != 0) && (water_centi_degrees < ABSOLUTE_MAX_WATER_TEMP)) {
+               /* Feed the dog if sensor values are relevant */
+               int allow_wd_feed = 1;
+               if ((solar_prod_value == 0) || (home_conso_value == 0)) {
+                       allow_wd_feed = 0;
+               }
+               if ((water_centi_degrees < 0) || (water_centi_degrees > (ABSOLUTE_MAX_WATER_TEMP + 200))) {
+                       allow_wd_feed = 0;
+               }
+               /* Blocked in overvoltage mode */
+               if ((mode == mode_overvoltage) && (overvoltage == 0)) {
+                       allow_wd_feed = 0;
+               }
+               /* Blocked in overtemperature mode */
+               if (mode == mode_overtemp) {
+                       if ((mosfet_temp_shutdown == 0) && (internal_temp_error_shutdown >= 0)) {
+                               allow_wd_feed = 0;
+                       }
+               }
+               /* Blocked in water critical temperature mode */
+               if (mode == mode_water_critical) {
+                       if (water_centi_degrees < ABSOLUTE_MAX_WATER_TEMP) {
+                               allow_wd_feed = 0;
+                       }
+               }
+               /* Otherwise, feed the dog */
+               if (allow_wd_feed == 1) {
                        watchdog_feed();
                }