备份--定时器中断

This commit is contained in:
王绪洁 2025-06-30 13:57:37 +08:00
parent 852d47483b
commit fa561c20b9
13 changed files with 5353 additions and 5211 deletions

View File

@ -53,6 +53,7 @@ void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void EXTI2_IRQHandler(void);
void TIM3_IRQHandler(void);
void TIM4_IRQHandler(void);
void EXTI15_10_IRQHandler(void);
void ETH_IRQHandler(void);

View File

@ -34,11 +34,14 @@ extern "C" {
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim3;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_TIM2_Init(void);
void MX_TIM3_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

View File

@ -147,35 +147,32 @@ void start_lwip_task(void const *argument)
tcp_echo_init();
for (;;)
{
// osThreadTerminate(NULL);
// uint32_t phyreg = 0;
// uint8_t tcp_hart_num = 0;
// HAL_ETH_ReadPHYRegister(&heth, 0x00, PHY_BSR, &phyreg);
// if (((phyreg >> 2) & 0x1) != 0x1) // PHY_BSR寄存器的第2位表示PHY是否连接 PHY_LINKED_STATUS
// {
// /* When the netif link is down this function must be called */
uint32_t phyreg = 0;
uint8_t tcp_hart_num = 0;
HAL_ETH_ReadPHYRegister(&heth, 0x00, PHY_BSR, &phyreg);
for (tcp_hart_num = 0; tcp_hart_num < TCP_MAX; tcp_hart_num++)
{
if (tcp_echo_flags[tcp_hart_num] == 1)
{
if (((phyreg >> 2) & 0x1) != 0x1) // PHY_BSR寄存器的<E599A8>?2位表示PHY是否连接 PHY_LINKED_STATUS
{
/* When the netif link is down this function must be called */
// netif_set_link_down(&gnetif);
// netif_set_down(&gnetif); // 热插拔下线时调用
// for (tcp_hart_num = 0; tcp_hart_num < TCP_MAX; tcp_hart_num++)
// {
// if (tcp_echo_flags[tcp_hart_num] == 1)
// {
// tcp_abort(server_pcb_hart[tcp_hart_num]); // 热插拔下线时调用
// tcp_echo_flags[tcp_hart_num] = 0;
// }
// }
// }
// else
// {
// /* When the netif is fully configured this function must be called */
// netif_set_link_up(&gnetif);
// netif_set_up(&gnetif); // 热插拔上线时调用
// }
ch438_interrupt_handler_data_ch438_chip_1();
ch438_interrupt_handler_data_ch438_chip_2();
netif_set_link_down(&gnetif);
netif_set_down(&gnetif); // 热插拔下线时调用
tcp_abort(server_pcb_hart[tcp_hart_num]); // 热插拔下线时调用
tcp_echo_flags[tcp_hart_num] = 0;
}
else
{
/* When the netif is fully configured this function must be called */
netif_set_link_up(&gnetif);
netif_set_up(&gnetif); // 热插拔上线时调用
}
}
}
vTaskDelay(10);
vTaskDelay(1000);
}
/* USER CODE END start_lwip_task */
}
@ -219,33 +216,9 @@ void start_ch438_task(void const *argument)
for (;;)
{
// osThreadTerminate(NULL);
uint32_t phyreg = 0;
uint8_t tcp_hart_num = 0;
HAL_ETH_ReadPHYRegister(&heth, 0x00, PHY_BSR, &phyreg);
for (tcp_hart_num = 0; tcp_hart_num < TCP_MAX; tcp_hart_num++)
{
if (tcp_echo_flags[tcp_hart_num] == 1)
{
if (((phyreg >> 2) & 0x1) != 0x1) // PHY_BSR寄存器的第2位表示PHY是否连接 PHY_LINKED_STATUS
{
/* When the netif link is down this function must be called */
netif_set_link_down(&gnetif);
netif_set_down(&gnetif); // 热插拔下线时调用
tcp_abort(server_pcb_hart[tcp_hart_num]); // 热插拔下线时调用
tcp_echo_flags[tcp_hart_num] = 0;
}
else
{
/* When the netif is fully configured this function must be called */
netif_set_link_up(&gnetif);
netif_set_up(&gnetif); // 热插拔上线时调用
}
}
vTaskDelay(500);
}
ch438_interrupt_handler_data_ch438_chip_1();
ch438_interrupt_handler_data_ch438_chip_2();
vTaskDelay(10);
}
/* USER CODE END start_ch438_task */
}

View File

@ -95,6 +95,7 @@ int main(void)
MX_TIM2_Init();
MX_SPI1_Init();
MX_FSMC_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
hart_ht1200m_reset(); // 初始化HT1200M模块
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); // PWM输出用于驱动HT1200M模块
@ -150,8 +151,7 @@ void SystemClock_Config(void)
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
@ -168,13 +168,13 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (CH438_1_INT_Pin == GPIO_Pin)
{
// ch438_1_int_flag = 1; // 霈曄蔭CH438_1<5F><31><EFBFBD><EFBFBD>敹梹<E695B9><E6A2B9><EFBFBD>銝剜鱏憭<E9B18F><E686AD><EFBFBD>賣㺭銝剖ế<E58996>剜糓<E5899C>虫蛹CH438_1<5F><31><EFBFBD>剛窈瘙?
ch438_interrupt_handler_ch438_chip_1();
ch438_1_int_flag = 1; // 设置CH438_1的中断标志用于中断处理函数中判断是否为CH438_1的中断请<E696AD>?
// ch438_interrupt_handler_ch438_chip_1();
}
if (CH438_2_INT_Pin == GPIO_Pin)
{
// ch438_2_int_flag = 1; // 霈曄蔭CH438_1<5F><31><EFBFBD><EFBFBD>敹梹<E695B9><E6A2B9><EFBFBD>銝剜鱏憭<E9B18F><E686AD><EFBFBD>賣㺭銝剖ế<E58996>剜糓<E5899C>虫蛹CH438_2<5F><32><EFBFBD>剛窈瘙?
ch438_interrupt_handler_ch438_chip_2();
ch438_2_int_flag = 1; // 设置CH438_1的中断标志用于中断处理函数中判断是否为CH438_2的中断请<E696AD>?
// ch438_interrupt_handler_ch438_chip_2();
}
}
/* USER CODE END 4 */
@ -192,11 +192,33 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM4) {
if (htim->Instance == TIM4)
{
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */
if (htim->Instance == TIM3)
{
if (ch438_1_int_flag == 2)
{
ch438_interrupt_handler_ch438_chip_1();
}
if (ch438_1_int_flag == 1)
{
ch438_1_int_flag++;
ch438_1_int_flag = 0;
}
if (ch438_2_int_flag == 2)
{
ch438_interrupt_handler_ch438_chip_2();
}
if (ch438_2_int_flag == 1)
{
ch438_2_int_flag++;
ch438_2_int_flag = 0;
}
}
/* USER CODE END Callback 1 */
}

View File

@ -57,6 +57,7 @@
/* External variables --------------------------------------------------------*/
extern ETH_HandleTypeDef heth;
extern TIM_HandleTypeDef htim3;
extern TIM_HandleTypeDef htim4;
/* USER CODE BEGIN EV */
@ -175,6 +176,20 @@ void EXTI2_IRQHandler(void)
/* USER CODE END EXTI2_IRQn 1 */
}
/**
* @brief This function handles TIM3 global interrupt.
*/
void TIM3_IRQHandler(void)
{
/* USER CODE BEGIN TIM3_IRQn 0 */
/* USER CODE END TIM3_IRQn 0 */
HAL_TIM_IRQHandler(&htim3);
/* USER CODE BEGIN TIM3_IRQn 1 */
/* USER CODE END TIM3_IRQn 1 */
}
/**
* @brief This function handles TIM4 global interrupt.
*/

View File

