mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
feat(pvt): add pvt enable flag & change pvt limit & sleep adapt time
This commit is contained in:
committed by
Jack
parent
02d9e2d0c3
commit
aa4728bec4
@@ -26,6 +26,8 @@
|
||||
#include "esp_hw_log.h"
|
||||
|
||||
static __attribute__((unused)) const char *TAG = "pmu_pvt";
|
||||
static bool pvt_enable_flag = false;
|
||||
static bool pvt_pump_enable_flag = false;
|
||||
|
||||
#if CONFIG_ESP_ENABLE_PVT
|
||||
|
||||
@@ -83,6 +85,9 @@ void pvt_auto_dbias_init(void)
|
||||
{
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
if (pvt_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
REG_SET_BIT(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_RST_EN); // Must reset after pd_cpu
|
||||
REG_CLR_BIT(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_RST_EN);
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
@@ -119,6 +124,9 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
if (enable) {
|
||||
if (pvt_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_DBIAS_INIT); // start calibration @HP_CALI_DBIAS_DEFAULT
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_FUNC_CLK_CONF_REG, PCR_PVT_MONITOR_FUNC_CLK_EN);
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
@@ -129,7 +137,11 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
CLEAR_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_DBIAS_INIT); // must clear @HP_CALI_DBIAS_DEFAULT
|
||||
SET_PERI_REG_MASK(PVT_DBIAS_TIMER_REG, PVT_TIMER_EN); // enable auto dbias
|
||||
esp_rom_delay_us(50);
|
||||
pvt_enable_flag = true;
|
||||
} else {
|
||||
if (pvt_enable_flag == false) {
|
||||
return;
|
||||
}
|
||||
uint32_t pvt_hp_dbias = get_pvt_hp_dbias();
|
||||
uint32_t pvt_lp_dbias = get_pvt_lp_dbias(); // update pvt_cali_dbias
|
||||
SET_PERI_REG_BITS(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_HP_ACTIVE_HP_REGULATOR_DBIAS, pvt_hp_dbias, PMU_HP_ACTIVE_HP_REGULATOR_DBIAS_S);
|
||||
@@ -138,6 +150,7 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
SET_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_REGULATOR0_DBIAS_SEL); // hand over control of dbias to pmu
|
||||
CLEAR_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
CLEAR_PERI_REG_MASK(PCR_PVT_MONITOR_FUNC_CLK_CONF_REG, PCR_PVT_MONITOR_FUNC_CLK_EN);
|
||||
pvt_enable_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +160,9 @@ void charge_pump_init(void)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
/*config for charge pump*/
|
||||
if (pvt_pump_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_BITS(PVT_PMUP_CHANNEL_CFG_REG, PVT_PUMP_CHANNEL_CODE0, PVT_PUMP_CHANNEL_CODE, PVT_PUMP_CHANNEL_CODE0_S); //Set channel code
|
||||
WRITE_PERI_REG(PVT_PMUP_BITMAP_LOW0_REG, (1 << PVT_PUMP_BITMAP)); // Select monitor cell for charge pump
|
||||
SET_PERI_REG_BITS(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_DRV0, PVT_PUMP_DRV, PVT_PUMP_DRV0_S); //Configure the charging intensity
|
||||
@@ -158,9 +174,17 @@ void IRAM_ATTR charge_pump_enable(bool enable)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
if (enable) {
|
||||
if (pvt_pump_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_MASK(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_EN); // enable charge pump
|
||||
pvt_pump_enable_flag = true;
|
||||
} else {
|
||||
if (pvt_pump_enable_flag == false) {
|
||||
return;
|
||||
}
|
||||
CLEAR_PERI_REG_MASK(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_EN); //disable charge pump
|
||||
pvt_pump_enable_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,10 +180,6 @@ static FORCE_IRAM_ATTR void rtc_clk_cpu_freq_to_xtal(int cpu_freq, int div)
|
||||
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_XTAL);
|
||||
clk_ll_bus_update();
|
||||
esp_rom_set_cpu_ticks_per_us(cpu_freq);
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rtc_clk_cpu_freq_to_8m(void)
|
||||
@@ -193,10 +189,6 @@ static void rtc_clk_cpu_freq_to_8m(void)
|
||||
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_RC_FAST);
|
||||
clk_ll_bus_update();
|
||||
esp_rom_set_cpu_ticks_per_us(20);
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,6 +469,10 @@ FORCE_IRAM_ATTR void rtc_clk_cpu_set_to_default_config(void)
|
||||
void rtc_clk_cpu_freq_set_xtal_for_sleep(void)
|
||||
{
|
||||
rtc_clk_cpu_set_to_default_config();
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef BOOTLOADER_BUILD
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
static __attribute__((unused)) const char *TAG = "pmu_pvt";
|
||||
|
||||
#if CONFIG_ESP_ENABLE_PVT
|
||||
static bool pvt_enable_flag = false;
|
||||
static bool pvt_pump_enable_flag = false;
|
||||
|
||||
static uint8_t get_lp_hp_gap(void)
|
||||
{
|
||||
@@ -83,6 +85,9 @@ void pvt_auto_dbias_init(void)
|
||||
{
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 3) {
|
||||
if (pvt_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
REG_SET_BIT(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_RST_EN); // Must reset after pd_cpu
|
||||
REG_CLR_BIT(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_RST_EN);
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
@@ -120,6 +125,9 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 3) {
|
||||
if (enable) {
|
||||
if (pvt_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_DBIAS_INIT); // start calibration @HP_CALI_DBIAS_DEFAUL
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_FUNC_CLK_CONF_REG, PCR_PVT_MONITOR_FUNC_CLK_EN);
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
@@ -129,7 +137,11 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
CLEAR_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_REGULATOR0_DBIAS_SEL); // hand over control of dbias to pvt
|
||||
CLEAR_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_DBIAS_INIT); // must clear @HP_CALI_DBIAS_DEFAULT
|
||||
SET_PERI_REG_MASK(PVT_DBIAS_TIMER_REG, PVT_TIMER_EN); // enable auto dbias
|
||||
pvt_enable_flag = true;
|
||||
} else {
|
||||
if (pvt_enable_flag == false) {
|
||||
return;
|
||||
}
|
||||
uint32_t pvt_hp_dbias = get_pvt_hp_dbias();
|
||||
uint32_t pvt_lp_dbias = get_pvt_lp_dbias(); // update pvt_cali_dbias
|
||||
SET_PERI_REG_BITS(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_HP_ACTIVE_HP_REGULATOR_DBIAS, pvt_hp_dbias, PMU_HP_ACTIVE_HP_REGULATOR_DBIAS_S);
|
||||
@@ -138,6 +150,7 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
SET_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_REGULATOR0_DBIAS_SEL); // hand over control of dbias to pmu
|
||||
CLEAR_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
CLEAR_PERI_REG_MASK(PCR_PVT_MONITOR_FUNC_CLK_CONF_REG, PCR_PVT_MONITOR_FUNC_CLK_EN);
|
||||
pvt_enable_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,6 +160,9 @@ void charge_pump_init(void)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 3) {
|
||||
/*config for charge pump*/
|
||||
if (pvt_pump_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_BITS(PVT_PMUP_CHANNEL_CFG_REG, PVT_PUMP_CHANNEL_CODE0, PVT_PUMP_CHANNEL_CODE, PVT_PUMP_CHANNEL_CODE0_S); //Set channel code
|
||||
WRITE_PERI_REG(PVT_PMUP_BITMAP_LOW0_REG, (1 << PVT_PUMP_BITMAP)); // Select monitor cell for charge pump
|
||||
SET_PERI_REG_BITS(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_DRV0, PVT_PUMP_DRV, PVT_PUMP_DRV0_S); //Configure the charging intensity
|
||||
@@ -158,9 +174,17 @@ void IRAM_ATTR charge_pump_enable(bool enable)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 3) {
|
||||
if (enable) {
|
||||
if (pvt_pump_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_MASK(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_EN); // enable charge pump
|
||||
pvt_pump_enable_flag = true;
|
||||
} else {
|
||||
if (pvt_pump_enable_flag == false) {
|
||||
return;
|
||||
}
|
||||
CLEAR_PERI_REG_MASK(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_EN); //disable charge pump
|
||||
pvt_pump_enable_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,10 +191,6 @@ static FORCE_IRAM_ATTR void rtc_clk_cpu_freq_to_xtal(int cpu_freq, int div)
|
||||
clk_ll_cpu_set_ls_divider(div);
|
||||
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_XTAL);
|
||||
esp_rom_set_cpu_ticks_per_us(cpu_freq);
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rtc_clk_cpu_freq_to_8m(void)
|
||||
@@ -203,10 +199,6 @@ static void rtc_clk_cpu_freq_to_8m(void)
|
||||
clk_ll_cpu_set_ls_divider(1);
|
||||
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_RC_FAST);
|
||||
esp_rom_set_cpu_ticks_per_us(20);
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,6 +363,10 @@ FORCE_IRAM_ATTR void rtc_clk_cpu_set_to_default_config(void)
|
||||
void rtc_clk_cpu_freq_set_xtal_for_sleep(void)
|
||||
{
|
||||
rtc_clk_cpu_set_to_default_config();
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtc_clk_cpu_freq_to_pll_and_pll_lock_release(int cpu_freq_mhz)
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "esp_hw_log.h"
|
||||
|
||||
static __attribute__((unused)) const char *TAG = "pmu_pvt";
|
||||
static bool pvt_enable_flag = false;
|
||||
static bool pvt_pump_enable_flag = false;
|
||||
|
||||
#if CONFIG_ESP_ENABLE_PVT
|
||||
|
||||
@@ -82,6 +84,9 @@ void pvt_auto_dbias_init(void)
|
||||
{
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
if (pvt_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
REG_SET_BIT(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_RST_EN); // Must reset after pd_cpu
|
||||
REG_CLR_BIT(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_RST_EN);
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
@@ -118,6 +123,9 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
if (enable) {
|
||||
if (pvt_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_DBIAS_INIT); // start calibration @HP_CALI_DBIAS_DEFAULT
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_FUNC_CLK_CONF_REG, PCR_PVT_MONITOR_FUNC_CLK_EN);
|
||||
SET_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
@@ -127,7 +135,11 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
CLEAR_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_REGULATOR0_DBIAS_SEL); // hand over control of dbias to pvt
|
||||
CLEAR_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_DBIAS_INIT); // must clear @HP_CALI_DBIAS_DEFAULT
|
||||
SET_PERI_REG_MASK(PVT_DBIAS_TIMER_REG, PVT_TIMER_EN); // enable auto dbias
|
||||
pvt_enable_flag = true;
|
||||
} else {
|
||||
if (pvt_enable_flag == false) {
|
||||
return;
|
||||
}
|
||||
uint32_t pvt_hp_dbias = get_pvt_hp_dbias();
|
||||
uint32_t pvt_lp_dbias = get_pvt_lp_dbias(); // update pvt_cali_dbias
|
||||
SET_PERI_REG_BITS(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_HP_ACTIVE_HP_REGULATOR_DBIAS, pvt_hp_dbias, PMU_HP_ACTIVE_HP_REGULATOR_DBIAS_S);
|
||||
@@ -136,6 +148,7 @@ void IRAM_ATTR pvt_func_enable(bool enable)
|
||||
SET_PERI_REG_MASK(PMU_HP_ACTIVE_HP_REGULATOR0_REG, PMU_DIG_REGULATOR0_DBIAS_SEL); // hand over control of dbias to pmu
|
||||
CLEAR_PERI_REG_MASK(PCR_PVT_MONITOR_CONF_REG, PCR_PVT_MONITOR_CLK_EN);
|
||||
CLEAR_PERI_REG_MASK(PCR_PVT_MONITOR_FUNC_CLK_CONF_REG, PCR_PVT_MONITOR_FUNC_CLK_EN);
|
||||
pvt_enable_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,6 +158,9 @@ void charge_pump_init(void)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
/*config for charge pump*/
|
||||
if (pvt_pump_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_BITS(PVT_PMUP_CHANNEL_CFG_REG, PVT_PUMP_CHANNEL_CODE0, PVT_PUMP_CHANNEL_CODE, PVT_PUMP_CHANNEL_CODE0_S); //Set channel code
|
||||
WRITE_PERI_REG(PVT_PMUP_BITMAP_LOW0_REG, (1 << PVT_PUMP_BITMAP)); // Select monitor cell for charge pump
|
||||
SET_PERI_REG_BITS(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_DRV0, PVT_PUMP_DRV, PVT_PUMP_DRV0_S); //Configure the charging intensity
|
||||
@@ -156,9 +172,17 @@ void IRAM_ATTR charge_pump_enable(bool enable)
|
||||
uint32_t blk_version = efuse_hal_blk_version();
|
||||
if (blk_version >= 2) {
|
||||
if (enable) {
|
||||
if (pvt_pump_enable_flag == true) {
|
||||
return;
|
||||
}
|
||||
SET_PERI_REG_MASK(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_EN); // enable charge pump
|
||||
pvt_pump_enable_flag = true;
|
||||
} else {
|
||||
if (pvt_pump_enable_flag == false) {
|
||||
return;
|
||||
}
|
||||
CLEAR_PERI_REG_MASK(PVT_PMUP_DRV_CFG_REG, PVT_PUMP_EN); //disable charge pump
|
||||
pvt_pump_enable_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,10 +178,6 @@ static FORCE_IRAM_ATTR void rtc_clk_cpu_freq_to_xtal(int cpu_freq, int div)
|
||||
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_XTAL);
|
||||
clk_ll_bus_update();
|
||||
esp_rom_set_cpu_ticks_per_us(cpu_freq);
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rtc_clk_cpu_freq_to_8m(void)
|
||||
@@ -191,10 +187,6 @@ static void rtc_clk_cpu_freq_to_8m(void)
|
||||
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_RC_FAST);
|
||||
clk_ll_bus_update();
|
||||
esp_rom_set_cpu_ticks_per_us(20);
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,6 +348,10 @@ FORCE_IRAM_ATTR void rtc_clk_cpu_set_to_default_config(void)
|
||||
void rtc_clk_cpu_freq_set_xtal_for_sleep(void)
|
||||
{
|
||||
rtc_clk_cpu_set_to_default_config();
|
||||
#if CONFIG_ESP_ENABLE_PVT && !defined(BOOTLOADER_BUILD)
|
||||
charge_pump_enable(false);
|
||||
pvt_func_enable(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtc_clk_cpu_freq_to_pll_and_pll_lock_release(int cpu_freq_mhz)
|
||||
|
||||
Reference in New Issue
Block a user