11/*
2- * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -23,14 +23,14 @@ static const char *TAG = "clk_ctrl_os";
2323static portMUX_TYPE periph_spinlock = portMUX_INITIALIZER_UNLOCKED ;
2424
2525static uint8_t s_periph_ref_counts = 0 ;
26- static uint32_t s_rc_fast_freq = 0 ; // Frequency of the RC_FAST clock in Hz
26+ static uint32_t s_rc_fast_freq_hz = 0 ; // Frequency of the RC_FAST clock in Hz
2727#if SOC_CLK_APLL_SUPPORTED
2828// Current APLL frequency, in HZ. Zero if APLL is not enabled.
29- static uint32_t s_cur_apll_freq = 0 ;
29+ static uint32_t s_cur_apll_freq_hz = 0 ;
3030static int s_apll_ref_cnt = 0 ;
3131#endif
3232#if SOC_CLK_MPLL_SUPPORTED
33- static uint32_t s_cur_mpll_freq = 0 ;
33+ static uint32_t s_cur_mpll_freq_hz = 0 ;
3434static int s_mpll_ref_cnt = 0 ;
3535static esp_ldo_channel_handle_t s_ldo_chan = NULL ;
3636#endif
@@ -41,8 +41,8 @@ bool periph_rtc_dig_clk8m_enable(void)
4141 if (s_periph_ref_counts == 0 ) {
4242 rtc_dig_clk8m_enable ();
4343#if SOC_CLK_RC_FAST_SUPPORT_CALIBRATION
44- s_rc_fast_freq = esp_clk_tree_rc_fast_get_freq_hz (ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT );
45- if (s_rc_fast_freq == 0 ) {
44+ s_rc_fast_freq_hz = esp_clk_tree_rc_fast_get_freq_hz (ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT );
45+ if (s_rc_fast_freq_hz == 0 ) {
4646 rtc_dig_clk8m_disable ();
4747 portEXIT_CRITICAL (& periph_spinlock );
4848 return false;
@@ -60,7 +60,7 @@ uint32_t periph_rtc_dig_clk8m_get_freq(void)
6060 /* Workaround: CLK8M calibration cannot be performed, we can only return its theoretic value */
6161 return SOC_CLK_RC_FAST_FREQ_APPROX ;
6262#else
63- return s_rc_fast_freq ;
63+ return s_rc_fast_freq_hz ;
6464#endif
6565}
6666
@@ -70,7 +70,7 @@ void periph_rtc_dig_clk8m_disable(void)
7070 assert (s_periph_ref_counts > 0 );
7171 s_periph_ref_counts -- ;
7272 if (s_periph_ref_counts == 0 ) {
73- s_rc_fast_freq = 0 ;
73+ s_rc_fast_freq_hz = 0 ;
7474 rtc_dig_clk8m_disable ();
7575 }
7676 portEXIT_CRITICAL (& periph_spinlock );
@@ -95,35 +95,35 @@ void periph_rtc_apll_release(void)
9595 s_apll_ref_cnt -- ;
9696 if (s_apll_ref_cnt == 0 ) {
9797 // If there is no peripheral using APLL, shut down the power
98- s_cur_apll_freq = 0 ;
98+ s_cur_apll_freq_hz = 0 ;
9999 rtc_clk_apll_enable (false);
100100 }
101101 portEXIT_CRITICAL (& periph_spinlock );
102102}
103103
104- esp_err_t periph_rtc_apll_freq_set (uint32_t expt_freq , uint32_t * real_freq )
104+ esp_err_t periph_rtc_apll_freq_set (uint32_t expt_freq_hz , uint32_t * real_freq_hz )
105105{
106106 uint32_t o_div = 0 ;
107107 uint32_t sdm0 = 0 ;
108108 uint32_t sdm1 = 0 ;
109109 uint32_t sdm2 = 0 ;
110110 // Guarantee 'periph_rtc_apll_acquire' has been called before set apll freq
111111 assert (s_apll_ref_cnt > 0 );
112- uint32_t apll_freq = rtc_clk_apll_coeff_calc (expt_freq , & o_div , & sdm0 , & sdm1 , & sdm2 );
112+ uint32_t apll_freq = rtc_clk_apll_coeff_calc (expt_freq_hz , & o_div , & sdm0 , & sdm1 , & sdm2 );
113113
114114 ESP_RETURN_ON_FALSE (apll_freq , ESP_ERR_INVALID_ARG , TAG , "APLL coefficients calculate failed" );
115115 bool need_config = true;
116116 portENTER_CRITICAL (& periph_spinlock );
117117 /* If APLL is not in use or only one peripheral in use, its frequency can be changed as will
118118 * But when more than one peripheral refers APLL, its frequency is not allowed to change once it is set */
119- if (s_cur_apll_freq == 0 || s_apll_ref_cnt < 2 ) {
120- s_cur_apll_freq = apll_freq ;
119+ if (s_cur_apll_freq_hz == 0 || s_apll_ref_cnt < 2 ) {
120+ s_cur_apll_freq_hz = apll_freq ;
121121 } else {
122- apll_freq = s_cur_apll_freq ;
122+ apll_freq = s_cur_apll_freq_hz ;
123123 need_config = false;
124124 }
125125 portEXIT_CRITICAL (& periph_spinlock );
126- * real_freq = apll_freq ;
126+ * real_freq_hz = apll_freq ;
127127
128128 if (need_config ) {
129129 ESP_LOGD (TAG , "APLL will working at %" PRIu32 " Hz with coefficients [sdm0] %" PRIu32 " [sdm1] %" PRIu32 " [sdm2] %" PRIu32 " [o_div] %" PRIu32 "" ,
@@ -172,35 +172,35 @@ void periph_rtc_mpll_release(void)
172172 s_mpll_ref_cnt -- ;
173173 if (s_mpll_ref_cnt == 0 ) {
174174 // If there is no peripheral using MPLL, shut down the power
175- s_cur_mpll_freq = 0 ;
175+ s_cur_mpll_freq_hz = 0 ;
176176 rtc_clk_mpll_disable ();
177177 }
178178 portEXIT_CRITICAL (& periph_spinlock );
179179}
180180
181- esp_err_t IRAM_ATTR periph_rtc_mpll_freq_set (uint32_t expt_freq , uint32_t * real_freq )
181+ esp_err_t IRAM_ATTR periph_rtc_mpll_freq_set (uint32_t expt_freq_hz , uint32_t * real_freq_hz )
182182{
183183 esp_err_t ret = ESP_OK ;
184184
185185 // Guarantee 'periph_rtc_apll_acquire' has been called before set apll freq
186186 assert (s_mpll_ref_cnt > 0 );
187187
188188 portENTER_CRITICAL (& periph_spinlock );
189- if (s_cur_mpll_freq == expt_freq ) {
189+ if (s_cur_mpll_freq_hz == expt_freq_hz ) {
190190 goto end ;
191191 }
192192 /* If MPLL is not in use or only one peripheral in use, its frequency can be changed as will
193193 * But when more than one peripheral refers MPLL, its frequency is not allowed to change once it is set */
194- if (s_cur_mpll_freq == 0 || s_mpll_ref_cnt < 2 ) {
194+ if (s_cur_mpll_freq_hz == 0 || s_mpll_ref_cnt < 2 ) {
195195 uint32_t xtal_freq_mhz = clk_ll_xtal_load_freq_mhz ();
196- rtc_clk_mpll_configure (xtal_freq_mhz , expt_freq / MHZ );
197- s_cur_mpll_freq = clk_ll_mpll_get_freq_mhz (xtal_freq_mhz );
196+ rtc_clk_mpll_configure (xtal_freq_mhz , expt_freq_hz / MHZ );
197+ s_cur_mpll_freq_hz = clk_ll_mpll_get_freq_mhz (xtal_freq_mhz ) * MHZ ;
198198 } else {
199199 ret = ESP_ERR_INVALID_STATE ;
200200 }
201201end :
202- if (real_freq != NULL ) {
203- * real_freq = s_cur_mpll_freq ;
202+ if (real_freq_hz != NULL ) {
203+ * real_freq_hz = s_cur_mpll_freq_hz ;
204204 }
205205 portEXIT_CRITICAL (& periph_spinlock );
206206 return ret ;
0 commit comments