esp_clk.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * @file esp_clk.h
  13. *
  14. * This file contains declarations of clock related functions.
  15. */
  16. /**
  17. * @brief Get the calibration value of RTC slow clock
  18. *
  19. * The value is in the same format as returned by rtc_clk_cal (microseconds,
  20. * in Q13.19 fixed-point format).
  21. *
  22. * @return the calibration value obtained using rtc_clk_cal, at startup time
  23. */
  24. uint32_t esp_clk_slowclk_cal_get(void);
  25. /**
  26. * @brief Update the calibration value of RTC slow clock
  27. *
  28. * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
  29. * in Q13.19 fixed-point format).
  30. * This value is used by timekeeping functions (such as gettimeofday) to
  31. * calculate current time based on RTC counter value.
  32. * @param value calibration value obtained using rtc_clk_cal
  33. */
  34. void esp_clk_slowclk_cal_set(uint32_t value);
  35. /**
  36. * @brief Return current CPU clock frequency
  37. * When frequency switching is performed, this frequency may change.
  38. * However it is guaranteed that the frequency never changes with a critical
  39. * section.
  40. *
  41. * @return CPU clock frequency, in Hz
  42. */
  43. int esp_clk_cpu_freq(void);
  44. /**
  45. * @brief Return current APB clock frequency
  46. *
  47. * When frequency switching is performed, this frequency may change.
  48. * However it is guaranteed that the frequency never changes with a critical
  49. * section.
  50. *
  51. * @return APB clock frequency, in Hz
  52. */
  53. int esp_clk_apb_freq(void);
  54. /**
  55. * @brief Return frequency of the main XTAL
  56. *
  57. * Frequency of the main XTAL can be either auto-detected or set at compile
  58. * time (see CONFIG_XTAL_FREQ_SEL sdkconfig option). In both cases, this
  59. * function returns the actual value at run time.
  60. *
  61. * @return XTAL frequency, in Hz
  62. */
  63. int esp_clk_xtal_freq(void);
  64. /**
  65. * @brief Read value of RTC counter, converting it to microseconds
  66. * @attention The value returned by this function may change abruptly when
  67. * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
  68. * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
  69. * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
  70. *
  71. * @return Value or RTC counter, expressed in microseconds
  72. */
  73. uint64_t esp_clk_rtc_time(void);
  74. /**
  75. * @brief obtain internal critical section used esp_clk implementation.
  76. *
  77. * This is used by the esp_light_sleep_start() to avoid deadlocking when it
  78. * calls esp_clk related API after stalling the other CPU.
  79. */
  80. void esp_clk_private_lock(void);
  81. /**
  82. * @brief counterpart of esp_clk_private_lock
  83. */
  84. void esp_clk_private_unlock(void);
  85. #ifdef __cplusplus
  86. }
  87. #endif