@ -25,6 +25,7 @@
/* USER CODE END 0 */
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim3;
/* TIM2 init function */
void MX_TIM2_Init(void)
@ -69,6 +70,46 @@ void MX_TIM2_Init(void)
/* USER CODE END TIM2_Init 2 */
HAL_TIM_MspPostInit(&htim2);
}
/* TIM3 init function */
void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 54;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 1000;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
}
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle)
@ -86,6 +127,26 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle)
/* USER CODE END TIM2_MspInit 1 */
}
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspInit 0 */
/* USER CODE END TIM3_MspInit 0 */
/* TIM3 clock enable */
__HAL_RCC_TIM3_CLK_ENABLE();
/* TIM3 interrupt Init */
HAL_NVIC_SetPriority(TIM3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(TIM3_IRQn);
/* USER CODE BEGIN TIM3_MspInit 1 */
/* USER CODE END TIM3_MspInit 1 */
}
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
{
@ -130,6 +191,25 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* tim_pwmHandle)
}
}
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
{
if(tim_baseHandle->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspDeInit 0 */
/* USER CODE END TIM3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM3_CLK_DISABLE();
/* TIM3 interrupt Deinit */
HAL_NVIC_DisableIRQ(TIM3_IRQn);
/* USER CODE BEGIN TIM3_MspDeInit 1 */
/* USER CODE END TIM3_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@ -16,8 +16,8 @@
<TargetCommonOption>
<Device>STM32F407ZGTx</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F4xx_DFP.2.16.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<PackID>Keil.STM32F4xx_DFP.2.12.0</PackID>
<PackURL>http://www.keil.com/pack</PackURL>
<Cpu>IRAM(0x20000000-0x2001BFFF) IRAM2(0x2001C000-0x2001FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(25000000) FPU2 CPUTYPE("Cortex-M4") TZ</Cpu>
<FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile>
@ -186,7 +186,6 @@
<RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>1</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>

View File

@ -1,61 +0,0 @@
<html>
<body>
<pre>
<h1>µVision Build Log</h1>
<h2>Tool Versions:</h2>
IDE-Version: ¦ÌVision V5.38.0.0
Copyright (C) 2022 ARM Ltd and ARM Germany GmbH. All rights reserved.
License Information: admin, , LIC=IC93N-YMBVW-HRFXN-YQEV3-SZ4P1-XNWP8
Tool Versions:
Toolchain: MDK-ARM Professional Version: 5.38.0.0
Toolchain Path: D:\app\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.38.0.0
Dialog DLL: DCM.DLL V1.17.5.0
Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V3.1.0.0
Dialog DLL: TCM.DLL V1.56.4.0
<h2>Project:</h2>
D:\1-workshop\valve_debugging\MDK-ARM\valve_debugging.uvprojx
Project File Date: 06/26/2025
<h2>Output:</h2>
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\app\Keil_v5\ARM\ARMCC\Bin'
Build target 'valve_debugging'
compiling freertos.c...
linking...
Program Size: Code=83940 RO-data=1404 RW-data=432 ZI-data=116892
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.9.0.pack
ARM.CMSIS.5.9.0
CMSIS (Common Microcontroller Software Interface Standard)
* Component: CORE Version: 5.6.0
Package Vendor: Keil
http://www.keil.com/pack/Keil.STM32F4xx_DFP.2.16.0.pack
Keil.STM32F4xx_DFP.2.16.0
STMicroelectronics STM32F4 Series Device Support, Drivers and Examples
<h2>Collection of Component include folders:</h2>
./RTE/_valve_debugging
D:/app/Keil_v5/Packs/ARM/CMSIS/5.9.0/CMSIS/Core/Include
D:/app/Keil_v5/Packs/Keil/STM32F4xx_DFP/2.16.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include
<h2>Collection of Component Files used:</h2>
* Component: ARM::CMSIS:CORE:5.6.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

@ -49,10 +49,13 @@ extern uint8_t tcp_echo_flags[TCP_MAX];
#define TCP_TRANSMIT_MAX 128
typedef struct
{
// uint16_t rx_num;
uint8_t rx_data[TCP_TRANSMIT_MAX];
uint8_t rx_data_temp[TCP_TRANSMIT_MAX];
uint8_t tx_data[TCP_TRANSMIT_MAX];
uint8_t rx_length; // 接收数据长度
uint8_t tx_length; // 发送数据长度
uint32_t rx_times; // 接收次数
uint32_t tx_times; // 发送次数
uint8_t rx_data[TCP_TRANSMIT_MAX]; // 接收数据
uint8_t rx_data_temp[TCP_TRANSMIT_MAX]; // 接收数据临时缓存
uint8_t tx_data[TCP_TRANSMIT_MAX]; // 发送数据
} uart_t;
extern uart_t hart_uart[TCP_MAX];

View File

@ -24,7 +24,6 @@ struct tcp_pcb *server_pcb_control = NULL;
communication_ao_t *user_communication_ao = NULL;
uint8_t tcp_echo_flags[TCP_MAX] = {0};
uint32_t tcp_times[TCP_MAX] = {0};
uart_t hart_uart[TCP_MAX] = {0};
/*接收回调函数*/
@ -36,9 +35,11 @@ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART1] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART1] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART1].tx_data, 0, TCP_TRANSMIT_MAX);
memcpy(hart_uart[TCP_HART1].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART1, hart_uart[TCP_HART1].tx_data, p->tot_len);
tcp_times[TCP_HART1]++;
hart_uart[TCP_HART1].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART1].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -56,9 +57,11 @@ static err_t tcpecho_recv_hart2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART2] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART2] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART2].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART2]++;
hart_uart[TCP_HART2].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART2].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -76,9 +79,11 @@ static err_t tcpecho_recv_hart3(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART3] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART3] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART3].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART3]++;
hart_uart[TCP_HART3].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART3].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -96,9 +101,11 @@ static err_t tcpecho_recv_hart4(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART4] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART4] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART4].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART4]++;
hart_uart[TCP_HART4].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART4].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -116,9 +123,11 @@ static err_t tcpecho_recv_hart5(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART5] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART5] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART5].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART5]++;
hart_uart[TCP_HART5].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART5].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -136,9 +145,11 @@ static err_t tcpecho_recv_hart6(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART6] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART6] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART6].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART6]++;
hart_uart[TCP_HART6].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART6].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -156,9 +167,11 @@ static err_t tcpecho_recv_hart7(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART7] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART7] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART7].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART7]++;
hart_uart[TCP_HART7].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART7].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -176,9 +189,11 @@ static err_t tcpecho_recv_hart8(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART8] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART8] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART8].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART8]++;
hart_uart[TCP_HART8].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART8].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -196,9 +211,11 @@ static err_t tcpecho_recv_hart9(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
tcp_echo_flags[TCP_HART9] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART9] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART9].tx_data, 0, TCP_TRANSMIT_MAX);
memcpy(hart_uart[TCP_HART9].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART9, hart_uart[TCP_HART9].tx_data, p->tot_len);
tcp_times[TCP_HART9]++;
hart_uart[TCP_HART9].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART9].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -216,9 +233,11 @@ static err_t tcpecho_recv_hart10(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
tcp_echo_flags[TCP_HART10] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART10] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART10].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART10]++;
hart_uart[TCP_HART10].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART10].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -236,9 +255,11 @@ static err_t tcpecho_recv_hart11(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
tcp_echo_flags[TCP_HART11] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART11] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART11].tx_data, 0, TCP_TRANSMIT_MAX);
memcpy(hart_uart[TCP_HART11].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART11, hart_uart[TCP_HART11].tx_data, p->tot_len);
tcp_times[TCP_HART11]++;
hart_uart[TCP_HART11].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART11].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -256,9 +277,11 @@ static err_t tcpecho_recv_hart12(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
tcp_echo_flags[TCP_HART12] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART12] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART12].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART12]++;
hart_uart[TCP_HART12].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART12].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -276,9 +299,11 @@ static err_t tcpecho_recv_hart13(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
tcp_echo_flags[TCP_HART13] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART13] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART13].tx_data, 0, TCP_TRANSMIT_MAX);
memcpy(hart_uart[TCP_HART13].tx_data, (int *)p->payload, p->tot_len);
ch438_send_data(TCP_HART13, hart_uart[TCP_HART13].tx_data, p->tot_len);
tcp_times[TCP_HART13]++;
hart_uart[TCP_HART13].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART13].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -296,9 +321,11 @@ static err_t tcpecho_recv_hart14(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
tcp_echo_flags[TCP_HART14] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART14] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART14].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART14]++;
hart_uart[TCP_HART14].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART14].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -316,9 +343,11 @@ static err_t tcpecho_recv_hart15(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
tcp_echo_flags[TCP_HART15] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART15] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART15].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART15]++;
hart_uart[TCP_HART15].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART15].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
@ -336,9 +365,11 @@ static err_t tcpecho_recv_hart16(void *arg, struct tcp_pcb *tpcb, struct pbuf *p
tcp_echo_flags[TCP_HART16] = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart[TCP_HART16] = tpcb; // 直接赋值
memset(hart_uart[TCP_HART16].tx_data, 0, TCP_TRANSMIT_MAX);
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);
tcp_times[TCP_HART16]++;
hart_uart[TCP_HART16].tx_length = p->tot_len; // 更新发送数据长度
hart_uart[TCP_HART16].tx_times++;
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空

