From 6faaa0ea6bc2f4267cbcffa57d8806c0bcccccf8 Mon Sep 17 00:00:00 2001 From: Xia Xiaotian Date: Wed, 19 Feb 2020 19:16:42 +0800 Subject: [PATCH] esp_wifi: run modem sleep on ESP32S2 --- components/esp_wifi/esp32/esp_adapter.c | 23 +++++++++++++++++-- components/esp_wifi/esp32s2/esp_adapter.c | 23 +++++++++++++++++-- .../include/esp_private/wifi_os_adapter.h | 7 +++--- components/esp_wifi/lib | 2 +- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/components/esp_wifi/esp32/esp_adapter.c b/components/esp_wifi/esp32/esp_adapter.c index 99ccd1434..cab86b407 100644 --- a/components/esp_wifi/esp32/esp_adapter.c +++ b/components/esp_wifi/esp32/esp_adapter.c @@ -38,6 +38,8 @@ #include "esp_private/wifi_os_adapter.h" #include "esp_private/wifi.h" #include "esp_phy_init.h" +#include "soc/dport_reg.h" +#include "soc/syscon_reg.h" #include "driver/periph_ctrl.h" #include "nvs.h" #include "os.h" @@ -408,6 +410,22 @@ static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repea ets_timer_arm_us(ptimer, us, repeat); } +static void wifi_reset_mac_wrapper(void) +{ + DPORT_SET_PERI_REG_MASK(DPORT_CORE_RST_EN_REG, DPORT_MAC_RST); + DPORT_CLEAR_PERI_REG_MASK(DPORT_CORE_RST_EN_REG, DPORT_MAC_RST); +} + +static void wifi_clock_enable_wrapper(void) +{ + periph_module_enable(PERIPH_WIFI_MODULE); +} + +static void wifi_clock_disable_wrapper(void) +{ + periph_module_disable(PERIPH_WIFI_MODULE); +} + static int get_time_wrapper(void *t) { return os_get_time(t); @@ -576,8 +594,9 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._timer_done = timer_done_wrapper, ._timer_setfn = timer_setfn_wrapper, ._timer_arm_us = timer_arm_us_wrapper, - ._periph_module_enable = periph_module_enable, - ._periph_module_disable = periph_module_disable, + ._wifi_reset_mac = wifi_reset_mac_wrapper, + ._wifi_clock_enable = wifi_clock_enable_wrapper, + ._wifi_clock_disable = wifi_clock_disable_wrapper, ._esp_timer_get_time = esp_timer_get_time, ._nvs_set_i8 = nvs_set_i8, ._nvs_get_i8 = nvs_get_i8, diff --git a/components/esp_wifi/esp32s2/esp_adapter.c b/components/esp_wifi/esp32s2/esp_adapter.c index 7e1ba7d99..cf0740086 100644 --- a/components/esp_wifi/esp32s2/esp_adapter.c +++ b/components/esp_wifi/esp32s2/esp_adapter.c @@ -39,6 +39,8 @@ #include "esp_private/wifi.h" #include "esp_phy_init.h" #include "esp32s2/clk.h" +#include "soc/dport_reg.h" +#include "soc/syscon_reg.h" #include "driver/periph_ctrl.h" #include "nvs.h" #include "os.h" @@ -398,6 +400,22 @@ static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repea ets_timer_arm_us(ptimer, us, repeat); } +static void wifi_reset_mac_wrapper(void) +{ + DPORT_SET_PERI_REG_MASK(DPORT_CORE_RST_EN_REG, DPORT_MAC_RST); + DPORT_CLEAR_PERI_REG_MASK(DPORT_CORE_RST_EN_REG, DPORT_MAC_RST); +} + +static void wifi_clock_enable_wrapper(void) +{ + periph_module_enable(PERIPH_WIFI_MODULE); +} + +static void wifi_clock_disable_wrapper(void) +{ + periph_module_disable(PERIPH_WIFI_MODULE); +} + static int get_time_wrapper(void *t) { return os_get_time(t); @@ -564,8 +582,9 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._timer_done = timer_done_wrapper, ._timer_setfn = timer_setfn_wrapper, ._timer_arm_us = timer_arm_us_wrapper, - ._periph_module_enable = periph_module_enable, - ._periph_module_disable = periph_module_disable, + ._wifi_reset_mac = wifi_reset_mac_wrapper, + ._wifi_clock_enable = wifi_clock_enable_wrapper, + ._wifi_clock_disable = wifi_clock_disable_wrapper, ._esp_timer_get_time = esp_timer_get_time, ._nvs_set_i8 = nvs_set_i8, ._nvs_get_i8 = nvs_get_i8, diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index e57fe24e3..cfac30182 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -21,7 +21,7 @@ extern "C" { #endif -#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000004 +#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000005 #define ESP_WIFI_OS_ADAPTER_MAGIC 0xDEADBEAF #define OSI_FUNCS_TIME_BLOCKING 0xffffffff @@ -89,8 +89,9 @@ typedef struct { void (* _timer_done)(void *ptimer); void (* _timer_setfn)(void *ptimer, void *pfunction, void *parg); void (* _timer_arm_us)(void *ptimer, uint32_t us, bool repeat); - void (* _periph_module_enable)(uint32_t periph); - void (* _periph_module_disable)(uint32_t periph); + void (* _wifi_reset_mac)(void); + void (* _wifi_clock_enable)(void); + void (* _wifi_clock_disable)(void); int64_t (* _esp_timer_get_time)(void); int32_t (* _nvs_set_i8)(uint32_t handle, const char* key, int8_t value); int32_t (* _nvs_get_i8)(uint32_t handle, const char* key, int8_t* out_value); diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 6b5e54a1f..dbb4a9734 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 6b5e54a1f75c78fef093262373d4b8781ac9ad1f +Subproject commit dbb4a97341cc38650f528330e94e48738f8d3700