Selaa lähdekoodia

Changed interrupt behavior in main and corrected Pin configuration in syscfg

namrota ghosh 7 kuukautta sitten
vanhempi
commit
feb3baf78f
2 muutettua tiedostoa jossa 40 lisäystä ja 42 poistoa
  1. 29 28
      main.c
  2. 11 14
      main.syscfg

+ 29 - 28
main.c

@@ -5,6 +5,8 @@
 #include "src/battery_data/battery.h"
 #include "src/cc_cv_charging.h"
 #include <stdio.h>
+#include "src/battery_data/battery.h"
+#include "mock_setup.h"
 
 volatile bool mcuSendCommand = false;
 volatile bool picommandPending = false;
@@ -21,18 +23,10 @@ void I2C_1_INST_IRQHandler(void)
             break;
 
         case DL_I2C_IIDX_CONTROLLER_RXFIFO_TRIGGER:
-            mcuSendCommand= true;
-            /* Store bytes received from target in Rx Msg Buffer */
-            while (DL_I2C_isControllerRXFIFOEmpty(I2C_1_INST) != true) {
-                if (rx_packet.rxCount < rx_packet.rxLen) {
-                    rx_packet.rxBuffer[rx_packet.rxCount] = DL_I2C_receiveControllerData(I2C_1_INST);
-                    rx_packet.rxCount++;
-                } else {
-                    /* Ignore and remove from FIFO if the buffer is full */
-                    DL_I2C_receiveControllerData(I2C_1_INST);
-                    
-                } 
+            if (DL_I2C_isTargetRXFIFOEmpty(I2C_1_INST)) {
+                return;
             }
+            mcuSendCommand= true;
             break;
 
         case DL_I2C_IIDX_CONTROLLER_TXFIFO_TRIGGER:
@@ -40,7 +34,7 @@ void I2C_1_INST_IRQHandler(void)
             mcuSendCommand = true;
             break;
         case DL_I2C_IIDX_CONTROLLER_STOP:
-            mcuSendCommand = false;
+            mcuSendCommand = true;
         case DL_I2C_IIDX_CONTROLLER_ARBITRATION_LOST:
         case DL_I2C_IIDX_CONTROLLER_NACK:
             break; 
@@ -55,16 +49,14 @@ void I2C_0_INST_IRQHandler(void)
     switch (DL_I2C_getPendingInterrupt(I2C_0_INST)) 
     {   
         case DL_I2C_IIDX_TARGET_START:
-            DL_I2C_flushTargetRXFIFO(I2C_0_INST);
             DL_I2C_flushTargetTXFIFO(I2C_0_INST);
             break;
 
         case DL_I2C_IIDX_TARGET_RXFIFO_TRIGGER:
-            picommandPending = true;
-            //printf("Rx Interrupt Triggered \n");
             if (DL_I2C_isTargetRXFIFOEmpty(I2C_0_INST)) {
                 return;
             }
+            picommandPending = true;
             break;
 
         case DL_I2C_IIDX_TARGET_TXFIFO_TRIGGER:
@@ -72,7 +64,9 @@ void I2C_0_INST_IRQHandler(void)
             picommandPending = true;
             break;
         case DL_I2C_IIDX_TARGET_STOP:
-            picommandPending = false;
+            picommandPending = true;
+            //DL_I2C_flushTargetTXFIFO(I2C_0_INST);
+            //DL_I2C_flushTargetRXFIFO(I2C_0_INST);
             break;
         case DL_I2C_IIDX_TARGET_ARBITRATION_LOST:
             break; 
@@ -89,10 +83,9 @@ int main(void)
     NVIC_EnableIRQ(I2C_0_INST_INT_IRQN);
     //Interrupt for target mcu
     NVIC_EnableIRQ(I2C_1_INST_INT_IRQN);
-
-
+    
     while(1)
-    {
+    { 
         if(picommandPending)
         {   printf("Pi Interrupt Triggered.\n");
             pi_i2c_mcu();
@@ -100,17 +93,25 @@ int main(void)
         }
         if(mcuSendCommand)
         {   printf("MCU Interrupt Triggered.\n");
-            //GET command from the target: target_address, slot, data:
-            controller_GetBatteryMeasurement(0x48, 0, &battery_data[0].battery_measurement);
-            //Set the current to the target: command, slot, current_value
-            controller_SetCurrent(0x48,0,1000);
+            controller_GetBatteryMeasurement(TARGET_MCU_ADDRESS, 0);
+            //test_Controller_SetCurrent();
+            //test_Controller_GetBatteryMeasurement();
+            //controller_SetCurrent(TARGET_MCU_ADDRESS, 0 , 90);
             mcuSendCommand = false;
         }
-        /*for(uint8_t slot=0; slot<NUM_SLOTS; slot++)
-        {
-            Battery_ReadState(slot);
-            CC_CV_ControlCharging(slot, );
-        }*/
+        for(uint8_t slot_id= 0; slot_id<NUM_SLOTS; slot_id++){
+            //Battery Measurement:
+            printf("*** Battery Details: Slot: %u, Voltage:%u, Current: %u, Temperature:%u, Slot State:%u ***\n",
+            slot_id, battery_data[slot_id].battery_measurement.voltage, battery_data[slot_id].battery_measurement.current, battery_data[slot_id].battery_measurement.temperature,
+            battery_data[slot_id].battery_measurement.slot_state);
+            //controller_EvaluateBatterySlotState(slot_id, &battery_data[slot_id].battery_measurement);
+            Battery_ReadState(slot_id);
+            /*printf("*** Battery Limits: Slot: %d, Max Voltage:%u, Min Voltage:%u, "
+           "Cutoff Current: %u, Capacitance:%u, Charge Fraction:%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);*/
+        
+        }
         
     }
 }

+ 11 - 14
main.syscfg

@@ -40,23 +40,21 @@ I2C1.$name                     = "I2C_0";
 I2C1.basicEnableTarget         = true;
 I2C1.intTarget                 = ["RXFIFO_TRIGGER","RX_DONE","START","STOP","TXFIFO_TRIGGER","TX_DONE"];
 I2C1.peripheral.$assign        = "I2C0";
-I2C1.peripheral.sdaPin.$assign = "PA10";
+I2C1.peripheral.sdaPin.$assign = "PA0";
 I2C1.peripheral.sclPin.$assign = "PA1";
 I2C1.sdaPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric0";
 I2C1.sclPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric1";
 
-I2C2.$name                         = "I2C_1";
-I2C2.basicEnableController         = true;
-I2C2.intController                 = ["ARBITRATION_LOST","NACK","RXFIFO_TRIGGER","RX_DONE","TXFIFO_TRIGGER","TX_DONE"];
-I2C2.peripheral.$assign            = "I2C1";
-I2C2.peripheral.sdaPin.$assign     = "PA3";
-I2C2.peripheral.sclPin.$assign     = "PA4";
-I2C2.sdaPinConfig.$name            = "ti_driverlib_gpio_GPIOPinGeneric2";
-I2C2.sdaPinConfig.enableConfig     = true;
-I2C2.sdaPinConfig.internalResistor = "PULL_UP";
-I2C2.sclPinConfig.$name            = "ti_driverlib_gpio_GPIOPinGeneric3";
-I2C2.sclPinConfig.enableConfig     = true;
-I2C2.sclPinConfig.internalResistor = "PULL_UP";
+I2C2.$name                     = "I2C_1";
+I2C2.basicEnableController     = true;
+I2C2.intController             = ["ARBITRATION_LOST","NACK","RXFIFO_TRIGGER","RX_DONE","TXFIFO_TRIGGER","TX_DONE"];
+I2C2.peripheral.$assign        = "I2C1";
+I2C2.peripheral.sdaPin.$assign = "PA3";
+I2C2.peripheral.sclPin.$assign = "PA4";
+I2C2.sdaPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric2";
+I2C2.sdaPinConfig.enableConfig = true;
+I2C2.sclPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric3";
+I2C2.sclPinConfig.enableConfig = true;
 
 PWM1.$name                      = "PWM_0";
 PWM1.timerCount                 = 320;
@@ -65,7 +63,6 @@ PWM1.ccIndex                    = [0];
 PWM1.peripheral.ccp0Pin.$assign = "PA5";
 PWM1.PWM_CHANNEL_0.$name        = "ti_driverlib_pwm_PWMTimerCC0";
 PWM1.PWM_CHANNEL_0.invert       = true;
-PWM1.PWM_CHANNEL_0.ccValue      = 320;
 PWM1.ccp0PinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric4";
 
 SYSCTL.peripheral.$assign = "SYSCTL";