@@ -74,7 +74,6 @@ static esp_err_t tcpip_adapter_reset_ip_info(tcpip_adapter_if_t tcpip_if);
74
74
static esp_err_t tcpip_adapter_start_ip_lost_timer (tcpip_adapter_if_t tcpip_if );
75
75
static void tcpip_adapter_dhcpc_cb (struct netif * netif );
76
76
static void tcpip_adapter_ip_lost_timer (void * arg );
77
- static void tcpip_adapter_dhcpc_done (TimerHandle_t arg );
78
77
static bool tcpip_inited = false;
79
78
80
79
static const char * TAG = "tcpip_adapter" ;
@@ -85,9 +84,25 @@ ESP_EVENT_DEFINE_BASE(IP_EVENT);
85
84
err_t ethernetif_init (struct netif * netif );
86
85
void system_station_got_ip_set ();
87
86
88
- static int dhcp_fail_time = 0 ;
89
87
static 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
+ }
91
106
92
107
static void tcpip_adapter_dhcps_cb (u8_t client_ip [4 ])
93
108
{
@@ -192,11 +207,6 @@ void tcpip_adapter_init(void)
192
207
IP4_ADDR (& esp_ip [TCPIP_ADAPTER_IF_AP ].ip , 192 , 168 , 4 , 1 );
193
208
IP4_ADDR (& esp_ip [TCPIP_ADAPTER_IF_AP ].gw , 192 , 168 , 4 , 1 );
194
209
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
- }
200
210
}
201
211
}
202
212
@@ -287,56 +297,6 @@ static int tcpip_adapter_sta_recv_cb(void *buffer, uint16_t len, void *eb)
287
297
return tcpip_adapter_recv_cb (esp_netif [ESP_IF_WIFI_STA ], buffer , len , eb );
288
298
}
289
299
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
-
340
300
static esp_err_t tcpip_adapter_update_default_netif (void )
341
301
{
342
302
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)
1073
1033
}
1074
1034
}
1075
1035
1036
+ tcpip_adapter_set_wifi_ps (false);
1076
1037
return ;
1077
1038
}
1078
1039
@@ -1171,16 +1132,13 @@ esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if)
1171
1132
return ESP_OK ;
1172
1133
}
1173
1134
1174
- esp_wifi_ps_lock ( );
1135
+ tcpip_adapter_set_wifi_ps (true );
1175
1136
1176
1137
if (tcpip_adapter_start_dhcp (p_netif ) != ERR_OK ) {
1177
- esp_wifi_ps_unlock ( );
1138
+ tcpip_adapter_set_wifi_ps (false );
1178
1139
ESP_LOGD (TAG , "dhcp client start failed" );
1179
1140
return ESP_ERR_TCPIP_ADAPTER_DHCPC_START_FAILED ;
1180
1141
}
1181
-
1182
- dhcp_fail_time = 0 ;
1183
- xTimerReset (dhcp_check_timer , portMAX_DELAY );
1184
1142
ESP_LOGD (TAG , "dhcp client start successfully" );
1185
1143
dhcpc_status [tcpip_if ] = TCPIP_ADAPTER_DHCP_STARTED ;
1186
1144
return ESP_OK ;
0 commit comments