Files
STM32F4-Base/App/task/net_task.c
2026-07-21 00:30:59 +08:00

80 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* 模块名称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, processing messages");
for (;;) {
net_poll();
net_process_messages();
#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_sock(p_sk, s_net_buf, sizeof(s_net_buf), NET_MSG_DONTWAIT);
if (n > 0) {
net_send_sock(p_sk, s_net_buf, n);
}
}
#endif
#ifdef ENABLE_PHASE5_TESTS
ch395f_phase5_tests();
#endif
#ifdef ENABLE_PHASE7_TESTS
ch395f_phase7_tests();
#endif
osDelay(10);
}
}