Просмотр исходного кода

workarounds for debugging the issue of the Battery Measurement

namrota ghosh 7 месяцев назад
Родитель
Сommit
17965ed9d9
4 измененных файлов с 14 добавлено и 15 удалено
  1. 7 9
      main.c
  2. 2 2
      src/cc_cv_charging.c
  3. 1 1
      src/config.h
  4. 4 3
      src/pi/i2c_pi_target.c

+ 7 - 9
main.c

@@ -25,7 +25,6 @@ void I2C_1_INST_IRQHandler(void)
     switch (DL_I2C_getPendingInterrupt(I2C_1_INST)) 
     {   
         case DL_I2C_IIDX_CONTROLLER_START:
-        
             break;
 
         case DL_I2C_IIDX_CONTROLLER_RXFIFO_TRIGGER:
@@ -94,8 +93,8 @@ void I2C_0_INST_IRQHandler(void)
             break;
         case DL_I2C_IIDX_TARGET_STOP:
             picommandPending = true;
-            //DL_I2C_flushTargetTXFIFO(I2C_0_INST);
-            //DL_I2C_flushTargetRXFIFO(I2C_0_INST);
+            DL_I2C_flushTargetTXFIFO(I2C_0_INST);
+            DL_I2C_flushTargetRXFIFO(I2C_0_INST);
             break;
         case DL_I2C_IIDX_TARGET_ARBITRATION_LOST:
             break; 
@@ -132,22 +131,21 @@ int main(void)
         
         for(uint8_t slot_id= 0; slot_id< NUM_SLOTS; slot_id++){
             //GET battery measurement from the Target
-            getBatteryMeasurement_test(slot_id);
+            getBatteryMeasurement(slot_id);
             //Reading battery state:
             Battery_StateCondition(slot_id);
             printf("Battery State: %d\n", battery_data[slot_id].battery_state);
-            
-            //If target received battery limits from Pi then start charging:       
+            //If target received battery limits from Pi then start charging, else wait with state: 3::       
+            //CC_CV_ControlCharging(slot_id, 50);     
             if(battery_data[slot_id].batteryLimitReceived){
                 printf("Battery Limits: Slot: %d, Max Voltage:%u, Min Voltage:%u, "
                 "Cutoff Current: %u, Capacitance:%u, Charge Fraction:%u, Cycle Number: %u\n", slot_id, battery_data[slot_id].max_voltage,
                 battery_data[slot_id].min_voltage, battery_data[slot_id].cut_off_current,
                 battery_data[slot_id].capacitance, battery_data[slot_id].charge_fraction, battery_data[slot_id].cycle_number);
-                //CC_CV_ControlCharging(slot_id, 100);
-                controller_SetCurrent(0x48, slot_id, 50);
+                CC_CV_ControlCharging(slot_id, 50);
                 
             }
-     
+            
             delay_cycles(MEASUREMENT_CHECK_INTERVAL);
         
         }

+ 2 - 2
src/cc_cv_charging.c

@@ -136,8 +136,8 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     // Calling function to get all the conditional states
     CC_CV_UpdateChargingState(slot_id);
     
-    //batt_voltage = battery_data[slot_id].battery_measurement.voltage;
-    //batt_current= battery_data[slot_id].battery_measurement.current;
+    batt_voltage = battery_data[slot_id].battery_measurement.voltage;
+    batt_current= battery_data[slot_id].battery_measurement.current;
     batt_min_voltage= battery_data[slot_id].min_voltage;
     batt_max_voltage= battery_data[slot_id].max_voltage;
     batt_cutoff_current = battery_data[slot_id].cut_off_current;

+ 1 - 1
src/config.h

@@ -3,7 +3,7 @@
 #ifndef CONFIG_H_
 #define CONFIG_H_
 #define I2C_TX_MAX_PACKET_SIZE  (8)
-#define I2C_RX_MAX_PACKET_SIZE  (8)
+#define I2C_RX_MAX_PACKET_SIZE  (12)
 #define BATTERY_THRESHOLD (50)
 #define TEMPERATURE_MAX_C (60)
 #define MAX_CYCLES (2)

+ 4 - 3
src/pi/i2c_pi_target.c

@@ -49,7 +49,7 @@ void dynamic_gpio_addressing(){
 }
 
 void pi_i2c_mcu(){
-
+    //uint8_t rxBuffer_getLimits[12];
     uint8_t receivedCommand= DL_I2C_receiveTargetData(I2C_0_INST);
     printf("Received Command: 0x%02X\n", receivedCommand);
     if(receivedCommand == CMD_GET_BATTERY_STATUS){
@@ -106,12 +106,13 @@ void pi_i2c_mcu(){
         uint8_t requestedSlot= (receivedCommand & 0xF0)>>4;
         while(rx_index < (sizeof(BatteryLimitMsg))){
             if(!DL_I2C_isTargetRXFIFOEmpty(I2C_0_INST)){
-                rxPacket.rxBuffer[rx_index] = DL_I2C_receiveTargetData(I2C_0_INST);
+                rxPacket.rxBuffer[rx_index]= DL_I2C_receiveTargetData(I2C_0_INST);
+                //rxPacket.rxBuffer[rx_index] = DL_I2C_receiveTargetData(I2C_0_INST);
                 //printf("Received Bytes[%d]: 0x%02X\n", rx_index, rx_packet.rxBuffer[rx_index]);
                 rx_index++;
             }
         }
-        printf("index:%d\n", rx_index);
+        //printf("index:%d\n", rx_index);
         //Check if all the data is received then store the battery limits in BatteryInfo struct:
         if(rx_index== (sizeof(BatteryLimitMsg))){
             BatteryLimitMsg battery_limit_received;