Просмотр исходного кода

1. uart还原使用dma
2. 如果霍尔在,但是uart上3s内收不到任何完整的frame,重新初始化串口
3. 加入uart的debug信息

Signed-off-by: huhui <huhui@sharkgulf.com>

huhui 4 лет назад
Родитель
Сommit
5084a9e7f6

+ 7 - 0
Application/app/protocol.c

@@ -11,6 +11,10 @@ void protocol_send_bms_info(uint8_t dest, uint8_t key, uint8_t *data, int len){
 	can_frame_t can_frame;
 	CAN_OUT(&(can_frame.head), dest);
 	can_frame.key = key;
+#if (CONFIG_BOARD_TYPE==SHARK_BOARD_SP700)
+	u8 dumy_bytes[2] = {0xaa, 0xaa}; //ÈúìÍâÕý³£	
+	shark_uart_write_bytes(current_uart, dumy_bytes, sizeof(dumy_bytes));
+#endif
 	shark_uart_frame_start(current_uart, (uint8_t *)&can_frame, sizeof(can_frame));
 	shark_uart_frame_continue(current_uart, data, len);
 	shark_uart_frame_end(current_uart);	
@@ -54,6 +58,7 @@ void protocol_notify_old_frame(uart_enum_t uart_no){
 	shark_uart_write_bytes(current_uart, (uint8_t *)&head, head.size);
 }
 extern u32 uart_new_prot;
+extern u64 uart_frame_time;
 void protocol_recv_frame(uart_enum_t uart_no, uint8_t *data, int len){
 	current_uart = uart_no;
 	if (len < sizeof(can_frame_t)){
@@ -66,6 +71,8 @@ void protocol_recv_frame(uart_enum_t uart_no, uint8_t *data, int len){
 		return;
 	}
 	uart_new_prot++;
+	uart_frame_time = shark_get_mseconds();
+
 	len -= sizeof(can_frame_t);
 	if (can_frame->key >= CAN_KEY_IAP_ENTER){
 		process_iap_message(can_frame, len);

+ 2 - 0
Application/app/protocol_old.c

@@ -120,6 +120,7 @@ static int get_response_data(uint8_t *data, uint8_t operate, uint8_t result){
 }
 
 extern u32 uart_old_prot;
+extern u64 uart_frame_time;
 static int protocol_old_process_binary(uart_enum_t uart_no, uint8_t *data, int len){
 	current_uart = uart_no;
 	comm_head_t *head = (comm_head_t *)data;
@@ -132,6 +133,7 @@ static int protocol_old_process_binary(uart_enum_t uart_no, uint8_t *data, int l
 		return -1;
 	}
 	uart_old_prot ++;
+	uart_frame_time = shark_get_mseconds();
 	data = head->data;
 	data += 6;
 	uint8_t operate = data[0];

+ 21 - 0
Application/app/sox/state.c

@@ -40,6 +40,8 @@ static int close_dfet_reson = 0;
 static int close_dfet_no_hall = 0;
 static int no_hall_time[5];
 static int no_hall_count = 0;
+u64 uart_frame_time = 0;
+static u32 uart_reinit_count = 0;
 
 static void put_no_hall_time(void){
 	no_hall_time[no_hall_count] = shark_get_seconds();
@@ -69,6 +71,8 @@ void bms_state_init(void){
 
 	pcb_temp = measure_value()->pack_temp[PCB_TEMP_INDEX];
 
+	uart_frame_time = shark_get_mseconds();
+
 	set_log_all(L_disable);
 }
 
@@ -404,6 +408,7 @@ static void _process_deepsleep(s32 health){
 	mcu_enter_deepsleep();
 	soc_update_for_deepsleep(mcu_get_sleeptime());//²¹³¥ÐÝÃߵŦºÄ
 	_sleep_time = shark_get_mseconds();
+	uart_frame_time = shark_get_mseconds();
 #endif	
 }
 
@@ -447,12 +452,28 @@ static void _process_iostate_changed(s32 unhealth){
 	}
 }
 
+static void _bms_uart_workaround(void) {
+	if (io_state()->hall_detect != 1){
+		return;
+	}
+	if (shark_get_mseconds() >= (uart_frame_time + 3000)){
+		UART0_IR_EN(0);
+		UART1_IR_EN(0);
+		task_udelay(50 * 1000);
+		UART0_IR_EN(1);
+		UART1_IR_EN(1);
+		uart_reinit_count++;
+		uart_frame_time = shark_get_mseconds();
+	}
+}
+
 static u32 _bms_main_task_handler(void){
 	s32 unhealth = _process_unheath();
 	_process_user_request(unhealth);
 	_process_deepsleep(unhealth);
 	_process_power_down();
 	_process_iostate_changed(unhealth);
+	_bms_uart_workaround();
 	return 0;
 }
 

+ 1 - 1
Application/bsp/uart.c

@@ -40,7 +40,7 @@
 #define SHARK_UART1_rx_dma_clk			RCU_DMA
 
 // ================================================================================
-#define ENABLE_RX_DMA 0
+#define ENABLE_RX_DMA 1
 
 static u8 shark_uart0_tx_cache[SHARK_UART_TX_MEM_SIZE];
 #if UART_NUM==2

+ 2 - 2
Application/bsp/uart.h

@@ -11,8 +11,8 @@
 #define CH_ESC_END						0x06
 #define CH_ESC_ESC						0x07
 
-#define SHARK_UART_TX_MEM_SIZE			384
-#define SHARK_UART_RX_MEM_SIZE			384
+#define SHARK_UART_TX_MEM_SIZE			512
+#define SHARK_UART_RX_MEM_SIZE			512
 #define RX_FRAME_MAX_LEN 260
 #define RX_OLD_FRAME_MAX_LEN 256