开通所有HART透传端口

This commit is contained in:
王绪洁 2025-04-07 19:23:09 +08:00
parent bca6e9342e
commit 61d4c005c7
13 changed files with 5505 additions and 5088 deletions

View File

@ -64,7 +64,7 @@
#define configTICK_RATE_HZ ((TickType_t)1000) #define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 32 ) #define configMAX_PRIORITIES ( 32 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128) #define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)15360) #define configTOTAL_HEAP_SIZE ((size_t)65536)
#define configMAX_TASK_NAME_LEN ( 24 ) #define configMAX_TASK_NAME_LEN ( 24 )
#define configUSE_16_BIT_TICKS 0 #define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1 #define configUSE_MUTEXES 1

View File

@ -86,8 +86,7 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackTyp
* @param None * @param None
* @retval None * @retval None
*/ */
void MX_FREERTOS_Init(void) void MX_FREERTOS_Init(void) {
{
/* USER CODE BEGIN Init */ /* USER CODE BEGIN Init */
/* USER CODE END Init */ /* USER CODE END Init */
@ -110,7 +109,7 @@ void MX_FREERTOS_Init(void)
/* Create the thread(s) */ /* Create the thread(s) */
/* definition and creation of lwip_task */ /* definition and creation of lwip_task */
osThreadDef(lwip_task, start_lwip_task, osPriorityNormal, 0, 512); osThreadDef(lwip_task, start_lwip_task, osPriorityNormal, 0, 8192);
lwip_taskHandle = osThreadCreate(osThread(lwip_task), NULL); lwip_taskHandle = osThreadCreate(osThread(lwip_task), NULL);
/* definition and creation of dac_task */ /* definition and creation of dac_task */
@ -124,6 +123,7 @@ void MX_FREERTOS_Init(void)
/* USER CODE BEGIN RTOS_THREADS */ /* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */ /* add threads, ... */
/* USER CODE END RTOS_THREADS */ /* USER CODE END RTOS_THREADS */
} }
/* USER CODE BEGIN Header_start_lwip_task */ /* USER CODE BEGIN Header_start_lwip_task */
@ -186,8 +186,8 @@ void start_ch438_task(void const *argument)
ch438_init(); ch438_init();
for (;;) for (;;)
{ {
// uint8_t data[9] = {0xFF, 0xff, 0xff, 0xff, 0xff, 0x34, 0x56, 0x78, 0x9a}; // uint8_t data[10] = {0xFF, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x02};
// ch438_send_data(CH438_UART0, data, 9); // ch438_send_data(9, data, 10);
vTaskDelay(500); vTaskDelay(500);
} }
/* USER CODE END start_ch438_task */ /* USER CODE END start_ch438_task */

View File

