From: 孙春阳 Date: Mon, 6 Oct 2025 01:06:43 +0000 (+0800) Subject: 修复tcp测试时间停止过早问题 X-Git-Tag: V1.0.9_20251128_194606_LN~277 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4bea67311588c6c992870ac58006deed8e41e979;p=mirrors%2FFD230.git 修复tcp测试时间停止过早问题 --- diff --git a/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c b/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c index 0f62ad9cd..482482e1e 100644 --- a/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c +++ b/code/sdk/zhihui/tcptest/src/zhihui_tcp_test.c @@ -28,6 +28,7 @@ /* 使用嵌入式环境的简化定义 */ #include "osal_mutex.h" #include "osal_task.h" + #include "osal_timer.h" /* 用于osal_get_jiffies() */ /* 简化的兼容性定义 */ #define TCP_MUTEX_INIT(mutex) osal_mutex_init(&(mutex)) @@ -793,28 +794,16 @@ static void tcp_test_stats_timer_callback(void *arg) /** * @brief 获取当前时间(毫秒) - 导出函数 + * + * 修复说明:监控线程使用osal_msleep(真实时间),工作线程也必须使用真实时间, + * 否则会导致时间不同步,300秒测试可能只跑80多秒就被监控线程停止。 */ uint32_t tcp_test_get_time_ms(void) { #ifdef USE_LWIP_SOCKET - /* 在lwIP环境中尝试使用真实的时间函数 */ - #ifdef OSAL_TIME_AVAILABLE - /* 如果OSAL时间函数可用,使用它 */ - return osal_get_jiffies(); - #else - /* 否则使用简化的时间模拟 */ - static uint32_t start_time = 0; - static uint32_t last_time = 0; - - if (start_time == 0) { - start_time = 1000; /* 从1秒开始 */ - last_time = start_time; - } - - /* 每次调用增加约1-10ms的随机时间 */ - last_time += (rand() % 10 + 1); - return last_time; - #endif + /* 在lwIP环境中直接使用OSAL时间函数 */ + /* osal_get_jiffies()返回系统启动以来的毫秒数,是真实时间 */ + return osal_get_jiffies(); #else /* 在POSIX环境中使用标准gettimeofday */ struct timeval tv;