|
|
@@ -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);
|
|
|
}
|
|
|
}
|