Skip to content

Commit 3e96bff

Browse files
committed
Merge branch 'feature/refactor_wifi_power_management' into 'master'
feat(wifi): refactor wifi power management See merge request sdk/ESP8266_RTOS_SDK!1434
2 parents 2fd6ea1 + e73c871 commit 3e96bff

File tree

23 files changed

+113
-18
lines changed

23 files changed

+113
-18
lines changed

components/esp8266/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ menu "ESP8266-specific"
22

33
choice ESP8266_DEFAULT_CPU_FREQ_MHZ
44
prompt "CPU frequency"
5-
default ESP8266_DEFAULT_CPU_FREQ_80
5+
default ESP8266_DEFAULT_CPU_FREQ_160
66
help
77
CPU frequency to be set on application startup.
88

@@ -298,7 +298,7 @@ config ESP8266_WIFI_RX_BUFFER_NUM
298298
config ESP8266_WIFI_LEFT_CONTINUOUS_RX_BUFFER_NUM
299299
int "The min number of WiFi continuous RX buffer"
300300
range 0 16
301-
default 8
301+
default 16
302302
help
303303
Set the number of WiFi continuous RX buffer num.
304304
The smaller the value, the easier RX hang will appear. Most of time we should NOT change the default

components/esp8266/include/esp_phy_init.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ esp_err_t esp_phy_rf_deinit(phy_rf_module_t module);
165165
*/
166166
void esp_phy_load_cal_and_init(phy_rf_module_t module);
167167

168+
/**
169+
* @brief Initializing system hardware clock.
170+
*/
171+
void esp_phy_init_clk(void);
172+
168173
#ifdef __cplusplus
169174
}
170175
#endif

components/esp8266/include/esp_sleep.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#pragma once
1616

1717
#include <stdint.h>
18+
#include <stdbool.h>
1819
#include "esp_err.h"
1920
#include "driver/gpio.h"
2021

@@ -261,6 +262,22 @@ esp_err_t esp_sleep_enable_gpio_wakeup(void);
261262
*/
262263
esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source);
263264

265+
/**
266+
* @brief Print power consumption information
267+
*
268+
* @note This function is used to print power consumption data. The current
269+
* when the RF and CPU are both turned on is 70 mA. The current when
270+
* only the CPU is turned on is 18 mA. 900uA when both CPU and RF are off.
271+
* There may be some errors compared to the actual power consumption.
272+
* The power consumption is based on the actual measurement, and the printing
273+
* in the function is for reference only.
274+
*
275+
* @param clear_old_data - Recalculate power consumption info or not.
276+
*
277+
* @return null
278+
*/
279+
void esp_power_consumption_info(bool clear_old_data);
280+
264281
#ifdef __cplusplus
265282
}
266283
#endif

components/esp8266/include/internal/esp_wifi_internal.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,42 @@ void esp_wifi_set_pm_recv_multi_data(bool enable);
191191
*/
192192
bool esp_wifi_get_pm_recv_multi_data(void);
193193

194+
/**
195+
* @brief Set max beacon early time.
196+
*
197+
* @param max_bcn_early_ms max beacon early time(2~15ms), default 4ms.
198+
*/
199+
void esp_wifi_set_pm_max_bcn_early(uint8_t max_bcn_early_ms);
200+
201+
/**
202+
* @brief get max beacon early time.
203+
*/
204+
uint8_t esp_wifi_get_pm_max_bcn_early(void);
205+
206+
/**
207+
* @brief Set max beacon timeout time.
208+
*
209+
* @param max_bcn_early_ms max beacon timeout time(12~32ms), default 24ms.
210+
*/
211+
void esp_wifi_set_pm_max_bcn_timeout(uint8_t max_bcn_timeout_ms);
212+
213+
/**
214+
* @brief get max beacon timeout time.
215+
*/
216+
uint8_t esp_wifi_get_pm_max_bcn_timeout(void);
217+
218+
/**
219+
* @brief Set max wait tx rx time.
220+
*
221+
* @param max_bcn_early_ms max wait tx rx time(10~2000ms), default 20ms.
222+
*/
223+
void esp_wifi_set_pm_wait_tx_rx_time(uint32_t wait_tx_rx_time_ms);
224+
225+
/**
226+
* @brief get max wait tx rx time.
227+
*/
228+
uint32_t esp_wifi_get_pm_wait_tx_rx_time();
229+
194230
#ifdef __cplusplus
195231
}
196232
#endif

components/esp8266/lib/VERSION

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
gwen:
2-
core: 01c569d
3-
net80211: 01c569d
4-
pp: 01c569d
5-
espnow: 01c569d
6-
wps: 01c569d
7-
wpa2: 01c569d
2+
core: 3c69aa1
3+
net80211: 3c69aa1
4+
pp: 3c69aa1
5+
espnow: 3c69aa1
6+
wps: 3c69aa1
7+
wpa2: 3c69aa1
88

99
smartconfig: 2.8.2
1010
phy: 1163.0

components/esp8266/lib/libcore.a

-48.1 KB
Binary file not shown.

components/esp8266/lib/libcore_dbg.a

-48.4 KB
Binary file not shown.

components/esp8266/lib/libespnow.a

1.52 KB
Binary file not shown.
1.52 KB
Binary file not shown.

components/esp8266/lib/libnet80211.a

