clk_ctrl_os.h 2.7 KB

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