|
|
@@ -56,6 +56,7 @@ void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_
|
|
|
data[0] = slot_id;
|
|
|
data[1] = current_mA & 0xFF; //Current LSB
|
|
|
data[2] = (current_mA >> 8) & 0xFF; //Current MSB
|
|
|
+ //battery_data[slot_id].charge_discharge= current_mA;
|
|
|
controller_SetCommandRequest(TARGET_ADDRESS, CMD_SET_CURRENT, data, sizeof(data));
|
|
|
}
|
|
|
|
|
|
@@ -77,3 +78,33 @@ bool controller_GetBatteryMeasurement(uint8_t const TARGET_ADDRESS, uint8_t slot
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+//Clear error flag to the target
|
|
|
+//Format: command + ((slot_id) + data (optional))
|
|
|
+void controller_ClearError(uint8_t const TARGET_ADDRESS, uint8_t slot_id){
|
|
|
+ uint8_t command= CMD_CLEAR_ERR| (slot_id<<4); //shift slot_id to the left by 4 bits
|
|
|
+ printf("[MCU] Clear Error Bitmasked Command:: 0x%02X\n", command);
|
|
|
+ uint8_t data[1];
|
|
|
+ data[0] = slot_id;
|
|
|
+ controller_SetCommandRequest(TARGET_ADDRESS, CMD_CLEAR_ERR, data, sizeof(data));
|
|
|
+}
|
|
|
+
|
|
|
+//Logic to handle Power Burning PWM on the controller side: is there any clamping required between a certain range?
|
|
|
+void controller_EvaluateBatterySlotState(uint8_t slot_id, BatteryMeasurement *measurement){
|
|
|
+ if(measurement->slot_state== SLOT_ERR_HOV){
|
|
|
+ battery_data[slot_id].pwm_value+= PWM_INCREMENT_VALUE;
|
|
|
+ DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX);
|
|
|
+ DL_TimerG_startCounter(PWM_0_INST);
|
|
|
+ printf("[Power Burning PWM] HOV state: Increased power burn PWM to %d\n", battery_data[slot_id].pwm_value);
|
|
|
+ }else if(measurement->slot_state == SLOT_STATE_SOV){
|
|
|
+ battery_data[slot_id].pwm_value+= PWM_INCREMENT_VALUE;
|
|
|
+ DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX);
|
|
|
+ DL_TimerG_startCounter(PWM_0_INST);
|
|
|
+ printf("[Power Burning PWM] SOV state: Increased power burn PWM to %d\n", battery_data[slot_id].pwm_value);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ battery_data[slot_id].pwm_value-= PWM_DECREMENT_VALUE;
|
|
|
+ DL_TimerG_setCaptureCompareValue(PWM_0_INST, battery_data[slot_id].pwm_value, DL_TIMER_CC_0_INDEX);
|
|
|
+ DL_TimerG_startCounter(PWM_0_INST);
|
|
|
+ printf("[Power Burning PWM] OK state: Decreased power burn PWM to %d\n", battery_data[slot_id].pwm_value);
|
|
|
+ }
|
|
|
+}
|