32.6 KB
Binary file not shown.
33 KB
Binary file not shown.

components/esp8266/lib/libpp.a

11.2 KB
Binary file not shown.

components/esp8266/lib/libpp_dbg.a

13.1 KB
Binary file not shown.

components/esp8266/lib/libwpa2.a

0 Bytes
Binary file not shown.

components/esp8266/lib/libwpa2_dbg.a

0 Bytes
Binary file not shown.

components/esp8266/lib/libwps.a

48 Bytes
Binary file not shown.

components/esp8266/lib/libwps_dbg.a

48 Bytes
Binary file not shown.

components/esp8266/source/esp_sleep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static inline uint32_t sleep_rtc_ticks(pm_soc_clk_t *clk)
146146

147147
static inline void update_soc_clk(pm_soc_clk_t *clk)
148148
{
149-
extern uint32_t WdevTimOffSet;
149+
extern uint64_t WdevTimOffSet;
150150

151151
uint32_t slept_us;
152152

components/esp8266/source/phy_init.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,31 @@ int phy_printf(const char *fmt, ...)
394394
{
395395
return 0;
396396
}
397+
398+
void esp_phy_init_clk(void)
399+
{
400+
uint8_t buf[128];
401+
const esp_phy_init_data_t *init_data;
402+
#ifdef CONFIG_CONSOLE_UART_BAUDRATE
403+
const uint32_t uart_baudrate = CONFIG_CONSOLE_UART_BAUDRATE;
404+
#else
405+
const uint32_t uart_baudrate = 74880; // ROM default baudrate
406+
#endif
407+
408+
init_data = esp_phy_get_init_data();
409+
if (init_data == NULL) {
410+
ESP_LOGE(TAG, "failed to obtain PHY init data");
411+
abort();
412+
}
413+
memcpy(buf, init_data->params, 128);
414+
415+
uart_tx_wait_idle(0);
416+
uart_div_modify(0, UART_CLK_FREQ / uart_baudrate);
417+
418+
uart_tx_wait_idle(1);
419+
uart_div_modify(1, UART_CLK_FREQ / uart_baudrate);
420+
421+
rtc_init_clk(buf);
422+
423+
esp_phy_release_init_data(init_data);
424+
}

components/esp8266/source/startup.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,10 @@ static void user_init_entry(void *param)
7474

7575
extern void app_main(void);
7676

77-
extern void phy_close_rf(void);
78-
79-
extern void esp_sleep_unlock();
80-
8177
/* initialize C++ construture function */
8278
for (func = &__init_array_start; func < &__init_array_end; func++)
8379
func[0]();
8480

85-
phy_get_bb_evm();
86-
8781
/*enable tsf0 interrupt for pwm*/
8882
REG_WRITE(PERIPHS_DPORT_BASEADDR, (REG_READ(PERIPHS_DPORT_BASEADDR) & ~0x1F) | 0x1);
8983
REG_WRITE(INT_ENA_WDEV, REG_READ(INT_ENA_WDEV) | WDEV_TSF0_REACH_INT);
@@ -92,12 +86,11 @@ static void user_init_entry(void *param)
9286
assert(rtc_init() == 0);
9387
assert(mac_init() == 0);
9488
assert(base_gpio_init() == 0);
95-
esp_phy_load_cal_and_init(0);
96-
phy_close_rf();
97-
esp_sleep_unlock();
9889

9990
esp_wifi_set_rx_pbuf_mem_type(WIFI_RX_PBUF_DRAM);
10091

92+
esp_phy_init_clk();
93+
10194
#if CONFIG_RESET_REASON
10295
esp_reset_reason_init();
10396
#endif

components/wpa_supplicant/port/esp_supplicant/esp_wpa_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ void ICACHE_FLASH_ATTR wpa_sta_init()
144144
wpa_config_assoc_ie, wpa_install_key, wpa_get_key, wpa_deauthenticate, wpa_neg_complete);
145145
}
146146

147+
void wpa_sta_deinit(void)
148+
{
149+
wpa_sm_deinit();
150+
}
151+
147152
void wpa_sta_connect(uint8_t *bssid)
148153
{
149154
wpa_config_profile();

components/wpa_supplicant/src/rsn_supp/wpa.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,15 @@ void ICACHE_FLASH_ATTR wpa_register(char* payload, WPA_SEND_FUNC snd_func,
20092009
return true;
20102010
}
20112011

2012+
/**
2013+
* * wpa_sm_deinit - Deinitialize WPA state machine
2014+
* */
2015+
void wpa_sm_deinit(void)
2016+
{
2017+
struct wpa_sm *sm = &gWpaSm;
2018+
pmksa_cache_deinit(sm->pmksa);
2019+
}
2020+
20122021
void wpa_set_profile(u32 wpa_proto, u8 auth_mode)
20132022
{
20142023
struct wpa_sm *sm = &gWpaSm;

components/wpa_supplicant/src/rsn_supp/wpa_i.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ void wpa_register(char * payload, WPA_SEND_FUNC snd_func, \
163163

164164
void eapol_txcb(void *eb);
165165

166+
void wpa_sm_deinit(void);
167+
166168
void wpa_set_profile(u32 wpa_proto, u8 auth_mode);
167169

168170
int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher, char *passphrase, u8 *ssid, size_t ssid_len);

0 commit comments

Comments
 (0)