View File

@ -262,8 +262,8 @@ void ch438_send_data(uint8_t uart_num, uint8_t *data, uint16_t len)
{
hart_ht1200m_rts_io_send(uart_num);
uint8_t ch438_num = 0;
data[len] = 0xFF; // 因为发送数据RHART的RTS需要延时这里用多一个字节的发送来代替延时
data[len + 1] = 0xFF; // 因为发送数据RHART的RTS需要延时这里用多两个字节的发送来代替延时
// data[len] = 0xFF; // 因为发送数据RHART的RTS需要延时这里用多一个字节的发送来代替延时
// data[len + 1] = 0xFF; // 因为发送数据RHART的RTS需要延时这里用多两个字节的发送来代替延时
if (uart_num < 8)
{
ch438_num = CH438_CHIP0;
@ -273,8 +273,8 @@ void ch438_send_data(uint8_t uart_num, uint8_t *data, uint16_t len)
ch438_num = CH438_CHIP1;
uart_num -= 8;
}
ch438_write_reg(ch438_num, offsetadd[uart_num] | REG_THR_ADDR, data[len], 1);
for (uint8_t i = 0; i < len + 1; i++)
// ch438_write_reg(ch438_num, offsetadd[uart_num] | REG_THR_ADDR, data[len], 1);
for (uint8_t i = 0; i < len; i++)
{
ch438_write_reg(ch438_num, offsetadd[uart_num] | REG_THR_ADDR, data[i], 1);
}
@ -450,19 +450,19 @@ void ch438_interrupt_handler_data_ch438_chip_1(void)
{
case INT_RCV_OVERTIME: /* 接收超时中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
hart_uart[i].rx_length = ch438_recv_data(i, hart_uart[i].rx_data);
if (tcp_echo_flags[i] == 1)
{
user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
uart_times[i]++;
user_send_data_hart(i, hart_uart[i].rx_data, hart_uart[i].rx_length);
hart_uart[i].rx_times++;
}
break;
case INT_RCV_SUCCESS: /* 接收数据可用中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
hart_uart[i].rx_length = ch438_recv_data(i, hart_uart[i].rx_data);
if (tcp_echo_flags[i] == 1)
{
user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
uart_times[i]++;
user_send_data_hart(i, hart_uart[i].rx_data, hart_uart[i].rx_length);
hart_uart[i].rx_times++;
}
break;
@ -496,19 +496,19 @@ void ch438_interrupt_handler_data_ch438_chip_2(void)
{
case INT_RCV_OVERTIME: /* 接收超时中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
hart_uart[i].rx_length = ch438_recv_data(i, hart_uart[i].rx_data);
if (tcp_echo_flags[i] == 1)
{
user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
uart_times[i]++;
user_send_data_hart(i, hart_uart[i].rx_data, hart_uart[i].rx_length);
hart_uart[i].rx_times++;
}
break;
case INT_RCV_SUCCESS: /* 接收数据可用中断 */
ch438_uart_data[i].receive_data_length = ch438_recv_data(i, ch438_uart_data[i].receive_data_buff);
hart_uart[i].rx_length = ch438_recv_data(i, hart_uart[i].rx_data);
if (tcp_echo_flags[i] == 1)
{
user_send_data_hart(i, ch438_uart_data[i].receive_data_buff, ch438_uart_data[i].receive_data_length);
uart_times[i]++;
user_send_data_hart(i, hart_uart[i].rx_data, hart_uart[i].rx_length);
hart_uart[i].rx_times++;
}
break;

View File

@ -67,7 +67,8 @@ Mcu.IP5=RCC
Mcu.IP6=SPI1
Mcu.IP7=SYS
Mcu.IP8=TIM2
Mcu.IPNb=9
Mcu.IP9=TIM3
Mcu.IPNb=10
Mcu.Name=STM32F407Z(E-G)Tx
Mcu.Package=LQFP144
Mcu.Pin0=PE2
@ -145,9 +146,10 @@ Mcu.Pin73=PE1
Mcu.Pin74=VP_FREERTOS_VS_CMSIS_V1
Mcu.Pin75=VP_LWIP_VS_Enabled
Mcu.Pin76=VP_SYS_VS_tim4
Mcu.Pin77=VP_TIM3_VS_ClockSourceINT
Mcu.Pin8=PF4
Mcu.Pin9=PF5
Mcu.PinsNb=77
Mcu.PinsNb=78
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F407ZGTx
@ -169,6 +171,7 @@ NVIC.SavedPendsvIrqHandlerGenerated=true
NVIC.SavedSvcallIrqHandlerGenerated=true
NVIC.SavedSystickIrqHandlerGenerated=true
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true\:false
NVIC.TIM3_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
NVIC.TIM4_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true
NVIC.TimeBase=TIM4_IRQn
NVIC.TimeBaseIP=TIM4
@ -629,11 +632,16 @@ TIM2.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
TIM2.IPParameters=Channel-PWM Generation4 CH4,Period,Pulse-PWM Generation4 CH4
TIM2.Period=119
TIM2.Pulse-PWM\ Generation4\ CH4=60
TIM3.IPParameters=Prescaler,Period
TIM3.Period=1000
TIM3.Prescaler=54
VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1
VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1
VP_LWIP_VS_Enabled.Mode=Enabled
VP_LWIP_VS_Enabled.Signal=LWIP_VS_Enabled
VP_SYS_VS_tim4.Mode=TIM4
VP_SYS_VS_tim4.Signal=SYS_VS_tim4
VP_TIM3_VS_ClockSourceINT.Mode=Internal
VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT
board=custom
rtos.0.ip=FREERTOS