|
|
@@ -93,24 +93,6 @@ void I2C_0_INST_IRQHandler(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)
|
|
|
{
|
|
|
@@ -118,59 +100,48 @@ int main(void)
|
|
|
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
|
|
|
NVIC_EnableIRQ(I2C_0_INST_INT_IRQN);
|
|
|
//Interrupt for target mcu
|
|
|
- NVIC_EnableIRQ(I2C_1_INST_INT_IRQN);
|
|
|
- //DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB7_PIN);
|
|
|
+ //NVIC_EnableIRQ(I2C_1_INST_INT_IRQN);
|
|
|
|
|
|
|
|
|
bool was_true = false;
|
|
|
|
|
|
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)
|
|
|
{ printf("Pi Interrupt Triggered.\n");
|
|
|
pi_i2c_mcu();
|
|
|
picommandPending = false;
|
|
|
}
|
|
|
- if(mcuSendCommand){
|
|
|
+ /*if(mcuSendCommand){
|
|
|
printf("MCU Interrupt Triggered.\n");
|
|
|
mcuSendCommand = false;
|
|
|
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
for(uint8_t slot_id= 0; slot_id< NUM_SLOTS; slot_id++){
|
|
|
//Reading the battery measurement:
|
|
|
printf("mainloop slot?\n");
|
|
|
- if (!was_true) {
|
|
|
+ /*if (!was_true) {
|
|
|
printf("executing?\n");
|
|
|
was_true = controller_GetBatteryMeasurement(slot_id);
|
|
|
printf("true? %d\n", was_true);
|
|
|
- }
|
|
|
+ }*/
|
|
|
//Reading battery state:
|
|
|
- Battery_ReadState(slot_id);
|
|
|
- //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);
|
|
|
+ Battery_StateCondition(slot_id);
|
|
|
+ //Reading Charging state condition
|
|
|
+ CC_CV_ControlCharging(slot_id, 50);
|
|
|
+ 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, "
|
|
|
"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);
|