mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp32c2/clk_cali: fix rtc slow clk cali logic
This commit is contained in:
parent
6d1f1eccfb
commit
d3d1d4e1df
@ -57,16 +57,21 @@ uint32_t rtc_clk_cal_internal(rtc_cal_sel_t cal_clk, uint32_t slowclk_cycles)
|
|||||||
rtc_clk_8m_enable(true, true);
|
rtc_clk_8m_enable(true, true);
|
||||||
clk_ll_rc_fast_d256_digi_enable();
|
clk_ll_rc_fast_d256_digi_enable();
|
||||||
}
|
}
|
||||||
/* Prepare calibration */
|
|
||||||
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_CLK_SEL, cal_clk);
|
|
||||||
/* There may be another calibration process already running during we call this function,
|
/* There may be another calibration process already running during we call this function,
|
||||||
* so we should wait the last process is done.
|
* so we should wait the last process is done.
|
||||||
*/
|
*/
|
||||||
if (!GET_PERI_REG_MASK(TIMG_RTCCALICFG2_REG(0), TIMG_RTC_CALI_TIMEOUT)) {
|
if (GET_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING)) {
|
||||||
if (GET_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING)) {
|
/**
|
||||||
while (!GET_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_RDY));
|
* Set a small timeout threshold to accelerate the generation of timeout.
|
||||||
}
|
* The internal circuit will be reset when the timeout occurs and will not affect the next calibration.
|
||||||
|
*/
|
||||||
|
REG_SET_FIELD(TIMG_RTCCALICFG2_REG(0), TIMG_RTC_CALI_TIMEOUT_THRES, 1);
|
||||||
|
while (!GET_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_RDY)
|
||||||
|
&& !GET_PERI_REG_MASK(TIMG_RTCCALICFG2_REG(0), TIMG_RTC_CALI_TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Prepare calibration */
|
||||||
|
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_CLK_SEL, cal_clk);
|
||||||
CLEAR_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING);
|
CLEAR_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING);
|
||||||
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_MAX, slowclk_cycles);
|
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_MAX, slowclk_cycles);
|
||||||
/* Figure out how long to wait for calibration to finish */
|
/* Figure out how long to wait for calibration to finish */
|
||||||
|
Loading…
Reference in New Issue
Block a user