esp_etm.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdio.h>
  9. #include "esp_err.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief ETM channel handle
  15. */
  16. typedef struct esp_etm_channel_t *esp_etm_channel_handle_t;
  17. /**
  18. * @brief ETM event handle
  19. */
  20. typedef struct esp_etm_event_t *esp_etm_event_handle_t;
  21. /**
  22. * @brief ETM task handle
  23. */
  24. typedef struct esp_etm_task_t *esp_etm_task_handle_t;
  25. /**
  26. * @brief ETM channel configuration
  27. */
  28. typedef struct {
  29. } esp_etm_channel_config_t;
  30. /**
  31. * @brief Allocate an ETM channel
  32. *
  33. * @note The channel can later be freed by `esp_etm_del_channel`
  34. *
  35. * @param[in] config ETM channel configuration
  36. * @param[out] ret_chan Returned ETM channel handle
  37. * @return
  38. * - ESP_OK: Allocate ETM channel successfully
  39. * - ESP_ERR_INVALID_ARG: Allocate ETM channel failed because of invalid argument
  40. * - ESP_ERR_NO_MEM: Allocate ETM channel failed because of out of memory
  41. * - ESP_ERR_NOT_FOUND: Allocate ETM channel failed because all channels are used up and no more free one
  42. * - ESP_FAIL: Allocate ETM channel failed because of other reasons
  43. */
  44. esp_err_t esp_etm_new_channel(const esp_etm_channel_config_t *config, esp_etm_channel_handle_t *ret_chan);
  45. /**
  46. * @brief Delete an ETM channel
  47. *
  48. * @param[in] chan ETM channel handle that created by `esp_etm_new_channel`
  49. * @return
  50. * - ESP_OK: Delete ETM channel successfully
  51. * - ESP_ERR_INVALID_ARG: Delete ETM channel failed because of invalid argument
  52. * - ESP_FAIL: Delete ETM channel failed because of other reasons
  53. */
  54. esp_err_t esp_etm_del_channel(esp_etm_channel_handle_t chan);
  55. /**
  56. * @brief Enable ETM channel
  57. *
  58. * @note This function will transit the channel state from init to enable.
  59. *
  60. * @param[in] chan ETM channel handle that created by `esp_etm_new_channel`
  61. * @return
  62. * - ESP_OK: Enable ETM channel successfully
  63. * - ESP_ERR_INVALID_ARG: Enable ETM channel failed because of invalid argument
  64. * - ESP_ERR_INVALID_STATE: Enable ETM channel failed because the channel has been enabled already
  65. * - ESP_FAIL: Enable ETM channel failed because of other reasons
  66. */
  67. esp_err_t esp_etm_channel_enable(esp_etm_channel_handle_t chan);
  68. /**
  69. * @brief Disable ETM channel
  70. *
  71. * @note This function will transit the channel state from enable to init.
  72. *
  73. * @param[in] chan ETM channel handle that created by `esp_etm_new_channel`
  74. * @return
  75. * - ESP_OK: Disable ETM channel successfully
  76. * - ESP_ERR_INVALID_ARG: Disable ETM channel failed because of invalid argument
  77. * - ESP_ERR_INVALID_STATE: Disable ETM channel failed because the channel is not enabled yet
  78. * - ESP_FAIL: Disable ETM channel failed because of other reasons
  79. */
  80. esp_err_t esp_etm_channel_disable(esp_etm_channel_handle_t chan);
  81. /**
  82. * @brief Connect an ETM event to an ETM task via a previously allocated ETM channel
  83. *
  84. * @note Setting the ETM event/task handle to NULL means to disconnect the channel from any event/task
  85. *
  86. * @param[in] chan ETM channel handle that created by `esp_etm_new_channel`
  87. * @param[in] event ETM event handle obtained from a driver/peripheral, e.g. `xxx_new_etm_event`
  88. * @param[in] task ETM task handle obtained from a driver/peripheral, e.g. `xxx_new_etm_task`
  89. * @return
  90. * - ESP_OK: Connect ETM event and task to the channel successfully
  91. * - ESP_ERR_INVALID_ARG: Connect ETM event and task to the channel failed because of invalid argument
  92. * - ESP_FAIL: Connect ETM event and task to the channel failed because of other reasons
  93. */
  94. esp_err_t esp_etm_channel_connect(esp_etm_channel_handle_t chan, esp_etm_event_handle_t event, esp_etm_task_handle_t task);
  95. /**
  96. * @brief Delete ETM event
  97. *
  98. * @note Although the ETM event comes from various peripherals, we provide the same user API to delete the event handle seamlessly.
  99. *
  100. * @param[in] event ETM event handle obtained from a driver/peripheral, e.g. `xxx_new_etm_event`
  101. * @return
  102. * - ESP_OK: Delete ETM event successfully
  103. * - ESP_ERR_INVALID_ARG: Delete ETM event failed because of invalid argument
  104. * - ESP_FAIL: Delete ETM event failed because of other reasons
  105. */
  106. esp_err_t esp_etm_del_event(esp_etm_event_handle_t event);
  107. /**
  108. * @brief Delete ETM task
  109. *
  110. * @note Although the ETM task comes from various peripherals, we provide the same user API to delete the task handle seamlessly.
  111. *
  112. * @param[in] task ETM task handle obtained from a driver/peripheral, e.g. `xxx_new_etm_task`
  113. * @return
  114. * - ESP_OK: Delete ETM task successfully
  115. * - ESP_ERR_INVALID_ARG: Delete ETM task failed because of invalid argument
  116. * - ESP_FAIL: Delete ETM task failed because of other reasons
  117. */
  118. esp_err_t esp_etm_del_task(esp_etm_task_handle_t task);
  119. /**
  120. * @brief Dump ETM channel usages to the given IO stream
  121. *
  122. * @param[in] out_stream IO stream (e.g. stdout)
  123. * @return
  124. * - ESP_OK: Dump ETM channel usages successfully
  125. * - ESP_ERR_INVALID_ARG: Dump ETM channel usages failed because of invalid argument
  126. * - ESP_FAIL: Dump ETM channel usages failed because of other reasons
  127. */
  128. esp_err_t esp_etm_dump(FILE *out_stream);
  129. #ifdef __cplusplus
  130. }
  131. #endif