|
|
@@ -30,9 +30,6 @@ 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 u64 open_dfet_time = 0;
|
|
|
-static u64 close_dfet_time = 0;
|
|
|
-
|
|
|
void bms_state_init(void){
|
|
|
set_log_level(MOD_STATE, L_debug);
|
|
|
state_debug("BMS System Starting......\n");
|
|
|
@@ -86,11 +83,16 @@ int bms_work_mode_set(int mode, int start){
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+void bms_set_ps_charger_in(uint16_t mask, uint16_t in){
|
|
|
+ _bms_state.ps_charger_in = in;
|
|
|
+ _bms_state.ps_charger_mask = mask;
|
|
|
+}
|
|
|
+
|
|
|
void bms_state_log(void){
|
|
|
state_debug("Life Time: %d\n", shark_get_seconds());
|
|
|
state_debug("Sleep Time: %ds\n", get_system_sleep_time());
|
|
|
state_debug("ml5238 cali: %d\n", ml5238_cali_count);
|
|
|
- state_debug("open/close dfet %lld, %lld\n", open_dfet_time, close_dfet_time);
|
|
|
+ state_debug("ps charger mask:in %d, %d\n", _bms_state.ps_charger_mask, _bms_state.ps_charger_in);
|
|
|
#if 0
|
|
|
state_debug("Charging: %d\n", _bms_state.charging);
|
|
|
state_debug("WorkMode %d\n", _bms_state.work_mode);
|
|
|
@@ -188,11 +190,17 @@ static s32 _process_unheath(void){
|
|
|
}
|
|
|
if (bms_health()->charger_over_current || bms_health()->charger_over_temp || bms_health()->charger_lower_temp ||
|
|
|
bms_health()->charger_over_voltage || bms_health()->sigle_cell_over_voltage){
|
|
|
- charger_open(0); //disable charger mosfet
|
|
|
- unhealth |= Health_charger_Fault;
|
|
|
+ if (_bms_state.ps_charger_mask && !_bms_state.ps_charger_in){
|
|
|
+
|
|
|
+ }else {
|
|
|
+ charger_open(0); //disable charger mosfet
|
|
|
+ unhealth |= Health_charger_Fault;
|
|
|
+ }
|
|
|
}
|
|
|
if (bms_health()->over_temp_deny_charger|| bms_health()->lower_temp_deny_charger) {
|
|
|
- if (_bms_state.charging) {
|
|
|
+ if (_bms_state.ps_charger_mask && !_bms_state.ps_charger_in){
|
|
|
+
|
|
|
+ }else if (_bms_state.charging) {
|
|
|
charger_open(0); //disable charger mosfet
|
|
|
unhealth |= Health_charger_Fault;
|
|
|
}
|
|
|
@@ -250,7 +258,6 @@ static void _process_user_request(s32 health){
|
|
|
}else if (_bms_state.user_request & USER_REQUEST_DISCHARGER_ON) {
|
|
|
if ((health & Health_Discharger_Failt) == 0){
|
|
|
discharger_open(1);
|
|
|
- open_dfet_time = shark_get_seconds();
|
|
|
}
|
|
|
}
|
|
|
_bms_state.user_request &= ~USER_REQUEST_PENDING;//clear user request pending
|
|
|
@@ -346,7 +353,6 @@ static void _process_iostate_changed(s32 unhealth){
|
|
|
if (!(io_state()->hall_detect)&& _can_close_mos_no_hall()){
|
|
|
if (ml5238_is_discharging() && (!_bms_state.charging)){
|
|
|
discharger_open(0);
|
|
|
- close_dfet_time = shark_get_seconds();
|
|
|
}
|
|
|
if (!AUX_VOL_IS_OPEN()){
|
|
|
start_aux_power(1);
|
|
|
@@ -354,6 +360,7 @@ static void _process_iostate_changed(s32 unhealth){
|
|
|
if (!io_state()->charger_detect_irq && ml5238_is_charging() && (!_bms_state.charging)){
|
|
|
charger_open(0);
|
|
|
}
|
|
|
+ bms_set_ps_charger_in(0, 0);
|
|
|
}
|
|
|
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
|