|
|
@@ -33,6 +33,7 @@ static shark_task_t _bms_main_task = {.handler = _bms_main_task_handler};
|
|
|
static shark_timer_t _debug_timer = {.handler = _debug_timer_handler};
|
|
|
static int open_dfet = 0;
|
|
|
static int open_dfet_failt = 0;
|
|
|
+static int close_dfet_reson = 0;
|
|
|
void bms_state_init(void){
|
|
|
set_log_level(MOD_STATE, L_debug);
|
|
|
state_debug("BMS System Starting......\n");
|
|
|
@@ -96,7 +97,7 @@ void bms_state_log(void){
|
|
|
state_debug("Sleep Time: %ds\n", get_system_sleep_time());
|
|
|
state_debug("ml5238 cali: %d\n", ml5238_cali_count);
|
|
|
state_debug("ps charger mask:in %d, %d\n", _bms_state.ps_charger_mask, _bms_state.ps_charger_in);
|
|
|
- state_debug("open dfet %d - %d\n", open_dfet, open_dfet_failt);
|
|
|
+ state_debug("open dfet %d - %d - %d\n", open_dfet, open_dfet_failt, close_dfet_reson);
|
|
|
#if 0
|
|
|
state_debug("Charging: %d\n", _bms_state.charging);
|
|
|
state_debug("WorkMode %d\n", _bms_state.work_mode);
|
|
|
@@ -192,6 +193,7 @@ static s32 _process_unheath(void){
|
|
|
charger_open(0); //disable charger mosfet
|
|
|
start_aux_power(0);
|
|
|
_bms_state.charging = 0;
|
|
|
+ close_dfet_reson = 2;
|
|
|
unhealth = (Health_Discharger_Failt | Health_charger_Fault);
|
|
|
}
|
|
|
if (!bms_work_is_normal()){
|
|
|
@@ -220,6 +222,7 @@ static s32 _process_unheath(void){
|
|
|
unhealth |= Health_aux_Fault;
|
|
|
}
|
|
|
discharger_open(0); //disable charger mosfet
|
|
|
+ close_dfet_reson = 3;
|
|
|
unhealth |= Health_Discharger_Failt;
|
|
|
}
|
|
|
|
|
|
@@ -230,6 +233,7 @@ static s32 _process_unheath(void){
|
|
|
unhealth |= Health_Discharger_Failt | Health_aux_Fault;
|
|
|
start_aux_power(0);
|
|
|
if (ml5238_is_discharging()) {
|
|
|
+ close_dfet_reson = 4;
|
|
|
discharger_open(0);
|
|
|
}
|
|
|
}
|
|
|
@@ -237,6 +241,7 @@ static s32 _process_unheath(void){
|
|
|
}
|
|
|
if (bms_health()->over_temp_deny_discharger|| bms_health()->lower_temp_deny_discharger) {
|
|
|
if (!_bms_state.charging) {
|
|
|
+ close_dfet_reson = 5;
|
|
|
discharger_open(0); //disable discharger mosfet
|
|
|
}
|
|
|
unhealth |= (Health_Discharger_Failt | Health_Fault_Can_Sleep);
|
|
|
@@ -383,6 +388,7 @@ static void _process_iostate_changed(s32 unhealth){
|
|
|
bms_set_ps_charger_in(0, 0);
|
|
|
if (ml5238_is_discharging() && (!_bms_state.charging)){
|
|
|
discharger_open(0);
|
|
|
+ close_dfet_reson = 1;
|
|
|
open_dfet = open_dfet_failt = 0; //clear open dfet count
|
|
|
}
|
|
|
if (!AUX_VOL_IS_OPEN()){
|
|
|
@@ -401,8 +407,10 @@ static void _process_iostate_changed(s32 unhealth){
|
|
|
}
|
|
|
if (io_state()->hall_detect){
|
|
|
_bms_state.bms_addr = 0x30 + 1;
|
|
|
+ bms_health()->hall_is_detected = 1;
|
|
|
}else {
|
|
|
_bms_state.bms_addr = 0x30;
|
|
|
+ bms_health()->hall_is_detected = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -423,8 +431,8 @@ static void check_charging(){
|
|
|
int may_error = 0;
|
|
|
if (measure_value()->load_current >= MIN_START_CHARGER_CURRENT) {
|
|
|
if (measure_value()->load_current != measure_value()->current_5238) {
|
|
|
- if (measure_value()->current_5238 < 0.0f) { //cs1180检测到充电电流,5238检测到负电流
|
|
|
- if (++cs1180_may_error_count >= 10) {
|
|
|
+ if (measure_value()->current_5238 <= 0) { //cs1180检测到充电电流,5238检测到负电流
|
|
|
+ if (++cs1180_may_error_count >= _charging_detect.max_count/2) {
|
|
|
measure_value()->load_current = measure_value()->current_5238;
|
|
|
cs1180_adc_shutdown();
|
|
|
cs1180_may_error_count = 0;
|