feat(pm): refactor power management according to IDF

This commit is contained in:
Zhang Jun Hao
2020-03-20 10:00:33 +08:00
parent ffa9749d65
commit ee4224ab66
9 changed files with 117 additions and 8 deletions

@ -18,6 +18,7 @@
#include "esp_log.h"
#include "esp_system.h"
#include "esp_sleep.h"
#include "esp_wifi.h"
#include "FreeRTOS.h"
#include "freertos/task.h"
#include "driver/soc.h"
@ -374,6 +375,10 @@ esp_err_t esp_light_sleep_start(void)
.flush_uart = 1
};
if (esp_wifi_get_state() >= WIFI_STATE_START) {
return ESP_ERR_INVALID_STATE;
}
return esp_light_sleep_internal(&proc);
}
@ -407,3 +412,18 @@ void esp_sleep_start(void)
esp_light_sleep_internal(&proc);
}
esp_err_t esp_pm_configure(const void* vconfig)
{
#ifndef CONFIG_PM_ENABLE
return ESP_ERR_NOT_SUPPORTED;
#endif
const esp_pm_config_esp8266_t* config = (const esp_pm_config_esp8266_t*) vconfig;
if (config->light_sleep_enable) {
s_sleep_mode = ESP_CPU_LIGHTSLEEP;
} else {
s_sleep_mode = ESP_CPU_WAIT;
}
return ESP_OK;
}

@ -74,6 +74,10 @@ static void user_init_entry(void *param)
extern void app_main(void);
extern void phy_close_rf(void);
extern void esp_sleep_unlock();
/* initialize C++ construture function */
for (func = &__init_array_start; func < &__init_array_end; func++)
func[0]();
@ -89,6 +93,8 @@ static void user_init_entry(void *param)
assert(mac_init() == 0);
assert(base_gpio_init() == 0);
esp_phy_load_cal_and_init(0);
phy_close_rf();
esp_sleep_unlock();
esp_wifi_set_rx_pbuf_mem_type(WIFI_RX_PBUF_DRAM);