|
|
@@ -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);
|
|
|
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,
|
|
|
* 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)) {
|
|
|
- while (!GET_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_RDY));
|
|
|
- }
|
|
|
+ if (GET_PERI_REG_MASK(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_START_CYCLING)) {
|
|
|
+ /**
|
|
|
+ * 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);
|
|
|
REG_SET_FIELD(TIMG_RTCCALICFG_REG(0), TIMG_RTC_CALI_MAX, slowclk_cycles);
|
|
|
/* Figure out how long to wait for calibration to finish */
|