tracing_buffer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2019 Intel corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _TRACE_BUFFER_H
  7. #define _TRACE_BUFFER_H
  8. #include <stdbool.h>
  9. #include <zephyr/types.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief Initialize tracing buffer.
  15. */
  16. void tracing_buffer_init(void);
  17. /**
  18. * @brief Tracing buffer is empty or not.
  19. *
  20. * @return true if the ring buffer is empty, or false if not.
  21. */
  22. bool tracing_buffer_is_empty(void);
  23. /**
  24. * @brief Get free space in the tracing buffer.
  25. *
  26. * @return Tracing buffer free space (in bytes).
  27. */
  28. uint32_t tracing_buffer_space_get(void);
  29. /**
  30. * @brief Get tracing buffer capacity (max size).
  31. *
  32. * @return Tracing buffer capacity (in bytes).
  33. */
  34. uint32_t tracing_buffer_capacity_get(void);
  35. /**
  36. * @brief Try to allocate buffer in the tracing buffer.
  37. *
  38. * @param data Pointer to the address. It's set to a location
  39. * within the tracing buffer.
  40. * @param size Requested buffer size (in bytes).
  41. *
  42. * @return Size of allocated buffer which can be smaller than
  43. * requested if there isn't enough free space or buffer wraps.
  44. */
  45. uint32_t tracing_buffer_put_claim(uint8_t **data, uint32_t size);
  46. /**
  47. * @brief Indicate number of bytes written to the allocated buffer.
  48. *
  49. * @param size Number of bytes written to the allocated buffer.
  50. *
  51. * @retval 0 Successful operation.
  52. * @retval -EINVAL Given @a size exceeds free space of tracing buffer.
  53. */
  54. int tracing_buffer_put_finish(uint32_t size);
  55. /**
  56. * @brief Write data to tracing buffer.
  57. *
  58. * @param data Address of data.
  59. * @param size Data size (in bytes).
  60. *
  61. * @retval Number of bytes written to tracing buffer.
  62. */
  63. uint32_t tracing_buffer_put(uint8_t *data, uint32_t size);
  64. /**
  65. * @brief Get address of the first valid data in tracing buffer.
  66. *
  67. * @param data Pointer to the address. It's set to a location pointing to
  68. * the first valid data within the tracing buffer.
  69. * @param size Requested buffer size (in bytes).
  70. *
  71. * @return Size of valid buffer which can be smaller than requested
  72. * if there isn't enough valid data or buffer wraps.
  73. */
  74. uint32_t tracing_buffer_get_claim(uint8_t **data, uint32_t size);
  75. /**
  76. * @brief Indicate number of bytes read from claimed buffer.
  77. *
  78. * @param size Number of bytes read from claimed buffer.
  79. *
  80. * @retval 0 Successful operation.
  81. * @retval -EINVAL Given @a size exceeds available data of tracing buffer.
  82. */
  83. int tracing_buffer_get_finish(uint32_t size);
  84. /**
  85. * @brief Read data from tracing buffer to output buffer.
  86. *
  87. * @param data Address of the output buffer.
  88. * @param size Data size (in bytes).
  89. *
  90. * @retval Number of bytes written to the output buffer.
  91. */
  92. uint32_t tracing_buffer_get(uint8_t *data, uint32_t size);
  93. /**
  94. * @brief Get buffer from tracing command buffer.
  95. *
  96. * @param data Pointer to tracing command buffer start address.
  97. *
  98. * @return Tracing command buffer size (in bytes).
  99. */
  100. uint32_t tracing_cmd_buffer_alloc(uint8_t **data);
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif