esp_clk.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Read value of RTC counter, converting it to microseconds
  60. * @attention The value returned by this function may change abruptly when
  61. * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
  62. * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
  63. * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
  64. *
  65. * @return Value or RTC counter, expressed in microseconds
  66. */
  67. uint64_t esp_clk_rtc_time();