备份,通过读取uart的接受标志位来判定通讯断开,恢复通讯
This commit is contained in:
parent
9e44135a34
commit
a54ae53b95
|
@ -23,7 +23,8 @@
|
||||||
#define __MAIN_H
|
#define __MAIN_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
@ -40,17 +41,17 @@ extern "C" {
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN ET */
|
/* USER CODE BEGIN ET */
|
||||||
extern uint8_t tcp_echo_flags_hart1; // æ ‡å¿—ä½<C3A4>,连接æˆ<C3A6>功ç½?1
|
extern uint8_t tcp_echo_flags_hart1;
|
||||||
extern uint8_t tcp_echo_flags_hart2; // æ ‡å¿—ä½<C3A4>,连接æˆ<C3A6>功ç½?1
|
extern uint8_t tcp_echo_flags_hart2;
|
||||||
extern uint8_t tcp_echo_flags_ble1;
|
extern uint8_t tcp_echo_flags_ble1;
|
||||||
extern uint8_t tcp_echo_flags_ble2;
|
extern uint8_t tcp_echo_flags_ble2;
|
||||||
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
|
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t rx_num; // 接收到数æ<C2B0>®ä¸ªæ•?
|
uint16_t rx_num;
|
||||||
uint8_t rx_data[512]; // 接收到数æ<C2B0>®åŒº
|
uint8_t rx_data[512];
|
||||||
uint8_t rx_data_temp[512]; // 接收到数æ<C2B0>®ç¼“冲区
|
uint8_t rx_data_temp[512];
|
||||||
uint8_t tx_data[512]; // å<>‘é?<3F>æ•°æ<C2B0>®åŒº
|
uint8_t tx_data[512];
|
||||||
} uart_t;
|
} uart_t;
|
||||||
|
|
||||||
extern uart_t lcd_uart4;
|
extern uart_t lcd_uart4;
|
||||||
|
@ -70,20 +71,20 @@ extern uart_t hart2_uart2;
|
||||||
|
|
||||||
#define LOCAL_PORT 5001
|
#define LOCAL_PORT 5001
|
||||||
|
|
||||||
/* USER CODE END ET */
|
/* USER CODE END ET */
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EC */
|
/* USER CODE BEGIN EC */
|
||||||
|
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EM */
|
/* USER CODE BEGIN EM */
|
||||||
|
|
||||||
/* USER CODE END EM */
|
/* USER CODE END EM */
|
||||||
|
|
||||||
/* Exported functions prototypes ---------------------------------------------*/
|
/* Exported functions prototypes ---------------------------------------------*/
|
||||||
void Error_Handler(void);
|
void Error_Handler(void);
|
||||||
|
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
||||||
|
@ -170,7 +171,7 @@ void Error_Handler(void);
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
#define TRUE 0
|
#define TRUE 0
|
||||||
#define FAIL -1
|
#define FAIL -1
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
#include "dac161s997.h"
|
#include "dac161s997.h"
|
||||||
#include "ad7124.h"
|
#include "ad7124.h"
|
||||||
|
#include "usart.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
@ -36,7 +37,7 @@
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN PD */
|
/* USER CODE BEGIN PD */
|
||||||
|
// extern UART_HandleTypeDef huart5;
|
||||||
/* USER CODE END PD */
|
/* USER CODE END PD */
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
@ -147,8 +148,20 @@ void start_tcp_task(void const *argument)
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
osThreadTerminate(NULL);
|
// osThreadTerminate(NULL);
|
||||||
osDelay(1);
|
// if (tcp_send_flags_hart1 == 1)
|
||||||
|
// {
|
||||||
|
// user_send_data_hart1(hart1_uart5.rx_data, hart1_uart5.rx_num);
|
||||||
|
// tcp_send_flags_hart1 = 0;
|
||||||
|
// }
|
||||||
|
// if (tcp_send_flags_hart2 == 1)
|
||||||
|
// {
|
||||||
|
// user_send_data_hart2(hart2_uart2.rx_data, hart2_uart2.rx_num);
|
||||||
|
// tcp_send_flags_hart2 = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
vTaskDelay(1);
|
||||||
|
// osDelay(1);
|
||||||
}
|
}
|
||||||
/* USER CODE END start_tcp_task */
|
/* USER CODE END start_tcp_task */
|
||||||
}
|
}
|
||||||
|
@ -167,7 +180,7 @@ void start_led_toggle_task(void const *argument)
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin);
|
HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin);
|
||||||
vTaskDelay(1000);
|
vTaskDelay(500);
|
||||||
}
|
}
|
||||||
/* USER CODE END start_led_toggle_task */
|
/* USER CODE END start_led_toggle_task */
|
||||||
}
|
}
|
||||||
|
@ -188,7 +201,7 @@ void start_dac_task(void const *argument)
|
||||||
{
|
{
|
||||||
dac161s997_output(DAC161S997_1, 12.0f);
|
dac161s997_output(DAC161S997_1, 12.0f);
|
||||||
dac161s997_output(DAC161S997_2, 12.0f);
|
dac161s997_output(DAC161S997_2, 12.0f);
|
||||||
vTaskDelay(200);
|
vTaskDelay(100);
|
||||||
}
|
}
|
||||||
/* USER CODE END start_dac_task */
|
/* USER CODE END start_dac_task */
|
||||||
}
|
}
|
||||||
|
@ -208,6 +221,14 @@ void start_adc_task(void const *argument)
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
ad7124_get_analog(STOP_NC_ADC);
|
ad7124_get_analog(STOP_NC_ADC);
|
||||||
|
if (huart5.RxState == HAL_UART_STATE_READY)
|
||||||
|
{
|
||||||
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
|
||||||
|
}
|
||||||
|
if (huart2.RxState == HAL_UART_STATE_READY)
|
||||||
|
{
|
||||||
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
|
||||||
|
}
|
||||||
vTaskDelay(1000);
|
vTaskDelay(1000);
|
||||||
}
|
}
|
||||||
/* USER CODE END start_adc_task */
|
/* USER CODE END start_adc_task */
|
||||||
|
|
|
@ -71,10 +71,12 @@ uart_t ble2_uart3 = {0};
|
||||||
uart_t hart2_uart2 = {0};
|
uart_t hart2_uart2 = {0};
|
||||||
uart_t hart1_uart5 = {0};
|
uart_t hart1_uart5 = {0};
|
||||||
float current_buff[2] = {12.0f, 12.0f};
|
float current_buff[2] = {12.0f, 12.0f};
|
||||||
|
|
||||||
uint8_t tcp_echo_flags_hart1 = 0;
|
uint8_t tcp_echo_flags_hart1 = 0;
|
||||||
uint8_t tcp_echo_flags_hart2 = 0;
|
uint8_t tcp_echo_flags_hart2 = 0;
|
||||||
uint8_t tcp_echo_flags_ble1 = 0;
|
uint8_t tcp_echo_flags_ble1 = 0;
|
||||||
uint8_t tcp_echo_flags_ble2 = 0;
|
uint8_t tcp_echo_flags_ble2 = 0;
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,6 +225,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||||
memcpy(hart1_uart5.rx_data, hart1_uart5.rx_data_temp, Size);
|
memcpy(hart1_uart5.rx_data, hart1_uart5.rx_data_temp, Size);
|
||||||
if (tcp_echo_flags_hart1 == 1)
|
if (tcp_echo_flags_hart1 == 1)
|
||||||
{
|
{
|
||||||
|
// tcp_send_flags_hart1 = 1;
|
||||||
user_send_data_hart1(hart1_uart5.rx_data, Size);
|
user_send_data_hart1(hart1_uart5.rx_data, Size);
|
||||||
}
|
}
|
||||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
|
||||||
|
@ -235,6 +238,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||||
memcpy(hart2_uart2.rx_data, hart2_uart2.rx_data_temp, Size);
|
memcpy(hart2_uart2.rx_data, hart2_uart2.rx_data_temp, Size);
|
||||||
if (tcp_echo_flags_hart2 == 1)
|
if (tcp_echo_flags_hart2 == 1)
|
||||||
{
|
{
|
||||||
|
// tcp_send_flags_hart2 = 1;
|
||||||
user_send_data_hart2(hart2_uart2.rx_data, Size);
|
user_send_data_hart2(hart2_uart2.rx_data, Size);
|
||||||
}
|
}
|
||||||
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
|
||||||
|
@ -283,10 +287,10 @@ void Error_Handler(void)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
__disable_irq();
|
// __disable_irq();
|
||||||
while (1)
|
// while (1)
|
||||||
{
|
// {
|
||||||
}
|
// }
|
||||||
/* USER CODE END Error_Handler_Debug */
|
/* USER CODE END Error_Handler_Debug */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
|
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
#include "ht1200m.h"
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
UART_HandleTypeDef huart4;
|
UART_HandleTypeDef huart4;
|
||||||
|
|
|
@ -225,6 +225,11 @@
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>osThread(lwip_task)</ItemText>
|
<ItemText>osThread(lwip_task)</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>15</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>hart1_uart5</ItemText>
|
||||||
|
</Ww>
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
<MemoryWindow1>
|
<MemoryWindow1>
|
||||||
<Mm>
|
<Mm>
|
||||||
|
|
|
@ -19,6 +19,7 @@ extern uint8_t tcp_echo_flags_hart1;
|
||||||
extern uint8_t tcp_echo_flags_hart2;
|
extern uint8_t tcp_echo_flags_hart2;
|
||||||
extern uint8_t tcp_echo_flags_ble1;
|
extern uint8_t tcp_echo_flags_ble1;
|
||||||
extern uint8_t tcp_echo_flags_ble2;
|
extern uint8_t tcp_echo_flags_ble2;
|
||||||
|
|
||||||
/*接收回调函数*/
|
/*接收回调函数*/
|
||||||
static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||||
{ // 对应接收数据连接的控制块 接收到的数据
|
{ // 对应接收数据连接的控制块 接收到的数据
|
||||||
|
|
Loading…
Reference in New Issue