Преглед изворни кода

修改iostate的状态检测,有hall的检测很宽容,无霍尔的检测相对严格

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui пре 5 година
родитељ
комит
69b086aa36
1 измењених фајлова са 21 додато и 6 уклоњено
  1. 21 6
      Application/app/sox/iostate.c

+ 21 - 6
Application/app/sox/iostate.c

@@ -5,22 +5,26 @@
 #include "health.h"
 #include "iostate.h"
 
+extern void bms_message_update_insert(int is_hall_detect);
+
 static io_state_t _io_state;
 
 typedef struct io_timer{
 	shark_timer_t _timer;
 	u16           detect_cnt;
 	u8            value;
+	u16           debounce_time_zero;
+	u16           debounce_time_one;
 }io_timer_t;
 
 #define io_detect_intv_time 1
 #define io_debounce_time 50
 
 static void io_timer_handler(shark_timer_t *t);
-static io_timer_t hall_io = {._timer.handler = io_timer_handler};
-static io_timer_t charger_io = {._timer.handler = io_timer_handler};
-static io_timer_t aux_short_io = {._timer.handler = io_timer_handler};
-static io_timer_t dcdc_pwr_io = {._timer.handler = io_timer_handler};
+static io_timer_t hall_io = {._timer.handler = io_timer_handler, .debounce_time_zero = 1000, .debounce_time_one = 2};
+static io_timer_t charger_io = {._timer.handler = io_timer_handler, .debounce_time_zero = 50, .debounce_time_one = 50};
+static io_timer_t aux_short_io = {._timer.handler = io_timer_handler, .debounce_time_zero = 50, .debounce_time_one = 50};
+static io_timer_t dcdc_pwr_io = {._timer.handler = io_timer_handler, .debounce_time_zero = 50, .debounce_time_one = 50};
 
 static void debug_io(void){
 	uint16_t *io = (uint16_t *)&_io_state;
@@ -40,6 +44,8 @@ void io_state_init(void){
 	shark_timer_post(&dcdc_pwr_io._timer, io_detect_intv_time);
 
 	small_current_short_irq_enable(1);
+
+	bms_message_update_insert(_io_state.hall_detect);
 	
 	debug_io();
 }
@@ -97,7 +103,13 @@ static void _set_io_value(io_timer_t *t){
 	debug_io();
 }
 
-
+static int _debounce_time_reach(io_timer_t *t){
+	u16 debounce_time = t->debounce_time_one;
+	if (t->value == 0){
+		debounce_time = t->debounce_time_zero;
+	}
+	return t->detect_cnt >= debounce_time;
+}
 static void io_timer_handler(shark_timer_t *t){
 	io_timer_t *io_t = (io_timer_t *)t;
 	int aux_lock_changed = 0;
@@ -107,13 +119,16 @@ static void io_timer_handler(shark_timer_t *t){
 		io_t->value = _get_io_value(io_t);
 		io_t->detect_cnt = 0;
 	}
-	if (io_t->detect_cnt >= io_debounce_time){
+	if (_debounce_time_reach(io_t)){
 		io_t->detect_cnt = 0;
 		if (_get_cached_value(io_t) != io_t->value) {
 			_set_io_value(io_t);
 			if (io_t == &aux_short_io){
 				aux_lock_changed = 1;
 			}
+			if (io_t == &hall_io){
+				bms_message_update_insert(_io_state.hall_detect);
+			}
 		}
 	}
 	shark_timer_post(t, io_detect_intv_time);