|
|
@@ -1,4 +1,4 @@
|
|
|
-//#include "ti/driverlib/dl_wwdt.h"
|
|
|
+
|
|
|
#include "ti/driverlib/m0p/dl_core.h"
|
|
|
#include "ti_msp_dl_config.h"
|
|
|
#include "src/pi/i2c_pi_target.h"
|
|
|
@@ -15,6 +15,8 @@
|
|
|
volatile bool mcuSendCommand = false;
|
|
|
volatile bool picommandPending = false;
|
|
|
volatile bool watchdog_triggered= false;
|
|
|
+volatile uint8_t current_command= 0x06;
|
|
|
+volatile bool txCommandSent= false;
|
|
|
|
|
|
// Interrupt for I2C instance -> MCU to Target
|
|
|
|
|
|
@@ -27,6 +29,7 @@ void I2C_1_INST_IRQHandler(void)
|
|
|
|
|
|
case DL_I2C_IIDX_CONTROLLER_RXFIFO_TRIGGER:
|
|
|
mcuSendCommand= true;
|
|
|
+
|
|
|
while(DL_I2C_isControllerRXFIFOEmpty(I2C_1_INST) != true) {
|
|
|
if(rxPacket.rxCount < rxPacket.rxLen){
|
|
|
//Get byte from the I2C RX FIFO of the target
|
|
|
@@ -36,21 +39,35 @@ void I2C_1_INST_IRQHandler(void)
|
|
|
DL_I2C_receiveControllerData(I2C_1_INST);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if(rxPacket.rxCount >= rxPacket.rxLen){
|
|
|
rxPacket.rxComplete= true;
|
|
|
}
|
|
|
-
|
|
|
break;
|
|
|
|
|
|
case DL_I2C_IIDX_CONTROLLER_TXFIFO_TRIGGER:
|
|
|
/* Fill TX FIFO with bytes to send */
|
|
|
mcuSendCommand = true;
|
|
|
- txPacket.txComplete= true;
|
|
|
+ txPacket.txBuffer[0] = (0<<4) | (CMD_GET_MEASUREMENT & 0x0F);
|
|
|
+ DL_I2C_fillControllerTXFIFO(I2C_1_INST, (uint8_t *)&txPacket.txBuffer[0], 1);
|
|
|
+ /*if(!txCommandSent){
|
|
|
+ txPacket.txBuffer[0]= (0<<4) | (CMD_GET_MEASUREMENT & 0x0F);
|
|
|
+ DL_I2C_fillControllerTXFIFO(I2C_1_INST, (uint8_t *)&txPacket.txBuffer[0], 1);
|
|
|
+ txPacket.txComplete= true;
|
|
|
+ mcuSendCommand = true;
|
|
|
+ txCommandSent= true;
|
|
|
+ }*/
|
|
|
+ /*else{
|
|
|
+ while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY);
|
|
|
+ DL_I2C_startControllerTransfer(I2C_1_INST, 0x49, DL_I2C_CONTROLLER_DIRECTION_RX, 8);
|
|
|
+ txCommandSent= false;
|
|
|
+ } */
|
|
|
break;
|
|
|
|
|
|
case DL_I2C_IIDX_CONTROLLER_STOP:
|
|
|
mcuSendCommand = true;
|
|
|
rxPacket.rxComplete= true;
|
|
|
+ txPacket.txComplete= true;
|
|
|
break;
|
|
|
|
|
|
case DL_I2C_IIDX_CONTROLLER_ARBITRATION_LOST:
|
|
|
@@ -103,40 +120,41 @@ int main(void)
|
|
|
//Interrupt routine for Pi
|
|
|
NVIC_EnableIRQ(I2C_0_INST_INT_IRQN);
|
|
|
//Interrupt for target mcu
|
|
|
- //NVIC_EnableIRQ(I2C_1_INST_INT_IRQN);
|
|
|
-
|
|
|
-
|
|
|
- bool was_true = false;
|
|
|
+ NVIC_EnableIRQ(I2C_1_INST_INT_IRQN);
|
|
|
|
|
|
while(1)
|
|
|
{
|
|
|
if(picommandPending)
|
|
|
- { printf("Pi Interrupt Triggered.\n");
|
|
|
+ { //printf("Pi Interrupt Triggered.\n");
|
|
|
pi_i2c_mcu();
|
|
|
picommandPending = false;
|
|
|
}
|
|
|
- /*if(mcuSendCommand){
|
|
|
- printf("MCU Interrupt Triggered.\n");
|
|
|
+ if(mcuSendCommand){
|
|
|
+ //printf("MCU Interrupt Triggered.\n");
|
|
|
+ //getBatteryMeasurement_test();
|
|
|
mcuSendCommand = false;
|
|
|
|
|
|
- }*/
|
|
|
+ }
|
|
|
|
|
|
for(uint8_t slot_id= 0; slot_id< NUM_SLOTS; slot_id++){
|
|
|
+ getBatteryMeasurement_test();
|
|
|
+ //controller_GetBatteryMeasurement(slot_id);
|
|
|
//Reading the battery measurement:
|
|
|
- printf("mainloop slot?\n");
|
|
|
+ //printf("mainloop slot?\n");
|
|
|
/*if (!was_true) {
|
|
|
printf("executing?\n");
|
|
|
- was_true = controller_GetBatteryMeasurement(slot_id);
|
|
|
+ controller_GetBatteryMeasurement(slot_id);
|
|
|
+ was_true =
|
|
|
printf("true? %d\n", was_true);
|
|
|
}*/
|
|
|
//Reading battery state:
|
|
|
Battery_StateCondition(slot_id);
|
|
|
//Reading Charging state condition
|
|
|
- CC_CV_ControlCharging(slot_id, 50);
|
|
|
- printf("Battery Charging State: %u\n", battery_data[slot_id].battery_charging_state);
|
|
|
- printf("Battery Limit Received: %u\n", battery_data[slot_id].batteryLimitReceived);
|
|
|
- printf("STATUS ***Reading Battery Measurement for Slot ID %u:: Battery State: %u, Voltage: %u, Current: %u, Temperature: %u, Slot state: %u***\n", slot_id, battery_data[slot_id].battery_state, 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);
|
|
|
+ //CC_CV_ControlCharging(slot_id, 50);
|
|
|
+ //printf("Battery Charging State: %u\n", battery_data[slot_id].battery_charging_state);
|
|
|
+ //printf("Battery Limit Received: %u\n", battery_data[slot_id].batteryLimitReceived);
|
|
|
+ //printf("STATUS ***Reading Battery Measurement for Slot ID %u:: Battery State: %u, Voltage: %u, Current: %u, Temperature: %u, Slot state: %u***\n", slot_id, battery_data[slot_id].battery_state, 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);
|
|
|
//If target received battery limits from Pi then start charging:
|
|
|
if(battery_data[slot_id].batteryLimitReceived){
|
|
|
printf("Battery Limits: Slot: %d, Max Voltage:%u, Min Voltage:%u, "
|