Pārlūkot izejas kodu

负载移除1分钟后,清除短路标志,可以重新打开大电

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 gadi atpakaļ
vecāks
revīzija
f78071ac3f
1 mainītis faili ar 11 papildinājumiem un 16 dzēšanām
  1. 11 16
      Application/app/sox/health.c

+ 11 - 16
Application/app/sox/health.c

@@ -43,18 +43,19 @@ static float min_discharger_pdown_cell_vol[] = {1900, 2200};
 
 /* health 模块,只检测状态,不做任何控制,如果有异常情况,控制中心会统一处理  */
 static void check_ml5238_state(int event);
-static void init_detect_timer(void);
-static void load_delect_handler(shark_timer_t *timer);
+static void load_detect_handler(shark_timer_t *timer);
+static void clear_short_current_handler(shark_timer_t *timer);
 static void charger_detect_handler(shark_timer_t *timer);
 static void _aux_lock_timer_handler(shark_timer_t *t);
 static void _aux_unlock_timer_handler(shark_timer_t *t);
+
 static bms_health_t _health;
-static debounce_timer_t _load_detect_timer;
-static debounce_timer_t _charger_detect_timer;
+static debounce_timer_t _load_detect_timer = {.max_count = 100, .interval = 10, ._timer.handler = load_detect_handler};
+static debounce_timer_t _charger_detect_timer = {.max_count = 500, .interval = 10, ._timer.handler = charger_detect_handler};
+static shark_timer_t _clear_short_current_timer = {.handler = clear_short_current_handler};
 void health_init(void){
 	/* 5238如果有异常情况,比如短路,负载移除,通过这个handler上报 */
 	ml5238_register_notify_handler(check_ml5238_state);
-	init_detect_timer();
 	set_log_level(MOD_HEALTH, L_debug);
 	for (int i = 0; i < CELLS_NUM; i++){
 		_health.internal_resistance[i] = 5;//毫欧,暂时用一个固定数据,后期需要计算R0=(U2-U1)/(I1-I2) - R1(R1为电路上的等效电阻+采样电阻)
@@ -66,27 +67,21 @@ bms_health_t *bms_health(){
 	return &_health;
 }
 
-static void init_detect_timer(void){
-	_load_detect_timer._timer.handler = load_delect_handler;
-	_load_detect_timer.max_count = 100;
-	_load_detect_timer.interval = 10;
-
-	_charger_detect_timer._timer.handler = charger_detect_handler;
-	_charger_detect_timer.max_count = 500;
-	_charger_detect_timer.interval = 10;	
+static void clear_short_current_handler(shark_timer_t *timer){
+	_health.load_current_short = 0; //负载移除,clear load current short
 }
 
-static void load_delect_handler(shark_timer_t *timer){
+static void load_detect_handler(shark_timer_t *timer){
 	if (ml5238_is_load_disconnect()){
 		_load_detect_timer.count ++;
 	}else {
 		_load_detect_timer.count = 0;
 	}
 	if (_load_detect_timer.count >= _load_detect_timer.max_count) {
-		_health.load_current_short = 0; //负载移除,clear load current short
 		ml5238_enable_load_detect(0);
+		shark_timer_post(&_clear_short_current_timer, 60 * 1000); //负载移除1分钟后,清除current short flags, can open discharger again
 		health_debug("load disconnect\n");
-	}else {		
+	}else {
 		shark_timer_post(&_load_detect_timer._timer, _load_detect_timer.interval);
 	}
 }