Merge branch 'bugfix/wifi_bt_power_domain_leakage_current' into 'master'

fix wifi and bt power domain leakage current in light sleep

See merge request espressif/esp-idf!15236
This commit is contained in:
Li Shuai 2021-10-14 05:10:55 +00:00
commit c2910c15f4
15 changed files with 198 additions and 118 deletions

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -488,6 +480,18 @@ static void btdm_slp_tmr_callback(void *arg);
#endif /* #ifdef CONFIG_PM_ENABLE */ #endif /* #ifdef CONFIG_PM_ENABLE */
static inline void esp_bt_power_domain_on(void)
{
// Bluetooth module power up
esp_wifi_bt_power_domain_on();
}
static inline void esp_bt_power_domain_off(void)
{
// Bluetooth module power down
esp_wifi_bt_power_domain_off();
}
static inline void btdm_check_and_init_bb(void) static inline void btdm_check_and_init_bb(void)
{ {
/* init BT-BB if PHY/RF has been switched off since last BT-BB init */ /* init BT-BB if PHY/RF has been switched off since last BT-BB init */
@ -1621,6 +1625,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
goto error; goto error;
} }
esp_bt_power_domain_on();
btdm_controller_mem_init(); btdm_controller_mem_init();
periph_module_enable(PERIPH_BT_MODULE); periph_module_enable(PERIPH_BT_MODULE);
@ -1774,6 +1780,8 @@ esp_err_t esp_bt_controller_deinit(void)
btdm_lpcycle_us = 0; btdm_lpcycle_us = 0;
btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_NONE); btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_NONE);
esp_bt_power_domain_off();
return ESP_OK; return ESP_OK;
} }

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -408,7 +400,7 @@ static DRAM_ATTR esp_pm_lock_handle_t s_light_sleep_pm_lock;
void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void)
{ {
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
// le module power down // Bluetooth module power down
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD);
@ -419,7 +411,7 @@ void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void)
void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void) void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void)
{ {
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
// le module power up // Bluetooth module power up
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO);
@ -427,6 +419,22 @@ void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void)
#endif #endif
} }
static inline void esp_bt_power_domain_on(void)
{
// Bluetooth module power up
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO);
esp_wifi_bt_power_domain_on();
}
static inline void esp_bt_power_domain_off(void)
{
// Bluetooth module power down
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD);
esp_wifi_bt_power_domain_off();
}
void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem) void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem)
{ {
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
@ -956,6 +964,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
// overwrite some parameters // overwrite some parameters
cfg->magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL; cfg->magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL;
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_init();
#endif
esp_bt_power_domain_on();
btdm_controller_mem_init(); btdm_controller_mem_init();
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
@ -1223,6 +1236,9 @@ esp_err_t esp_bt_controller_deinit(void)
esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb); esp_unregister_mac_bb_pd_callback(btdm_mac_bb_power_down_cb);
esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb);
#endif #endif
esp_bt_power_domain_off();
free(osi_funcs_p); free(osi_funcs_p);
osi_funcs_p = NULL; osi_funcs_p = NULL;

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -407,10 +399,6 @@ static DRAM_ATTR esp_pm_lock_handle_t s_light_sleep_pm_lock;
void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void) void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void)
{ {
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
// le module power down
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD);
esp_mac_bb_power_down(); esp_mac_bb_power_down();
#endif #endif
} }
@ -418,10 +406,6 @@ void IRAM_ATTR btdm_hw_mac_power_down_wrapper(void)
void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void) void IRAM_ATTR btdm_hw_mac_power_up_wrapper(void)
{ {
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
// le module power up
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO);
esp_mac_bb_power_up(); esp_mac_bb_power_up();
#endif #endif
} }
@ -433,6 +417,18 @@ void IRAM_ATTR btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uin
#endif #endif
} }
static inline void esp_bt_power_domain_on(void)
{
// Bluetooth module power up
esp_wifi_bt_power_domain_on();
}
static inline void esp_bt_power_domain_off(void)
{
// Bluetooth module power down
esp_wifi_bt_power_domain_off();
}
static void interrupt_set_wrapper(int32_t cpu_no, int32_t intr_source, int32_t intr_num, int32_t intr_prio) static void interrupt_set_wrapper(int32_t cpu_no, int32_t intr_source, int32_t intr_num, int32_t intr_prio)
{ {
intr_matrix_set(cpu_no, intr_source, intr_num); intr_matrix_set(cpu_no, intr_source, intr_num);
@ -936,6 +932,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
// overwrite some parameters // overwrite some parameters
cfg->magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL; cfg->magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL;
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_init();
#endif
esp_bt_power_domain_on();
btdm_controller_mem_init(); btdm_controller_mem_init();
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
@ -1143,6 +1144,8 @@ error:
esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb);
#endif #endif
esp_bt_power_domain_off();
if (osi_funcs_p != NULL) { if (osi_funcs_p != NULL) {
free(osi_funcs_p); free(osi_funcs_p);
osi_funcs_p = NULL; osi_funcs_p = NULL;

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_BT_H__ #ifndef __ESP_BT_H__
#define __ESP_BT_H__ #define __ESP_BT_H__
@ -530,6 +522,16 @@ esp_err_t esp_bt_sleep_disable(void);
*/ */
esp_err_t esp_ble_scan_dupilcate_list_flush(void); esp_err_t esp_ble_scan_dupilcate_list_flush(void);
/**
* @brief bt Wi-Fi power domain power on
*/
void esp_wifi_bt_power_domain_on(void);
/**
* @brief bt Wi-Fi power domain power off
*/
void esp_wifi_bt_power_domain_off(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_BT_H__ #ifndef __ESP_BT_H__
#define __ESP_BT_H__ #define __ESP_BT_H__
@ -527,6 +519,16 @@ void esp_bt_controller_wakeup_request(void);
*/ */
int esp_bt_h4tl_eif_io_event_notify(int event); int esp_bt_h4tl_eif_io_event_notify(int event);
/**
* @brief bt Wi-Fi power domain power on
*/
void esp_wifi_bt_power_domain_on(void);
/**
* @brief bt Wi-Fi power domain power off
*/
void esp_wifi_bt_power_domain_off(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_BT_H__ #ifndef __ESP_BT_H__
#define __ESP_BT_H__ #define __ESP_BT_H__
@ -526,6 +518,16 @@ void esp_bt_controller_wakeup_request(void);
*/ */
int esp_bt_h4tl_eif_io_event_notify(int event); int esp_bt_h4tl_eif_io_event_notify(int event);
/**
* @brief bt Wi-Fi power domain power on
*/
void esp_wifi_bt_power_domain_on(void);
/**
* @brief bt Wi-Fi power domain power off
*/
void esp_wifi_bt_power_domain_off(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -88,6 +88,9 @@ void rtc_init(rtc_config_t cfg)
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO);
} }
/* force power down wifi and bt power domain */
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
REG_WRITE(RTC_CNTL_INT_ENA_REG, 0); REG_WRITE(RTC_CNTL_INT_ENA_REG, 0);
REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX); REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX);

View File

@ -143,6 +143,13 @@ void rtc_init(rtc_config_t cfg)
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO);
} }
/* force power down wifi and bt power domain */
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
/* force power down bt power domain */
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_BT_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_BT_FORCE_PD);
REG_WRITE(RTC_CNTL_INT_ENA_REG, 0); REG_WRITE(RTC_CNTL_INT_ENA_REG, 0);
REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX); REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX);
} }

