ccomp_timer_impl.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2019 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. #include <stdbool.h>
  17. #include "esp_err.h"
  18. /**
  19. * @brief Initialize the underlying implementation for cache compensated timer. This might involve
  20. * setting up architecture-specific event counters and or allocating interrupts that handle events for those counters.
  21. * @return
  22. * - ESP_OK: Success
  23. * - ESP_ERR_INVALID_STATE: The timer has already been started previously.
  24. * - Others: Fail
  25. */
  26. esp_err_t ccomp_timer_impl_init(void);
  27. /**
  28. * @brief Deinitialize the underlying implementation for cache compensated timer. This should restore
  29. * the state of the program to before ccomp_timer_impl_init.
  30. * @return
  31. * - ESP_OK: Success
  32. * - ESP_ERR_INVALID_STATE: The timer has already been started previously.
  33. * - Others: Fail
  34. */
  35. esp_err_t ccomp_timer_impl_deinit(void);
  36. /**
  37. * @brief Make the underlying implementation start keeping time.
  38. *
  39. * @return
  40. * - ESP_OK: Success
  41. * - Others: Fail
  42. */
  43. esp_err_t ccomp_timer_impl_start(void);
  44. /**
  45. * @brief Make the underlying implementation stop keeping time.
  46. *
  47. * @return
  48. * - ESP_OK: Success
  49. * - Others: Fail
  50. */
  51. esp_err_t ccomp_timer_impl_stop(void);
  52. /**
  53. * @brief Reset the timer to its initial state.
  54. *
  55. * @return
  56. * - ESP_OK: Success
  57. * - Others: Fail
  58. */
  59. esp_err_t ccomp_timer_impl_reset(void);
  60. /**
  61. * @brief Get the elapsed time kept track of by the underlying implementation in microseconds.
  62. *
  63. * @return The elapsed time in microseconds. Set to -1 if the operation is unsuccessful.
  64. */
  65. int64_t ccomp_timer_impl_get_time(void);
  66. /**
  67. * @brief Obtain an internal critical section used in the implementation. Should be treated
  68. * as a spinlock.
  69. */
  70. void ccomp_timer_impl_lock(void);
  71. /**
  72. * @brief Start the performance timer on the current core.
  73. */
  74. void ccomp_timer_impl_unlock(void);
  75. /**
  76. * @brief Check if timer has been initialized.
  77. *
  78. * @return
  79. * - true: the timer has been initialized using ccomp_timer_impl_init
  80. * - false: the timer has not been initialized, or ccomp_timer_impl_deinit has been called recently
  81. */
  82. bool ccomp_timer_impl_is_init(void);
  83. /**
  84. * @brief Check if timer is keeping time.
  85. *
  86. * @return
  87. * - true: the timer is keeping track of elapsed time from ccomp_timer_impl_start
  88. * - false: the timer is not keeping track of elapsed time since ccomp_timer_impl_start has not yet been called or ccomp_timer_impl_stop has been called recently
  89. */
  90. bool ccomp_timer_impl_is_active(void);