esp_app_trace.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // infinite waiting timeout
  18. #define ESP_APPTRACE_TMO_INFINITE ((uint32_t)-1)
  19. // Trace memory block size
  20. #define ESP_APPTRACE_TRAX_BLOCK_SIZE 0x4000UL
  21. /**
  22. * Application trace data destinations bits.
  23. */
  24. typedef enum {
  25. ESP_APPTRACE_DEST_TRAX = 0x1,
  26. ESP_APPTRACE_DEST_UART0 = 0x2,
  27. //ESP_APPTRACE_DEST_UART1 = 0x4,
  28. } esp_apptrace_dest_t;
  29. /**
  30. * @brief Initializes application tracing module.
  31. *
  32. * @note Should be called before any esp_apptrace_xxx call.
  33. *
  34. * @return ESP_OK on success, otherwise \see esp_err_t
  35. */
  36. esp_err_t esp_apptrace_init();
  37. /**
  38. * @brief Allocates buffer for trace data.
  39. * After data in buffer are ready to be sent off esp_apptrace_buffer_put must be called to indicate it.
  40. *
  41. * @param dest Indicates HW interface to send data.
  42. * @param size Size of data to write to trace buffer.
  43. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  44. *
  45. * @return non-NULL on success, otherwise NULL.
  46. */
  47. uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, size_t size, uint32_t tmo);
  48. /**
  49. * @brief Indicates that the data in buffer are ready to be sent off.
  50. * This function is a counterpart of must be preceeded by esp_apptrace_buffer_get.
  51. *
  52. * @param dest Indicates HW interface to send data. Should be identical to the same parameter in call to esp_apptrace_buffer_get.
  53. * @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_buffer_get.
  54. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  55. *
  56. * @return ESP_OK on success, otherwise \see esp_err_t
  57. */
  58. esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
  59. /**
  60. * @brief Writes data to trace buffer.
  61. *
  62. * @param dest Indicates HW interface to send data.
  63. * @param data Address of data to write to trace buffer.
  64. * @param size Size of data to write to trace buffer.
  65. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  66. *
  67. * @return ESP_OK on success, otherwise \see esp_err_t
  68. */
  69. esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, void *data, size_t size, uint32_t tmo);
  70. /**
  71. * @brief vprintf-like function to sent log messages to host via specified HW interface.
  72. *
  73. * @param dest Indicates HW interface to send data.
  74. * @param fmt Address of format string.
  75. * @param ap List of arguments.
  76. *
  77. * @return Number of bytes written.
  78. */
  79. int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t user_tmo, const char *fmt, va_list ap);
  80. /**
  81. * @brief vprintf-like function to sent log messages to host.
  82. *
  83. * @param fmt Address of format string.
  84. * @param ap List of arguments.
  85. *
  86. * @return Number of bytes written.
  87. */
  88. int esp_apptrace_vprintf(const char *fmt, va_list ap);
  89. /**
  90. * @brief Flushes remaining data in trace buffer to host.
  91. *
  92. * @param dest Indicates HW interface to flush data on.
  93. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  94. *
  95. * @return ESP_OK on success, otherwise \see esp_err_t
  96. */
  97. esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t tmo);
  98. /**
  99. * @brief Flushes remaining data in trace buffer to host without locking internal data.
  100. This is special version of esp_apptrace_flush which should be called from panic handler.
  101. *
  102. * @param dest Indicates HW interface to flush data on.
  103. * @param min_sz Threshold for flushing data. If current filling level is above this value, data will be flushed. TRAX destinations only.
  104. * @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
  105. *
  106. * @return ESP_OK on success, otherwise \see esp_err_t
  107. */
  108. esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t tmo);
  109. #endif