修复多连接的问题
This commit is contained in:
78
App/task/net_task.c
Normal file
78
App/task/net_task.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 模块名称:Network Application Task
|
||||
* 模块功能:CH395F 协议栈轮询 + TCP/UDP 业务处理
|
||||
* 与 net_socket.h 配合,在 FreeRTOS 独立任务中运行
|
||||
* 适用平台:STM32F407ZGTx + CH395F
|
||||
* 作者:王建锋
|
||||
* 创建日期:2026-07-19
|
||||
* 修改记录:
|
||||
* v1.0 2026-07-19 王建锋 创建初始版本
|
||||
* v1.1 2026-07-19 王建锋 migrate from freertos.c StartNetTask
|
||||
*/
|
||||
|
||||
#include "net_task.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "net_socket.h"
|
||||
#include "net_select.h"
|
||||
#include "ch395f_test.h"
|
||||
|
||||
#define DBG_TAG "[NET_TASK]"
|
||||
#include "dbg_log.h"
|
||||
|
||||
static uint8_t s_net_buf[1500];
|
||||
|
||||
/*
|
||||
* 函数功能:网络任务初始化
|
||||
* 入口参数:无
|
||||
* 返 回 值:0 - 成功,-1 - 失败
|
||||
* 限定条件:CH395F 协议栈已初始化
|
||||
* 函数说明:创建 TCP Server 监听 Socket,注册回调等
|
||||
*/
|
||||
int net_task_init(void)
|
||||
{
|
||||
DBG_INFO("net_task_init");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:网络任务主函数
|
||||
* 入口参数:arg - FreeRTOS 传入参数(未使用)
|
||||
* 返 回 值:无
|
||||
* 函数说明:FreeRTOS 任务函数,启动后先等待 2 秒再进入轮询循环
|
||||
* 依次处理 net_poll、TCP echo、UDP/Select 测试
|
||||
*/
|
||||
void net_task_func(void const *arg)
|
||||
{
|
||||
(void)arg;
|
||||
|
||||
osDelay(2000);
|
||||
DBG_INFO("netTask: started");
|
||||
|
||||
for (;;) {
|
||||
net_poll();
|
||||
|
||||
#ifdef ENABLE_PHASE4_TESTS
|
||||
for (int i = 1; i < 8; i++) {
|
||||
net_sock_t *p_sk = net_get_sock(i);
|
||||
if (p_sk == NULL || p_sk->state != NET_SOCK_STATE_ESTABLISHED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int n = net_recv(i, s_net_buf, sizeof(s_net_buf), NET_MSG_DONTWAIT);
|
||||
if (n > 0) {
|
||||
net_send(i, s_net_buf, n, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_PHASE5_TESTS
|
||||
ch395f_phase5_tests();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_PHASE7_TESTS
|
||||
ch395f_phase7_tests();
|
||||
#endif
|
||||
|
||||
osDelay(10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user