@ -61,7 +61,7 @@ void MX_FSMC_Init(void)
hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE; hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
hsram1.Init.PageSize = FSMC_PAGE_SIZE_NONE; hsram1.Init.PageSize = FSMC_PAGE_SIZE_NONE;
/* Timing */ /* Timing */
Timing.AddressSetupTime = 10; Timing.AddressSetupTime = 15;
Timing.AddressHoldTime = 15; Timing.AddressHoldTime = 15;
Timing.DataSetupTime = 10; Timing.DataSetupTime = 10;
Timing.BusTurnAroundDuration = 15; Timing.BusTurnAroundDuration = 15;
@ -137,6 +137,7 @@ static void HAL_FSMC_MspInit(void){
PF4 ------> FSMC_A4 PF4 ------> FSMC_A4
PF5 ------> FSMC_A5 PF5 ------> FSMC_A5
PF12 ------> FSMC_A6 PF12 ------> FSMC_A6
PF13 ------> FSMC_A7
PE7 ------> FSMC_D4 PE7 ------> FSMC_D4
PE8 ------> FSMC_D5 PE8 ------> FSMC_D5
PE9 ------> FSMC_D6 PE9 ------> FSMC_D6
@ -152,7 +153,7 @@ static void HAL_FSMC_MspInit(void){
*/ */
/* GPIO_InitStruct */ /* GPIO_InitStruct */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12; |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12|GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
@ -224,6 +225,7 @@ static void HAL_FSMC_MspDeInit(void){
PF4 ------> FSMC_A4 PF4 ------> FSMC_A4
PF5 ------> FSMC_A5 PF5 ------> FSMC_A5
PF12 ------> FSMC_A6 PF12 ------> FSMC_A6
PF13 ------> FSMC_A7
PE7 ------> FSMC_D4 PE7 ------> FSMC_D4
PE8 ------> FSMC_D5 PE8 ------> FSMC_D5
PE9 ------> FSMC_D6 PE9 ------> FSMC_D6
@ -239,7 +241,7 @@ static void HAL_FSMC_MspDeInit(void){
*/ */
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 HAL_GPIO_DeInit(GPIOF, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12); |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12|GPIO_PIN_13);
HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10); HAL_GPIO_DeInit(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);

View File

@ -2,7 +2,7 @@
/** /**
****************************************************************************** ******************************************************************************
* File Name : ethernetif.c * File Name : ethernetif.c
* Description : This file provides code for the configuration * @file ethernetif.c
* of the ethernetif.c MiddleWare. * of the ethernetif.c MiddleWare.
****************************************************************************** ******************************************************************************
* @attention * @attention
@ -202,7 +202,10 @@ static void low_level_init(struct netif *netif)
heth.Init.RxBuffLen = 1536; heth.Init.RxBuffLen = 1536;
/* USER CODE BEGIN MACADDRESS */ /* USER CODE BEGIN MACADDRESS */
MACAddr[3] = (uint8_t)HAL_GetUIDw0();
MACAddr[4] = (uint8_t)HAL_GetUIDw1();
MACAddr[5] = (uint8_t)HAL_GetUIDw2();
heth.Init.MACAddr = &MACAddr[0];
/* USER CODE END MACADDRESS */ /* USER CODE END MACADDRESS */
hal_eth_init_status = HAL_ETH_Init(&heth); hal_eth_init_status = HAL_ETH_Init(&heth);

View File

@ -49,6 +49,8 @@
/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/ /* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
/*----- Value in opt.h for MEM_ALIGNMENT: 1 -----*/ /*----- Value in opt.h for MEM_ALIGNMENT: 1 -----*/
#define MEM_ALIGNMENT 4 #define MEM_ALIGNMENT 4
/*----- Default Value for MEMP_NUM_TCP_PCB_LISTEN: 8 ---*/
#define MEMP_NUM_TCP_PCB_LISTEN 20
/*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/ /*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/
#define LWIP_ETHERNET 1 #define LWIP_ETHERNET 1
/*----- Value in opt.h for LWIP_DNS_SECURE: (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) -*/ /*----- Value in opt.h for LWIP_DNS_SECURE: (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) -*/

View File

@ -170,12 +170,32 @@
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>gnetif</ItemText> <ItemText>gnetif</ItemText>
</Ww> </Ww>
<Ww>
<count>4</count>
<WinNumber>1</WinNumber>
<ItemText>hart1_uart</ItemText>
</Ww>
<Ww>
<count>5</count>
<WinNumber>1</WinNumber>
<ItemText>ch438_uart_data</ItemText>
</Ww>
<Ww>
<count>6</count>
<WinNumber>1</WinNumber>
<ItemText>hart9_uart</ItemText>
</Ww>
<Ww>
<count>7</count>
<WinNumber>1</WinNumber>
<ItemText>tcpecho_accept_hart</ItemText>
</Ww>
</WatchWindow1> </WatchWindow1>
<MemoryWindow1> <MemoryWindow1>
<Mm> <Mm>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<SubType>0</SubType> <SubType>0</SubType>
<ItemText>0x60000000</ItemText> <ItemText>0x08014428</ItemText>
<AccSizeX>0</AccSizeX> <AccSizeX>0</AccSizeX>
</Mm> </Mm>
</MemoryWindow1> </MemoryWindow1>

View File

@ -339,7 +339,7 @@
<MiscControls></MiscControls> <MiscControls></MiscControls>
<Define>USE_HAL_DRIVER,STM32F407xx</Define> <Define>USE_HAL_DRIVER,STM32F407xx</Define>
<Undefine></Undefine> <Undefine></Undefine>
<IncludePath>../Core/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;../Drivers/CMSIS/Include;../LWIP/App;../LWIP/Target;../Middlewares/Third_Party/LwIP/src/include;../Middlewares/Third_Party/LwIP/system;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Drivers/BSP/Components/lan8742;../Middlewares/Third_Party/LwIP/src/include/netif/ppp;../Middlewares/Third_Party/LwIP/src/include/lwip;../Middlewares/Third_Party/LwIP/src/include/lwip/apps;../Middlewares/Third_Party/LwIP/src/include/lwip/priv;../Middlewares/Third_Party/LwIP/src/include/lwip/prot;../Middlewares/Third_Party/LwIP/src/include/netif;../Middlewares/Third_Party/LwIP/src/include/compat/posix;../Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa;../Middlewares/Third_Party/LwIP/src/include/compat/posix/net;../Middlewares/Third_Party/LwIP/src/include/compat/posix/sys;../Middlewares/Third_Party/LwIP/src/include/compat/stdc;../Middlewares/Third_Party/LwIP/system/arch;../User/driver;../User/system;..\User\application\inc</IncludePath> <IncludePath>../Core/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;../Drivers/CMSIS/Include;../LWIP/App;../LWIP/Target;../Middlewares/Third_Party/LwIP/src/include;../Middlewares/Third_Party/LwIP/system;../Middlewares/Third_Party/FreeRTOS/Source/include;../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS;../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM4F;../Drivers/BSP/Components/lan8742;../Middlewares/Third_Party/LwIP/src/include/netif/ppp;../Middlewares/Third_Party/LwIP/src/include/lwip;../Middlewares/Third_Party/LwIP/src/include/lwip/apps;../Middlewares/Third_Party/LwIP/src/include/lwip/priv;../Middlewares/Third_Party/LwIP/src/include/lwip/prot;../Middlewares/Third_Party/LwIP/src/include/netif;../Middlewares/Third_Party/LwIP/src/include/compat/posix;../Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa;../Middlewares/Third_Party/LwIP/src/include/compat/posix/net;../Middlewares/Third_Party/LwIP/src/include/compat/posix/sys;../Middlewares/Third_Party/LwIP/src/include/compat/stdc;../Middlewares/Third_Party/LwIP/system/arch;../User/driver;../User/system;../User/application/inc</IncludePath>
</VariousControls> </VariousControls>
</Cads> </Cads>
<Aads> <Aads>

View File

@ -1,61 +0,0 @@
<html>
<body>
<pre>
<h1>µVision Build Log</h1>
<h2>Tool Versions:</h2>
IDE-Version: ¦ÌVision V5.36.0.0
Copyright (C) 2021 ARM Ltd and ARM Germany GmbH. All rights reserved.
License Information: aaa Administrator, aaa, LIC=6XJT4-F8J98-8YUVV-P833R-DBAKX-Y8EU6
Tool Versions:
Toolchain: MDK-ARM Professional Version: 5.36.0.0
Toolchain Path: C:\Keil_v5\ARM\ARMCC\Bin
C Compiler: Armcc.exe V5.06 update 7 (build 960)
Assembler: Armasm.exe V5.06 update 7 (build 960)
Linker/Locator: ArmLink.exe V5.06 update 7 (build 960)
Library Manager: ArmAr.exe V5.06 update 7 (build 960)
Hex Converter: FromElf.exe V5.06 update 7 (build 960)
CPU DLL: SARMCM3.DLL V5.36.0.0
Dialog DLL: DCM.DLL V1.17.3.0
Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V3.0.9.0
Dialog DLL: TCM.DLL V1.53.0.0
<h2>Project:</h2>
D:\WORK\positioner_testing\valve_debugging\MDK-ARM\valve_debugging.uvprojx
Project File Date: 03/26/2025
<h2>Output:</h2>
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'valve_debugging'
compiling freertos.c...
linking...
Program Size: Code=80324 RO-data=1372 RW-data=448 ZI-data=57304
FromELF: creating hex file...
"valve_debugging\valve_debugging.axf" - 0 Error(s), 0 Warning(s).
<h2>Software Packages used:</h2>
Package Vendor: ARM
http://www.keil.com/pack/ARM.CMSIS.5.8.0.pack
ARM.CMSIS.5.8.0
CMSIS (Common Microcontroller Software Interface Standard)
* Component: CORE Version: 5.5.0
Package Vendor: Keil
https://www.keil.com/pack/Keil.STM32F4xx_DFP.2.17.1.pack
Keil.STM32F4xx_DFP.2.17.1
STMicroelectronics STM32F4 Series Device Support, Drivers and Examples
<h2>Collection of Component include folders:</h2>
.\RTE\_valve_debugging
C:\Users\Administrator\AppData\Local\Arm\Packs\ARM\CMSIS\5.8.0\CMSIS\Core\Include
C:\Users\Administrator\AppData\Local\Arm\Packs\Keil\STM32F4xx_DFP\2.17.1\Drivers\CMSIS\Device\ST\STM32F4xx\Include
<h2>Collection of Component Files used:</h2>
* Component: ARM::CMSIS:CORE:5.5.0
Include file: CMSIS\Core\Include\tz_context.h
Build Time Elapsed: 00:00:03
</pre>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -4,27 +4,58 @@
#include "main.h" #include "main.h"
#define TCP_PORT_HART1 1001 #define TCP_PORT_HART1 1001
#define TCP_PORT_HART9 2002 #define TCP_PORT_HART2 1002
#define TCP_PORT_HART3 1003
#define TCP_PORT_HART4 1004
#define TCP_PORT_HART5 1005
#define TCP_PORT_HART6 1006
#define TCP_PORT_HART7 1007
#define TCP_PORT_HART8 1008
#define TCP_PORT_HART9 1009
#define TCP_PORT_HART10 1010
#define TCP_PORT_HART11 1011
#define TCP_PORT_HART12 1012
#define TCP_PORT_HART13 1013
#define TCP_PORT_HART14 1014
#define TCP_PORT_HART15 1015
#define TCP_PORT_HART16 1016
#define TCP_PORT_CONTROL 5003 typedef enum
{
TCP_HART1 = 0,
TCP_HART2,
TCP_HART3,
TCP_HART4,
TCP_HART5,
TCP_HART6,
TCP_HART7,
TCP_HART8,
TCP_HART9,
TCP_HART10,
TCP_HART11,
TCP_HART12,
TCP_HART13,
TCP_HART14,
TCP_HART15,
TCP_HART16,
// TCP_CONTROL,
TCP_MAX,
} tcp_port_e;
extern uint8_t tcp_echo_flags_hart1; extern uint8_t tcp_echo_flags[TCP_MAX];
extern uint8_t tcp_echo_flags_hart9;
#define TCP_TRANSMIT_MAX 128
typedef struct typedef struct
{ {
uint16_t rx_num; // uint16_t rx_num;
uint8_t rx_data[512]; uint8_t rx_data[TCP_TRANSMIT_MAX];
uint8_t rx_data_temp[512]; uint8_t rx_data_temp[TCP_TRANSMIT_MAX];
uint8_t tx_data[512]; uint8_t tx_data[TCP_TRANSMIT_MAX];
} uart_t; } uart_t;
extern uart_t hart1_uart; extern uart_t hart_uart[TCP_MAX];
extern uart_t hart9_uart;
extern void tcp_echo_init(void); extern void tcp_echo_init(void);
extern void user_send_data_hart1(uint8_t *data, uint16_t len); extern void user_send_data_hart(uint8_t ch, uint8_t *data, uint16_t len);
extern void user_send_data_hart9(uint8_t *data, uint16_t len);
extern void user_send_data_control(uint8_t *data, uint16_t len);
#endif #endif

View File

@ -15,21 +15,17 @@
#include "user_gpio.h" #include "user_gpio.h"
#include "ch438q.h" #include "ch438q.h"
struct tcp_pcb *server_pcb_hart1 = NULL; err_t (*tcpecho_accept_hart[TCP_MAX])(void *arg, struct tcp_pcb *newpcb, err_t err);
struct tcp_pcb *server_pcb_hart9 = NULL; struct tcp_pcb *server_pcb_hart[TCP_MAX] = {0};
struct tcp_pcb *server_pcb_control = NULL; // communication_di_t *user_communication_di = NULL;
// communication_do_t *user_communication_do = NULL;
// communication_ai_t *user_communication_ai = NULL;
// communication_ao_t *user_communication_ao = NULL;
communication_di_t *user_communication_di = NULL; uint8_t tcp_echo_flags[TCP_MAX] = {0};
communication_do_t *user_communication_do = NULL;
communication_ai_t *user_communication_ai = NULL;
communication_ao_t *user_communication_ao = NULL;
uint8_t tcp_echo_flags_hart1 = 0; uart_t hart_uart[TCP_MAX] = {0};
uint8_t tcp_echo_flags_hart9 = 0;
uart_t hart9_uart = {0};
uart_t hart1_uart = {0};
extern uint8_t tcp_echo_flags_control; extern uint8_t tcp_echo_flags_control;
extern uint8_t send_data_flag_cmd; extern uint8_t send_data_flag_cmd;
@ -40,12 +36,145 @@ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
if (p != NULL) if (p != NULL)
{ {
/* 更新窗口*/ /* 更新窗口*/
tcp_echo_flags_hart1 = 1; tcp_echo_flags[TCP_HART1] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度 tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart1 = tpcb; // 直接赋值 server_pcb_hart[TCP_HART1] = tpcb; // 直接赋值
memcpy(hart1_uart.tx_data, (int *)p->payload, p->tot_len); memcpy(hart_uart[TCP_HART1].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(0, hart1_uart.tx_data, p->tot_len); ch438_send_data(TCP_HART1, hart_uart[TCP_HART1].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART2] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART2] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART2].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART2, hart_uart[TCP_HART2].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart3(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART3] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART3] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART3].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART3, hart_uart[TCP_HART3].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart4(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART4] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART4] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART4].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART4, hart_uart[TCP_HART4].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart5(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART5] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART5] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART5].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART5, hart_uart[TCP_HART5].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart6(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART6] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART6] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART6].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART6, hart_uart[TCP_HART6].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart7(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART7] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART7] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART7].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART7, hart_uart[TCP_HART7].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart8(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART8] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART8] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART8].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART8, hart_uart[TCP_HART8].tx_data, p->tot_len);
pbuf_free(p); pbuf_free(p);
} }
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空 else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -60,11 +189,11 @@ static err_t tcpecho_recv_hart9(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
if (p != NULL) if (p != NULL)
{ {
/* 更新窗口*/ /* 更新窗口*/
tcp_echo_flags_hart9 = 1; tcp_echo_flags[TCP_HART9] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度 tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart9 = tpcb; // 直接赋值 server_pcb_hart[TCP_HART9] = tpcb; // 直接赋值
memcpy(hart9_uart.tx_data, (int *)p->payload, p->tot_len); memcpy(hart_uart[TCP_HART9].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(8, hart9_uart.tx_data, p->tot_len); ch438_send_data(TCP_HART9, hart_uart[TCP_HART9].tx_data, p->tot_len);
pbuf_free(p); pbuf_free(p);
} }
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空 else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -74,97 +203,139 @@ static err_t tcpecho_recv_hart9(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
return ERR_OK; return ERR_OK;
} }
// static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) static err_t tcpecho_recv_hart10(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
// { { // 对应接收数据连接的控制块 接收到的数据
// uint8_t tcp_rx_data[128] = {0}; // 接受数据缓存区 if (p != NULL)
// uint8_t tcp_tx_data[128] = {0}; // 发送数据缓存区 {
// uint8_t rx_data_len = 0; /* 更新窗口*/
// uint8_t tx_data_len = 0; tcp_echo_flags[TCP_HART10] = 1;
// communication_data_u communication_data; tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
// if (p != NULL) server_pcb_hart[TCP_HART10] = tpcb; // 直接赋值
// { memcpy(hart_uart[TCP_HART10].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART10, hart_uart[TCP_HART10].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
// /* 更新窗口*/ static err_t tcpecho_recv_hart11(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
// tcp_echo_flags_control = 1; { // 对应接收数据连接的控制块 接收到的数据
// tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度 if (p != NULL)
// server_pcb_control = tpcb; // 直接赋值 {
// memcpy(tcp_rx_data, (int *)p->payload, p->tot_len); /* 更新窗口*/
// rx_data_len = p->tot_len; tcp_echo_flags[TCP_HART11] = 1;
// /*1. 对接收的数据做异或校验、帧头帧尾判断,校验失败返回信息,校验通过继续下一步、校验数据从帧头后面到校验位结束*/ tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
// if (tcp_rx_data[0] != 0xAA || tcp_rx_data[rx_data_len - 1] != 0x3C) // 帧头帧尾判断 server_pcb_hart[TCP_HART11] = tpcb; // 直接赋值
// { memcpy(hart_uart[TCP_HART11].tx_data, (int *)p->payload, p->tot_len);
// tx_data_len = COM_ERROR_CODE_SIZE; ch438_send_data(TCP_HART11, hart_uart[TCP_HART11].tx_data, p->tot_len);
// communication_exception(tcp_tx_data, tcp_rx_data, FRAMING_ERROR); pbuf_free(p);
// tcp_write(tpcb, tcp_tx_data, tx_data_len, 1); }
// } else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
// else {
// { return tcp_close(tpcb);
// if (tcp_rx_data[rx_data_len - 2] != xor_compute(tcp_rx_data + 1, rx_data_len - 3)) // 异或校验 }
// { return ERR_OK;
// tx_data_len = COM_ERROR_CODE_SIZE; }
// communication_exception(tcp_tx_data, tcp_rx_data, CHECK_ERROR);
// tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
// }
// else
// {
// memcpy(communication_data.data, tcp_rx_data + 5, tcp_rx_data[4]);
// if (tcp_rx_data[3] == READ_ANALOG_CMD) // 读模拟量指令
// {
// /*读操作,从寄存器读取数据,组包返回*/
// tx_data_len = COM_AI_DATA_SIZE;
// user_communication_ai = &communication_data.ai_data;
// communication_get_ai(user_communication_ai, tcp_tx_data, tcp_rx_data);
// tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
// }
// else if (tcp_rx_data[3] == WRITE_ANALOG_CMD) // 写模拟量指令
// {
// /*写操作,将数据写入寄存器,组包返回*/
// user_communication_ao = &communication_data.ao_data; static err_t tcpecho_recv_hart12(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
// communication_set_ao(user_communication_ao); { // 对应接收数据连接的控制块 接收到的数据
// tcp_write(tpcb, tcp_rx_data, rx_data_len, 1); if (p != NULL)
// } {
// else if (tcp_rx_data[3] == READ_DIGITAL_CMD) // 读数字量指令 /* 更新窗口*/
// { tcp_echo_flags[TCP_HART12] = 1;
// /*读操作,从寄存器读取数据,组包返回*/ tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART12] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART12].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART12, hart_uart[TCP_HART12].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
// user_communication_di = &communication_data.di_data; static err_t tcpecho_recv_hart13(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
// tx_data_len = 7 + user_communication_di->num; { // 对应接收数据连接的控制块 接收到的数据
// user_read_gpio(user_communication_di, tcp_tx_data, tcp_rx_data); if (p != NULL)
// tcp_write(tpcb, tcp_tx_data, tx_data_len, 1); {
// } /* 更新窗口*/
// else if (tcp_rx_data[3] == WRITE_DIGITAL_CMD) // 写数字量指令 tcp_echo_flags[TCP_HART13] = 1;
// { tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
// /*写操作,将数据写入寄存器,组包返回*/ server_pcb_hart[TCP_HART13] = tpcb; // 直接赋值
// user_communication_do = &communication_data.do_data; memcpy(hart_uart[TCP_HART13].tx_data, (int *)p->payload, p->tot_len);
// user_write_gpio(user_communication_do); ch438_send_data(TCP_HART13, hart_uart[TCP_HART13].tx_data, p->tot_len);
// tcp_write(tpcb, tcp_rx_data, rx_data_len, 1); pbuf_free(p);
// } }
// else if (tcp_rx_data[3] == SEND_STATE_CMD) else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
// { {
// send_data_flag_cmd = 0; // 上位机返回数据,发送状态标志位清零 return tcp_close(tpcb);
// } }
// else return ERR_OK;
// { }
// // 返回命令号错误
// tx_data_len = COM_ERROR_CODE_SIZE;
// communication_exception(tcp_tx_data, tcp_rx_data, COMMAND_ERROR);
// tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
// }
// }
// /*2. 判断所要执行的操作 读或写指令*/ static err_t tcpecho_recv_hart14(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
// /*3. 对要发送的数据进行校验,组包,返回数据*/ { // 对应接收数据连接的控制块 接收到的数据
// } if (p != NULL)
// pbuf_free(p); {
// } /* 更新窗口*/
// else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空 tcp_echo_flags[TCP_HART14] = 1;
// { tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
// return tcp_close(tpcb); server_pcb_hart[TCP_HART14] = tpcb; // 直接赋值
// } memcpy(hart_uart[TCP_HART14].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART14, hart_uart[TCP_HART14].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart15(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART15] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART15] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART15].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART15, hart_uart[TCP_HART15].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_hart16(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
tcp_echo_flags[TCP_HART16] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART16] = tpcb; // 直接赋值
memcpy(hart_uart[TCP_HART16].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART16, hart_uart[TCP_HART16].tx_data, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
// return ERR_OK;
// }
static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的 static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致 // 形参的数量和类型必须一致
{ {
@ -172,7 +343,61 @@ static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err)
return ERR_OK; return ERR_OK;
} }
static err_t tcpecho_accept_hart2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart2); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart3(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart3); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart4(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart4); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart5(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart5); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart6(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart6); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart7(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart7); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart8(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart8); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart9(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的 static err_t tcpecho_accept_hart9(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{ {
tcp_recv(newpcb, tcpecho_recv_hart9); // 当收到数据时回调用户自己写的tcpecho_recv tcp_recv(newpcb, tcpecho_recv_hart9); // 当收到数据时回调用户自己写的tcpecho_recv
@ -180,67 +405,119 @@ static err_t tcpecho_accept_hart9(void *arg, struct tcp_pcb *newpcb, err_t err)
return ERR_OK; return ERR_OK;
} }
// static err_t tcpecho_accept_control(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的 static err_t tcpecho_accept_hart10(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// { {
// tcp_recv(newpcb, tcpecho_recv_control); // 当收到数据时回调用户自己写的tcpecho_recv tcp_recv(newpcb, tcpecho_recv_hart10); // 当收到数据时回调用户自己写的tcpecho_recv
// return ERR_OK; return ERR_OK;
// } }
static err_t tcpecho_accept_hart11(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_hart11); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart12(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_hart12); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart13(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_hart13); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart14(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_hart14); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart15(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_hart15); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart16(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_hart16); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
void tcp_echo_init(void) void tcp_echo_init(void)
{ {
struct tcp_pcb *server_hart1 = NULL; struct tcp_pcb *server_hart[TCP_MAX] = {0};
struct tcp_pcb *server_hart9 = NULL; // struct tcp_pcb *server_hart2 = NULL;
// struct tcp_pcb *server_ble1 = NULL; // struct tcp_pcb *server_hart3 = NULL;
// struct tcp_pcb *server_ble2 = NULL; // struct tcp_pcb *server_hart4 = NULL;
// struct tcp_pcb *server_control = NULL; // struct tcp_pcb *server_hart5 = NULL;
// struct tcp_pcb *server_hart6 = NULL;
// struct tcp_pcb *server_hart7 = NULL;
// struct tcp_pcb *server_hart8 = NULL;
// struct tcp_pcb *server_hart9 = NULL;
// struct tcp_pcb *server_hart10 = NULL;
// struct tcp_pcb *server_hart11 = NULL;
// struct tcp_pcb *server_hart12 = NULL;
// struct tcp_pcb *server_hart13 = NULL;
// struct tcp_pcb *server_hart14 = NULL;
// struct tcp_pcb *server_hart15 = NULL;
// struct tcp_pcb *server_hart16 = NULL;
tcpecho_accept_hart[TCP_HART1] = tcpecho_accept_hart1;
tcpecho_accept_hart[TCP_HART2] = tcpecho_accept_hart2;
tcpecho_accept_hart[TCP_HART3] = tcpecho_accept_hart3;
tcpecho_accept_hart[TCP_HART4] = tcpecho_accept_hart4;
tcpecho_accept_hart[TCP_HART5] = tcpecho_accept_hart5;
tcpecho_accept_hart[TCP_HART6] = tcpecho_accept_hart6;
tcpecho_accept_hart[TCP_HART7] = tcpecho_accept_hart7;
tcpecho_accept_hart[TCP_HART8] = tcpecho_accept_hart8;
tcpecho_accept_hart[TCP_HART9] = tcpecho_accept_hart9;
tcpecho_accept_hart[TCP_HART10] = tcpecho_accept_hart10;
tcpecho_accept_hart[TCP_HART11] = tcpecho_accept_hart11;
tcpecho_accept_hart[TCP_HART12] = tcpecho_accept_hart12;
tcpecho_accept_hart[TCP_HART13] = tcpecho_accept_hart13;
tcpecho_accept_hart[TCP_HART14] = tcpecho_accept_hart14;
tcpecho_accept_hart[TCP_HART15] = tcpecho_accept_hart15;
tcpecho_accept_hart[TCP_HART16] = tcpecho_accept_hart16;
/* 创建一路HART */ /* 创建一路HART */
server_hart1 = tcp_new(); for (uint8_t i = TCP_HART1; i < TCP_MAX; i++)
{
server_hart[i] = NULL;
tcp_echo_flags[i] = 0;
server_hart[i] = tcp_new();
/* 绑定TCP控制块 */ /* 绑定TCP控制块 */
tcp_bind(server_hart1, IP_ADDR_ANY, TCP_PORT_HART1); tcp_bind(server_hart[i], IP_ADDR_ANY, TCP_PORT_HART1 + i);
/* 进入监听状态 */ /* 进入监听状态 */
server_hart1 = tcp_listen(server_hart1); server_hart[i] = tcp_listen(server_hart[i]);
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */ /* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_hart1, tcpecho_accept_hart1); // 侦听到连接后回调用户编写的tcpecho_accept tcp_accept(server_hart[i], tcpecho_accept_hart[i]); // 侦听到连接后回调用户编写的tcpecho_accept
}
/* 创建二路HART */ // for (uint8_t i = TCP_HART9; i < TCP_MAX; i++)
server_hart9 = tcp_new(); // {
// server_hart[i] = NULL;
/* 绑定TCP控制块 */ // tcp_echo_flags[i] = 0;
tcp_bind(server_hart9, IP_ADDR_ANY, TCP_PORT_HART9); // server_hart[i] = tcp_new();
/* 进入监听状态 */
server_hart9 = tcp_listen(server_hart9);
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_hart9, tcpecho_accept_hart9); // 侦听到连接后回调用户编写的tcpecho_accept
// /* 创建控制块 */
// server_control = tcp_new();
// /* 绑定TCP控制块 */ // /* 绑定TCP控制块 */
// tcp_bind(server_control, IP_ADDR_ANY, TCP_PORT_CONTROL); // tcp_bind(server_hart[i], IP_ADDR_ANY, TCP_PORT_HART9 + i);
// /* 进入监听状态 */ // /* 进入监听状态 */
// server_control = tcp_listen(server_control); // server_hart[i] = tcp_listen(server_hart[i]);
// /* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */ // /* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
// tcp_accept(server_control, tcpecho_accept_control); // 侦听到连接后回调用户编写的tcpecho_accept // tcp_accept(server_hart[i], tcpecho_accept_hart[i]); // 侦听到连接后回调用户编写的tcpecho_accept
// }
} }
void user_send_data_hart1(uint8_t *data, uint16_t len) void user_send_data_hart(uint8_t ch, uint8_t *data, uint16_t len)
{ {
tcp_write(server_pcb_hart1, data, len, 1); tcp_write(server_pcb_hart[ch], data, len, 1);
} }
void user_send_data_hart9(uint8_t *data, uint16_t len) // void user_send_data_hart9(uint8_t *data, uint16_t len)
{ // {
tcp_write(server_pcb_hart9, data, len, 1); // tcp_write(server_pcb_hart9, data, len, 1);
} // }
// void user_send_data_control(uint8_t *data, uint16_t len) // void user_send_data_control(uint8_t *data, uint16_t len)
// { // {

View File

@ -275,7 +275,6 @@ void ch438_send_data(uint8_t uart_num, uint8_t *data, uint16_t len)
} }
} }
uint8_t ch438_recv_data(uint8_t uart_num, uint8_t *data) uint8_t ch438_recv_data(uint8_t uart_num, uint8_t *data)
{ {
uint8_t data_len = 0; uint8_t data_len = 0;
uint8_t *receive_data; uint8_t *receive_data;
@ -342,16 +341,16 @@ void ch438_interrupt_handler_ch438_chip_1(void)
case INT_RCV_OVERTIME: /* 接收超时中断 */ case INT_RCV_OVERTIME: /* 接收超时中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff); ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
// ch438_send_data(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length); // ch438_send_data(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
if (tcp_echo_flags_hart1 == 1) if (tcp_echo_flags[i] == 1)
{ {
user_send_data_hart1(ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length); user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
} }
break; break;
case INT_RCV_SUCCESS: /* 接收数据可用中断 */ case INT_RCV_SUCCESS: /* 接收数据可用中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff); ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
if (tcp_echo_flags_hart1 == 1) if (tcp_echo_flags[i] == 1)
{ {
user_send_data_hart1(ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length); user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
} }
break; break;
case INT_RCV_LINES: /* 接收线路状态中断 */ case INT_RCV_LINES: /* 接收线路状态中断 */
@ -395,16 +394,16 @@ void ch438_interrupt_handler_ch438_chip_2(void)
break; break;
case INT_RCV_OVERTIME: /* 接收超时中断 */ case INT_RCV_OVERTIME: /* 接收超时中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff); ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
if (tcp_echo_flags_hart9 == 1) if (tcp_echo_flags[i] == 1)
{ {
user_send_data_hart9(ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length); user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
} }
break; break;
case INT_RCV_SUCCESS: /* 接收数据可用中断 */ case INT_RCV_SUCCESS: /* 接收数据可用中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff); ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
if (tcp_echo_flags_hart9 == 1) if (tcp_echo_flags[i] == 1)
{ {
user_send_data_hart9(ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length); user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
} }
break; break;
case INT_RCV_LINES: /* 接收线路状态中断 */ case INT_RCV_LINES: /* 接收线路状态中断 */

View File

@ -8,12 +8,14 @@ ETH.MediaInterface=HAL_ETH_RMII_MODE
ETH.RxBuffLen=1536 ETH.RxBuffLen=1536
ETH.RxMode=ETH_RXINTERRUPT_MODE ETH.RxMode=ETH_RXINTERRUPT_MODE
FREERTOS.FootprintOK=true FREERTOS.FootprintOK=true
FREERTOS.IPParameters=Tasks01,configENABLE_FPU,configMAX_PRIORITIES,configMAX_TASK_NAME_LEN,FootprintOK FREERTOS.IPParameters=Tasks01,configENABLE_FPU,configMAX_PRIORITIES,configMAX_TASK_NAME_LEN,FootprintOK,configTOTAL_HEAP_SIZE,configMINIMAL_STACK_SIZE
FREERTOS.Tasks01=lwip_task,0,512,start_lwip_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;ch438_task,0,512,start_ch438_task,Default,NULL,Dynamic,NULL,NULL FREERTOS.Tasks01=lwip_task,0,8192,start_lwip_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;ch438_task,0,512,start_ch438_task,Default,NULL,Dynamic,NULL,NULL
FREERTOS.configENABLE_FPU=1 FREERTOS.configENABLE_FPU=1
FREERTOS.configMAX_PRIORITIES=32 FREERTOS.configMAX_PRIORITIES=32
FREERTOS.configMAX_TASK_NAME_LEN=24 FREERTOS.configMAX_TASK_NAME_LEN=24
FSMC.AddressSetupTime1=10 FREERTOS.configMINIMAL_STACK_SIZE=128
FREERTOS.configTOTAL_HEAP_SIZE=65536
FSMC.AddressSetupTime1=15
FSMC.DataSetupTime1=10 FSMC.DataSetupTime1=10
FSMC.DataSetupTime2=10 FSMC.DataSetupTime2=10
FSMC.ExtendedMode1=FSMC_EXTENDED_MODE_DISABLE FSMC.ExtendedMode1=FSMC_EXTENDED_MODE_DISABLE
@ -25,9 +27,10 @@ GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false KeepUserPlacement=false
LWIP.BSP.number=1 LWIP.BSP.number=1
LWIP.GATEWAY_ADDRESS=192.168.001.222 LWIP.GATEWAY_ADDRESS=192.168.001.222
LWIP.IPParameters=LWIP_DHCP,IP_ADDRESS,NETMASK_ADDRESS,GATEWAY_ADDRESS LWIP.IPParameters=LWIP_DHCP,IP_ADDRESS,NETMASK_ADDRESS,GATEWAY_ADDRESS,MEMP_NUM_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Mcu.Pin8=PF4 Mcu.Pin8=PF4
Mcu.Pin9=PF5 Mcu.Pin9=PF5
Mcu.PinsNb=76 Mcu.PinsNb=77
Mcu.ThirdPartyNb=0 Mcu.ThirdPartyNb=0
Mcu.UserConstants= Mcu.UserConstants=
Mcu.UserName=STM32F407ZGTx Mcu.UserName=STM32F407ZGTx
@ -373,6 +377,7 @@ PE9.Signal=FSMC_D6_DA6
PF0.Signal=FSMC_A0 PF0.Signal=FSMC_A0
PF1.Signal=FSMC_A1 PF1.Signal=FSMC_A1
PF12.Signal=FSMC_A6 PF12.Signal=FSMC_A6
PF13.Signal=FSMC_A7
PF14.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label PF14.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label
PF14.GPIO_Label=CH438_AMOD PF14.GPIO_Label=CH438_AMOD
PF14.GPIO_PuPd=GPIO_PULLDOWN PF14.GPIO_PuPd=GPIO_PULLDOWN
@ -537,27 +542,30 @@ RCC.VCOI2SOutputFreq_Value=353894400
RCC.VCOInputFreq_Value=1843200 RCC.VCOInputFreq_Value=1843200
RCC.VCOOutputFreq_Value=221184000 RCC.VCOOutputFreq_Value=221184000
RCC.VcooutputI2S=176947200 RCC.VcooutputI2S=176947200
SH.FSMC_A0.0=FSMC_A0,7b-a1 SH.FSMC_A0.0=FSMC_A0,8b-a1
SH.FSMC_A0.1=FSMC_A0,7b-a2 SH.FSMC_A0.1=FSMC_A0,8b-a2
SH.FSMC_A0.ConfNb=2 SH.FSMC_A0.ConfNb=2
SH.FSMC_A1.0=FSMC_A1,7b-a1 SH.FSMC_A1.0=FSMC_A1,8b-a1
SH.FSMC_A1.1=FSMC_A1,7b-a2 SH.FSMC_A1.1=FSMC_A1,8b-a2
SH.FSMC_A1.ConfNb=2 SH.FSMC_A1.ConfNb=2
SH.FSMC_A2.0=FSMC_A2,7b-a1 SH.FSMC_A2.0=FSMC_A2,8b-a1
SH.FSMC_A2.1=FSMC_A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