Переглянути джерело

The lag which was observed with the slot extension where slot 0 was initually all 0s and the later slots had lag of -1, this has been resolved

namrota ghosh 6 місяців тому
батько
коміт
3afcd9ba5c
1 змінених файлів з 15 додано та 15 видалено
  1. 15 15
      src/controller/controller.c

+ 15 - 15
src/controller/controller.c

@@ -95,7 +95,7 @@ bool getBatteryMeasurement(uint8_t slot_id){
     //Dynamic addressing:
 
     uint8_t target_address= TARGET_BASE_ADDRESS + ((slot_id & 0b00000100) >> 2);
-    printf("Target Address 0x%02X \n", target_address);
+    //printf("Target Address 0x%02X \n", target_address);
     
     //Enable the Interrupt:
     DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_TRIGGER);
@@ -146,17 +146,15 @@ bool getBatteryMeasurement(uint8_t slot_id){
     rxPacket.rxCount= 0;
     rxPacket.rxLen= 8;
     rxPacket.rxComplete= false;
-    timeout= 32000;
+    timeout= 3200000;
 
     //Make RX Buffer ready to receive the data
-    DL_I2C_flushControllerRXFIFO(I2C_1_INST);
+    //DL_I2C_flushControllerRXFIFO(I2C_1_INST);
+    
+    
+    while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY)
+    ;
     
-    DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
-
-    while(!(rxPacket.rxComplete) && timeout--);
-    if(timeout==0){
-        printf("Rx transmit not completed");
-    }
 
     //while (DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS);
 
@@ -165,24 +163,26 @@ bool getBatteryMeasurement(uint8_t slot_id){
                                            DL_I2C_CONTROLLER_STOP_ENABLE,
                                            DL_I2C_CONTROLLER_ACK_ENABLE);
 
-    while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY)
-    ;
+    while(rxPacket.rxCount < 8 && timeout--);
+    if(timeout==0){
+        printf("Rx transmit not completed");
+    }
+    
+    DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
     
     measurement.voltage= rxPacket.rxBuffer[0] | (rxPacket.rxBuffer[1] << 8);
     measurement.current= rxPacket.rxBuffer[2]|(rxPacket.rxBuffer[3] << 8);
     measurement.temperature = rxPacket.rxBuffer[4] | (rxPacket.rxBuffer[5] << 8);
     measurement.slot_state = (SlotState)(rxPacket.rxBuffer[6]);
-    
+    DL_I2C_flushControllerRXFIFO(I2C_1_INST);
     //Storing the measurements in Battery structure:
     battery_data[slot_id].battery_measurement= measurement;
-
+    
     //DEBUG
     //printf("[I2C] Successfully read %d bytes from target 0x%02X\n", rxPacket.rxCount, TARGET_BASE_ADDRESS);
     printf("Voltage: %u\n", battery_data[slot_id].battery_measurement.voltage);
     printf("Current: %u\n", battery_data[slot_id].battery_measurement.current);
     printf("Temp: %u\n",battery_data[slot_id].battery_measurement.temperature);
     printf("Slot state: %u\n",battery_data[slot_id].battery_measurement.slot_state);
-
-    DL_I2C_flushControllerRXFIFO(I2C_1_INST);
     return true;
 }