فهرست منبع

pcba测试工具测试通过

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 سال پیش
والد
کامیت
716ce7321e

+ 2 - 2
Application/app/nv_storage.c

@@ -30,10 +30,10 @@ int nv_read_write_test(void){
 	AT24CXX_Read(0, data, sizeof(data));
 	for (int i = 0; i < sizeof(data); i++){
 		if (data[i] != 0x5a) {
-			return 0;
+			return 1;
 		}
 	}
-	return 1;
+	return 0;
 }
 
 

+ 46 - 21
Application/app/pcba_test.c

@@ -1,17 +1,28 @@
+#include <string.h>
 #include "bsp/gpio.h"
 #include "bsp/ml5238.h"
 #include "bsp/uart.h"
 #include "bsp/gd32_adc.h"
+#include "bsp/cs1180.h"
 #include "nv_storage.h"
 #include "pcba_test.h"
-
+static void pcba_test_timer_handler(shark_timer_t *timer);
+static shark_timer_t pcba_test_timer = {.handler = pcba_test_timer_handler};
+static int pcba_test_item = -1;
+static int powerdown_flags = 0;
+static void pcba_test_timer_handler(shark_timer_t *timer) {
+	if (pcba_test_item == 1) {
+		UART0_IR_EN(1);
+	}
+	pcba_test_item = -1;
+}
 int pcba_test(uint8_t *data, int len, uint8_t *response){
 	uint8_t *payload = data + 2;
 	int resp_len = 0;
 	response[resp_len ++] = 0xFE;
 	response[resp_len ++] = 0xFE;
 	response[resp_len ++] = 0; //len
-	response[resp_len ++] = payload[0];
+	//response[resp_len ++] = payload[0];
 	response[resp_len ++] = payload[1];
 	uint8_t cmd = payload[1];
 	if (cmd == 0x00) {
@@ -19,17 +30,11 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 	}else if (cmd == 0x01) {
 		response[resp_len ++] = (uint8_t)nv_read_write_test();
 	}else if (cmd == 0x02){
-		int8_t temp;
-		uint8_t result = 0;
 		for (int i = 0; i < PACK_TEMPS_NUM; i++){
-			temp = get_pack_temperature(i);
-			if(!(((temp >= 24) && (temp <= 26))||((temp >= 63) && (temp <= 67)))){
-				result = 1;
-			}
+			response[resp_len ++] = (uint8_t)get_pack_temperature(i) + 40;
 		}
-		response[resp_len ++] = result;
 	}else if (cmd == 0x03) {
-		response[resp_len ++] = 0;
+		response[resp_len ++] = io_state()->aux_lock_detect?0:1;
 	}else if (cmd == 0x04) {
 		LED1_ON(0);
 		LED3_ON(0);
@@ -53,9 +58,10 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 		response[resp_len ++] = 0;
 	}else if (cmd == 0x07) {
 		start_aux_power(1);
+		io_state()->aux_lock_irq = 0;
 		response[resp_len ++] = 0;
 	}else if (cmd == 0x08) {
-		response[resp_len ++] = io_state()->aux_lock_detect;
+		response[resp_len ++] = io_state()->aux_lock_irq;
 	}else if (cmd == 0x09) {
 		start_aux_power(0);
 		response[resp_len ++] = 0;
@@ -81,6 +87,7 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 		discharger_open(1);
 		start_aux_power(0);
 		response[resp_len ++] = 0;
+		powerdown_flags = 0xF;
 		system_power_down();
 	}else if (cmd == 0xf){
 		response[resp_len ++] = !IS_HALL1_DETECTED();
@@ -114,8 +121,8 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 		response[resp_len ++] = aux_power_adc;
 		response[resp_len ++] = aux_power_adc >> 8;		
 	}else if (cmd == 0x13) {
-		shark_uart_deinit(SHARK_UART1);
-		rcu_periph_clock_enable(RCU_GPIOA);
+		//shark_uart_deinit(SHARK_UART1);
+		//rcu_periph_clock_enable(RCU_GPIOA);
 		gpio_mode_output(GPIOA, GPIO_PUPD_NONE, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_2);
 		gpio_mode_input(GPIOA, GPIO_PUPD_NONE, GPIO_PIN_3);
 		gpio_bit_set(GPIOA, GPIO_PIN_2);
@@ -126,21 +133,25 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 	}else if (cmd == 0x14) {
 		UART0_IR_EN(0);
 		response[resp_len ++] = gpio_output_bit_get(GPIOC,GPIO_PIN_14);
+		pcba_test_item = 1;
+		shark_timer_post(&pcba_test_timer, 500);
 	}else if (cmd == 0x15) {
-		UART1_IR_EN(0);
-		response[resp_len ++] = gpio_output_bit_get(GPIOF,GPIO_PIN_0);
+		UART0_IR_EN(1);
+		pcba_test_item = -1;
+		shark_timer_cancel(&pcba_test_timer);
+		response[resp_len ++] = gpio_output_bit_get(GPIOC,GPIO_PIN_14);
 	}else if (cmd == 0x17) {
-		uint16_t vol = 0;
+		uint8_t cell_index = 0;
 		for (int i = 0; i < CELLS_NUM; i++){
 			if (measure_value()->cell_vol[i] > 3000 && measure_value()->cell_vol[i] < 3400) {
-				vol = measure_value()->cell_vol[i];
+				cell_index = i;
 				break;
 			}
 		}
-		response[resp_len ++] = vol;
-		response[resp_len ++] = vol >> 8;	
+		response[resp_len ++] = cell_index;
 	}else if (cmd == 0x18) {
 		uint8_t result = 1;
+		response[resp_len ++] = payload[2];
 		if (payload[2] == 1) {
 			charger_open(1);
 			discharger_open(1);
@@ -150,7 +161,7 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 				result = 0;
 			}
 		}else if (payload[2] == 3) {
-			if (io_state()->aux_lock_detect) {
+			if (bms_health()->load_current_short) {
 				result = 0;
 			}
 		}else if (payload[2] == 4) {
@@ -159,8 +170,22 @@ int pcba_test(uint8_t *data, int len, uint8_t *response){
 			result = 0;			
 		}
 		response[resp_len ++] = result;
+	}else if (cmd == 0x20) {
+		response[resp_len ++] = payload[2];
+		if (payload[2] == 1) {
+			response[resp_len ++] = cs1180_is_ready();
+		}else if (payload[2] == 2) {
+			charger_open(1);
+			discharger_open(1);
+			response[resp_len ++] = 0;
+		}else if (payload[2] == 3) {
+			memcpy(response + resp_len, &measure_value()->load_current, 4);
+			resp_len += 4;
+		}
+	}else if (cmd == 0x21) {
+		response[resp_len ++] = powerdown_flags;
 	}
-	response[2] = resp_len;
+	response[2] = resp_len - 2;
 
 	return resp_len;
 }

+ 1 - 1
Application/app/protocol_old.c

@@ -180,7 +180,7 @@ void protocol_old_recv_frame(uart_enum_t uart_no, uint8_t *data, int len){
 			}
 		}else if (memcmp(data + 4, "ceshi", 5) == 0) {
 			bms_work_mode_set(WORK_MODE_PCBA_TEST, 1);
-			printf("pcba ceshi OK!\n");
+			printf("ceshi success!\n");
 		}
 	}else if (bms_work_is_pcba_test() && data[0] == 0xFE && data[1] == 0xFE){
 		uint8_t response[16];

+ 1 - 0
Application/app/sox/iostate.c

@@ -158,6 +158,7 @@ void small_current_short_irq_handler(void){
 		io_debug("close aux power,cause the short irq\n");
 		return;
 	}
+	_io_state.aux_lock_irq = 1;
 	shark_timer_post(&_small_current_irq_timer, 0);
 	//io_debug("aux lock irq\n");
 }

