From: 孙春阳 Date: Thu, 16 Oct 2025 07:09:59 +0000 (+0800) Subject: slip和ppp都加上了AT^CAT1SUSPEND,AT^CAT1RESUME指令,调试功耗。 X-Git-Tag: V1.0.9_20251128_194606_LN~228^2~1 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4a6199f0e9bb60650402e2add706239699563348;p=mirrors%2FFD230.git slip和ppp都加上了AT^CAT1SUSPEND,AT^CAT1RESUME指令,调试功耗。 --- diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_utils.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_utils.c index 1bbdc4eef..74ef96daa 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/cat1_utils.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/cat1_utils.c @@ -381,7 +381,44 @@ errcode_t cat1_register_time_ctl_functions(time_ctl_funcs_t *funcs) return ERRCODE_SUCC; } -//设置4G能力开关是否开启 + +void cat1_api_suspend_protocol(void) +{ + #ifdef SUPPORT_LWIP + tcpip_thread_suspend(); + slipif_loop_thread_suspend(); + #endif +} + +/** + * @brief 恢复SLIP协议栈 (SLIP模式专用实现) + * + * 注意: + * - 本函数仅在 SLIP 模式下编译使用 + * - PPP 模式下,该函数在 ppp_cat1_api.c 中实现 + * + * 功能: + * 1. 恢复lwIP tcpip线程 + * 2. 恢复SLIP接收线程 + */ +void cat1_api_resume_protocol(void) +{ + #ifdef SUPPORT_LWIP + tcpip_thread_resume(); + slipif_loop_thread_resume(); + #endif + +} + +/** + * @brief 设置4G能力开关是否开启 (SLIP模式专用实现) + * + * 注意: + * - 本函数仅在 SLIP 模式下编译使用 + * - PPP 模式下,该函数在 ppp_cat1_api.c 中实现 + * + * @param isopen true=开机, false=关机 + */ void cat1_api_enable_cat1(bool isopen) { errcode_t ret = 0; @@ -392,10 +429,7 @@ void cat1_api_enable_cat1(bool isopen) if(cat1_api_runtime_get_cat1_powerstat()) return; -#ifdef SUPPORT_LWIP - tcpip_thread_resume(); - slipif_loop_thread_resume(); -#endif + cat1_api_resume_protocol(); cat1_api_power_on_cat1(); // if(!cat1_api_runtime_get_saveele_status()) { @@ -408,10 +442,8 @@ void cat1_api_enable_cat1(bool isopen) { // if(!cat1_api_runtime_get_cat1_powerstat()) // return; -#ifdef SUPPORT_LWIP - tcpip_thread_suspend(); - slipif_loop_thread_suspend(); -#endif + + cat1_api_suspend_protocol(); cat1_api_power_off_cat1(); // if(!cat1_api_runtime_get_saveele_status()) { @@ -425,7 +457,6 @@ void cat1_api_enable_cat1(bool isopen) } - static bool g_enable_uart_rx = true; /** * return uart enable flag diff --git a/code/sdk/zhihui/4g/cat1Service/include/cat1_utils.h b/code/sdk/zhihui/4g/cat1Service/include/cat1_utils.h index 412bf51aa..440767d7a 100644 --- a/code/sdk/zhihui/4g/cat1Service/include/cat1_utils.h +++ b/code/sdk/zhihui/4g/cat1Service/include/cat1_utils.h @@ -92,9 +92,12 @@ errcode_t cat1_write_security_key(void *se_keybuf,uint16_t se_keylen); //来电 int cat1_handle_call_incomming(char * msg); +void cat1_api_suspend_protocol(void); +void cat1_api_resume_protocol(void); errcode_t permition_verify(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/code/sdk/zhihui/4gTest/cat1_at_cmd.c b/code/sdk/zhihui/4gTest/cat1_at_cmd.c index e766f43c6..c51825f40 100644 --- a/code/sdk/zhihui/4gTest/cat1_at_cmd.c +++ b/code/sdk/zhihui/4gTest/cat1_at_cmd.c @@ -11,6 +11,7 @@ #include #include "cat1_log.h" #include "osal_task.h" +#include "cat1_utils.h" // For cat1_api_suspend_protocol/cat1_api_resume_protocol #ifdef __cplusplus @@ -929,6 +930,68 @@ static errcode_t at_4g_tcp_test_stats(uint8_t *para, uint32_t paraLen) #endif } +/** + * @brief AT^CAT1SUSPEND - 挂起CAT1协议栈 + * + * 功能:调用cat1_api_suspend_protocol()挂起: + * - lwIP tcpip线程 + * - SLIP/PPP接收线程 + * + * 用途:系统进入休眠前调用 + */ +static errcode_t at_cat1_suspend_protocol(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(para); + UNUSED(paraLen); + UNUSED(strCommonCmd); + + cat1_print_info("=== AT^CAT1SUSPEND: Suspending CAT1 protocol stack ===\n"); + + // 调用 cat1_api_suspend_protocol,它会根据编译宏自动选择: + // #ifdef SUPPORT_PPP_SERVICE -> ppp_suspend() + // #else -> slipif_loop_thread_suspend() + // 同时挂起 lwIP tcpip 线程 + cat1_api_suspend_protocol(); + + cat1_print_info("AT^CAT1SUSPEND: CAT1 protocol stack suspended successfully\n"); + cat1_print_info(" - lwIP tcpip thread suspended\n"); + cat1_print_info(" - Network threads suspended\n"); + cat1_print_info(" - System ready for deep sleep\n"); + + return ERRCODE_SUCC; +} + +/** + * @brief AT^CAT1RESUME - 恢复CAT1协议栈 + * + * 功能:调用cat1_api_resume_protocol()恢复: + * - lwIP tcpip线程 + * - SLIP/PPP接收线程 + * + * 用途:系统从休眠恢复后调用 + */ +static errcode_t at_cat1_resume_protocol(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(para); + UNUSED(paraLen); + UNUSED(strCommonCmd); + + cat1_print_info("=== AT^CAT1RESUME: Resuming CAT1 protocol stack ===\n"); + + // 调用 cat1_api_resume_protocol,它会根据编译宏自动选择: + // #ifdef SUPPORT_PPP_SERVICE -> ppp_resume() + // #else -> slipif_loop_thread_resume() + // 同时恢复 lwIP tcpip 线程 + cat1_api_resume_protocol(); + + cat1_print_info("AT^CAT1RESUME: CAT1 protocol stack resumed successfully\n"); + cat1_print_info(" - lwIP tcpip thread resumed\n"); + cat1_print_info(" - Network threads resumed\n"); + cat1_print_info(" - System ready for normal operation\n"); + + return ERRCODE_SUCC; +} + static const at_cmd_table_t g_cat1_cmd[] = { { (char *)"AT^CAT1POWER", cat1_power, (char *)"1" }, { (char *)"AT^CAT1DIAL", at_cat1_dial, (char *)"1" }, @@ -946,6 +1009,9 @@ static const at_cmd_table_t g_cat1_cmd[] = { { (char *)"AT^SENDDTMF", at_cat1_senddtmf, (char *)"1" }, { (char *)"AT^HTTPDOWNLOAD", custom_start_ota_download, (char *)" " }, { (char *)"AT^CAT1LOGLEVEL", custom_enable_cat1_debug_log, (char *)" " }, + /* CAT1休眠/唤醒控制指令 (支持PPP和SLIP两种协议) */ + { (char *)"AT^CAT1SUSPEND", at_cat1_suspend_protocol, (char *)" " }, + { (char *)"AT^CAT1RESUME", at_cat1_resume_protocol, (char *)" " }, #ifdef SUPPORT_ZHIHUI_WEBSOCKET { (char *)"AT^WEBSOCKETTEST", at_websocket_test_start, (char *)"serverip,port,test_time" }, { (char *)"AT^STOPWEBSOCKET", at_websocket_test_stop, (char *)" " }, diff --git a/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp index 9dfc9c2a0..345934d43 100644 --- a/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp +++ b/code/sdk/zhihui/leiniao/factory_test/PPPTestView.cpp @@ -505,7 +505,7 @@ static bool g_ppp_init_completed = false; // 定时器相关变量 static osTimerId_t g_ppp_update_timer_handle = nullptr; -static bool g_ppp_timer_running = false; +static bool g_ppp_test_timer_running = false; #ifdef SUPPORT_PPP_SERVICE // 前向声明 @@ -792,7 +792,7 @@ static void switch_to_at_mode_and_continue() { static void ppp_update_timer_callback(void* arg) { (void)arg; // 未使用的参数 - if (!g_ppp_init_completed || !g_ppp_timer_running) { + if (!g_ppp_init_completed || !g_ppp_test_timer_running) { return; } @@ -823,7 +823,7 @@ static void ppp_update_timer_callback(void* arg) { // 启动定时器 static void start_ppp_update_timer() { - if (g_ppp_timer_running) { + if (g_ppp_test_timer_running) { printf("PPP更新定时器已经在运行\n"); return; } @@ -839,7 +839,7 @@ static void start_ppp_update_timer() { if (g_ppp_update_timer_handle != nullptr) { osStatus_t status = osTimerStart(g_ppp_update_timer_handle, 3000); // 3秒间隔 if (status == osOK) { - g_ppp_timer_running = true; + g_ppp_test_timer_running = true; printf("PPP更新定时器启动成功,间隔3秒\n"); } else { printf("PPP更新定时器启动失败: %d\n", status); @@ -854,7 +854,7 @@ static void start_ppp_update_timer() { // 停止定时器 static void stop_ppp_update_timer() { - if (!g_ppp_timer_running || g_ppp_update_timer_handle == nullptr) { + if (!g_ppp_test_timer_running || g_ppp_update_timer_handle == nullptr) { printf("PPP更新定时器未运行\n"); return; } @@ -873,7 +873,7 @@ static void stop_ppp_update_timer() { printf("PPP更新定时器停止失败: %d\n", status); } - g_ppp_timer_running = false; + g_ppp_test_timer_running = false; g_ppp_update_timer_handle = nullptr; } diff --git a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c index 19fc8698e..5e617eb8c 100644 --- a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c +++ b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c @@ -20,6 +20,7 @@ #include "ConfigModelC.h" #include "osal_task.h" #include "custom_utils.h" // 添加:用于uapi_create_osThread_custom_with_args +#include "cat1_utils.h" // 添加:用于cat1_api_suspend/resume_protocol @@ -2490,6 +2491,66 @@ static errcode_t at_ppp_get_config_baudrate(uint8_t *para, uint32_t paraLen, cha return ERRCODE_SUCC; } +/** + * @brief AT^PPPSUSPEND - 挂起PPP和CAT1协议栈 + * + * 功能:调用cat1_api_suspend_protocol()挂起: + * - lwIP tcpip线程 + * - SLIP/PPP接收线程 + * + * 用途:系统进入休眠前调用 + */ +static errcode_t at_ppp_suspend_protocol(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(para); + UNUSED(paraLen); + UNUSED(strCommonCmd); + + ppp_print_info("=== AT^PPPSUSPEND: Suspending protocol stack ===\n"); + + // 调用CAT1的suspend函数,它会根据宏定义调用对应的suspend + // #ifdef SUPPORT_PPP_SERVICE -> ppp_suspend() + // #else -> slipif_loop_thread_suspend() + cat1_api_suspend_protocol(); + + ppp_print_info("AT^PPPSUSPEND: Protocol stack suspended successfully\n"); + ppp_print_info(" - lwIP tcpip thread suspended\n"); + ppp_print_info(" - PPP/SLIP receive thread suspended\n"); + ppp_print_info(" - System ready for deep sleep\n"); + + return ERRCODE_SUCC; +} + +/** + * @brief AT^PPPRESUME - 恢复PPP和CAT1协议栈 + * + * 功能:调用cat1_api_resume_protocol()恢复: + * - lwIP tcpip线程 + * - SLIP/PPP接收线程 + * + * 用途:系统从休眠恢复后调用 + */ +static errcode_t at_ppp_resume_protocol(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(para); + UNUSED(paraLen); + UNUSED(strCommonCmd); + + ppp_print_info("=== AT^PPPRESUME: Resuming protocol stack ===\n"); + + // 调用CAT1的resume函数,它会根据宏定义调用对应的resume + // #ifdef SUPPORT_PPP_SERVICE -> ppp_resume() + // #else -> slipif_loop_thread_resume() + cat1_api_resume_protocol(); + + ppp_print_info("AT^PPPRESUME: Protocol stack resumed successfully\n"); + ppp_print_info(" - lwIP tcpip thread resumed\n"); + ppp_print_info(" - PPP/SLIP receive thread resumed\n"); + ppp_print_info(" - System ready for normal operation\n"); + + return ERRCODE_SUCC; +} + static const at_cmd_table_t g_ppp_cmd[] = { { (char *)"AT^CAT1POWER", cat1_power, (char *)"1" }, { (char *)"AT^CAT1GETSIGNAL", at_cat1_getsignal, (char *)"1" }, @@ -2502,6 +2563,9 @@ static const at_cmd_table_t g_ppp_cmd[] = { { (char *)"AT^CAT1AT", at_cat1_atcmd, (char *)"1" }, { (char *)"AT^HTTPDOWNLOAD", custom_start_ota_download, (char *)" " }, { (char *)"AT^CAT1LOGLEVEL", custom_enable_cat1_debug_log, (char *)" " }, + /* PPP休眠/唤醒控制指令 (仅在PPP模式下可用) */ + { (char *)"AT^CAT1SUSPEND", at_ppp_suspend_protocol, (char *)" " }, + { (char *)"AT^cAT1RESUME", at_ppp_resume_protocol, (char *)" " }, /* PPP串口测试指令 */ { (char *)"AT^PPPSTATUS", at_ppp_status, (char *)" " }, { (char *)"AT^PPPTRANS", at_ppp_transparent, (char *)"AT_COMMAND" }, diff --git a/code/sdk/zhihui/ppp/include/ppp_api.h b/code/sdk/zhihui/ppp/include/ppp_api.h index c70a86fd5..8fcbbdd18 100644 --- a/code/sdk/zhihui/ppp/include/ppp_api.h +++ b/code/sdk/zhihui/ppp/include/ppp_api.h @@ -307,6 +307,18 @@ void ppp_lwip_print_discard_stats(void); */ void ppp_lwip_print_mru_status(void); + + +/** + * @brief PPP模块挂起 + */ +void ppp_suspend(void); + +/** + * @brief PPP模块恢复 + */ +void ppp_resume(void); + #ifdef __cplusplus } #endif diff --git a/code/sdk/zhihui/ppp/include/ppp_power_ctl.h b/code/sdk/zhihui/ppp/include/ppp_power_ctl.h index b00eff95c..687e4708c 100644 --- a/code/sdk/zhihui/ppp/include/ppp_power_ctl.h +++ b/code/sdk/zhihui/ppp/include/ppp_power_ctl.h @@ -96,15 +96,6 @@ void ppp_api_wakeup_cat1(uint8_t wakeup); */ void ppp_api_keep_wakeup(uint8_t keep_wakeup); -/** - * @brief PPP模块挂起 - */ -void ppp_suspend(void); - -/** - * @brief PPP模块恢复 - */ -void ppp_resume(void); /** * @brief PPP模块注册4G控制引脚配置 diff --git a/code/sdk/zhihui/ppp/src/ppp_api.c b/code/sdk/zhihui/ppp/src/ppp_api.c index 49213488f..ed74494cd 100644 --- a/code/sdk/zhihui/ppp/src/ppp_api.c +++ b/code/sdk/zhihui/ppp/src/ppp_api.c @@ -14,6 +14,7 @@ #include "schedule/osal_task.h" #include "securec.h" #include "ppp_log.h" +#include "custom_utils.h" // 添加线程挂起/恢复API // lwIP头文件,用于访问netif结构体和系统抽象层 #ifdef LWIP_PPP_SUPPORT @@ -2817,4 +2818,183 @@ errcode_t ppp_get_network_signal_info(void) PPP_DEBUG_CRITICAL("=== End Signal Summary ==="); return ERRCODE_SUCC; +} + + +/** + * @brief PPP模块挂起 - 用于系统休眠,暂停线程和定时器 + * + * 实现说明(参考slipif_loop_thread_suspend): + * 1. 设置运行标志为false(线程会进入长时间休眠) + * 2. 停止定时器 + * 3. 挂起线程(使用系统API) + * 4. 不操作4G模块(只在需要发送数据时才唤醒) + */ +void ppp_suspend(void) +{ + PPP_DEBUG_CRITICAL("=== PPP Suspend Started ==="); + +#if PPP_USE_INTERRUPT_MODE + // 中断模式:暂停IRQ处理线程 + extern volatile bool g_ppp_irq_task_running; + extern uint32_t g_ppp_irq_process_task; + extern volatile bool g_ppp_timer_running; + extern osal_timer g_ppp_timeout_timer; + + // 1. 设置运行标志为false + g_ppp_irq_task_running = false; + + // 2. 停止定时器 + if (g_ppp_timer_running) { + g_ppp_timer_running = false; + osal_timer_stop(&g_ppp_timeout_timer); + PPP_DEBUG_INFO("PPP timeout timer stopped"); + } + + // 3. 挂起线程 + if (g_ppp_irq_process_task != 0) { + int ret = uapi_suspend_thread((unsigned long)g_ppp_irq_process_task); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to suspend IRQ process thread: %d", ret); + } else { + PPP_DEBUG_INFO("PPP IRQ process thread suspended"); + } + } +#else + // 轮询模式:暂停接收线程和处理线程 + extern volatile bool g_ppp_rx_thread_running; + extern volatile bool g_ppp_process_thread_running; + extern uint32_t g_ppp_rx_thread_handle; + extern uint32_t g_ppp_process_thread_handle; + extern volatile bool g_ppp_timer_running; + extern osal_timer g_ppp_timeout_timer; + + // 1. 设置运行标志为false + g_ppp_rx_thread_running = false; + g_ppp_process_thread_running = false; + + // 2. 停止定时器 + if (g_ppp_timer_running) { + g_ppp_timer_running = false; + osal_timer_stop(&g_ppp_timeout_timer); + PPP_DEBUG_INFO("PPP timeout timer stopped"); + } + + // 3. 挂起接收线程 + if (g_ppp_rx_thread_handle != 0) { + int ret = uapi_suspend_thread((unsigned long)g_ppp_rx_thread_handle); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to suspend RX thread: %d", ret); + } else { + PPP_DEBUG_INFO("PPP receive thread suspended"); + } + } + + // 4. 挂起处理线程 + if (g_ppp_process_thread_handle != 0) { + int ret = uapi_suspend_thread((unsigned long)g_ppp_process_thread_handle); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to suspend process thread: %d", ret); + } else { + PPP_DEBUG_INFO("PPP process thread suspended"); + } + } +#endif + + PPP_DEBUG_CRITICAL("=== PPP Suspended (threads and timer stopped) ==="); + PPP_DEBUG_INFO("Note: 4G module not affected, will be woken up when data needs to be sent"); +} + +/** + * @brief PPP模块恢复 - 从系统休眠恢复,重启线程和定时器 + * + * 实现说明(参考slipif_loop_thread_resume): + * 1. 设置运行标志为true + * 2. 恢复线程 + * 3. 重启定时器 + * 4. 不操作4G模块 + */ +void ppp_resume(void) +{ + PPP_DEBUG_CRITICAL("=== PPP Resume Started ==="); + +#if PPP_USE_INTERRUPT_MODE + // 中断模式:恢复IRQ处理线程 + extern volatile bool g_ppp_irq_task_running; + extern uint32_t g_ppp_irq_process_task; + extern volatile bool g_ppp_timer_running; + extern osal_timer g_ppp_timeout_timer; + + // 1. 设置运行标志为true + g_ppp_irq_task_running = true; + + // 2. 恢复线程 + if (g_ppp_irq_process_task != 0) { + int ret = uapi_resume_thread((unsigned long)g_ppp_irq_process_task); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to resume IRQ process thread: %d", ret); + } else { + PPP_DEBUG_INFO("PPP IRQ process thread resumed"); + } + } + + // 3. 重启定时器 + if (!g_ppp_timer_running) { + g_ppp_timer_running = true; + int ret = osal_timer_start(&g_ppp_timeout_timer); + if (ret != OSAL_SUCCESS) { + PPP_DEBUG_ERROR("Failed to restart timeout timer: 0x%x", ret); + g_ppp_timer_running = false; + } else { + PPP_DEBUG_INFO("PPP timeout timer restarted"); + } + } +#else + // 轮询模式:恢复接收线程和处理线程 + extern volatile bool g_ppp_rx_thread_running; + extern volatile bool g_ppp_process_thread_running; + extern uint32_t g_ppp_rx_thread_handle; + extern uint32_t g_ppp_process_thread_handle; + extern volatile bool g_ppp_timer_running; + extern osal_timer g_ppp_timeout_timer; + + // 1. 设置运行标志为true + g_ppp_rx_thread_running = true; + g_ppp_process_thread_running = true; + + // 2. 恢复处理线程 + if (g_ppp_process_thread_handle != 0) { + int ret = uapi_resume_thread((unsigned long)g_ppp_process_thread_handle); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to resume process thread: %d", ret); + } else { + PPP_DEBUG_INFO("PPP process thread resumed"); + } + } + + // 3. 恢复接收线程 + if (g_ppp_rx_thread_handle != 0) { + int ret = uapi_resume_thread((unsigned long)g_ppp_rx_thread_handle); + if (ret != ERRCODE_SUCC) { + PPP_DEBUG_ERROR("Failed to resume RX thread: %d", ret); + } else { + PPP_DEBUG_INFO("PPP receive thread resumed"); + } + } + + // 4. 重启定时器 + if (!g_ppp_timer_running) { + g_ppp_timer_running = true; + int ret = osal_timer_start(&g_ppp_timeout_timer); + if (ret != OSAL_SUCCESS) { + PPP_DEBUG_ERROR("Failed to restart timeout timer: 0x%x", ret); + g_ppp_timer_running = false; + } else { + PPP_DEBUG_INFO("PPP timeout timer restarted"); + } + } +#endif + + PPP_DEBUG_CRITICAL("=== PPP Resumed (threads and timer restarted) ==="); + PPP_DEBUG_INFO("Note: 4G module will be woken up when data needs to be sent"); } \ No newline at end of file diff --git a/code/sdk/zhihui/ppp/src/ppp_cat1_api.c b/code/sdk/zhihui/ppp/src/ppp_cat1_api.c index 2dfd779e0..28b4d8fe1 100644 --- a/code/sdk/zhihui/ppp/src/ppp_cat1_api.c +++ b/code/sdk/zhihui/ppp/src/ppp_cat1_api.c @@ -420,6 +420,60 @@ void cat1_ring_isr_callback(pin_t pin, uintptr_t param) ppp_ring_isr_callback(pin, param); } +/********************** 协议栈休眠/唤醒接口 (PPP专用) **********************/ + +/** + * @brief 挂起PPP协议栈 (PPP模式专用实现) + * + * 功能: + * 1. 挂起lwIP tcpip线程 + * 2. 挂起PPP接收/处理线程 + * 3. 停止PPP定时器 + */ +void cat1_api_suspend_protocol(void) +{ + PPP_DEBUG_INFO("=== PPP: cat1_api_suspend_protocol (PPP mode) ===\n"); + + // 1. 挂起lwIP tcpip线程 + #ifdef SUPPORT_LWIP + tcpip_thread_suspend(); + PPP_DEBUG_INFO("PPP: lwIP tcpip thread suspended\n"); + #endif + + // 2. 挂起PPP协议栈 (PPP专用) + extern void ppp_suspend(void); + ppp_suspend(); + PPP_DEBUG_INFO("PPP: PPP protocol stack suspended\n"); + + PPP_DEBUG_INFO("=== PPP: Protocol stack suspended successfully ===\n"); +} + +/** + * @brief 恢复PPP协议栈 (PPP模式专用实现) + * + * 功能: + * 1. 恢复lwIP tcpip线程 + * 2. 恢复PPP接收/处理线程 + * 3. 重启PPP定时器 + */ +void cat1_api_resume_protocol(void) +{ + PPP_DEBUG_INFO("=== PPP: cat1_api_resume_protocol (PPP mode) ===\n"); + + // 1. 恢复lwIP tcpip线程 + #ifdef SUPPORT_LWIP + tcpip_thread_resume(); + PPP_DEBUG_INFO("PPP: lwIP tcpip thread resumed\n"); + #endif + + // 2. 恢复PPP协议栈 (PPP专用) + extern void ppp_resume(void); + ppp_resume(); + PPP_DEBUG_INFO("PPP: PPP protocol stack resumed\n"); + + PPP_DEBUG_INFO("=== PPP: Protocol stack resumed successfully ===\n"); +} + /********************** 其他接口(暂时返回默认值或空实现) **********************/ /** diff --git a/code/sdk/zhihui/ppp/src/ppp_interrupt.c b/code/sdk/zhihui/ppp/src/ppp_interrupt.c index fcd6fc456..040f0f489 100644 --- a/code/sdk/zhihui/ppp/src/ppp_interrupt.c +++ b/code/sdk/zhihui/ppp/src/ppp_interrupt.c @@ -71,9 +71,10 @@ typedef struct { static volatile bool g_ppp_interrupt_enabled = false; /* 处理线程相关 */ -static uint32_t g_ppp_irq_process_task = 0; // 改为uint32_t以配合uapi_create_osThread_custom +// 中断模式全局变量(供 ppp_suspend/resume 访问) +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; +volatile bool g_ppp_irq_task_running = false; // 移除 static,供外部访问 /* 乒乓缓冲区(动态分配,避免占用DTCM) */ static ppp_ping_pong_buffer_t *g_ping_pong_buffers = NULL; // 改为指针,通过malloc动态分配 @@ -83,8 +84,9 @@ static volatile uint8_t g_current_buffer_index = 0; // ⚠️ volatile不保证 static volatile uint32_t g_timer_timestamp_ms = 0; /* 定时器相关 */ -static osal_timer g_ppp_timeout_timer; -static volatile bool g_ppp_timer_running = false; +// Timer 全局变量(供 ppp_suspend/resume 访问) +osal_timer g_ppp_timeout_timer; // 移除 static +volatile bool g_ppp_timer_running = false; // 移除 static /* 统计信息 */ static ppp_interrupt_stats_t g_ppp_interrupt_stats = {0}; diff --git a/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c b/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c index e4330e25a..e396e50d6 100644 --- a/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c +++ b/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c @@ -64,10 +64,11 @@ typedef struct { } ppp_msg_t; /* PPP线程相关 */ -static uint32_t g_ppp_rx_thread_handle = 0; // 接收线程句柄 -static uint32_t g_ppp_process_thread_handle = 0; // 处理线程句柄 -static volatile bool g_ppp_rx_thread_running = false; -static volatile bool g_ppp_process_thread_running = false; +// 轮询模式全局变量(供 ppp_suspend/resume 访问) +uint32_t g_ppp_rx_thread_handle = 0; // 接收线程句柄,移除 static +uint32_t g_ppp_process_thread_handle = 0; // 处理线程句柄,移除 static +volatile bool g_ppp_rx_thread_running = false; // 移除 static,供外部访问 +volatile bool g_ppp_process_thread_running = false; // 移除 static,供外部访问 static volatile bool g_ppp_rx_thread_completed = false; static volatile bool g_ppp_process_thread_completed = false; @@ -78,9 +79,11 @@ static unsigned long g_ppp_msg_queue = 0; static ppp_ping_pong_buffer_t g_ping_pong_buffers[PPP_PING_PONG_BUFFER_COUNT]; static volatile uint8_t g_current_buffer_index = 0; // ⚠️ volatile不保证原子性,但单字节写入在ARM上通常是原子的 -/* 定时器相关 */ -static osal_timer g_ppp_timeout_timer; -static volatile bool g_ppp_timer_running = false; +/* 定时器相关(轮询模式使用,但在中断模式下也需要,所以放在 ppp_api.c 中统一定义) */ +// Timer 变量在 ppp_interrupt.c 中定义(中断模式) +// 轮询模式和中断模式共享这些变量 +extern osal_timer g_ppp_timeout_timer; +extern volatile bool g_ppp_timer_running; /* 统计信息 */ typedef struct { diff --git a/code/sdk/zhihui/ppp/src/ppp_power_ctl.c b/code/sdk/zhihui/ppp/src/ppp_power_ctl.c index 231ab1023..74d86b08c 100644 --- a/code/sdk/zhihui/ppp/src/ppp_power_ctl.c +++ b/code/sdk/zhihui/ppp/src/ppp_power_ctl.c @@ -373,22 +373,6 @@ void ppp_api_keep_wakeup(uint8_t keep_wakeup) PPP_DEBUG_PRINT("PPP: Keep wakeup Cat1: %d\n", keep_wakeup); } -/** - * @brief PPP模块挂起 - */ -void ppp_suspend(void) -{ - PPP_DEBUG_PRINT("PPP: Module suspended\n"); -} - -/** - * @brief PPP模块恢复 - */ -void ppp_resume(void) -{ - PPP_DEBUG_PRINT("PPP: Module resumed\n"); -} - /** * @brief PPP模块注册4G控制引脚配置 */