clk_ctrl_os.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "soc/rtc.h"
  7. #include "esp_err.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * @brief This function is used to enable the digital 8m rtc clock,
  13. * to support the peripherals.
  14. *
  15. * @note If this function is called a number of times, the `periph_rtc_dig_clk8m_disable`
  16. * function needs to be called same times to disable.
  17. *
  18. * @return true: success for enable the rtc 8M clock, false: rtc 8M clock enable failed
  19. */
  20. bool periph_rtc_dig_clk8m_enable(void);
  21. /**
  22. * @brief This function is used to disable the rtc digital clock, which should be called
  23. * with the `periph_rtc_dig_clk8m_enable` pairedly
  24. *
  25. * @note If this function is called a number of times, the `periph_rtc_dig_clk8m_disable`
  26. * function needs to be called same times to disable.
  27. */
  28. void periph_rtc_dig_clk8m_disable(void);
  29. /**
  30. * @brief This function is used to get the real clock frequency value of the rtc clock
  31. *
  32. * @return The real clock value
  33. */
  34. uint32_t periph_rtc_dig_clk8m_get_freq(void);
  35. #if SOC_CLK_APLL_SUPPORTED
  36. /**
  37. * @brief Enable APLL power if it has not enabled
  38. */
  39. void periph_rtc_apll_acquire(void);
  40. /**
  41. * @brief Shut down APLL power if no peripherals using APLL
  42. */
  43. void periph_rtc_apll_release(void);
  44. /**
  45. * @brief Calculate and set APLL coefficients by given frequency
  46. * @note Have to call 'periph_rtc_apll_acquire' to enable APLL power before setting frequency
  47. * @note This calculation is based on the inequality:
  48. * xtal_freq * (4 + sdm2 + sdm1/256 + sdm0/65536) >= SOC_APLL_MULTIPLIER_OUT_MIN_HZ(350 MHz)
  49. * It will always calculate the minimum coefficients that can satisfy the inequality above, instead of loop them one by one.
  50. * which means more appropriate coefficients are likely to exist.
  51. * But this algorithm can meet almost all the cases and the accuracy can be guaranteed as well.
  52. * @note The APLL frequency is only allowed to set when there is only one peripheral refer to it.
  53. * If APLL is already set by another peripheral, this function will return `ESP_ERR_INVALID_STATE`
  54. * and output the current frequency by parameter `real_freq`.
  55. *
  56. * @param expt_freq Expected APLL frequency (unit: Hz)
  57. * @param real_freq APLL real working frequency [output] (unit: Hz)
  58. * @return
  59. * - ESP_OK: APLL frequency set success
  60. * - ESP_ERR_INVALID_ARG: The input expt_freq is out of APLL support range
  61. * - ESP_ERR_INVALID_STATE: APLL is refered by more than one peripherals, not allowed to change its frequency now
  62. */
  63. esp_err_t periph_rtc_apll_freq_set(uint32_t expt_freq, uint32_t *real_freq);
  64. #endif // SOC_CLK_APLL_SUPPORTED
  65. #ifdef __cplusplus
  66. }
  67. #endif