|
|
@@ -48,6 +48,7 @@ static void init_detect_timer(void);
|
|
|
static void load_delect_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;
|
|
|
@@ -118,7 +119,7 @@ static void check_ml5238_state(int event){
|
|
|
static void debug_health(void){
|
|
|
uint32_t *value = (uint32_t *)&_health;
|
|
|
if (*value != 0){
|
|
|
- health_error("health value = 0x%x\n", *value);
|
|
|
+ //health_error("health value = 0x%x\n", *value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -276,32 +277,47 @@ static int _is_low_temp(int8_t *temps){
|
|
|
|
|
|
static uint8_t small_power_detect_count = 0;
|
|
|
static shark_timer_t _aux_lock_timer = {.handler = _aux_lock_timer_handler};
|
|
|
+static shark_timer_t _aux_unlock_timer = {.handler = _aux_unlock_timer_handler};
|
|
|
+
|
|
|
static void _aux_lock_timer_handler(shark_timer_t *t){
|
|
|
- //有可能这个时候,用户发了关小电的指令
|
|
|
- if (bms_state_get()->user_request & USER_REQUEST_SMALLCURRENT_ON){
|
|
|
- AUX_VOL_OPEN(1);
|
|
|
- if (++small_power_detect_count >= 10){
|
|
|
- delay_us(1000);
|
|
|
- //端口电压小于阈值,判断为小电流短路
|
|
|
- if (get_small_current_voltage() < SMALL_CURRENT_MIN_VOLTAGE){//real short
|
|
|
- bms_health()->small_current_short = 1;
|
|
|
- AUX_VOL_OPEN(0);
|
|
|
- small_power_detect_count = 0;
|
|
|
- shark_timer_post( &_aux_lock_timer, 30 * 1000); //30s后再次尝试打开
|
|
|
- }
|
|
|
+ AUX_VOL_OPEN(1);
|
|
|
+ shark_timer_post( &_aux_unlock_timer, 200);
|
|
|
+ health_debug("open aux[re-enable], %lld\n", shark_get_mseconds());
|
|
|
+ if (++small_power_detect_count >= 10){
|
|
|
+ delay_us(1000);
|
|
|
+ //端口电压小于阈值,判断为小电流短路
|
|
|
+ if (get_small_current_voltage() < SMALL_CURRENT_MIN_VOLTAGE){//real short
|
|
|
+ bms_health()->small_current_short = 1;
|
|
|
+ AUX_VOL_OPEN(0);
|
|
|
+ small_power_detect_count = 0;
|
|
|
+ shark_timer_post( &_aux_lock_timer, 30 * 1000); //30s后再次尝试打开
|
|
|
+ shark_timer_cancel(&_aux_unlock_timer);
|
|
|
+ health_debug("set aux short current, and retry after 30s\n");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void _aux_unlock_timer_handler(shark_timer_t *t){
|
|
|
+ if (!io_state()->aux_lock_detect){
|
|
|
+ health_debug("unlock aux detect\n");
|
|
|
+ small_power_detect_count = 0;
|
|
|
+ bms_health()->small_current_short = 0;
|
|
|
+ AUX_VOL_OPEN(1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
void health_process_aux_lock(void){
|
|
|
if (io_state()->aux_lock_detect) {
|
|
|
if (AUX_VOL_IS_OPEN()){
|
|
|
AUX_VOL_OPEN(0);
|
|
|
+ health_debug("close aux[locked], %lld\n", shark_get_mseconds());
|
|
|
shark_timer_post( &_aux_lock_timer, 1);
|
|
|
+ shark_timer_cancel(&_aux_unlock_timer);
|
|
|
}
|
|
|
}else {
|
|
|
- if ((AUX_VOL_IS_OPEN())){
|
|
|
- small_power_detect_count = 0;
|
|
|
+ if (AUX_VOL_IS_OPEN()) {
|
|
|
+ shark_timer_post( &_aux_unlock_timer, 500);
|
|
|
shark_timer_cancel(&_aux_lock_timer);
|
|
|
}
|
|
|
}
|