Bläddra i källkod

powerdown 之前判断5238是否正常,否则不powerdown和设置最小容量

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

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

@@ -235,7 +235,6 @@ static int _can_powerdown(void){
 
 
 void check_voltage_state(void) {
-	static int no_pd_count = 0;
 	if (bms_state_get()->charging){ //check sigle cell's voltage for charger
 		_health.discharger_shutpower_voltage = 0;
 		_health.sigle_cell_lower_voltage = 0;
@@ -304,7 +303,6 @@ void check_voltage_state(void) {
 
 	/* check for power down */
 	if (_can_powerdown()){
-		no_pd_count = 0;
 		if (judge_debounce(!_health.powerdown_lower_voltage, &_power_down_voltage)) {
 			/*
 			 * no need to clear powerdown(bms is shutdown), when charger insert, 
@@ -312,10 +310,6 @@ void check_voltage_state(void) {
 			*/			
 			_health.powerdown_lower_voltage = 1;
 		}
-	}else {
-		if (no_pd_count ++ == 2) {
-			shark_rtc_set_pd_magic(0);
-		}
 	}
 	debug_health();
 }

+ 4 - 3
Application/app/sox/soc.c

@@ -1,3 +1,4 @@
+#include "bsp/ml5238.h"
 #include "soc.h"
 #include "app/sox/measure.h"
 #include "app/sox/measure_task.h"
@@ -235,6 +236,9 @@ static __inline__ float _delta_time(void){
 }
 
 static __inline__ int can_modify_min_cap(void){
+	if (ml5238_is_spi_ok() == 0){//如果5238异常,不修改最小容量
+		return 0;
+	}
 	if (shark_get_seconds() > force_full_ts){
 		if ((shark_get_seconds() - force_full_ts) > MAX_TIME_FULL_TO_EMPTY) {
 			return 0;
@@ -251,9 +255,6 @@ static void _force_capacity_full(void){
 }
 
 static int _soc_is_under_voltage(void) {
-	if (bms_health()->powerdown_lower_voltage && bms_is_reset_befor_pd()){//如果先做reset处理,不修改最小容量
-		return 0;
-	}
 	return (bms_health()->powerdown_lower_voltage || bms_health()->sigle_cell_lower_voltage || 
 		bms_health()->discharger_lower_voltage);
 }

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

@@ -351,8 +351,7 @@ int bms_is_reset_befor_pd(void) {
 static void _process_power_down(void){
 #if (ALLOW_POWER_DOWN==1)	
 	if (bms_health()->powerdown_lower_voltage){
-		if (shark_rtc_get_pd_magic() != PD_MAGIC) {
-			shark_rtc_set_pd_magic(PD_MAGIC);
+		if (ml5238_is_spi_ok() == 0) {
 			nv_save_all_soc();
 			system_reboot();
 		}

+ 13 - 0
Application/bsp/ml5238.c

@@ -14,9 +14,22 @@ static shark_timer_t irq_task = {.handler = irq_hander_in_timer};
 void ml5238_init(void){
 	spi0_init();
 	ml5238_softreset();
+	ml5238_write(ML5238_NOOP, 0xaa);
 	ml5238_irq_enable(1);
 }
 
+int ml5238_is_spi_ok(void) {
+	uint8_t data;
+	int count = 5;
+	while(count-- >= 0) {
+		data = 0;
+		ml5238_read(ML5238_FET, &data);
+		if (data == 0xaa) {
+			return 1;
+		}
+	}
+	return 0;
+}
 
 uint8_t ml5238_noop_register_rw(uint8_t data){
 	uint8_t value = data;

+ 1 - 0
Application/bsp/ml5238.h

@@ -22,6 +22,7 @@ uint8_t ml5238_read_imon(void);
 int ml5238_enable_all_mosfet(int enable);
 int ml5238_disable_mosdrv(void);
 int ml5238_is_mosdrv_strong(void);
+int ml5238_is_spi_ok(void);
 
 typedef void (*ml5238_notify_hander)(int event);
 void ml5238_register_notify_handler(ml5238_notify_hander handler);