@@ -74,7 +74,6 @@ static esp_err_t tcpip_adapter_reset_ip_info(tcpip_adapter_if_t tcpip_if);
7474static esp_err_t tcpip_adapter_start_ip_lost_timer (tcpip_adapter_if_t tcpip_if );
7575static void tcpip_adapter_dhcpc_cb (struct netif * netif );
7676static void tcpip_adapter_ip_lost_timer (void * arg );
77- static void tcpip_adapter_dhcpc_done (TimerHandle_t arg );
7877static bool tcpip_inited = false;
7978
8079static const char * TAG = "tcpip_adapter" ;
@@ -85,9 +84,25 @@ ESP_EVENT_DEFINE_BASE(IP_EVENT);
8584err_t ethernetif_init (struct netif * netif );
8685void system_station_got_ip_set ();
8786
88- static int dhcp_fail_time = 0 ;
8987static tcpip_adapter_ip_info_t esp_ip [TCPIP_ADAPTER_IF_MAX ];
90- static TimerHandle_t * dhcp_check_timer ;
88+
89+ static void tcpip_adapter_set_wifi_ps (bool flag )
90+ {
91+ static bool is_ps_set = false;
92+ if (flag ) {
93+ if (!is_ps_set ) {
94+ ESP_LOGD (TAG , "enable wifi ps" );
95+ esp_wifi_ps_lock ();
96+ is_ps_set = true;
97+ }
98+ } else {
99+ if (is_ps_set ) {
100+ ESP_LOGD (TAG , "disable wifi ps" );
101+ esp_wifi_ps_unlock ();
102+ is_ps_set = false;
103+ }
104+ }
105+ }
91106
92107static void tcpip_adapter_dhcps_cb (u8_t client_ip [4 ])
93108{
@@ -192,11 +207,6 @@ void tcpip_adapter_init(void)
192207 IP4_ADDR (& esp_ip [TCPIP_ADAPTER_IF_AP ].ip , 192 , 168 , 4 , 1 );
193208 IP4_ADDR (& esp_ip [TCPIP_ADAPTER_IF_AP ].gw , 192 , 168 , 4 , 1 );
194209 IP4_ADDR (& esp_ip [TCPIP_ADAPTER_IF_AP ].netmask , 255 , 255 , 255 , 0 );
195-
196- dhcp_check_timer = xTimerCreate ("check_dhcp" , 500 / portTICK_RATE_MS , true, NULL , tcpip_adapter_dhcpc_done );
197- if (!dhcp_check_timer ) {
198- ESP_LOGI (TAG , "TCPIP adapter timer create error" );
199- }
200210 }
201211}
202212
@@ -287,56 +297,6 @@ static int tcpip_adapter_sta_recv_cb(void *buffer, uint16_t len, void *eb)
287297 return tcpip_adapter_recv_cb (esp_netif [ESP_IF_WIFI_STA ], buffer , len , eb );
288298}
289299
290- static void tcpip_adapter_dhcpc_done (TimerHandle_t xTimer )
291- {
292- bool unlock_ps = true;
293- struct dhcp * clientdhcp = netif_dhcp_data (esp_netif [TCPIP_ADAPTER_IF_STA ]) ;
294- struct netif * netif = esp_netif [TCPIP_ADAPTER_IF_STA ];
295-
296- if (!netif ) {
297- ESP_LOGD (TAG , "null netif=%p" , netif );
298- return ;
299- }
300-
301- #if LWIP_IPV4 && LWIP_AUTOIP
302- struct autoip * autoip = netif_autoip_data (netif );
303- #endif
304-
305- xTimerStop (dhcp_check_timer , 0 );
306- if (netif_is_up (esp_netif [TCPIP_ADAPTER_IF_STA ])) {
307- if ((clientdhcp && clientdhcp -> state == DHCP_STATE_BOUND )
308- #if LWIP_IPV4 && LWIP_AUTOIP
309- || (autoip && autoip -> state == AUTOIP_STATE_ANNOUNCING )
310- #endif
311- ) {
312- /*send event here*/
313- tcpip_adapter_dhcpc_cb (esp_netif [TCPIP_ADAPTER_IF_STA ]);
314- ESP_LOGD (TAG ,"ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n" , IP2STR (ip_2_ip4 (& (esp_netif [0 ]-> ip_addr ))),
315- IP2STR (ip_2_ip4 (& (esp_netif [0 ]-> netmask ))), IP2STR (ip_2_ip4 (& (esp_netif [0 ]-> gw ))));
316- dhcp_fail_time = 0 ;
317- } else if (dhcp_fail_time < (CONFIG_IP_LOST_TIMER_INTERVAL * 1000 / 500 )) {
318- ESP_LOGD (TAG ,"dhcpc time(ms): %d\n" , dhcp_fail_time * 500 );
319- dhcp_fail_time ++ ;
320- xTimerReset (dhcp_check_timer , 0 );
321- unlock_ps = false;
322- } else {
323- dhcp_fail_time = 0 ;
324- ESP_LOGD (TAG ,"ERROR dhcp get ip error\n" );
325- }
326- } else {
327- dhcp_fail_time = 0 ;
328- tcpip_adapter_release_dhcp (esp_netif [TCPIP_ADAPTER_IF_STA ]);
329-
330- dhcpc_status [TCPIP_ADAPTER_IF_STA ] = TCPIP_ADAPTER_DHCP_INIT ;
331-
332- tcpip_adapter_reset_ip_info (TCPIP_ADAPTER_IF_STA );
333- }
334-
335- if (unlock_ps ) {
336- esp_wifi_ps_unlock ();
337- }
338- }
339-
340300static esp_err_t tcpip_adapter_update_default_netif (void )
341301{
342302 if ((esp_netif [TCPIP_ADAPTER_IF_STA ] != NULL ) && netif_is_up (esp_netif [TCPIP_ADAPTER_IF_STA ])) {
@@ -1073,6 +1033,7 @@ static void tcpip_adapter_dhcpc_cb(struct netif *netif)
10731033 }
10741034 }
10751035
1036+ tcpip_adapter_set_wifi_ps (false);
10761037 return ;
10771038}
10781039
@@ -1171,16 +1132,13 @@ esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if)
11711132 return ESP_OK ;
11721133 }
11731134
1174- esp_wifi_ps_lock ( );
1135+ tcpip_adapter_set_wifi_ps (true );
11751136
11761137 if (tcpip_adapter_start_dhcp (p_netif ) != ERR_OK ) {
1177- esp_wifi_ps_unlock ( );
1138+ tcpip_adapter_set_wifi_ps (false );
11781139 ESP_LOGD (TAG , "dhcp client start failed" );
11791140 return ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED ;
11801141 }
1181-
1182- dhcp_fail_time = 0 ;
1183- xTimerReset (dhcp_check_timer , portMAX_DELAY );
11841142 ESP_LOGD (TAG , "dhcp client start successfully" );
11851143 dhcpc_status [tcpip_if ] = TCPIP_ADAPTER_DHCP_STARTED ;
11861144 return ESP_OK ;
0 commit comments