+ 1 - 0
Application/app/sox/iostate.h

@@ -8,6 +8,7 @@ typedef struct{
 	uint16_t pwr_good_detect:1;
 	uint16_t dcdc_good_detect:1;
 	uint16_t charger_detect_irq:1;
+	uint16_t aux_lock_irq:1; //for pcba test
 }io_state_t;
 
 void io_state_init(void);

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

@@ -65,7 +65,7 @@ int bms_work_is_pcba_test(void){
 }
 
 int bms_work_is_pack_test(void){
-	return _bms_state.work_mode == WORK_MODE_PCBA_TEST;
+	return _bms_state.work_mode == WORK_MODE_PACK_TEST;
 }
 
 int bms_work_is_calibrating(void){
@@ -300,21 +300,25 @@ static void _process_power_down(void){
 	if (bms_health()->powerdown_lower_voltage){
 		state_debug("BMS System PowerDown!!\n");
 
-		if (soc_update_by_ocv()) {
+		if (bms_work_is_normal() && soc_update_by_ocv()) {
 			nv_save_soc();
 		}
 		
 		shark_uart_flush();
-		if (io_state()->charger_detect_irq || io_state()->charger_detect){//have charger, do'nt power down
-			bms_health()->powerdown_lower_voltage = 0;
-			return;
+		if (bms_work_is_normal()) {
+			if (io_state()->charger_detect_irq || io_state()->charger_detect){//have charger, do'nt power down
+				bms_health()->powerdown_lower_voltage = 0;
+				return;
+			}
 		}
 		start_aux_power(0);
 		discharger_open(0);
 		charger_open(0);
 		
 		/*需要等待B-和P-之间的电容放电掉后,才能设置5238 power down,
-		否则5238会触发充电器插入检测,导致重新开机,进入powerdown <->开机的无限循环*/		
+		否则5238会触发充电器插入检测,导致重新开机,进入powerdown <->开机的无限循环*/
+		/* 需要先关闭负载检测,否则充电器检测会分压掉一部分 */
+		ml5238_enable_load_detect(0);
 		ml5238_enable_charger_detect(AUX_VOL_IS_OPEN(), 1);
 		delay_us(2* 1000);
 		u64 wait_start = shark_get_mseconds();