瀏覽代碼

update uart poll delay

Signed-off-by: FuangCao <cavan.cao@foxmail.com>
FuangCao 5 年之前
父節點
當前提交
022cdcdbd7
共有 7 個文件被更改,包括 39 次插入23 次删除
  1. 1 1
      Project/version.txt
  2. 5 5
      Source/app.c
  3. 3 0
      Source/app_end_ctr.c
  4. 2 4
      Source/app_rs485_1.c
  5. 5 3
      Source/app_rs485_1.h
  6. 22 9
      Source/drv_usart.c
  7. 1 1
      Source/sw_build_info.h

+ 1 - 1
Project/version.txt

@@ -1 +1 @@
-PS100XX_V10_11131114
+PS100XX_V10_11131703

+ 5 - 5
Source/app.c

@@ -111,13 +111,13 @@ shark_bool battery_wait_voltage_parallel(void)
 	u64 time2 = shark_get_time() + 5000;
 	u32 voltage_min, voltage_max;
 
-	if (sub_bms_info_1.connected == CONFIG_LINK_GOOD) {
-		if (sub_bms_info_2.connected == CONFIG_LINK_GOOD) {
+	if (sub_bms_info_1.connected == CONFIG_UART_GOOD) {
+		if (sub_bms_info_2.connected == CONFIG_UART_GOOD) {
 			voltage_max = shark_battery_get_voltage_max();
 		} else {
 			voltage_max = shark_battery_get_voltage1();
 		}
-	} else if (sub_bms_info_2.connected == CONFIG_LINK_GOOD) {
+	} else if (sub_bms_info_2.connected == CONFIG_UART_GOOD) {
 		voltage_max = shark_battery_get_voltage2();
 	} else {
 		return shark_false;
@@ -152,11 +152,11 @@ shark_bool battery_wait_voltage_series(u32 voltage_min)
 {
 	u64 time = shark_get_time() + 1000;
 
-	if (sub_bms_info_1.connected != CONFIG_LINK_GOOD) {
+	if (sub_bms_info_1.connected != CONFIG_UART_GOOD) {
 		return shark_false;
 	}
 
-	if (sub_bms_info_1.connected != CONFIG_LINK_GOOD) {
+	if (sub_bms_info_1.connected != CONFIG_UART_GOOD) {
 		return shark_false;
 	}
 

+ 3 - 0
Source/app_end_ctr.c

@@ -526,10 +526,13 @@ int8_t Rsp_Can_Ctr_CMD(CAN_FRAME*can_ctr_frame)
 					break;
 				case 6:
 					buf[len++] = cb_operate_state;
+					buf[len++] = sub_bms_info_1.err_times;
+					buf[len++] = sub_bms_info_2.err_times;
 					buf[len++] = sub_bms_info_1.connected;
 					buf[len++] = sub_bms_info_2.connected;
 					buf[len++] = sub_bms_info_1.exit_code;
 					buf[len++] = sub_bms_info_2.exit_code;
+					sub_bms_info_1.err_times = sub_bms_info_2.err_times = 0;
 					sub_bms_info_1.exit_code = sub_bms_info_2.exit_code = SHARK_BATT_EXIT_SUCCESS;
 					break;
 				case 7:

+ 2 - 4
Source/app_rs485_1.c

@@ -79,7 +79,7 @@ static int8_t Handle_Sub_BMS_CMD_1(SUB_BMS_INFO *info, const u8 *buff, u8 length
 			break;
 		}
 
-		info->connected = CONFIG_LINK_GOOD;
+		info->connected = CONFIG_UART_GOOD;
 		info->send_state = SHARK_SEND_SUCCESS;
 
 		//handle frame
@@ -284,8 +284,6 @@ shark_bool shark_battery_send_command(SUB_BMS_INFO *info)
 	}
 
 	info->send_state = SHARK_SEND_PENDING;
-	info->poll_ticks = 0;
-	info->tx_busy = 100;
 	shark_uart_write(info, body->size);
 
 	return shark_true;
@@ -474,7 +472,7 @@ static void shark_battery_set_power_param(SUB_BMS_INFO *info, shark_battery_powe
 
 shark_battery_power_t shark_battery_get_power(SUB_BMS_INFO *info)
 {
-	if (info->connected != CONFIG_LINK_GOOD) {
+	if (info->connected != CONFIG_UART_GOOD) {
 		return SHARK_BATT_POWER_FAULT;
 	}
 

+ 5 - 3
Source/app_rs485_1.h

@@ -3,7 +3,9 @@
 
 #define CONFIG_TX_BUFF_SIZE		256
 #define CONFIG_RX_BUFF_SIZE		256
-#define CONFIG_LINK_GOOD		5
+#define CONFIG_UART_GOOD		12
+#define CONFIG_UART_TIMEOUT		100
+#define CONFIG_UART_POLL_DELAY	500
 
 enum
 {
@@ -199,6 +201,7 @@ typedef struct
 	u32 uart;
 	u8 address;
 	u8 connected;
+	u8 err_times;
 	shark_bool used;
 	shark_send_state_t send_state;
 	shark_battery_exit_t exit_code;
@@ -209,10 +212,9 @@ typedef struct
 	u16 rx_length;
 	u16 tx_length;
 	u16 tx_index;
-	u16 poll_ticks;
 
-	shark_bool poll_pending;
 	shark_bool rx_pending;
+	shark_bool tx_pending;
 	u8 rx_busy;
 	u8 tx_busy;
 

+ 22 - 9
Source/drv_usart.c

@@ -2,6 +2,9 @@
 #include "app_rs485_1.h"
 #include "app_can.h"
 
+static u16 shark_uart_poll_ticks;
+static u8 shark_uart_poll_index;
+
 static void shark_uart_gpio_init(void)
 {
 	/* enable GPIO clock */
@@ -93,6 +96,7 @@ void shark_uart_write(SUB_BMS_INFO *info, u16 size)
 {
 	info->tx_index = 0;
 	info->tx_length = size;
+	info->tx_busy = CONFIG_UART_TIMEOUT;
 	usart_interrupt_enable(info->uart, USART_INT_TC);
 }
 
@@ -139,27 +143,36 @@ static void shark_uart_tick_raw(SUB_BMS_INFO *info)
 			info->tx_busy--;
 		} else {
 			info->send_state = SHARK_SEND_TIMEOUT;
+			info->err_times++;
 
 			if (info->connected > 0) {
 				if (info->connected > 1) {
 					info->connected--;
-					info->poll_pending = shark_true;
+					info->tx_pending = shark_true;
 				} else {
 					info->connected = 0;
 					shark_uart_disconnect(info);
 				}
 			}
 		}
-	} else if (info->poll_ticks < 500) {
-		info->poll_ticks++;
-	} else {
-		info->poll_ticks = 0;
-		info->poll_pending = shark_true;
 	}
 }
 
 void shark_uart_tick(void)
 {
+	if (shark_uart_poll_ticks < (CONFIG_UART_POLL_DELAY / 2)) {
+		shark_uart_poll_ticks++;
+	} else {
+		shark_uart_poll_ticks = 0;
+		shark_uart_poll_index++;
+
+		if ((shark_uart_poll_index & 1) == 0) {
+			sub_bms_info_1.tx_pending = shark_true;
+		} else {
+			sub_bms_info_2.tx_pending = shark_true;
+		}
+	}
+
 	shark_uart_tick_raw(&sub_bms_info_1);
 	shark_uart_tick_raw(&sub_bms_info_2);
 }
@@ -172,10 +185,10 @@ void shark_uart_poll_raw(SUB_BMS_INFO *info)
 		info->rx_length = 0;
 	}
 
-	if (info->poll_pending) {
-		info->poll_pending = shark_false;
+	if (info->tx_pending) {
+		info->tx_pending = shark_false;
 
-		if (shark_battery_switch_busy == shark_false) {
+		if (!shark_battery_switch_busy) {
 			shark_battery_send_command(info);
 		}
 	}

+ 1 - 1
Source/sw_build_info.h

@@ -1,3 +1,3 @@
 #pragma once
 
-#define CONFIG_VERSION "PS100XX_V10_11131114"
+#define CONFIG_VERSION "PS100XX_V10_11131703"