|
|
@@ -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);*/
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|