esp_app_trace.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef ESP_APP_TRACE_H_
  14. #define ESP_APP_TRACE_H_
  15. #include <stdarg.h>
  16. #include "esp_err.h"
  17. #include "freertos/portmacro.h"
  18. /** Infinite waiting timeout */
  19. #define ESP_APPTRACE_TMO_INFINITE ((uint32_t)-1)
  20. /**
  21. * Application trace data destinations bits.
  22. */
  23. typedef enum {
  24. ESP_APPTRACE_DEST_TRAX = 0x1, ///< JTAG destination
  25. ESP_APPTRACE_DEST_UART0 = 0x2, ///< UART destination
  26. } esp_apptrace_dest_t;
  27. /**
  28. * @brief Initializes application tracing module.
  29. *
  30. * @note Should be called before any esp_apptrace_xxx call.
  31. *
  32. * @return ESP_OK on success, otherwise see esp_err_t
  33. */
  34. esp_err_t esp_apptrace_init();
  35. /**
  36. * @brief Allocates buffer for trace data.
  37. * After data in buffer are ready to be sent off esp_apptrace_buffer_put must be called to indicate it.
  38. *
  39. * @param dest Indicates HW interface to send data.
  40. * @param size Size of data to write to trace buffer.
  41. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  42. *
  43. * @return non-NULL on success, otherwise NULL.
  44. */
  45. uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, size_t size, uint32_t tmo);
  46. /**
  47. * @brief Indicates that the data in buffer are ready to be sent off.
  48. * This function is a counterpart of must be preceeded by esp_apptrace_buffer_get.
  49. *
  50. * @param dest Indicates HW interface to send data. Should be identical to the same parameter in call to esp_apptrace_buffer_get.
  51. * @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_buffer_get.
  52. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  53. *
  54. * @return ESP_OK on success, otherwise see esp_err_t
  55. */
  56. esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
  57. /**
  58. * @brief Writes data to trace buffer.
  59. *
  60. * @param dest Indicates HW interface to send data.
  61. * @param data Address of data to write to trace buffer.
  62. * @param size Size of data to write to trace buffer.
  63. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  64. *
  65. * @return ESP_OK on success, otherwise see esp_err_t
  66. */
  67. esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, size_t size, uint32_t tmo);
  68. /**
  69. * @brief vprintf-like function to sent log messages to host via specified HW interface.
  70. *
  71. * @param dest Indicates HW interface to send data.
  72. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  73. * @param fmt Address of format string.
  74. * @param ap List of arguments.
  75. *
  76. * @return Number of bytes written.
  77. */
  78. int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t tmo, const char *fmt, va_list ap);
  79. /**
  80. * @brief vprintf-like function to sent log messages to host.
  81. *
  82. * @param fmt Address of format string.
  83. * @param ap List of arguments.
  84. *
  85. * @return Number of bytes written.
  86. */
  87. int esp_apptrace_vprintf(const char *fmt, va_list ap);
  88. /**
  89. * @brief Flushes remaining data in trace buffer to host.
  90. *
  91. * @param dest Indicates HW interface to flush data on.
  92. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  93. *
  94. * @return ESP_OK on success, otherwise see esp_err_t
  95. */
  96. esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t tmo);
  97. /**
  98. * @brief Flushes remaining data in trace buffer to host without locking internal data.
  99. * This is special version of esp_apptrace_flush which should be called from panic handler.
  100. *
  101. * @param dest Indicates HW interface to flush data on.
  102. * @param min_sz Threshold for flushing data. If current filling level is above this value, data will be flushed. TRAX destinations only.
  103. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  104. *
  105. * @return ESP_OK on success, otherwise see esp_err_t
  106. */
  107. esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t tmo);
  108. /**
  109. * @brief Reads host data from trace buffer.
  110. *
  111. * @param dest Indicates HW interface to read the data on.
  112. * @param data Address of buffer to put data from trace buffer.
  113. * @param size Pointer to store size of read data. Before call to this function pointed memory must hold requested size of data
  114. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  115. *
  116. * @return ESP_OK on success, otherwise see esp_err_t
  117. */
  118. esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *data, size_t *size, uint32_t tmo);
  119. #endif