View File

@ -145,6 +145,9 @@ void rtc_init(rtc_config_t cfg)
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO);
} }
/* force power down wifi and bt power domain */
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
#if !CONFIG_IDF_ENV_FPGA #if !CONFIG_IDF_ENV_FPGA
if (cfg.cali_ocode) { if (cfg.cali_ocode) {

View File

@ -192,6 +192,9 @@ void rtc_init(rtc_config_t cfg)
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_UNHOLD);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_DG_PAD_FORCE_NOISO);
} }
/* force power down wifi and bt power domain */
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
REG_WRITE(RTC_CNTL_INT_ENA_REG, 0); REG_WRITE(RTC_CNTL_INT_ENA_REG, 0);
REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX); REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX);

View File

@ -25,3 +25,4 @@ entries:
if ESP_WIFI_SLP_IRAM_OPT =y: if ESP_WIFI_SLP_IRAM_OPT =y:
phy_init:esp_phy_enable (noflash) phy_init:esp_phy_enable (noflash)
phy_init:esp_phy_disable (noflash) phy_init:esp_phy_disable (noflash)
phy_init:esp_wifi_bt_power_domain_off (noflash)

View File

@ -28,11 +28,10 @@
#include "esp_rom_crc.h" #include "esp_rom_crc.h"
#include "esp_rom_sys.h" #include "esp_rom_sys.h"
#if CONFIG_IDF_TARGET_ESP32C3
#include "soc/rtc_cntl_reg.h" #include "soc/rtc_cntl_reg.h"
#if CONFIG_IDF_TARGET_ESP32C3
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
#elif CONFIG_IDF_TARGET_ESP32S3 #elif CONFIG_IDF_TARGET_ESP32S3
#include "soc/rtc_cntl_reg.h"
#include "soc/syscon_reg.h" #include "soc/syscon_reg.h"
#endif #endif
@ -44,6 +43,11 @@ static const char* TAG = "phy_init";
static _lock_t s_phy_access_lock; static _lock_t s_phy_access_lock;
static DRAM_ATTR struct {
int count; /* power on count of wifi and bt power domain */
_lock_t lock;
} s_wifi_bt_pd_controller = { .count = 0 };
/* Indicate PHY is calibrated or not */ /* Indicate PHY is calibrated or not */
static bool s_is_phy_calibrated = false; static bool s_is_phy_calibrated = false;
@ -273,6 +277,30 @@ void esp_phy_disable(void)
_lock_release(&s_phy_access_lock); _lock_release(&s_phy_access_lock);
} }
void IRAM_ATTR esp_wifi_bt_power_domain_on(void)
{
_lock_acquire(&s_wifi_bt_pd_controller.lock);
if (s_wifi_bt_pd_controller.count++ == 0) {
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
SET_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_BB_RST | SYSTEM_FE_RST);
CLEAR_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_BB_RST | SYSTEM_FE_RST);
#endif
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
}
_lock_release(&s_wifi_bt_pd_controller.lock);
}
void esp_wifi_bt_power_domain_off(void)
{
_lock_acquire(&s_wifi_bt_pd_controller.lock);
if (--s_wifi_bt_pd_controller.count == 0) {
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
}
_lock_release(&s_wifi_bt_pd_controller.lock);
}
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
void esp_mac_bb_pd_mem_init(void) void esp_mac_bb_pd_mem_init(void)
{ {
@ -287,12 +315,12 @@ void esp_mac_bb_pd_mem_init(void)
IRAM_ATTR void esp_mac_bb_power_up(void) IRAM_ATTR void esp_mac_bb_power_up(void)
{ {
if (s_mac_bb_pd_mem != NULL && (!s_mac_bb_pu)) { if (s_mac_bb_pd_mem == NULL) {
return;
}
esp_wifi_bt_power_domain_on();
if (!s_mac_bb_pu) {
esp_phy_common_clock_enable(); esp_phy_common_clock_enable();
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
SET_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_BB_RST | SYSTEM_FE_RST);
CLEAR_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, SYSTEM_BB_RST | SYSTEM_FE_RST);
CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
phy_freq_mem_backup(false, s_mac_bb_pd_mem); phy_freq_mem_backup(false, s_mac_bb_pd_mem);
esp_phy_common_clock_disable(); esp_phy_common_clock_disable();
s_mac_bb_pu = true; s_mac_bb_pu = true;
@ -301,14 +329,16 @@ IRAM_ATTR void esp_mac_bb_power_up(void)
IRAM_ATTR void esp_mac_bb_power_down(void) IRAM_ATTR void esp_mac_bb_power_down(void)
{ {
if (s_mac_bb_pd_mem != NULL && s_mac_bb_pu) { if (s_mac_bb_pd_mem == NULL) {
return;
}
if (s_mac_bb_pu) {
esp_phy_common_clock_enable(); esp_phy_common_clock_enable();
phy_freq_mem_backup(true, s_mac_bb_pd_mem); phy_freq_mem_backup(true, s_mac_bb_pd_mem);
SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
esp_phy_common_clock_disable(); esp_phy_common_clock_disable();
s_mac_bb_pu = false; s_mac_bb_pu = false;
} }
esp_wifi_bt_power_domain_off();
} }
#endif #endif
@ -905,3 +935,6 @@ esp_err_t esp_phy_update_country_info(const char *country)
#endif #endif
return ESP_OK; return ESP_OK;
} }
void esp_wifi_power_domain_on(void) __attribute__((alias("esp_wifi_bt_power_domain_on")));
void esp_wifi_power_domain_off(void) __attribute__((alias("esp_wifi_bt_power_domain_off")));

View File

@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/* /*
* All the APIs declared here are internal only APIs, it can only be used by * All the APIs declared here are internal only APIs, it can only be used by
@ -505,6 +497,16 @@ bool esp_wifi_internal_is_tsf_active(void);
void esp_wifi_internal_update_light_sleep_wake_ahead_time(uint32_t); void esp_wifi_internal_update_light_sleep_wake_ahead_time(uint32_t);
#endif #endif
/**
* @brief Wifi power domain power on
*/
void esp_wifi_power_domain_on(void);
/**
* @brief Wifi power domain power off
*/
void esp_wifi_power_domain_off(void);
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
/** /**
* @brief Enable or disable powering down MAC and baseband when Wi-Fi is sleeping. * @brief Enable or disable powering down MAC and baseband when Wi-Fi is sleeping.

View File

@ -125,6 +125,7 @@ esp_err_t esp_wifi_deinit(void)
esp_unregister_mac_bb_pd_callback(pm_mac_sleep); esp_unregister_mac_bb_pd_callback(pm_mac_sleep);
esp_unregister_mac_bb_pu_callback(pm_mac_wakeup); esp_unregister_mac_bb_pu_callback(pm_mac_wakeup);
#endif #endif
esp_wifi_power_domain_off();
return err; return err;
} }
@ -169,6 +170,7 @@ static void esp_wifi_config_info(void)
esp_err_t esp_wifi_init(const wifi_init_config_t *config) esp_err_t esp_wifi_init(const wifi_init_config_t *config)
{ {
esp_wifi_power_domain_on();
#ifdef CONFIG_PM_ENABLE #ifdef CONFIG_PM_ENABLE
if (s_wifi_modem_sleep_lock == NULL) { if (s_wifi_modem_sleep_lock == NULL) {
esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "wifi", esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "wifi",

View File

@ -70,11 +70,8 @@ components/bt/common/osi/mutex.c
components/bt/common/osi/osi.c components/bt/common/osi/osi.c
components/bt/common/osi/semaphore.c components/bt/common/osi/semaphore.c
components/bt/common/osi/thread.c components/bt/common/osi/thread.c
components/bt/controller/esp32/bt.c
components/bt/controller/esp32/hli_api.c components/bt/controller/esp32/hli_api.c
components/bt/controller/esp32/hli_api.h components/bt/controller/esp32/hli_api.h
components/bt/controller/esp32c3/bt.c
components/bt/controller/esp32s3/bt.c
components/bt/esp_ble_mesh/api/core/esp_ble_mesh_ble_api.c components/bt/esp_ble_mesh/api/core/esp_ble_mesh_ble_api.c
components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c
components/bt/esp_ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c components/bt/esp_ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c
@ -702,9 +699,6 @@ components/bt/host/nimble/port/include/console/console.h
components/bt/host/nimble/port/include/esp_nimble_cfg.h components/bt/host/nimble/port/include/esp_nimble_cfg.h
components/bt/host/nimble/port/include/esp_nimble_mem.h components/bt/host/nimble/port/include/esp_nimble_mem.h
components/bt/host/nimble/port/src/esp_nimble_mem.c components/bt/host/nimble/port/src/esp_nimble_mem.c
components/bt/include/esp32/include/esp_bt.h
components/bt/include/esp32c3/include/esp_bt.h
components/bt/include/esp32s3/include/esp_bt.h
components/bt/test/test_bt_common.c components/bt/test/test_bt_common.c
components/bt/test/test_smp.c components/bt/test/test_smp.c
components/cbor/port/include/cbor.h components/cbor/port/include/cbor.h
@ -1205,7 +1199,6 @@ components/esp_wifi/include/esp_mesh_internal.h
components/esp_wifi/include/esp_now.h components/esp_wifi/include/esp_now.h
components/esp_wifi/include/esp_private/esp_wifi_private.h components/esp_wifi/include/esp_private/esp_wifi_private.h
components/esp_wifi/include/esp_private/esp_wifi_types_private.h components/esp_wifi/include/esp_private/esp_wifi_types_private.h
components/esp_wifi/include/esp_private/wifi.h
components/esp_wifi/include/esp_private/wifi_os_adapter.h components/esp_wifi/include/esp_private/wifi_os_adapter.h
components/esp_wifi/include/esp_private/wifi_types.h components/esp_wifi/include/esp_private/wifi_types.h
components/esp_wifi/include/esp_smartconfig.h components/esp_wifi/include/esp_smartconfig.h