|
@@ -1,3 +1,5 @@
|
|
|
|
|
+#include "ti/driverlib/dl_wwdt.h"
|
|
|
|
|
+#include "ti/driverlib/m0p/dl_core.h"
|
|
|
#include "ti_msp_dl_config.h"
|
|
#include "ti_msp_dl_config.h"
|
|
|
#include "src/pi/i2c_pi_target.h"
|
|
#include "src/pi/i2c_pi_target.h"
|
|
|
#include "src/controller/controller.h"
|
|
#include "src/controller/controller.h"
|
|
@@ -8,8 +10,11 @@
|
|
|
#include "src/battery_data/battery.h"
|
|
#include "src/battery_data/battery.h"
|
|
|
#include "mock_setup.h"
|
|
#include "mock_setup.h"
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+//define the varibales:
|
|
|
volatile bool mcuSendCommand = false;
|
|
volatile bool mcuSendCommand = false;
|
|
|
volatile bool picommandPending = false;
|
|
volatile bool picommandPending = false;
|
|
|
|
|
+volatile bool watchdog_triggered= false;
|
|
|
|
|
|
|
|
// Interrupt for I2C instance -> MCU to Target
|
|
// Interrupt for I2C instance -> MCU to Target
|
|
|
|
|
|
|
@@ -32,6 +37,7 @@ void I2C_1_INST_IRQHandler(void)
|
|
|
case DL_I2C_IIDX_CONTROLLER_TXFIFO_TRIGGER:
|
|
case DL_I2C_IIDX_CONTROLLER_TXFIFO_TRIGGER:
|
|
|
/* Fill TX FIFO with bytes to send */
|
|
/* Fill TX FIFO with bytes to send */
|
|
|
mcuSendCommand = true;
|
|
mcuSendCommand = true;
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
case DL_I2C_IIDX_CONTROLLER_STOP:
|
|
case DL_I2C_IIDX_CONTROLLER_STOP:
|
|
|
mcuSendCommand = true;
|
|
mcuSendCommand = true;
|
|
@@ -75,46 +81,81 @@ void I2C_0_INST_IRQHandler(void)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int main(void)
|
|
|
|
|
|
|
+//interrupt added for Windows Watchdog Timer:
|
|
|
|
|
+void GROUP0_IRQHandler(void)
|
|
|
{
|
|
{
|
|
|
|
|
+ switch (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_0)) {
|
|
|
|
|
+ case DL_INTERRUPT_GROUP0_IIDX_WWDT0:
|
|
|
|
|
+ if (DL_WWDT_getPendingInterrupt(WWDT0)) {
|
|
|
|
|
+ //Clears the interrupt
|
|
|
|
|
+ DL_WWDT_clearInterruptStatus(WWDT0);
|
|
|
|
|
+ //Resets the timer:
|
|
|
|
|
+ DL_WWDT_reset(WWDT0);
|
|
|
|
|
+ //Set the flag to True
|
|
|
|
|
+ watchdog_triggered= true;
|
|
|
|
|
+ //how to handle in the case of failure?
|
|
|
|
|
+ }
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+int main(void)
|
|
|
|
|
+{
|
|
|
SYSCFG_DL_init();
|
|
SYSCFG_DL_init();
|
|
|
Battery_Init();
|
|
Battery_Init();
|
|
|
|
|
+ //dynamic addressing function call for Pi
|
|
|
|
|
+ dynamic_gpio_addressing();
|
|
|
|
|
+ /* Enable WWDT interrupts on device */
|
|
|
|
|
+ NVIC_EnableIRQ(WWDT0_INT_IRQN);
|
|
|
//Interrupt routine for Pi
|
|
//Interrupt routine for Pi
|
|
|
NVIC_EnableIRQ(I2C_0_INST_INT_IRQN);
|
|
NVIC_EnableIRQ(I2C_0_INST_INT_IRQN);
|
|
|
//Interrupt for target mcu
|
|
//Interrupt for target mcu
|
|
|
NVIC_EnableIRQ(I2C_1_INST_INT_IRQN);
|
|
NVIC_EnableIRQ(I2C_1_INST_INT_IRQN);
|
|
|
-
|
|
|
|
|
|
|
+ //DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
while(1)
|
|
while(1)
|
|
|
- {
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ if(watchdog_triggered){
|
|
|
|
|
+ printf("ERROR: ***WATCHDOG TRIGGERED***\n");
|
|
|
|
|
+ //Resetting the flags to its original state
|
|
|
|
|
+ picommandPending= false;
|
|
|
|
|
+ mcuSendCommand= false;
|
|
|
|
|
+ watchdog_triggered= false;
|
|
|
|
|
+ //Reinitialize the system
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(picommandPending)
|
|
if(picommandPending)
|
|
|
{ printf("Pi Interrupt Triggered.\n");
|
|
{ printf("Pi Interrupt Triggered.\n");
|
|
|
pi_i2c_mcu();
|
|
pi_i2c_mcu();
|
|
|
picommandPending = false;
|
|
picommandPending = false;
|
|
|
}
|
|
}
|
|
|
- if(mcuSendCommand)
|
|
|
|
|
- { printf("MCU Interrupt Triggered.\n");
|
|
|
|
|
- controller_GetBatteryMeasurement(TARGET_MCU_ADDRESS, 0);
|
|
|
|
|
- //test_Controller_SetCurrent();
|
|
|
|
|
- //test_Controller_GetBatteryMeasurement();
|
|
|
|
|
- //controller_SetCurrent(TARGET_MCU_ADDRESS, 0 , 90);
|
|
|
|
|
|
|
+ if(mcuSendCommand){
|
|
|
|
|
+ printf("MCU Interrupt Triggered.\n");
|
|
|
|
|
+ for(uint8_t i=0; i<NUM_SLOTS; i++){
|
|
|
|
|
+ controller_GetBatteryMeasurement(TARGET_MCU_ADDRESS, i);
|
|
|
|
|
+ }
|
|
|
mcuSendCommand = false;
|
|
mcuSendCommand = false;
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- for(uint8_t slot_id= 0; slot_id<NUM_SLOTS; slot_id++){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ for(uint8_t slot_id= 0; slot_id< NUM_SLOTS; slot_id++){
|
|
|
//Reading battery state:
|
|
//Reading battery state:
|
|
|
Battery_ReadState(slot_id);
|
|
Battery_ReadState(slot_id);
|
|
|
- //Reading CC CV Charging:
|
|
|
|
|
- //charge_current: 50
|
|
|
|
|
- CC_CV_ControlCharging(slot_id, 50);
|
|
|
|
|
- //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);
|
|
|
|
|
-
|
|
|
|
|
- /*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);*/
|
|
|
|
|
|
|
+ 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("STATUS ***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);
|
|
|
|
|
+ CC_CV_ControlCharging(slot_id, 50);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ delay_cycles(MEASUREMENT_CHECK_INTERVAL);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|