From bc0c38bd2105f5b5dfea1c53ee79f84761ed2198 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=AD=99=E6=98=A5=E9=98=B3?= Date: Wed, 15 Oct 2025 17:59:36 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E4=BD=8E=E5=8A=9F=E8=80=97?= =?utf8?q?=EF=BC=8C=E6=8A=8A=E6=89=80=E6=9C=89=E7=9A=84wakeup=5Fcat1?= =?utf8?q?=E6=94=BE=E5=88=B0=20=E4=B8=B2=E5=8F=A3=E5=8F=91=E9=80=81?= =?utf8?q?=E9=87=8C=E9=9D=A2=EF=BC=8C=E5=B9=B6=E5=9C=A8=E8=AF=BB=E5=8F=96?= =?utf8?q?=E4=B8=AD=E6=96=AD=E6=9D=A5=E4=BA=86=E6=B7=BB=E5=8A=A0=E6=8A=95?= =?utf8?q?=E7=A5=A8=EF=BC=8Cidle=E7=9A=84=E6=97=B6=E5=80=99=E5=8E=BB?= =?utf8?q?=E9=99=A4=E6=8A=95=E7=A5=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../lwip/lwip_adapter/liteos/src/arch/sio.c | 65 +++++++++++++++++++ .../lwip/lwip_v2.1.3/src/apps/sntp/sntp.c | 3 - .../zhihui/4g/cat1Service/Service/cat1_ctl.c | 4 +- .../4g/cat1Service/Service/cat1_server.c | 2 - .../4g/cat1Service/Service/cat1_tcpServer.c | 2 - code/sdk/zhihui/4g/cat1Service/Service/sntp.c | 3 - code/sdk/zhihui/4gTest/cat1_at_cmd.c | 10 --- code/sdk/zhihui/leiniao/imsl_ln/ln_api.c | 2 - .../leiniao/imsl_ln/ln_api_device_info.c | 6 -- .../sdk/zhihui/leiniao/imsl_ln/ln_api_emoji.c | 4 -- code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c | 4 -- .../leiniao/imsl_ln/ln_api_speech_chat.c | 2 - .../leiniao/imsl_ln/ln_api_story_choose.c | 2 - .../leiniao/imsl_ln/ln_api_story_exit.c | 2 - .../leiniao/imsl_ln/ln_api_story_finish.c | 2 - .../leiniao/imsl_ln/ln_api_story_random.c | 2 - .../imsl_ln/ln_api_timeline_activities.c | 2 - .../sdk/zhihui/leiniao/imsl_ln/ln_api_token.c | 2 - .../zhihui/leiniao/imsl_ln/ln_api_websocket.c | 2 - code/sdk/zhihui/ppp/example/ppp_at_cmd.c | 12 ++-- code/sdk/zhihui/ppp/include/ppp_config.h | 1 + code/sdk/zhihui/ppp/src/ppp_api.c | 3 - code/sdk/zhihui/ppp/src/ppp_interrupt.c | 54 +++++++++++++++ code/sdk/zhihui/ppp/src/ppp_power_ctl.c | 9 +-- code/sdk/zhihui/ppp/src/ppp_serial.c | 21 ++++-- .../services/gnss/src/gnss_http_server.c | 14 ---- .../zhihui/websocket/os_ws/haisi_websocket.c | 2 - 27 files changed, 144 insertions(+), 93 deletions(-) diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c index ace61d0af..99a65b787 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_adapter/liteos/src/arch/sio.c @@ -61,6 +61,11 @@ #define SIO_IRQ_PROCESS_TASK_PRIO 24 // 处理线程优先级 #define SIO_IRQ_PROCESS_STACK_SIZE 4096 // 处理线程栈大小 +/* CAT1 vote 管理配置(与PPP保持一致) */ +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT +#define SIO_CAT1_VOTE_IDLE_MS 3000 // 3秒空闲后移除CAT1 vote +#endif + /* 乒乓缓冲区状态 */ typedef enum { SIO_BUFFER_STATE_EMPTY = 0, // 空闲,可以写入 @@ -159,6 +164,16 @@ static sio_stats_t g_sio_stats = {0}; /* 数据处理回调函数指针 - 用于将数据传递给SLIP */ static void (*g_sio_data_callback)(const uint8_t *data, uint32_t len) = NULL; +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT +/* CAT1 vote 状态管理(与PPP保持一致) */ +static volatile bool g_sio_cat1_vote_added = false; +static volatile uint32_t g_sio_last_rx_time_ms = 0; // 最后接收数据时间 + +/* 外部函数声明(CAT1 API) */ +extern void cat1_api_add_cat1_vote(void); +extern void cat1_api_remove_cat1_vote(void); +#endif + /* 内部函数声明 */ static uint32_t sio_get_current_time_ms(void); static errcode_t sio_flush_buffer(uint8_t buffer_index); @@ -310,6 +325,21 @@ static void sio_timeout_timer_callback(unsigned long arg) // ⚠️ 更新全局时间戳(供ISR使用,ISR中不能调用时间函数) g_sio_timer_timestamp_ms = current_time; +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // ✅ CAT1 vote 管理:检测 idle 状态,超过阈值时移除 vote + if (g_sio_cat1_vote_added) { + if (g_sio_last_rx_time_ms > 0) { + uint32_t idle_time = current_time - g_sio_last_rx_time_ms; + if (idle_time >= SIO_CAT1_VOTE_IDLE_MS) { + // 空闲时间超过阈值,移除 vote 允许 CAT1 休眠 + cat1_api_remove_cat1_vote(); + g_sio_cat1_vote_added = false; + printf("[SIO_CAT1_VOTE] Removed vote after %ums idle\n", idle_time); + } + } + } +#endif + if (g_sio_ping_pong_buffers == NULL) { goto restart_timer; } @@ -371,6 +401,17 @@ static void sio_uart_rx_interrupt_handler(const void *buffer, uint16_t length, b g_sio_stats.total_interrupts++; g_sio_stats.total_bytes_received += length; +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // ✅ 更新最后接收时间(用于空闲检测) + g_sio_last_rx_time_ms = g_sio_timer_timestamp_ms; + + // ✅ CAT1 vote 管理:接收数据时添加 vote(保持 CAT1 唤醒) + if (!g_sio_cat1_vote_added) { + cat1_api_add_cat1_vote(); + g_sio_cat1_vote_added = true; + } +#endif + uint8_t current_idx = g_sio_current_buffer_index; sio_ping_pong_buffer_t *current_buffer = &g_sio_ping_pong_buffers[current_idx]; @@ -559,6 +600,12 @@ errcode_t sio_interrupt_enable(void (*data_callback)(const uint8_t *data, uint32 } g_sio_current_buffer_index = 0; +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // 初始化 CAT1 vote 状态 + g_sio_cat1_vote_added = false; + g_sio_last_rx_time_ms = 0; +#endif + printf("[SIO] Allocated %d x %d bytes = %.2f KB total\n", SIO_PING_PONG_BUFFER_COUNT, SIO_PING_PONG_BUFFER_SIZE, (SIO_PING_PONG_BUFFER_COUNT * SIO_PING_PONG_BUFFER_SIZE) / 1024.0); @@ -710,6 +757,16 @@ errcode_t sio_interrupt_disable(void) // 5. 清零统计 memset(&g_sio_stats, 0, sizeof(sio_stats_t)); +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // 6. 清理 CAT1 vote(如果之前添加过) + if (g_sio_cat1_vote_added) { + cat1_api_remove_cat1_vote(); + g_sio_cat1_vote_added = false; + printf("[SIO] CAT1 vote removed during disable\n"); + } + g_sio_last_rx_time_ms = 0; +#endif + g_sio_interrupt_enabled = false; g_sio_irq_process_task = 0; g_sio_data_callback = NULL; @@ -726,6 +783,14 @@ void sio_print_stats(void) { printf("=== SIO Interrupt Statistics (Ping-Pong Mode) ===\n"); printf("Interrupt Status: %s\n", g_sio_interrupt_enabled ? "ENABLED" : "DISABLED"); +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + printf("CAT1 Vote Status: %s\n", + g_sio_cat1_vote_added ? "ADDED (awake)" : "REMOVED (sleep)"); + if (g_sio_last_rx_time_ms > 0) { + uint32_t idle_time = sio_get_current_time_ms() - g_sio_last_rx_time_ms; + printf("RX Idle Time: %u ms\n", idle_time); + } +#endif printf("Ping-Pong Buffers: %d x %d bytes = %d KB total\n", SIO_PING_PONG_BUFFER_COUNT, SIO_PING_PONG_BUFFER_SIZE, (SIO_PING_PONG_BUFFER_COUNT * SIO_PING_PONG_BUFFER_SIZE) / 1024); diff --git a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/apps/sntp/sntp.c b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/apps/sntp/sntp.c index 5b58a15ab..f05155bea 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/apps/sntp/sntp.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/lwip_v2.1.3/src/apps/sntp/sntp.c @@ -615,7 +615,6 @@ sntp_request(void *arg) LWIP_DEBUGF(SNTP_DEBUG_STATE, ("ble connected, skip sntp_request.\n")); return; } - uapi_cat1_wakeup_cat1(1); /* initialize SNTP server address */ #if SNTP_SERVER_DNS if (sntp_servers[sntp_current_server].name) { @@ -626,7 +625,6 @@ sntp_request(void *arg) if (err == ERR_INPROGRESS) { /* DNS request sent, wait for sntp_dns_found being called */ LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_request: Waiting for server address to be resolved.\n")); - uapi_cat1_wakeup_cat1(0); return; } else if (err == ERR_OK) { sntp_servers[sntp_current_server].addr = sntp_server_address; @@ -648,7 +646,6 @@ sntp_request(void *arg) sys_untimeout(sntp_try_next_server, NULL); sys_timeout((u32_t)SNTP_RETRY_TIMEOUT, sntp_try_next_server, NULL); } - uapi_cat1_wakeup_cat1(0); } /** diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c index 3e869b9c0..3993f19d1 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c @@ -290,9 +290,7 @@ void cat1_ring_isr_callback(pin_t pin, uintptr_t param) cat1_api_add_cat1_vote(); //中断会在此添加休眠投票,在收到cat1的消息后,会移除投票进入休眠。 //之前的5秒后移除投票延迟太久,与5秒更新一次信号强度 - #ifdef USE_CAT1_SLEEP_TIMER - restart_sleep_cat1_timer(); - #endif + } static uint8_t cat1_keepon_wakeup = 0; diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c index 5bf66d1c3..532200d9e 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c @@ -420,7 +420,6 @@ void udp_send_msg_toCat1(uint8_t cmd,char *content) return ; } - cat1_api_wakeup_cat1(1); // uart_port_register_irq(UART_BUS_0); osal_irq_enable(UART_1_IRQN); @@ -436,7 +435,6 @@ void udp_send_msg_toCat1(uint8_t cmd,char *content) } - cat1_api_wakeup_cat1(0); } #define BOOTMSG_HEADER_STR "BOOTUP" diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c index 2c8a957eb..f98f6087b 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c @@ -209,7 +209,6 @@ void ble_tcp_send_msg_toCat1(uint8_t mode,uint8_t cmd,char *content) cat1_print_err("Error cat1 poweroff tcp skipp send data\n"); return ; } - cat1_api_wakeup_cat1(1); // uart_port_register_irq(UART_BUS_0); osal_irq_enable(UART_1_IRQN); @@ -223,7 +222,6 @@ void ble_tcp_send_msg_toCat1(uint8_t mode,uint8_t cmd,char *content) udp_send_response(station_tx_buffer,mode,cmd, content); } - cat1_api_wakeup_cat1(0); } diff --git a/code/sdk/zhihui/4g/cat1Service/Service/sntp.c b/code/sdk/zhihui/4g/cat1Service/Service/sntp.c index 67f81851a..6c16d4846 100644 --- a/code/sdk/zhihui/4g/cat1Service/Service/sntp.c +++ b/code/sdk/zhihui/4g/cat1Service/Service/sntp.c @@ -615,7 +615,6 @@ sntp_request(void *arg) // LWIP_DEBUGF(SNTP_DEBUG_STATE, ("ble connected, skip sntp_request.\n")); // return; // } - cat1_api_wakeup_cat1(1); /* initialize SNTP server address */ #if SNTP_SERVER_DNS if (sntp_servers[sntp_current_server].name) { @@ -626,7 +625,6 @@ sntp_request(void *arg) if (err == ERR_INPROGRESS) { /* DNS request sent, wait for sntp_dns_found being called */ LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_request: Waiting for server address to be resolved.\n")); - cat1_api_wakeup_cat1(0); return; } else if (err == ERR_OK) { sntp_servers[sntp_current_server].addr = sntp_server_address; @@ -648,7 +646,6 @@ sntp_request(void *arg) sys_untimeout(sntp_try_next_server, NULL); sys_timeout((u32_t)SNTP_RETRY_TIMEOUT, sntp_try_next_server, NULL); } - cat1_api_wakeup_cat1(0); } /** diff --git a/code/sdk/zhihui/4gTest/cat1_at_cmd.c b/code/sdk/zhihui/4gTest/cat1_at_cmd.c index 0bac7e0d6..e766f43c6 100644 --- a/code/sdk/zhihui/4gTest/cat1_at_cmd.c +++ b/code/sdk/zhihui/4gTest/cat1_at_cmd.c @@ -199,12 +199,10 @@ static uint32_t cat1_wakeup(uint8_t *para, uint32_t paraLen, char *strCommonCmd) if(enabled == 0) { cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); } else { cat1_api_keep_wakeup(1); - cat1_api_wakeup_cat1(1); } cat1_print_info("CAT1TEST ATCMD keepwakeup cat1 enabled = %d\n",enabled); @@ -222,12 +220,8 @@ static uint32_t cat1_ping(uint8_t *para, uint32_t paraLen, char *strCommonCmd) cat1_print_err("CAT1TEST ATCMD Convert Command Failed\n"); return ERRCODE_FAIL; } - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); u32_t sret= OsShellPing( argc, (const char *)argv[0]); cat1_print_info("CAT1TEST ATCMD ping ret = 0x%X\n",sret); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); return ERRCODE_SUCC; } static uint32_t cat1_ifconfig(uint8_t *para, uint32_t paraLen, char *strCommonCmd) @@ -321,8 +315,6 @@ errcode_t http_single_download_start( uint8_t *server, uint16_t port,uint8_t *ur //通讯开始,唤醒cat1 cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(1); //httpc_connection_t settings = {0}; @@ -361,8 +353,6 @@ errcode_t http_single_download_stop(void) //通讯结束,休眠cat1 g_http_download_started = 0; cat1_api_remove_cat1_vote(); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); cat1_api_disable_cat1_cmd(0); return ERRCODE_SUCC; } diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c index 2be4e975d..5b6fd3606 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api.c @@ -967,8 +967,6 @@ static uint32_t ln_download_mp3_file_advanced(const char *audio_url, const char #ifdef SUPPORT_CAT1_SERVICE /* CAT1 网络保活处理 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(300); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c index 2768a9ec8..a2449f363 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_device_info.c @@ -269,8 +269,6 @@ uint32_t ln_device_get_character_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif @@ -340,8 +338,6 @@ uint32_t ln_device_get_user_id_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif @@ -447,8 +443,6 @@ uint32_t ln_device_get_chat_stamina_http(const char *device_id, const char *devi #ifdef SUPPORT_CAT1_SERVICE cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_emoji.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_emoji.c index d00c8bdff..6b639163e 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_emoji.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_emoji.c @@ -809,8 +809,6 @@ static uint32_t ln_emoji_report_status_http(const char *device_id, // CAT1 保活 #ifdef SUPPORT_CAT1_SERVICE cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif @@ -935,8 +933,6 @@ static uint32_t ln_emoji_report_all_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c index be8b0fcd8..2d3467ee3 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_ota.c @@ -241,8 +241,6 @@ uint32_t ln_ota_get_task_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif @@ -361,8 +359,6 @@ static int ln_download_file_to_path(const char *full_url, const char *save_path, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 网络保活处理 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(500); // 等待模块就绪 #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c index 8c03ac20b..a7d9829d0 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_speech_chat.c @@ -146,8 +146,6 @@ uint32_t ln_speech_chat_stream_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(500); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c index 3efd7c0cf..98c3a6b63 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_choose.c @@ -143,8 +143,6 @@ uint32_t ln_story_choose_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 网络保活处理 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(500); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_exit.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_exit.c index 6175f53e7..483e203d9 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_exit.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_exit.c @@ -9,8 +9,6 @@ uint32_t ln_story_exit_inquiry_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_finish.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_finish.c index 5a8961670..7c9a79c75 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_finish.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_finish.c @@ -10,8 +10,6 @@ uint32_t ln_story_finish_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 保活 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c index 218e4e707..b90588d9e 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_story_random.c @@ -32,8 +32,6 @@ uint32_t ln_story_random_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* CAT1 网络保活处理 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(500); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_timeline_activities.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_timeline_activities.c index 11780f521..c360adafd 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_timeline_activities.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_timeline_activities.c @@ -61,8 +61,6 @@ uint32_t ln_timeline_get_status_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(200); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_token.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_token.c index fcdf2341a..2e8be61b5 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_token.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_token.c @@ -286,8 +286,6 @@ uint32_t ln_get_device_token_http(const char *device_id, #ifdef SUPPORT_CAT1_SERVICE /* 4. 保活CAT1,准备网络 */ cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); LOS_Msleep(500); #endif diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c index 2ad5e74f3..78675ef0d 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c @@ -872,8 +872,6 @@ int ln_ws_start(ws_message_callback_t_ln callback, uint32_t audio_timeout_ticks) // 注册音频数据写入回调 AI_RegisterWriteAudioDataCallback(ln_ws_audio_write_callback); - cat1_api_keep_wakeup(1); - cat1_api_wakeup_cat1(1); return 0; } diff --git a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c index 50f867d49..19fc8698e 100644 --- a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c +++ b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c @@ -166,13 +166,13 @@ static uint32_t cat1_wakeup(uint8_t *para, uint32_t paraLen, char *strCommonCmd) int enabled = atoi((char*)argv[0]); if(enabled == 0) { - // cat1_api_keep_wakeup(0); - // cat1_api_wakeup_cat1(0); + cat1_api_keep_wakeup(0); + cat1_api_wakeup_cat1(0); } else { - // cat1_api_keep_wakeup(1); - // cat1_api_wakeup_cat1(1); + cat1_api_keep_wakeup(1); + cat1_api_wakeup_cat1(1); } ppp_print_info("CAT1TEST ATCMD keepwakeup cat1 enabled = %d\n",enabled); @@ -190,12 +190,8 @@ static uint32_t cat1_ping(uint8_t *para, uint32_t paraLen, char *strCommonCmd) ppp_print_err("CAT1TEST ATCMD Convert Command Failed\n"); return ERRCODE_FAIL; } - // cat1_api_wakeup_cat1(1); - // cat1_api_keep_wakeup(1); u32_t sret= OsShellPing( argc, (const char *)argv[0]); ppp_print_info("CAT1TEST ATCMD ping ret = 0x%X\n",sret); - // cat1_api_keep_wakeup(0); - // cat1_api_wakeup_cat1(0); return ERRCODE_SUCC; } static uint32_t cat1_ifconfig(uint8_t *para, uint32_t paraLen, char *strCommonCmd) diff --git a/code/sdk/zhihui/ppp/include/ppp_config.h b/code/sdk/zhihui/ppp/include/ppp_config.h index a5ad45e63..bf881bd6d 100644 --- a/code/sdk/zhihui/ppp/include/ppp_config.h +++ b/code/sdk/zhihui/ppp/include/ppp_config.h @@ -9,6 +9,7 @@ extern "C" { #include /* PPP配置参数 - UART配置统一使用SIO (在lwipopts_default.h中定义) */ +#define PPP_LOW_POWER_MODE 1 /* SIO设备号配置 - 与SLIP区分开 */ #define PPP_IFNUM 0 // PPP使用的SIO设备号,与SLIP_IFNUM(0)区分 diff --git a/code/sdk/zhihui/ppp/src/ppp_api.c b/code/sdk/zhihui/ppp/src/ppp_api.c index ebff75625..49213488f 100644 --- a/code/sdk/zhihui/ppp/src/ppp_api.c +++ b/code/sdk/zhihui/ppp/src/ppp_api.c @@ -91,13 +91,10 @@ errcode_t ppp_api_power_control(bool is_open) // 唤醒4G模块 PPP_DEBUG_PRINT("Waking up 4G module...\n"); - cat1_api_wakeup_cat1(true); } else { PPP_DEBUG_PRINT("Sleeping 4G module power...\n"); // 唤醒4G模块 - cat1_api_wakeup_cat1(false); - osal_msleep(500); // 启用4G电源 PPP_DEBUG_PRINT("Disabling 4G module power...\n"); cat1_api_enable_cat1(false); diff --git a/code/sdk/zhihui/ppp/src/ppp_interrupt.c b/code/sdk/zhihui/ppp/src/ppp_interrupt.c index 4f62eff8f..fcd6fc456 100644 --- a/code/sdk/zhihui/ppp/src/ppp_interrupt.c +++ b/code/sdk/zhihui/ppp/src/ppp_interrupt.c @@ -130,10 +130,22 @@ static ppp_data_state_t g_ppp_data_state = {0}; #define PPP_SAFE_SWITCH_IDLE_MS 5000 // 5秒空闲才安全切换 #define PPP_LIGHT_THRESHOLD_BPS 100 // 100 bps以下为轻量传输 +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT +#define PPP_CAT1_VOTE_IDLE_MS 3000 // 3秒空闲后移除CAT1 vote +/* CAT1 vote 状态管理 */ +static volatile bool g_ppp_cat1_vote_added = false; // CAT1 vote 状态标志 +#endif + /* 外部函数声明(在ppp_lwip.c中实现) */ extern ppp_pcb* ppp_lwip_get_pcb(void); extern bool ppp_lwip_is_initialized(void); +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT +/* 外部函数声明(CAT1 API) */ +extern void cat1_api_add_cat1_vote(void); +extern void cat1_api_remove_cat1_vote(void); +#endif + /* 内部函数声明 */ static uint32_t ppp_get_current_time_ms(void); static ppp_error_t ppp_flush_buffer(uint8_t buffer_index); @@ -403,6 +415,21 @@ static void ppp_timeout_timer_callback(unsigned long arg) last_rate_update_time = current_time; } +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // ✅ CAT1 vote 管理:检测 idle 状态,超过阈值时移除 vote + if (g_ppp_cat1_vote_added) { + if (g_ppp_data_state.last_rx_time_ms > 0) { + uint32_t idle_time = current_time - g_ppp_data_state.last_rx_time_ms; + if (idle_time >= PPP_CAT1_VOTE_IDLE_MS) { + // 空闲时间超过阈值,移除 vote 允许 CAT1 休眠 + cat1_api_remove_cat1_vote(); + g_ppp_cat1_vote_added = false; + PPP_DEBUG_INFO("[CAT1_VOTE] Removed vote after %ums idle", idle_time); + } + } + } +#endif + uint8_t current_idx = g_current_buffer_index; // 读取一次,避免重复读取 // ⚠️ 检查内存是否已分配 @@ -546,6 +573,14 @@ void _ppp_uart_rx_interrupt_handler(const void *buffer, uint16_t length, bool er g_ppp_data_state.last_rx_time_ms = g_timer_timestamp_ms; g_ppp_data_state.rx_bytes_this_second += length; +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // ✅ CAT1 vote 管理:接收数据时添加 vote(保持 CAT1 唤醒) + if (!g_ppp_cat1_vote_added) { + cat1_api_add_cat1_vote(); + g_ppp_cat1_vote_added = true; + } +#endif + // 获取当前buffer uint8_t current_idx = g_current_buffer_index; ppp_ping_pong_buffer_t *current_buffer = &g_ping_pong_buffers[current_idx]; @@ -710,6 +745,11 @@ ppp_error_t ppp_interrupt_enable(void) } g_current_buffer_index = 0; +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // 2.1 初始化 CAT1 vote 状态 + g_ppp_cat1_vote_added = false; +#endif + PPP_DEBUG_INFO("Ping-pong buffers initialized: %d x %d bytes = %d KB total", PPP_PING_PONG_BUFFER_COUNT, PPP_PING_PONG_BUFFER_SIZE, (PPP_PING_PONG_BUFFER_COUNT * PPP_PING_PONG_BUFFER_SIZE) / 1024); @@ -957,6 +997,16 @@ ppp_error_t ppp_interrupt_disable(void) memset(&g_ppp_interrupt_stats, 0, sizeof(ppp_interrupt_stats_t)); memset(&g_pingpong_stats, 0, sizeof(ppp_pingpong_stats_t)); memset(&g_uart_error_stats, 0, sizeof(ppp_uart_error_stats_t)); + memset(&g_ppp_data_state, 0, sizeof(ppp_data_state_t)); + +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + // 9. 清理 CAT1 vote(如果之前添加过) + if (g_ppp_cat1_vote_added) { + cat1_api_remove_cat1_vote(); + g_ppp_cat1_vote_added = false; + PPP_DEBUG_INFO("CAT1 vote removed during PPP interrupt disable"); + } +#endif g_ppp_interrupt_enabled = false; g_ppp_irq_process_task = 0; @@ -1288,6 +1338,10 @@ void ppp_interrupt_print_data_state(void) ppp_lwip_is_connected() ? "YES" : "NO "); PPP_DEBUG_WARN("║ RX Idle Time: %u ms ║", idle_ms); PPP_DEBUG_WARN("║ RX Rate: %u bytes/sec ║", g_ppp_data_state.rx_rate_bps); +#ifdef SUPPORT_PPP_SERVICE_INTERRUPT + PPP_DEBUG_WARN("║ CAT1 Vote: %s ║", + g_ppp_cat1_vote_added ? "ADDED (awake)" : "REMOVED (sleep)"); +#endif PPP_DEBUG_WARN("║ Safe for +++: %s ║", ppp_interrupt_is_safe_for_command_switch() ? "YES ✓" : "NO ✗"); PPP_DEBUG_WARN("╠═══════════════════════════════════════╣"); diff --git a/code/sdk/zhihui/ppp/src/ppp_power_ctl.c b/code/sdk/zhihui/ppp/src/ppp_power_ctl.c index 99b1f335d..231ab1023 100644 --- a/code/sdk/zhihui/ppp/src/ppp_power_ctl.c +++ b/code/sdk/zhihui/ppp/src/ppp_power_ctl.c @@ -416,14 +416,11 @@ void ppp_ring_isr_callback(pin_t pin, uintptr_t param) gpio_level_t val = uapi_gpio_get_val(pin); if (val == GPIO_LEVEL_HIGH) { PPP_DEBUG_PRINT("PPP: Cat1 ring interrupt on pin %d high \n", pin); - #ifdef PPP_LOW_POWER_MODE - ppp_api_wakeup_cat1(true); - #endif + cat1_api_add_cat1_vote(); } else { PPP_DEBUG_PRINT("PPP: Cat1 ring interrupt on pin %d low\n", pin); - #ifdef PPP_LOW_POWER_MODE - ppp_api_wakeup_cat1(false); - #endif + //idle后 remove + // cat1_api_remove_cat1_vote(); } uapi_gpio_clear_interrupt(pin); } diff --git a/code/sdk/zhihui/ppp/src/ppp_serial.c b/code/sdk/zhihui/ppp/src/ppp_serial.c index 84ee6f153..3305c3798 100644 --- a/code/sdk/zhihui/ppp/src/ppp_serial.c +++ b/code/sdk/zhihui/ppp/src/ppp_serial.c @@ -342,7 +342,7 @@ ppp_error_t ppp_serial_write(const uint8_t *data, uint32_t length) } PPP_DEBUG_DEBUG("=== PPP Serial Write Start ==="); - #ifdef PPP_LOW_POWER_MODE + #if defined(PPP_LOW_POWER_MODE) && (PPP_LOW_POWER_MODE == 1) ppp_api_wakeup_cat1(true); osal_msleep(1); #endif @@ -424,7 +424,7 @@ ppp_error_t ppp_serial_write(const uint8_t *data, uint32_t length) result == PPP_ERR_OK ? "SUCCESS" : "FAILED", result); PPP_DEBUG_INFO("Statistics: tx_bytes=%u, tx_errors=%u", g_serial_ctx.tx_bytes, g_serial_ctx.tx_errors); PPP_DEBUG_INFO("=== PPP Serial Write End ==="); - #ifdef PPP_LOW_POWER_MODE + #if defined(PPP_LOW_POWER_MODE) && (PPP_LOW_POWER_MODE == 1) ppp_api_wakeup_cat1(false); #endif @@ -439,6 +439,10 @@ ppp_error_t ppp_serial_read(uint8_t *buffer, uint32_t buffer_size, uint32_t *byt if (!g_serial_ctx.initialized || !buffer || !bytes_read || buffer_size == 0) { return PPP_ERR_INVALID_PARAM; } + #if defined(PPP_LOW_POWER_MODE) && (PPP_LOW_POWER_MODE == 1) + ppp_api_wakeup_cat1(true); + osal_msleep(1); + #endif *bytes_read = 0; ppp_error_t result = PPP_ERR_OK; @@ -523,7 +527,8 @@ ppp_error_t ppp_serial_read(uint8_t *buffer, uint32_t buffer_size, uint32_t *byt // 读取错误 if (total_read == 0) { PPP_DEBUG_ERROR("PPP UART Read: Error %d", read_result); - return PPP_ERR_UART; + result = PPP_ERR_UART; + break; } break; } @@ -533,9 +538,11 @@ ppp_error_t ppp_serial_read(uint8_t *buffer, uint32_t buffer_size, uint32_t *byt if (total_read > 0) { PPP_DEBUG_DEBUG("PPP optimized read: %u bytes in %u batches", total_read, batch_count); - return PPP_ERR_OK; + result = PPP_ERR_OK; + break; } else { - return PPP_ERR_OK; // 无数据但无错误 + result = PPP_ERR_OK; + break; // 无数据但无错误 } } break; @@ -571,6 +578,10 @@ ppp_error_t ppp_serial_read(uint8_t *buffer, uint32_t buffer_size, uint32_t *byt break; } + #if defined(PPP_LOW_POWER_MODE) && (PPP_LOW_POWER_MODE == 1) + ppp_api_wakeup_cat1(false); + osal_msleep(1); + #endif return result; } diff --git a/code/sdk/zhihui/services/gnss/src/gnss_http_server.c b/code/sdk/zhihui/services/gnss/src/gnss_http_server.c index d48568669..c65a3f719 100644 --- a/code/sdk/zhihui/services/gnss/src/gnss_http_server.c +++ b/code/sdk/zhihui/services/gnss/src/gnss_http_server.c @@ -178,8 +178,6 @@ static void agnss_download_result_handler(const char *filename, HTTPC_RESULT res // HTTP请求失败,清理CAT1资源 #ifdef SUPPORT_CAT1_SERVICE cat1_api_remove_cat1_vote(); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); cat1_api_disable_cat1_cmd(0); #endif } @@ -1392,8 +1390,6 @@ static void agnss_process_complete_response(void) #ifdef SUPPORT_CAT1_SERVICE cat1_api_remove_cat1_vote(); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); cat1_api_disable_cat1_cmd(0); #endif @@ -1546,8 +1542,6 @@ int download_agnss_files(void) //通讯开始,唤醒cat1 #ifdef SUPPORT_CAT1_SERVICE cat1_api_add_cat1_vote(); - cat1_api_wakeup_cat1(1); - cat1_api_keep_wakeup(1); cat1_api_disable_cat1_cmd(0); // 修改:允许CAT1命令,确保DNS查询可用 #endif // 等待CAT1就绪 @@ -1651,8 +1645,6 @@ int download_agnss_files(void) #ifdef SUPPORT_CAT1_SERVICE cat1_api_remove_cat1_vote(); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); cat1_api_disable_cat1_cmd(0); #endif @@ -2368,8 +2360,6 @@ int gnss_start_agnss_download_simple(void) // 下载取消,清理CAT1资源 #ifdef SUPPORT_CAT1_SERVICE cat1_api_remove_cat1_vote(); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); cat1_api_disable_cat1_cmd(0); #endif return -1; @@ -2384,8 +2374,6 @@ int gnss_start_agnss_download_simple(void) // 下载取消,清理CAT1资源 #ifdef SUPPORT_CAT1_SERVICE cat1_api_remove_cat1_vote(); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); cat1_api_disable_cat1_cmd(0); #endif return -1; @@ -2470,8 +2458,6 @@ errcode_t uapi_gnss_http_server_deinit(void) // 清理CAT1资源 #ifdef SUPPORT_CAT1_SERVICE cat1_api_remove_cat1_vote(); - cat1_api_keep_wakeup(0); - cat1_api_wakeup_cat1(0); cat1_api_disable_cat1_cmd(0); PRINT("CAT1 resources cleaned up\r\n"); #endif diff --git a/code/sdk/zhihui/websocket/os_ws/haisi_websocket.c b/code/sdk/zhihui/websocket/os_ws/haisi_websocket.c index 0530aef84..17baf7584 100644 --- a/code/sdk/zhihui/websocket/os_ws/haisi_websocket.c +++ b/code/sdk/zhihui/websocket/os_ws/haisi_websocket.c @@ -625,8 +625,6 @@ int uapi_ws_start(const ws_call_backs_t *callbacks) }; (void)uapi_create_osThread_custom_with_args(&main_task); } - cat1_api_keep_wakeup(1); - cat1_api_wakeup_cat1(1); return 0; } -- 2.17.1