|
|
@@ -11,6 +11,7 @@
|
|
|
#include "app_end_ctr.h"
|
|
|
#include "drv_io.h"
|
|
|
#include "shark_xl.h"
|
|
|
+#include "shark_charge.h"
|
|
|
|
|
|
// CB_VAL cb_val_last;
|
|
|
uint8_t cb_operate_state = CB_BAT_NO;
|
|
|
@@ -24,8 +25,6 @@ uint8_t cfg_operate = CFG_BAT_NO;
|
|
|
uint8_t work_normal = 0;
|
|
|
|
|
|
uint8_t is_intelligent = 1;
|
|
|
-uint8_t CB_OPERATE_PRECEDENCE_PARRALLEL = PRE_SERIES;
|
|
|
-uint8_t CB_OPERATE_PRECEDENCE_Config = PRE_SERIES;
|
|
|
|
|
|
DELAY_COMMON Series_delay;
|
|
|
|
|
|
@@ -60,7 +59,6 @@ void CB_Operate_Initial(void)
|
|
|
|
|
|
void App_Initial(void)
|
|
|
{
|
|
|
- CB_OPERATE_PRECEDENCE_PARRALLEL = CB_OPERATE_PRECEDENCE_Config;
|
|
|
memset(&Series_delay,0x00,sizeof(Series_delay));
|
|
|
Initial_Neng_Hao_Bi();
|
|
|
}
|
|
|
@@ -309,6 +307,10 @@ static u8 shark_battery_switch_single(void)
|
|
|
|
|
|
static shark_bool shark_battery_series_enabled(void)
|
|
|
{
|
|
|
+ if (shark_charger_detected) {
|
|
|
+ return shark_false;
|
|
|
+ }
|
|
|
+
|
|
|
if (QD_Dect()) {
|
|
|
if (shark_xl_check()) {
|
|
|
return shark_false;
|
|
|
@@ -341,10 +343,6 @@ static shark_bool shark_battery_series_enabled(void)
|
|
|
return shark_false;
|
|
|
}
|
|
|
|
|
|
- if (IS_CHARGE_IN()) {
|
|
|
- return shark_false;
|
|
|
- }
|
|
|
-
|
|
|
return shark_true;
|
|
|
}
|
|
|
|
|
|
@@ -354,15 +352,16 @@ static shark_bool shark_battery_check_series(u8 operate)
|
|
|
if (is_intelligent == 0) {
|
|
|
return shark_false;
|
|
|
}
|
|
|
-
|
|
|
- if (CB_OPERATE_PRECEDENCE_PARRALLEL != PRE_SERIES) {
|
|
|
- return shark_false;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
return shark_battery_series_enabled();
|
|
|
}
|
|
|
|
|
|
+static shark_bool shark_battery_parrallel_enabled(void)
|
|
|
+{
|
|
|
+ return shark_charger_detected;
|
|
|
+}
|
|
|
+
|
|
|
static shark_bool shark_battery_check_parrallel(u8 operate)
|
|
|
{
|
|
|
if (operate != CB_BAT1_BAT2_PARRALLEL) {
|
|
|
@@ -370,18 +369,14 @@ static shark_bool shark_battery_check_parrallel(u8 operate)
|
|
|
return shark_false;
|
|
|
}
|
|
|
|
|
|
- if (CB_OPERATE_PRECEDENCE_PARRALLEL != PRE_PARRALLEL) {
|
|
|
+ if (shark_battery_get_voltage_delta() > SHARK_PARRALLEL_VOL_MIN) {
|
|
|
return shark_false;
|
|
|
}
|
|
|
|
|
|
return shark_false;
|
|
|
}
|
|
|
|
|
|
- if (shark_battery_get_voltage_delta() > PARRALLEL_BL_DELTA_VOL) {
|
|
|
- return shark_false;
|
|
|
- }
|
|
|
-
|
|
|
- return IS_CHARGE_IN();
|
|
|
+ return shark_battery_parrallel_enabled();
|
|
|
}
|
|
|
|
|
|
static u8 shark_battery_switch_auto(u8 operate)
|
|
|
@@ -419,7 +414,7 @@ static u8 shark_battery_switch_auto(u8 operate)
|
|
|
return operate;
|
|
|
} else if (shark_battery_check_parrallel(operate)) {
|
|
|
return shark_battery_switch_parrallel();
|
|
|
- } else if (IS_CHARGE_IN()) {
|
|
|
+ } else if (shark_charger_detected) {
|
|
|
return shark_battery_switch_charge();
|
|
|
} else {
|
|
|
return shark_battery_switch_single();
|
|
|
@@ -444,7 +439,13 @@ int8_t Battery_CB_Switch(uint8_t cb_operate)
|
|
|
sub_bms_info_1.exit_times = 0;
|
|
|
sub_bms_info_2.exit_times = 0;
|
|
|
shark_battery_switch_busy = shark_false;
|
|
|
+
|
|
|
println("switch: %d", cb_operate_state);
|
|
|
+
|
|
|
+ if (shark_charger_detected) {
|
|
|
+ shark_charger_set_enable(shark_true);
|
|
|
+ }
|
|
|
+
|
|
|
return cb_operate_state;
|
|
|
#else
|
|
|
#define COM_TIMEOUT (15)
|
|
|
@@ -954,53 +955,6 @@ void test_io(void)
|
|
|
|
|
|
uint8_t Select_One_BAT(void)
|
|
|
{
|
|
|
-#if 0
|
|
|
- uint8_t temp_op = CB_BAT_NO;
|
|
|
-
|
|
|
- println("select one");
|
|
|
-
|
|
|
- sub_bms_info_1.state = SHARK_BATT_STATE_IDLE;
|
|
|
- sub_bms_info_2.state = SHARK_BATT_STATE_IDLE;
|
|
|
-
|
|
|
- if(Is_Sub_BMS_1_Normal() == SHARK_BATT_EXIT_SUCCESS)
|
|
|
- {
|
|
|
- if(Is_Sub_BMS_2_Normal() == SHARK_BATT_EXIT_SUCCESS)
|
|
|
- {
|
|
|
- if(sub_bms_info_1.packet_common.m_total_vol >= sub_bms_info_2.packet_common.m_total_vol)
|
|
|
- {
|
|
|
- if(IS_CHARGE_IN())
|
|
|
- {
|
|
|
- temp_op = CB_BAT2;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- temp_op = CB_BAT1;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(IS_CHARGE_IN())
|
|
|
- {
|
|
|
- temp_op = CB_BAT1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- temp_op = CB_BAT2;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- temp_op = CB_BAT1;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(Is_Sub_BMS_2_Normal() == SHARK_BATT_EXIT_SUCCESS)
|
|
|
- {
|
|
|
- temp_op = CB_BAT2;
|
|
|
- }
|
|
|
-
|
|
|
- return temp_op;
|
|
|
-#else
|
|
|
if (sub_bms_info_1.connected) {
|
|
|
return CB_BAT1_BAT2_AUTO;
|
|
|
}
|
|
|
@@ -1020,7 +974,6 @@ uint8_t Select_One_BAT(void)
|
|
|
}
|
|
|
|
|
|
return CB_BAT_NO;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1099,7 +1052,7 @@ uint8_t Check_CB_BAT1_BAT2_PARRALLEL(void)
|
|
|
{
|
|
|
uint8_t temp_op = CB_MAX;
|
|
|
|
|
|
- if(is_intelligent && CB_OPERATE_PRECEDENCE_PARRALLEL != PRE_PARRALLEL)
|
|
|
+ if (!shark_battery_parrallel_enabled())
|
|
|
{
|
|
|
temp_op = Select_One_BAT();
|
|
|
return temp_op;
|
|
|
@@ -1160,7 +1113,7 @@ uint8_t Select_One_BAT_Han_Guo(void)
|
|
|
{
|
|
|
if(sub_bms_info_1.packet_common.m_total_vol >= sub_bms_info_2.packet_common.m_total_vol)
|
|
|
{
|
|
|
- if(IS_CHARGE_IN())
|
|
|
+ if(shark_charger_detected)
|
|
|
{
|
|
|
temp_op = CB_BAT2;
|
|
|
}
|
|
|
@@ -1171,7 +1124,7 @@ uint8_t Select_One_BAT_Han_Guo(void)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(IS_CHARGE_IN())
|
|
|
+ if(shark_charger_detected)
|
|
|
{
|
|
|
temp_op = CB_BAT1;
|
|
|
}
|
|
|
@@ -1229,12 +1182,6 @@ uint8_t Check_CB_BAT1_BAT2_SERIES(void)
|
|
|
{
|
|
|
uint8_t temp_op = CB_MAX;
|
|
|
|
|
|
- if(is_intelligent && CB_OPERATE_PRECEDENCE_PARRALLEL != PRE_SERIES)
|
|
|
- {
|
|
|
- temp_op = Select_One_BAT();
|
|
|
- return temp_op;
|
|
|
- }
|
|
|
-
|
|
|
#ifndef HAN_GUO_VERSION
|
|
|
if (shark_battery_series_locked)
|
|
|
{
|
|
|
@@ -1243,7 +1190,7 @@ uint8_t Check_CB_BAT1_BAT2_SERIES(void)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- if(IS_CHARGE_IN())
|
|
|
+ if (shark_charger_detected)
|
|
|
{
|
|
|
temp_op = Select_One_BAT();
|
|
|
return temp_op;
|
|
|
@@ -1433,109 +1380,6 @@ uint8_t Is_BAT2_Lock(void)
|
|
|
|
|
|
}
|
|
|
|
|
|
-void Charger_Out(void)
|
|
|
-{
|
|
|
- Set_Charger_In(0);
|
|
|
-
|
|
|
- if(sub_bms_info_1.packet_common.m_percent >= 100 && sub_bms_info_2.packet_common.m_percent >= 100)
|
|
|
- battery_charged_full = 1;
|
|
|
-}
|
|
|
-void Check_Charge_In(void)
|
|
|
-{
|
|
|
-
|
|
|
- if(sub_bms_info_1.packet_common.m_percent < 97 || sub_bms_info_2.packet_common.m_percent < 97)
|
|
|
- battery_charged_full = 0;
|
|
|
- //if(gpio_input_bit_get(GPIOC,GPIO_PIN_4) == 0)
|
|
|
- {
|
|
|
- // Set_Charger_In(1);
|
|
|
- }
|
|
|
-
|
|
|
- if(IS_CHARGE_IN())
|
|
|
- {
|
|
|
-
|
|
|
- if(is_intelligent)
|
|
|
- {
|
|
|
- CB_OPERATE_PRECEDENCE_PARRALLEL = PRE_PARRALLEL;
|
|
|
- if(cb_operate_state == CB_BAT1_BAT2_SERIES)
|
|
|
- {
|
|
|
- if(Battery_Change_Mode(CFG_BAT1_BAT2_PARRALLEL) == CB_BAT1_BAT2_PARRALLEL)
|
|
|
- CHARG_PROTECT_OPEN(1);
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CHARG_PROTECT_OPEN(1);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(cb_operate_state == CB_BAT1_BAT2_SERIES)
|
|
|
- {
|
|
|
- ;
|
|
|
- }
|
|
|
- else
|
|
|
- CHARG_PROTECT_OPEN(1);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if(IS_CHARGER_ON())
|
|
|
- {
|
|
|
- if(sub_bms_info_1.packet_common.charge_flag == 0 && sub_bms_info_2.packet_common.charge_flag == 0)
|
|
|
- {
|
|
|
- if(charge_delay.set == 0)
|
|
|
- {
|
|
|
- charge_delay.set = 1;
|
|
|
- charge_delay.count = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if(charge_delay.count >= CHARGE_DELAY_TIME_OUT_COUNT)
|
|
|
- {
|
|
|
- memset(&charge_delay,0x00,sizeof(charge_delay));
|
|
|
- Charger_Out();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- memset(&charge_delay,0x00,sizeof(charge_delay));
|
|
|
- }
|
|
|
-
|
|
|
- if(cb_operate_state == CB_BAT1_BAT2_PARRALLEL)
|
|
|
- {
|
|
|
- if(sub_bms_info_1.packet_common.charge_flag)
|
|
|
- {
|
|
|
- if((sub_bms_info_2.packet_common.work_status&ST_DISCHRG_CUR)!= 0)
|
|
|
- {
|
|
|
- if(sub_bms_info_1.packet_common.m_current + sub_bms_info_2.packet_common.m_current\
|
|
|
- < 5000)
|
|
|
- Charger_Out();
|
|
|
- }
|
|
|
- }
|
|
|
- else if(sub_bms_info_2.packet_common.charge_flag)
|
|
|
- {
|
|
|
- if((sub_bms_info_1.packet_common.work_status&ST_DISCHRG_CUR)!= 0)
|
|
|
- {
|
|
|
- if(sub_bms_info_1.packet_common.m_current + sub_bms_info_2.packet_common.m_current\
|
|
|
- < 5000)
|
|
|
- Charger_Out();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CHARG_PROTECT_OPEN(0);
|
|
|
- if(is_intelligent)
|
|
|
- {
|
|
|
- CB_OPERATE_PRECEDENCE_PARRALLEL = CB_OPERATE_PRECEDENCE_Config;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
uint8_t Change_Mode_Sub_BMS_1_Normal(void)
|
|
|
{
|
|
|
return Is_Sub_BMS_1_Normal() == SHARK_BATT_EXIT_SUCCESS;
|
|
|
@@ -1547,19 +1391,15 @@ uint8_t Change_Mode_Sub_BMS_2_Normal(void)
|
|
|
|
|
|
uint8_t Change_Mode_Sub_BMS_PARRALLEL(void)
|
|
|
{
|
|
|
- //
|
|
|
- if(cb_operate_state == CB_BAT_NO)
|
|
|
+ if (!shark_battery_parrallel_enabled()) {
|
|
|
return 0;
|
|
|
+ }
|
|
|
|
|
|
- if(is_intelligent && CB_OPERATE_PRECEDENCE_PARRALLEL != PRE_PARRALLEL)
|
|
|
- return 0;
|
|
|
- //
|
|
|
- if(Is_Sub_BMS_1_Normal() == SHARK_BATT_EXIT_SUCCESS && Is_Sub_BMS_2_Normal() == SHARK_BATT_EXIT_SUCCESS)
|
|
|
- ;
|
|
|
- else
|
|
|
+ if(Is_Sub_BMS_1_Normal() != SHARK_BATT_EXIT_SUCCESS || Is_Sub_BMS_2_Normal() != SHARK_BATT_EXIT_SUCCESS) {
|
|
|
return 0;
|
|
|
+ }
|
|
|
|
|
|
- if (shark_battery_get_voltage_delta() > PARRALLEL_BL_DELTA_VOL) {
|
|
|
+ if (shark_battery_get_voltage_delta() > SHARK_PARRALLEL_VOL_MIN) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -1572,22 +1412,9 @@ uint8_t Change_Mode_Sub_BMS_SERIES(void)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
- //
|
|
|
- if(!(cb_operate_state == CB_BAT1 || cb_operate_state == CB_BAT2))
|
|
|
- return 0;
|
|
|
-#endif
|
|
|
-
|
|
|
- if(is_intelligent && CB_OPERATE_PRECEDENCE_PARRALLEL != PRE_SERIES)
|
|
|
- return 0;
|
|
|
-
|
|
|
-#if 0
|
|
|
- if(IS_CHARGE_IN())
|
|
|
- return 0;
|
|
|
-#endif
|
|
|
-
|
|
|
- if(!(Is_Sub_BMS_1_Normal() == SHARK_BATT_EXIT_SUCCESS && Is_Sub_BMS_2_Normal() == SHARK_BATT_EXIT_SUCCESS))
|
|
|
+ if (Is_Sub_BMS_1_Normal() != SHARK_BATT_EXIT_SUCCESS || Is_Sub_BMS_2_Normal() != SHARK_BATT_EXIT_SUCCESS) {
|
|
|
return 0;
|
|
|
+ }
|
|
|
|
|
|
/*if(cb_operate_state == CB_BAT1)
|
|
|
{
|
|
|
@@ -1671,7 +1498,7 @@ void Intelligent_Management_Battery(void)
|
|
|
{
|
|
|
if(is_intelligent)
|
|
|
{
|
|
|
- if(CB_OPERATE_PRECEDENCE_PARRALLEL == PRE_PARRALLEL)
|
|
|
+ if(shark_charger_detected)
|
|
|
{
|
|
|
if(cb_operate_state == CB_BAT1_BAT2_PARRALLEL)
|
|
|
return;
|
|
|
@@ -1698,13 +1525,9 @@ void Intelligent_Management_Battery(void)
|
|
|
Battery_Change_Mode(CFG_BAT2);
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ else if (shark_xl_detected == 0 && shark_battery_get_voltage2() > shark_battery_get_voltage1() + SHARK_BATT_SINGLE_DELTA)
|
|
|
{
|
|
|
- if((abs(sub_bms_info_1.packet_common.m_current) <= 1000)\
|
|
|
- &&(shark_battery_get_voltage2() > shark_battery_get_voltage1()+ONE_BATTERY_DELTA_VOL))
|
|
|
- {
|
|
|
- Battery_Change_Mode(CFG_BAT2);
|
|
|
- }
|
|
|
+ Battery_Change_Mode(CFG_BAT2);
|
|
|
}
|
|
|
break;
|
|
|
case CB_BAT2:
|
|
|
@@ -1715,13 +1538,9 @@ void Intelligent_Management_Battery(void)
|
|
|
Battery_Change_Mode(CFG_BAT1);
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ else if (shark_xl_detected == 0 && shark_battery_get_voltage1() > shark_battery_get_voltage2() + SHARK_BATT_SINGLE_DELTA)
|
|
|
{
|
|
|
- if((abs(sub_bms_info_2.packet_common.m_current) <= 1000)\
|
|
|
- &&(shark_battery_get_voltage1() > shark_battery_get_voltage2()+ONE_BATTERY_DELTA_VOL))
|
|
|
- {
|
|
|
- Battery_Change_Mode(CFG_BAT1);
|
|
|
- }
|
|
|
+ Battery_Change_Mode(CFG_BAT1);
|
|
|
}
|
|
|
break;
|
|
|
case CB_BAT_NO:
|