#include "uart.h"
#include "ConfigModelC.h"
#include "osal_task.h"
+#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom_with_args
#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
}
*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");
#include "osal_task.h"
#include "soc_osal.h"
#include "debug_print.h"
+#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* 全局变量 */
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;
/**
}
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;
}
#include "osal_msgqueue.h"
#include "time/osal_timer.h"
#include "soc_osal.h"
+#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
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;
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 创建时指定优先级)
- // â\9a ï¸\8f å\85³é\94®ä¿®å¤\8dï¼\9aå¿\85é¡»å\9c¨å\88\9b建æ\97¶å°±æ\8c\87å®\9aä¼\98å\85\88级ï¼\8cå\90¦å\88\99线ç¨\8b以é»\98认ä½\8eä¼\98å\85\88级å\88\9b建å\8f¯è\83½æ°¸è¿\9cå¾\97ä¸\8då\88°è°\83度
+ // 4. 启动处理线程(使用 uapi_create_osThread_custom 在 PSRAM 中分配栈)
+ // â\9c\85 ä¼\98å\8c\96ï¼\9aé\80\9aè¿\87 USE_EXTEND_MEM å°\86线ç¨\8bæ \88å\88\86é\85\8då\88° PSRAMï¼\8cè\8a\82ç\9c\81ç\8f\8dè´µç\9a\84 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;
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超时)
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)");
#include "osal_timer.h" // 添加OSAL时间函数头文件
#include "soc_osal.h" // 添加OSAL任务管理头文件
#include "schedule/osal_task.h" // 添加任务创建头文件
+#include "custom_utils.h" // 添加:用于uapi_create_osThread_custom
#include <string.h>
/* lwIP相关头文件 - 需要在编译时确保PPP支持已启用 */
/* 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输出统计结构 */
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;
}
g_ppp_monitor_enabled = false;
/* 等待线程退出 */
osal_msleep(500);
+ g_ppp_monitor_thread_handle = 0; // 清空线程句柄
PPP_DEBUG_INFO("PPP connection monitor stopped");
}
}