xtensa_perfmon_access.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2018-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. #ifndef _PERF_MON_ACCESS_H_
  15. #define _PERF_MON_ACCESS_H_
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "esp_err.h"
  19. #include "esp_log.h"
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. /**@{*/
  25. /**
  26. * @brief Init Performance Monitoor
  27. *
  28. * Initialize performance monitor register with define values
  29. *
  30. * @param[in] id: performance counter number
  31. * @param[in] select: select value from PMCTRLx register
  32. * @param[in] mask: mask value from PMCTRLx register
  33. * @param[in] kernelcnt: kernelcnt value from PMCTRLx register
  34. * @param[in] tracelevel: tracelevel value from PMCTRLx register
  35. *
  36. * @return
  37. * - ESP_OK on success
  38. * - ESP_ERR_INVALID_ARG if one of the arguments is not correct
  39. */
  40. esp_err_t xtensa_perfmon_init(int id, uint16_t select, uint16_t mask, int kernelcnt, int tracelevel);
  41. /**@}*/
  42. /**@{*/
  43. /**
  44. * @brief Reset PM counter
  45. *
  46. * Reset PM counter. Writes 0 to the PMx register.
  47. *
  48. * @param[in] id: performance counter number
  49. *
  50. * @return
  51. * - ESP_OK on success
  52. * - ESP_ERR_INVALID_ARG if id out of range
  53. */
  54. esp_err_t xtensa_perfmon_reset(int id);
  55. /**@}*/
  56. /**@{*/
  57. /**
  58. * @brief Start PM counters
  59. *
  60. * Start all PM counters synchronously. Write 1 to the PGM register
  61. */
  62. void xtensa_perfmon_start(void);
  63. /**@}*/
  64. /**@{*/
  65. /**
  66. * @brief Stop PM counters
  67. *
  68. * Stop all PM counters synchronously. Write 0 to the PGM register
  69. */
  70. void xtensa_perfmon_stop(void);
  71. /**@}*/
  72. /**@{*/
  73. /**
  74. * @brief Read PM counter
  75. *
  76. * Read value of defined PM counter.
  77. *
  78. * @param[in] id: performance counter number
  79. *
  80. * @return
  81. * - Performance counter value
  82. */
  83. uint32_t xtensa_perfmon_value(int id);
  84. /**@}*/
  85. /**@{*/
  86. /**
  87. * @brief Read PM overflow state
  88. *
  89. * Read overflow value of defined PM counter.
  90. *
  91. * @param[in] id: performance counter number
  92. *
  93. * @return
  94. * - ESP_OK if there is no overflow (overflow = 0)
  95. * - ESP_FAIL if overflow occure (overflow = 1)
  96. */
  97. esp_err_t xtensa_perfmon_overflow(int id);
  98. /**@}*/
  99. /**@{*/
  100. /**
  101. * @brief Dump PM values
  102. *
  103. * Dump all PM register to the console.
  104. *
  105. */
  106. void xtensa_perfmon_dump(void);
  107. /**@}*/
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif // _PERF_MON_ACCESS_H_