2021-08-05 10:30:10 -04:00
|
|
|
/*
|
2022-01-12 01:53:47 -05:00
|
|
|
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
2021-08-05 10:30:10 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-11-23 02:35:09 -05:00
|
|
|
|
2022-12-01 07:48:27 -05:00
|
|
|
#include <stdbool.h>
|
2021-08-18 07:45:51 -04:00
|
|
|
#include "soc/soc_caps.h"
|
2021-12-02 07:24:19 -05:00
|
|
|
#include "esp_err.h"
|
2020-11-23 02:35:09 -05:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2022-12-01 07:48:27 -05:00
|
|
|
* @brief This function is used to enable the digital RC_FAST clock,
|
2020-11-23 02:35:09 -05:00
|
|
|
* to support the peripherals.
|
|
|
|
*
|
|
|
|
* @note If this function is called a number of times, the `periph_rtc_dig_clk8m_disable`
|
|
|
|
* function needs to be called same times to disable.
|
|
|
|
*
|
2022-12-01 07:48:27 -05:00
|
|
|
* @return true: success for enable the RC_FAST clock, false: RC_FAST clock enable failed
|
2020-11-23 02:35:09 -05:00
|
|
|
*/
|
|
|
|
bool periph_rtc_dig_clk8m_enable(void);
|
|
|
|
|
|
|
|
/**
|
2022-12-01 07:48:27 -05:00
|
|
|
* @brief This function is used to disable the digital RC_FAST clock, which should be called
|
2020-11-23 02:35:09 -05:00
|
|
|
* with the `periph_rtc_dig_clk8m_enable` pairedly
|
|
|
|
*
|
|
|
|
* @note If this function is called a number of times, the `periph_rtc_dig_clk8m_disable`
|
|
|
|
* function needs to be called same times to disable.
|
|
|
|
*/
|
|
|
|
void periph_rtc_dig_clk8m_disable(void);
|
|
|
|
|
|
|
|
/**
|
2022-12-01 07:48:27 -05:00
|
|
|
* @brief This function is used to get the real clock frequency value of RC_FAST clock
|
2020-11-23 02:35:09 -05:00
|
|
|
*
|
2022-12-01 07:48:27 -05:00
|
|
|
* @return The real clock value, in Hz
|
2020-11-23 02:35:09 -05:00
|
|
|
*/
|
|
|
|
uint32_t periph_rtc_dig_clk8m_get_freq(void);
|
|
|
|
|
2021-12-02 07:24:19 -05:00
|
|
|
#if SOC_CLK_APLL_SUPPORTED
|
|
|
|
/**
|
|
|
|
* @brief Enable APLL power if it has not enabled
|
|
|
|
*/
|
|
|
|
void periph_rtc_apll_acquire(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Shut down APLL power if no peripherals using APLL
|
|
|
|
*/
|
|
|
|
void periph_rtc_apll_release(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Calculate and set APLL coefficients by given frequency
|
|
|
|
* @note Have to call 'periph_rtc_apll_acquire' to enable APLL power before setting frequency
|
|
|
|
* @note This calculation is based on the inequality:
|
2023-09-05 22:55:47 -04:00
|
|
|
* xtal_freq * (4 + sdm2 + sdm1/256 + sdm0/65536) >= CLK_LL_APLL_MULTIPLIER_MIN_HZ(350 MHz)
|
2021-12-02 07:24:19 -05:00
|
|
|
* It will always calculate the minimum coefficients that can satisfy the inequality above, instead of loop them one by one.
|
|
|
|
* which means more appropriate coefficients are likely to exist.
|
|
|
|
* But this algorithm can meet almost all the cases and the accuracy can be guaranteed as well.
|
|
|
|
* @note The APLL frequency is only allowed to set when there is only one peripheral refer to it.
|
|
|
|
* If APLL is already set by another peripheral, this function will return `ESP_ERR_INVALID_STATE`
|
|
|
|
* and output the current frequency by parameter `real_freq`.
|
|
|
|
*
|
|
|
|
* @param expt_freq Expected APLL frequency (unit: Hz)
|
|
|
|
* @param real_freq APLL real working frequency [output] (unit: Hz)
|
|
|
|
* @return
|
|
|
|
* - ESP_OK: APLL frequency set success
|
|
|
|
* - ESP_ERR_INVALID_ARG: The input expt_freq is out of APLL support range
|
|
|
|
* - ESP_ERR_INVALID_STATE: APLL is refered by more than one peripherals, not allowed to change its frequency now
|
|
|
|
*/
|
|
|
|
esp_err_t periph_rtc_apll_freq_set(uint32_t expt_freq, uint32_t *real_freq);
|
|
|
|
#endif // SOC_CLK_APLL_SUPPORTED
|
|
|
|
|
2020-11-23 02:35:09 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|