修复了网络参数的保存逻辑
This commit is contained in:
@@ -40,6 +40,7 @@ static int s_net_errno = 0; /* 最后错误码 */
|
||||
static uint8_t s_net_initialized = 0; /* 初始化标志 */
|
||||
static uint8_t s_local_ip[4]; /* 本机 IP 缓存(网络序,net_getsockname 用) */
|
||||
static uint16_t s_dynamic_port = 49152; /* 动态端口分配起始值 */
|
||||
static volatile uint32_t s_net_generation = 0; /* 网络代次号:网络重建完成时递增(服务据此重建监听) */
|
||||
|
||||
/*
|
||||
* 消息队列 - 线程安全核心
|
||||
@@ -142,10 +143,11 @@ static bool s_mac_is_zero(const uint8_t *p_mac) {
|
||||
ch395f_set_retrans_count(8); /* 重传 8 次*/
|
||||
ch395f_set_retrans_period(500); /* 每次间隔 500ms,总计 4s 重传窗口 */
|
||||
|
||||
/* 设置 TCP KeepAlive 参数(必须在 INIT_CH395 之前,单位 ms,必须为 500 的倍数,且 IDLE > INTVL)*/
|
||||
ch395f_set_keepalive_idle(60000); /* 空闲 60 秒后开始探测*/
|
||||
ch395f_set_keepalive_intvl(5000); /* 5 秒探测一次*/
|
||||
ch395f_set_keepalive_cnt(3); /* 最多探 3 次*/
|
||||
/* 设置 TCP KeepAlive 参数(必须在 INIT_CH395 之前,单位 ms,必须为 500 的倍数,且 IDLE > INTVL)
|
||||
* 值来自 net_config.h 的 NET_KEEPALIVE_*(60s/5s/3)*/
|
||||
ch395f_set_keepalive_idle(NET_KEEPALIVE_IDLE_MS); /* 空闲 60 秒后开始探测*/
|
||||
ch395f_set_keepalive_intvl(NET_KEEPALIVE_INTVL_MS); /* 5 秒探测一次*/
|
||||
ch395f_set_keepalive_cnt(NET_KEEPALIVE_CNT); /* 最多探 3 次*/
|
||||
|
||||
/* 设置网络参数(必须在 INIT_CH395 之前调用 */
|
||||
if (ip != NULL) {
|
||||
@@ -207,6 +209,28 @@ static bool s_mac_is_zero(const uint8_t *p_mac) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:取网络代次号
|
||||
* 入口参数:无
|
||||
* 返回值:代次号(每次网络重建完成递增) uint32_t
|
||||
* 限定条件:无
|
||||
* 函数说明:见 net_socket.h 同名函数说明
|
||||
*/
|
||||
uint32_t net_get_generation(void) {
|
||||
return s_net_generation;
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:递增网络代次号(网络重建完成、对外可用时调用)
|
||||
* 入口参数:无
|
||||
* 返回值:无
|
||||
* 限定条件:net_init() 成功且 PHY/链路就绪后调用(当前仅 net_stack_bring_up)
|
||||
* 函数说明:见 net_socket.h 同名函数说明
|
||||
*/
|
||||
void net_generation_inc(void) {
|
||||
s_net_generation++;
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:轮询 CH395F 中断状态,更新 Socket 连接状态并处理事件
|
||||
* 返回值:本次轮询中发生事件的 Socket 数量 int >= 0
|
||||
|
||||
Reference in New Issue
Block a user