From dcf68a6d66174fbc224ceb25c4d9f530e09f3c0c Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Tue, 17 Nov 2020 17:07:16 +0800 Subject: [PATCH] feat(tcpip_adapter): Lock power save when start DHCP client --- components/tcpip_adapter/tcpip_adapter_lwip.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index 88f778c6..d3a31d63 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -289,6 +289,7 @@ static int tcpip_adapter_sta_recv_cb(void *buffer, uint16_t len, void *eb) static void tcpip_adapter_dhcpc_done(TimerHandle_t xTimer) { + bool unlock_ps = true; struct dhcp *clientdhcp = netif_dhcp_data(esp_netif[TCPIP_ADAPTER_IF_STA]) ; struct netif *netif = esp_netif[TCPIP_ADAPTER_IF_STA]; @@ -317,6 +318,7 @@ static void tcpip_adapter_dhcpc_done(TimerHandle_t xTimer) ESP_LOGD(TAG,"dhcpc time(ms): %d\n", dhcp_fail_time * 500); dhcp_fail_time ++; xTimerReset(dhcp_check_timer, 0); + unlock_ps = false; } else { dhcp_fail_time = 0; ESP_LOGD(TAG,"ERROR dhcp get ip error\n"); @@ -329,6 +331,10 @@ static void tcpip_adapter_dhcpc_done(TimerHandle_t xTimer) tcpip_adapter_reset_ip_info(TCPIP_ADAPTER_IF_STA); } + + if (unlock_ps) { + esp_wifi_ps_unlock(); + } } static esp_err_t tcpip_adapter_update_default_netif(void) @@ -1165,13 +1171,16 @@ esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if) return ESP_OK; } + esp_wifi_ps_lock(); + if (tcpip_adapter_start_dhcp(p_netif) != ERR_OK) { + esp_wifi_ps_unlock(); ESP_LOGD(TAG, "dhcp client start failed"); return ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED; } dhcp_fail_time = 0; - xTimerReset(dhcp_check_timer, 0); + xTimerReset(dhcp_check_timer, portMAX_DELAY); ESP_LOGD(TAG, "dhcp client start successfully"); dhcpc_status[tcpip_if] = TCPIP_ADAPTER_DHCP_STARTED; return ESP_OK;