|
|
@@ -30,7 +30,8 @@ static int pcb_temp_count = 0;
|
|
|
static int ml5238_cali_count = 0;
|
|
|
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;
|
|
|
void bms_state_init(void){
|
|
|
set_log_level(MOD_STATE, L_debug);
|
|
|
state_debug("BMS System Starting......\n");
|
|
|
@@ -94,6 +95,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);
|
|
|
#if 0
|
|
|
state_debug("Charging: %d\n", _bms_state.charging);
|
|
|
state_debug("WorkMode %d\n", _bms_state.work_mode);
|
|
|
@@ -263,27 +265,32 @@ static void _process_user_request(s32 health){
|
|
|
//开关小电
|
|
|
if (_bms_state.user_request & USER_REQUEST_SMALLCURRENT_OFF){
|
|
|
start_aux_power(0);
|
|
|
- }else if (_bms_state.user_request & USER_REQUEST_SMALLCURRENT_ON){
|
|
|
- if ((health & Health_aux_Fault) == 0){
|
|
|
- start_aux_power(1);
|
|
|
- }
|
|
|
}
|
|
|
- //开关放电
|
|
|
+ if (_bms_state.user_request & USER_REQUEST_DISCHARGER_OFF){
|
|
|
+ discharger_open(0);
|
|
|
+ }
|
|
|
if (_bms_state.user_request & USER_REQUEST_CHARGER_OFF){
|
|
|
charger_open(0);
|
|
|
- }else if (_bms_state.user_request & USER_REQUEST_CHARGER_ON){
|
|
|
- if ((health & Health_charger_Fault) == 0){
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_bms_state.user_request & USER_REQUEST_SMALLCURRENT_ON){
|
|
|
+ if (!(health & Health_aux_Fault)){
|
|
|
+ start_aux_power(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (_bms_state.user_request & USER_REQUEST_CHARGER_ON){
|
|
|
+ if (!(health & Health_charger_Fault)){
|
|
|
charger_open(1);
|
|
|
}
|
|
|
}
|
|
|
- //开关充电
|
|
|
- if (_bms_state.user_request & USER_REQUEST_DISCHARGER_OFF){
|
|
|
- discharger_open(0);
|
|
|
- }else if (_bms_state.user_request & USER_REQUEST_DISCHARGER_ON) {
|
|
|
- if ((health & Health_Discharger_Failt) == 0){
|
|
|
+ if (_bms_state.user_request & USER_REQUEST_DISCHARGER_ON) {
|
|
|
+ open_dfet ++;
|
|
|
+ if (!(health & Health_Discharger_Failt)){
|
|
|
discharger_open(1);
|
|
|
+ }else {
|
|
|
+ open_dfet_failt ++;
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
_bms_state.user_request &= ~USER_REQUEST_PENDING;//clear user request pending
|
|
|
}
|
|
|
}
|
|
|
@@ -375,23 +382,18 @@ static int _can_close_mos_no_hall(void){
|
|
|
}
|
|
|
|
|
|
static void _process_iostate_changed(s32 unhealth){
|
|
|
- static u64 _hall_no_time = 0;
|
|
|
if (!(io_state()->hall_detect)&& _can_close_mos_no_hall()){
|
|
|
bms_set_ps_charger_in(0, 0);
|
|
|
- /* 无hall延时2s关大电,确保仪表等负载快速插拔电池能正常,不闪屏 */
|
|
|
- if (shark_get_mseconds() - _hall_no_time >= 2 * 1000) {
|
|
|
- if (ml5238_is_discharging() && (!_bms_state.charging)){
|
|
|
- discharger_open(0);
|
|
|
- }
|
|
|
- if (!AUX_VOL_IS_OPEN()){
|
|
|
- start_aux_power(1);
|
|
|
- }
|
|
|
- if (!io_state()->charger_detect_irq && ml5238_is_charging() && (!_bms_state.charging)){
|
|
|
- charger_open(0);
|
|
|
- }
|
|
|
+ if (ml5238_is_discharging() && (!_bms_state.charging)){
|
|
|
+ discharger_open(0);
|
|
|
+ open_dfet = open_dfet_failt = 0; //clear open dfet count
|
|
|
+ }
|
|
|
+ if (!AUX_VOL_IS_OPEN()){
|
|
|
+ start_aux_power(1);
|
|
|
+ }
|
|
|
+ if (!io_state()->charger_detect_irq && ml5238_is_charging() && (!_bms_state.charging)){
|
|
|
+ charger_open(0);
|
|
|
}
|
|
|
- }else {
|
|
|
- _hall_no_time = shark_get_mseconds();
|
|
|
}
|
|
|
if (io_state()->charger_detect_irq && ((unhealth & Health_charger_Fault) == 0) && (_bms_state.cell_max_vol < SIGLE_CELL_MAX_CHARGER_VOLTAGE)) {
|
|
|
if (!ml5238_is_charging() && shark_uart_timeout()){//不在车上,底座上,充电柜上,检测到充电器插入,自动打开充电,否则的话,只能通过指令来打开充电mos
|