Bläddra i källkod

powerdown等待5s,同时不统计最小容量

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 4 år sedan
förälder
incheckning
67eef019f6

+ 4 - 0
Application/app/sox/health.c

@@ -309,7 +309,11 @@ void check_voltage_state(void) {
 			 * system will power on with powerdown_lower_voltage cleared
 			*/			
 			_health.powerdown_lower_voltage = 1;
+			_health.pd_time = shark_get_seconds();
 		}
+	}else {
+		_health.powerdown_lower_voltage = 0;
+		_health.pd_time = shark_get_seconds();
 	}
 	debug_health();
 }

+ 2 - 1
Application/app/sox/health.h

@@ -48,7 +48,8 @@ typedef struct {
 	uint32_t is_work_temp_normal:1;
 	uint32_t small_current_real_short:1; //ÕæÊµ¶Ì·
 
-	uint8_t    internal_resistance[CELLS_NUM];   //cell's internal resistance
+	uint8_t  internal_resistance[CELLS_NUM];   //cell's internal resistance
+	uint32_t pd_time;
 }bms_health_t;
 
 typedef struct {

+ 1 - 1
Application/app/sox/soc.c

@@ -236,7 +236,7 @@ static __inline__ float _delta_time(void){
 }
 
 static __inline__ int can_modify_min_cap(void){
-	if (ml5238_is_spi_ok() == 0){//如果5238异常,不修改最小容量
+	if (bms_health()->powerdown_lower_voltage){//如果powerdown,先不修改最小容量
 		return 0;
 	}
 	if (shark_get_seconds() > force_full_ts){

+ 10 - 5
Application/app/sox/state.c

@@ -214,9 +214,10 @@ void start_aux_power(int start){
 		health_stop_aux_detect();
 	}
 }
-
+static int system_force_pd = 0;
 void system_power_down(void){
 	bms_health()->powerdown_lower_voltage = 1;
+	system_force_pd = 1;
 	_process_power_down();
 }
 
@@ -349,16 +350,20 @@ int bms_is_reset_befor_pd(void) {
 }
 
 static void _process_power_down(void){
-#if (ALLOW_POWER_DOWN==1)	
+#if (ALLOW_POWER_DOWN==1)
 	if (bms_health()->powerdown_lower_voltage){
-		if (ml5238_is_spi_ok() == 0) {
-			nv_save_all_soc();
-			system_reboot();
+		if (system_force_pd == 0) {
+			ml5238_enable_all_mosfet(0);
+			if (shark_get_seconds() < (bms_health()->pd_time + 5)) {
+				return;
+			}
 		}
 		state_debug("BMS System PowerDown!!\n");
 
 		if (bms_work_is_normal() && soc_update_by_ocv()) {
+			bms_health()->powerdown_lower_voltage = 0;
 			nv_save_all_soc();
+			bms_health()->powerdown_lower_voltage = 1;
 		}
 		
 		shark_uart_flush();

+ 2 - 1
Application/bsp/ml5238.c

@@ -20,13 +20,14 @@ void ml5238_init(void){
 
 int ml5238_is_spi_ok(void) {
 	uint8_t data;
-	int count = 5;
+	int count = 20;
 	while(count-- >= 0) {
 		data = 0;
 		ml5238_read(ML5238_FET, &data);
 		if (data == 0xaa) {
 			return 1;
 		}
+		task_udelay(10);
 	}
 	return 0;
 }