esp_clk.h 2.5 KB

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