Explorar o código

add ml8238 api, and disable enhance mos driver after 3ms when open
mosfet

Signed-off-by: huhui <huhui@sharkgulf.com>

huhui %!s(int64=4) %!d(string=hai) anos
pai
achega
297fc8d02e
Modificáronse 3 ficheiros con 43 adicións e 3 borrados
  1. 14 2
      Application/app/sox/state.c
  2. 26 0
      Application/bsp/ml5238.c
  3. 3 1
      Application/bsp/ml5238.h

+ 14 - 2
Application/app/sox/state.c

@@ -27,6 +27,7 @@ static u32 _bms_main_task_handler(void);
 static void _debug_timer_handler(shark_timer_t *t);
 static void _process_power_down(void);
 static uint8_t calc_cell_voltage(void);
+static int _can_close_mos_no_hall(void);
 
 static bms_state_t _bms_state;
 static int pcb_temp = 100;
@@ -293,6 +294,7 @@ static s32 _process_unheath(void){
 
 //处理PS100/310/320/360,充电底座,充电柜的指令或者bms自己发给自己的指令
 static void _process_user_request(s32 health){
+	bool mos_drv = false;
 	if (_bms_state.user_request & USER_REQUEST_PENDING){
 		//开关小电
 		if (_bms_state.user_request & USER_REQUEST_SMALLCURRENT_OFF){
@@ -313,17 +315,27 @@ static void _process_user_request(s32 health){
 		}
 		if (_bms_state.user_request & USER_REQUEST_CHARGER_ON){
 			if (!(health & Health_charger_Fault)){
-				charger_open(1);
+				if ((io_state()->hall_detect) || !_can_close_mos_no_hall()){
+					charger_open(1);
+					mos_drv = true;
+				}
 			}
 		}
 		if (_bms_state.user_request & USER_REQUEST_DISCHARGER_ON) {
 			open_dfet ++;
 			if (!(health & Health_Discharger_Failt)){
-				discharger_open(1);
+				if ((io_state()->hall_detect) || !_can_close_mos_no_hall()){
+					discharger_open(1);
+					mos_drv = true;
+				}
 			}else {
 				open_dfet_failt ++;
 			}
 		}
+		if (mos_drv && ml5238_is_mosdrv_strong()) {
+			task_udelay(3000);
+			ml5238_disable_mosdrv();
+		}
 		_bms_state.user_request &= ~USER_REQUEST_PENDING;//clear user request pending
 	}
 }

+ 26 - 0
Application/bsp/ml5238.c

@@ -180,6 +180,32 @@ int ml5238_enable_charger_mosfet(int enable){
 	return -1;
 }
 
+int ml5238_enable_all_mosfet(int enable) {
+	if (enable) {
+		return ml5238_write(ML5238_FET, (FET_CF | FET_DF | FET_DRV));
+	}else {
+		return ml5238_write(ML5238_FET, 0);
+	}
+}
+
+int ml5238_disable_mosdrv(void){
+	
+	uint8_t data;
+	if ((ml5238_read(ML5238_FET, &data) == 0) && (data & FET_DRV)){
+		data &= ~FET_DRV;
+		return ml5238_write(ML5238_FET, data);
+	}
+	return -1;
+}
+
+int ml5238_is_mosdrv_strong(void){
+	
+	uint8_t data = 0xFF;
+	if ((ml5238_read(ML5238_FET, &data) == 0) && (data & FET_DRV)){
+		return 1;
+	}
+	return -1;
+}
 
 int ml5238_short_current_detect(int mode){
 	uint8_t rsense = 0;

+ 3 - 1
Application/bsp/ml5238.h

@@ -19,7 +19,9 @@ int ml5238_is_short_current_enabled(int mode);
 uint8_t ml5238_noop_register_rw(uint8_t data);//ml5238 ¶Áд²âÊÔ
 void ml5238_reg_log(void);
 uint8_t ml5238_read_imon(void);
-
+int ml5238_enable_all_mosfet(int enable);
+int ml5238_disable_mosdrv(void);
+int ml5238_is_mosdrv_strong(void);
 
 typedef void (*ml5238_notify_hander)(int event);
 void ml5238_register_notify_handler(ml5238_notify_hander handler);