esp_clk.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2015-2020 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. #include <stdint.h>
  16. /**
  17. * @file esp_clk.h
  18. *
  19. * This file contains declarations of clock related functions.
  20. */
  21. /**
  22. * @brief Get the calibration value of RTC slow clock
  23. *
  24. * The value is in the same format as returned by rtc_clk_cal (microseconds,
  25. * in Q13.19 fixed-point format).
  26. *
  27. * @return the calibration value obtained using rtc_clk_cal, at startup time
  28. */
  29. uint32_t esp_clk_slowclk_cal_get(void);
  30. /**
  31. * @brief Update the calibration value of RTC slow clock
  32. *
  33. * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
  34. * in Q13.19 fixed-point format).
  35. * This value is used by timekeeping functions (such as gettimeofday) to
  36. * calculate current time based on RTC counter value.
  37. * @param value calibration value obtained using rtc_clk_cal
  38. */
  39. void esp_clk_slowclk_cal_set(uint32_t value);
  40. /**
  41. * @brief Return current CPU clock frequency
  42. * When frequency switching is performed, this frequency may change.
  43. * However it is guaranteed that the frequency never changes with a critical
  44. * section.
  45. *
  46. * @return CPU clock frequency, in Hz
  47. */
  48. int esp_clk_cpu_freq(void);
  49. /**
  50. * @brief Return current APB clock frequency
  51. *
  52. * When frequency switching is performed, this frequency may change.
  53. * However it is guaranteed that the frequency never changes with a critical
  54. * section.
  55. *
  56. * @return APB clock frequency, in Hz
  57. */
  58. int esp_clk_apb_freq(void);
  59. /**
  60. * @brief Read value of RTC counter, converting it to microseconds
  61. * @attention The value returned by this function may change abruptly when
  62. * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
  63. * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
  64. * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
  65. *
  66. * @return Value or RTC counter, expressed in microseconds
  67. */
  68. uint64_t esp_clk_rtc_time(void);