Explorar el Código

adding previous_count varibale to keep track of the controller reset

namrota ghosh hace 6 meses
padre
commit
7c812acdfc
Se han modificado 1 ficheros con 9 adiciones y 6 borrados
  1. 9 6
      src/cc_cv_charging.c

+ 9 - 6
src/cc_cv_charging.c

@@ -1,7 +1,6 @@
 #include "cc_cv_charging.h"
 #include "src/config.h"
 #include "src/battery_data/battery.h"
-#include <cstdint>
 #include <stdio.h>
 #include "ti/driverlib/dl_gpio.h"
 #include "ti_msp_dl_config.h"
@@ -27,9 +26,9 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
     uint8_t batt_cutoff_current = battery->cut_off_current;
     uint16_t batt_capacitance = battery->capacitance;
     int16_t batt_charge_discharge= battery->charge_discharge;
-    uint8_t previous_cycle= battery->previous_cycle_number;
     uint8_t *cycle_count = &battery->cycle_number;
-    uint8_t *previous_cycle= &battery->previous_cycle_number;
+    //this is received from Pi
+    uint8_t *previous_count= &battery->previous_cycle_number;
     battery->battery_charging_state= charging_state;
 
 
@@ -40,9 +39,6 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
             printf("Persistent zero voltage. Setting to IDLE.\n");
             battery->battery_charging_state = STATE_IDLE;
             cv_charging_started = false;
-        }else{
-            //reset:
-            battery_data[slot_id].counter= 0;
         }
         return;
     }
@@ -57,6 +53,13 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
     // Once the battery limits are received then start with the charging
     if(battery_data[slot_id].batteryLimitReceived == 1){
         printf("Battery Limit %d received for Slot ID %d\n", battery_data[slot_id].batteryLimitReceived, slot_id);
+
+        //Handling WWDT Reset, if the Cycle count received from Pi is greater than the current cycle:count then set the cycle_count to the previous count as received from Pi
+        if (*previous_count > *cycle_count && *previous_count < MAX_CYCLES){
+            printf("WWDT Reset detected. Setting cycle count to previous count: %d\n", *previous_count);
+            *cycle_count= *previous_count;
+        }
+
         //1. Pre Charge: if the battery is deeply discharged
         if ((batt_voltage < batt_min_voltage)) {
             battery->battery_charging_state = STATE_PRE_CHARGE;