From: 孙春阳 Date: Mon, 13 Oct 2025 08:08:18 +0000 (+0800) Subject: ppp所有线程都放到psram中 X-Git-Tag: V1.0.9_20251128_194606_LN~250^2~8^2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=ee5630fa6464a0b7e3c31725b679bf1c56d7f2e3;p=mirrors%2FFD230.git ppp所有线程都放到psram中 --- diff --git a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c index f9d79958e..45bc06fc1 100644 --- a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c +++ b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c @@ -19,6 +19,7 @@ #include "uart.h" #include "ConfigModelC.h" #include "osal_task.h" +#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom_with_args @@ -35,6 +36,8 @@ extern "C" { #define CUSTOM_UTILS_SUCCESS 0 #define CUSTOM_UTILS_FAILED (-1) +/* TCP监控线程句柄 */ +static uint32_t g_tcp_monitor_thread_handle = 0; #include "app_at_process.h" #ifdef SUPPORT_ZHIHUI_WEBSOCKET @@ -1862,22 +1865,29 @@ static errcode_t at_ppp_tcp_performance_test(uint8_t *para, uint32_t paraLen) } *duration_arg = test_time; - osal_task *monitor_thread = osal_kthread_create( - tcp_test_monitor_thread, - duration_arg, - "tcp_monitor", - 2048 // 2KB栈空间 - ); - - if (monitor_thread == NULL) { - PRINT("[PPP_ERR]PPP TCP PERF: Failed to create monitor thread\r\n"); + // 创建监控线程 - 使用 uapi_create_osThread_custom_with_args 在 PSRAM 中分配栈 + // ✅ 优化:通过 USE_EXTEND_MEM 将线程栈分配到 PSRAM,节省珍贵的 DTCM + app_task_definition_ext_t tcp_monitor_cfg = {0}; + tcp_monitor_cfg.attr.name = "tcp_monitor"; + tcp_monitor_cfg.attr.priority = osPriorityNormal; + tcp_monitor_cfg.attr.stack_size = 2048; + tcp_monitor_cfg.func = (osThreadFunc_t)tcp_test_monitor_thread; + tcp_monitor_cfg.task_handle = &g_tcp_monitor_thread_handle; + tcp_monitor_cfg.use_mem = USE_EXTEND_MEM; // ⭐ 关键:使用 PSRAM 分配栈 + tcp_monitor_cfg.create_queue_handle = NULL; + tcp_monitor_cfg.inst_args = duration_arg; // 传递参数 + + ret = uapi_create_osThread_custom_with_args(&tcp_monitor_cfg); + if (ret != ERRCODE_SUCC) { + PRINT("[PPP_ERR]PPP TCP PERF: Failed to create monitor thread: 0x%x\r\n", ret); free(duration_arg); tcp_test_stop(); tcp_test_deinit(); return ERRCODE_FAIL; } - PRINT("[PPP_INFO]PPP TCP PERF: Monitor thread created, will auto-stop after %d seconds\r\n", test_time); + PRINT("[PPP_INFO]PPP TCP PERF: Monitor thread created with PSRAM stack (handle=0x%X), will auto-stop after %d seconds\r\n", + g_tcp_monitor_thread_handle, test_time); PRINT("[PPP_INFO]PPP TCP PERF: Use AT^PPPTCPSTOP to stop early\r\n"); PRINT("[PPP_INFO]PPP TCP PERF: Use AT^PPPTCPSTATS to check status\r\n"); diff --git a/code/sdk/zhihui/ppp/example/ppp_example.c b/code/sdk/zhihui/ppp/example/ppp_example.c index d3078d3ce..cc9d04d19 100644 --- a/code/sdk/zhihui/ppp/example/ppp_example.c +++ b/code/sdk/zhihui/ppp/example/ppp_example.c @@ -6,6 +6,7 @@ #include "osal_task.h" #include "soc_osal.h" #include "debug_print.h" +#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom #include #include #include @@ -22,7 +23,7 @@ static void network_monitor_task(void *arg); /* 全局变量 */ static bool g_ppp_connected = false; -static osal_task *g_monitor_task = NULL; +static uint32_t g_monitor_task = 0; // 改为uint32_t以配合uapi_create_osThread_custom static bool g_ppp_env_initialized = false; static uint32_t g_ppp_baudrate = PPP_UART_BAUDRATE; /** @@ -88,17 +89,30 @@ void set_ppp_baudrate(uint32_t value) } int ppp_env_init_monitor_task(void) { - /* 4. 创建网络监控任务 */ - if (g_monitor_task != NULL) { + /* 4. 创建网络监控任务 - 使用 uapi_create_osThread_custom 在 PSRAM 中分配栈 */ + if (g_monitor_task != 0) { PRINT("Monitor task already exists\r\n"); return 0; } PRINT("Creating network monitor task...\r\n"); - g_monitor_task = osal_kthread_create(network_monitor_task, NULL, "net_monitor", (2048+1024)); // 恢复原始栈大小,AT函数已优化 - if (g_monitor_task == NULL) { - PRINT("Failed to create monitor task\r\n"); + + // ✅ 优化:通过 USE_EXTEND_MEM 将线程栈分配到 PSRAM,节省珍贵的 DTCM + app_task_definition_t monitor_cfg = {0}; + monitor_cfg.attr.name = "net_monitor"; + monitor_cfg.attr.priority = osPriorityNormal; + monitor_cfg.attr.stack_size = 3072; // 2048 + 1024 + monitor_cfg.func = (osThreadFunc_t)network_monitor_task; + monitor_cfg.task_handle = &g_monitor_task; + monitor_cfg.use_mem = USE_EXTEND_MEM; // ⭐ 关键:使用 PSRAM 分配栈 + monitor_cfg.create_queue_handle = NULL; + + errcode_t ret = uapi_create_osThread_custom(&monitor_cfg); + if (ret != ERRCODE_SUCC) { + PRINT("Failed to create monitor task: 0x%x\r\n", ret); return -1; } + + PRINT("Network monitor task created with PSRAM stack (handle=0x%X)\r\n", g_monitor_task); return 0; } diff --git a/code/sdk/zhihui/ppp/src/ppp_interrupt.c b/code/sdk/zhihui/ppp/src/ppp_interrupt.c index 8b9bd8457..75df7cd90 100644 --- a/code/sdk/zhihui/ppp/src/ppp_interrupt.c +++ b/code/sdk/zhihui/ppp/src/ppp_interrupt.c @@ -21,6 +21,7 @@ #include "osal_msgqueue.h" #include "time/osal_timer.h" #include "soc_osal.h" +#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom #include #include #include @@ -70,7 +71,7 @@ typedef struct { static volatile bool g_ppp_interrupt_enabled = false; /* 处理线程相关 */ -static osal_task *g_ppp_irq_process_task = NULL; +static uint32_t g_ppp_irq_process_task = 0; // 改为uint32_t以配合uapi_create_osThread_custom static unsigned long g_ppp_irq_msg_queue = 0; // 消息队列ID (OSAL使用unsigned long) static volatile bool g_ppp_irq_task_running = false; @@ -701,24 +702,22 @@ ppp_error_t ppp_interrupt_enable(void) PPP_DEBUG_INFO("Message queue created (depth=%d, item_size=%d bytes)", PPP_IRQ_MSG_QUEUE_SIZE, sizeof(ppp_irq_msg_t)); - // 4. 启动处理线程(使用 osal_kthread_create_ext 创建时指定优先级) - // ⚠️ 关键修复:必须在创建时就指定优先级,否则线程以默认低优先级创建可能永远得不到调度 + // 4. 启动处理线程(使用 uapi_create_osThread_custom 在 PSRAM 中分配栈) + // ✅ 优化:通过 USE_EXTEND_MEM 将线程栈分配到 PSRAM,节省珍贵的 DTCM g_ppp_irq_task_running = true; - osal_kthread_init init_cfg = { - .handler = (osal_kthread_handler)ppp_irq_process_thread, - .data = NULL, - .taskname = "ppp_irq_proc", - .stacksize = PPP_IRQ_PROCESS_STACK_SIZE, - .taskprio = OSAL_TASK_PRIORITY_MIDDLE // 使用中等优先级(6),避免阻塞看门狗 - }; - - osal_kthread_lock(); - g_ppp_irq_process_task = osal_kthread_create_ext(&init_cfg); - osal_kthread_unlock(); + app_task_definition_t irq_task_cfg = {0}; + irq_task_cfg.attr.name = "ppp_irq_proc"; + irq_task_cfg.attr.priority = osPriorityNormal; // 优先级24(对应原MIDDLE) + irq_task_cfg.attr.stack_size = PPP_IRQ_PROCESS_STACK_SIZE; + irq_task_cfg.func = (osThreadFunc_t)ppp_irq_process_thread; + irq_task_cfg.task_handle = &g_ppp_irq_process_task; + irq_task_cfg.use_mem = USE_EXTEND_MEM; // ⭐ 关键:使用 PSRAM 分配栈 + irq_task_cfg.create_queue_handle = NULL; - if (!g_ppp_irq_process_task) { - PPP_DEBUG_ERROR("Failed to create process thread"); + ret = uapi_create_osThread_custom(&irq_task_cfg); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to create IRQ process thread: 0x%x", ret); osal_msg_queue_delete(g_ppp_irq_msg_queue); g_ppp_irq_msg_queue = 0; g_ppp_irq_task_running = false; @@ -727,9 +726,9 @@ ppp_error_t ppp_interrupt_enable(void) return PPP_ERR_MEMORY; } - PPP_DEBUG_WARN("IRQ process thread created @ %p with MIDDLE priority (6)", + PPP_DEBUG_WARN("IRQ process thread created with PSRAM stack (handle=0x%X)", g_ppp_irq_process_task); - PPP_DEBUG_INFO("Process thread: stack=%d bytes, priority=MIDDLE(6)", + PPP_DEBUG_INFO("Process thread: stack=%d bytes in PSRAM, priority=Normal(24)", PPP_IRQ_PROCESS_STACK_SIZE); // 5. 启动定时器(30ms周期检查buffer超时) @@ -929,7 +928,7 @@ ppp_error_t ppp_interrupt_disable(void) memset(&g_uart_error_stats, 0, sizeof(ppp_uart_error_stats_t)); g_ppp_interrupt_enabled = false; - g_ppp_irq_process_task = NULL; + g_ppp_irq_process_task = 0; PPP_DEBUG_INFO("PPP UART interrupt disabled (memory freed)"); diff --git a/code/sdk/zhihui/ppp/src/ppp_lwip.c b/code/sdk/zhihui/ppp/src/ppp_lwip.c index c694fcb63..03e1ae5c5 100644 --- a/code/sdk/zhihui/ppp/src/ppp_lwip.c +++ b/code/sdk/zhihui/ppp/src/ppp_lwip.c @@ -10,6 +10,7 @@ #include "osal_timer.h" // 添加OSAL时间函数头文件 #include "soc_osal.h" // 添加OSAL任务管理头文件 #include "schedule/osal_task.h" // 添加任务创建头文件 +#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom #include /* lwIP相关头文件 - 需要在编译时确保PPP支持已启用 */ @@ -48,6 +49,7 @@ static ppp_lwip_context_t g_lwip_ctx = {0}; /* PPP连接监控相关 */ static bool g_ppp_monitor_enabled = false; static uint32_t g_last_data_activity_time = 0; +static uint32_t g_ppp_monitor_thread_handle = 0; // 监控线程句柄 static uint32_t g_connection_idle_timeout = 60000; /* 60秒无数据活动后检查连接 */ /* PPP输出统计结构 */ @@ -141,16 +143,26 @@ ppp_error_t ppp_lwip_start_connection_monitor(void) g_ppp_monitor_enabled = true; g_last_data_activity_time = ppp_lwip_get_time_ms(); - /* 创建监控线程 - 使用osal_kthread_create */ - osal_task *monitor_task = osal_kthread_create(ppp_lwip_monitor_thread, NULL, - "ppp_monitor", 4096); - if (monitor_task == NULL) { - PPP_DEBUG_ERROR("Failed to create PPP monitor thread"); + /* 创建监控线程 - 使用 uapi_create_osThread_custom 在 PSRAM 中分配栈 */ + // ✅ 优化:通过 USE_EXTEND_MEM 将线程栈分配到 PSRAM,节省珍贵的 DTCM + app_task_definition_t monitor_task_cfg = {0}; + monitor_task_cfg.attr.name = "ppp_monitor"; + monitor_task_cfg.attr.priority = osPriorityNormal; + monitor_task_cfg.attr.stack_size = 4096; + monitor_task_cfg.func = (osThreadFunc_t)ppp_lwip_monitor_thread; + monitor_task_cfg.task_handle = &g_ppp_monitor_thread_handle; + monitor_task_cfg.use_mem = USE_EXTEND_MEM; // ⭐ 关键:使用 PSRAM 分配栈 + monitor_task_cfg.create_queue_handle = NULL; + + errcode_t ret = uapi_create_osThread_custom(&monitor_task_cfg); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to create PPP monitor thread: 0x%x", ret); g_ppp_monitor_enabled = false; return PPP_ERR_UNKNOWN; } - PPP_DEBUG_INFO("PPP connection monitor started successfully"); + PPP_DEBUG_INFO("PPP connection monitor started successfully with PSRAM stack (handle=0x%X)", + g_ppp_monitor_thread_handle); return PPP_ERR_OK; } @@ -164,6 +176,7 @@ void ppp_lwip_stop_connection_monitor(void) g_ppp_monitor_enabled = false; /* 等待线程退出 */ osal_msleep(500); + g_ppp_monitor_thread_handle = 0; // 清空线程句柄 PPP_DEBUG_INFO("PPP connection monitor stopped"); } }