增加文件系统
This commit is contained in:
@@ -1,24 +1,50 @@
|
||||
/*
|
||||
* 模块名称:Network Select Implementation
|
||||
* 模块功能:I/O 多路复用实现,包<EFBFBD>?select <EFBFBD>?poll 模式<EFBFBD>? * 用于同时监控多个 Socket 的读写事<EFBFBD>? * 适用平台:STM32F4 系列(CH395F 以太网芯片)
|
||||
* 作者:王建<EFBFBD>? * 创建日期<E697A5>?026-07-18
|
||||
* 修改记录<EFBFBD>? */
|
||||
* 模块功能:I/O 多路复用实现,包括 select 和 poll 两种模式,用于同时监控多个 Socket 的读写事件
|
||||
* 适用平台:STM32F407ZGTx + CH395F 以太网芯片
|
||||
* 作者:王建锋
|
||||
* 创建日期:2026-07-18
|
||||
* 修改记录:
|
||||
* 2026-07-18 王建锋 创建初始版本
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cmsis_os.h" /* CMSIS-RTOS2 API: osDelay() */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "net_select.h"
|
||||
#include "net_socket.h"
|
||||
#include "ch395f.h"
|
||||
#include "main.h"
|
||||
|
||||
/*
|
||||
* 私有函数声明<EFBFBD>? */
|
||||
* 私有函数声明区
|
||||
*/
|
||||
|
||||
static int check_socket_readable(int sockfd);
|
||||
static int check_socket_writable(int sockfd);
|
||||
static int check_socket_error(int sockfd);
|
||||
|
||||
/*
|
||||
* 公共函数实现<EFBFBD>? */
|
||||
* 公共函数实现区
|
||||
*/
|
||||
|
||||
/*
|
||||
* 函数功能:I/O 多路复用(select 模式<EFBFBD>? */
|
||||
* 函数功能:I/O 多路复用(select 模式),等待多个 Socket 的读写事件就绪
|
||||
* 入口参数:nfds - 最大文件描述符数 +1 int > 0
|
||||
* readfds - 读事件集合指针 net_fd_set *(可为 NULL)
|
||||
* writefds - 写事件集合指针 net_fd_set *(可为 NULL)
|
||||
* exceptfds- 异常事件集合指针 net_fd_set *(可为 NULL)
|
||||
* timeout - 超时时间结构体指针 net_timeval *(NULL=无限等待)
|
||||
* 返回值:就绪的 Socket 数量 int >= 0 || -1
|
||||
* -1 - 参数无效 int
|
||||
* 限定条件:net_init() + MX_FREERTOS_Init() 已执行;必须在 netTask 上下文中调用
|
||||
* 函数说明:轮询所有 Socket,检查读/写/异常事件是否就绪。阻塞等待直到有事件或超时
|
||||
*/
|
||||
|
||||
int net_select(int nfds, net_fd_set *readfds, net_fd_set *writefds,
|
||||
net_fd_set *exceptfds, net_timeval *timeout) {
|
||||
uint32_t start_tick;
|
||||
@@ -89,8 +115,8 @@ int net_select(int nfds, net_fd_set *readfds, net_fd_set *writefds,
|
||||
}
|
||||
}
|
||||
|
||||
/* 短暂延时避免忙等 */
|
||||
HAL_Delay(NET_POLL_DELAY_MS);
|
||||
/* 让出 CPU:FreeRTOS osDelay() 会正确进入休眠,允许其他任务运行 */
|
||||
osDelay(1); /* 1ms 周期轮询,平衡实时性和 CPU 利用率 */
|
||||
}
|
||||
|
||||
/* 复制结果 */
|
||||
@@ -108,7 +134,15 @@ int net_select(int nfds, net_fd_set *readfds, net_fd_set *writefds,
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:I/O 多路复用(poll 模式<EFBFBD>? */
|
||||
* 函数功能:I/O 多路复用(poll 模式),等待多个 Socket 的读写事件就绪
|
||||
* 入口参数:fds - pollfd 数组指针 net_pollfd *
|
||||
* nfds - 数组元素数量 int > 0
|
||||
* timeout - 超时时间(毫秒) int >= 0
|
||||
* 返回值:就绪的 fd 数量 int >= 0 || -1
|
||||
* -1 - 参数无效 int
|
||||
* 限定条件:net_init() + MX_FREERTOS_Init() 已执行;必须在 netTask 上下文中调用
|
||||
* 函数说明:轮询所有 Socket,检查读/写/错误/挂起事件是否就绪。阻塞等待直到有事件或超时
|
||||
*/
|
||||
int net_poll_events(net_pollfd *fds, int nfds, int timeout) {
|
||||
uint32_t start_tick;
|
||||
int ready = 0;
|
||||
@@ -185,7 +219,8 @@ int net_poll_events(net_pollfd *fds, int nfds, int timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
HAL_Delay(NET_POLL_DELAY_MS);
|
||||
/* 让出 CPU:FreeRTOS osDelay() 会正确进入休眠,允许其他任务运行 */
|
||||
osDelay(1); /* 1ms 周期轮询,平衡实时性和 CPU 利用率 */
|
||||
}
|
||||
|
||||
return ready;
|
||||
|
||||
Reference in New Issue
Block a user