esp_clk.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. /**
  16. * @file esp_clk.h
  17. *
  18. * This file contains declarations of clock related functions.
  19. */
  20. /**
  21. * @brief Get the calibration value of RTC slow clock
  22. *
  23. * The value is in the same format as returned by rtc_clk_cal (microseconds,
  24. * in Q13.19 fixed-point format).
  25. *
  26. * @return the calibration value obtained using rtc_clk_cal, at startup time
  27. */
  28. uint32_t esp_clk_slowclk_cal_get();
  29. /**
  30. * @brief Update the calibration value of RTC slow clock
  31. *
  32. * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
  33. * in Q13.19 fixed-point format).
  34. * This value is used by timekeeping functions (such as gettimeofday) to
  35. * calculate current time based on RTC counter value.
  36. * @param value calibration value obtained using rtc_clk_cal
  37. */
  38. void esp_clk_slowclk_cal_set(uint32_t value);
  39. /**
  40. * @brief Return current CPU clock frequency
  41. * When frequency switching is performed, this frequency may change.
  42. * However it is guaranteed that the frequency never changes with a critical
  43. * section.
  44. *
  45. * @return CPU clock frequency, in Hz
  46. */
  47. int esp_clk_cpu_freq(void);
  48. /**
  49. * @brief Return current APB clock frequency
  50. *
  51. * When frequency switching is performed, this frequency may change.
  52. * However it is guaranteed that the frequency never changes with a critical
  53. * section.
  54. *
  55. * @return APB clock frequency, in Hz
  56. */
  57. int esp_clk_apb_freq(void);
  58. /**
  59. * @brief Return frequency of the main XTAL
  60. *
  61. * Frequency of the main XTAL can be either auto-detected or set at compile
  62. * time (see CONFIG_ESP32_XTAL_FREQ_SEL sdkconfig option). In both cases, this
  63. * function returns the actual value at run time.
  64. *
  65. * @return XTAL frequency, in Hz
  66. */
  67. int esp_clk_xtal_freq(void);
  68. /**
  69. * @brief Read value of RTC counter, converting it to microseconds
  70. * @attention The value returned by this function may change abruptly when
  71. * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
  72. * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
  73. * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
  74. *
  75. * @return Value or RTC counter, expressed in microseconds
  76. */
  77. uint64_t esp_clk_rtc_time();