trcInternalEventBuffer.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Trace Recorder for Tracealyzer v4.9.2
  3. * Copyright 2023 Percepio AB
  4. * www.percepio.com
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. *
  8. * The implementation of the internal buffer.
  9. */
  10. #include <trcRecorder.h>
  11. #if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) && (TRC_USE_INTERNAL_BUFFER == 1)
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdarg.h>
  15. static TraceMultiCoreEventBuffer_t *pxInternalEventBuffer TRC_CFG_RECORDER_DATA_ATTRIBUTE;
  16. traceResult xTraceInternalEventBufferInitialize(uint8_t* puiBuffer, uint32_t uiSize)
  17. {
  18. /* uiSize must be larger than sizeof(TraceMultiCoreEventBuffer_t) or there will be no room for any data */
  19. /* This should never fail */
  20. TRC_ASSERT(uiSize > sizeof(TraceMultiCoreEventBuffer_t));
  21. /* pxInternalBuffer will be placed at the beginning of the puiBuffer */
  22. pxInternalEventBuffer = (TraceMultiCoreEventBuffer_t*)puiBuffer;
  23. /* Send in a an address pointing after the TraceMultiCoreEventBuffer_t */
  24. /* We need to check this */
  25. if (xTraceMultiCoreEventBufferInitialize(pxInternalEventBuffer, TRC_EVENT_BUFFER_OPTION_SKIP,
  26. &puiBuffer[sizeof(TraceMultiCoreEventBuffer_t)], uiSize - sizeof(TraceMultiCoreEventBuffer_t)) == TRC_FAIL)
  27. {
  28. return TRC_FAIL;
  29. }
  30. xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_INTERNAL_EVENT_BUFFER);
  31. return TRC_SUCCESS;
  32. }
  33. traceResult xTraceInternalEventBufferAlloc(uint32_t uiSize, void **ppvData)
  34. {
  35. /* This should never fail */
  36. TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_INTERNAL_EVENT_BUFFER));
  37. return xTraceMultiCoreEventBufferAlloc(pxInternalEventBuffer, uiSize, ppvData);
  38. }
  39. traceResult xTraceInternalEventBufferAllocCommit(void *pvData, uint32_t uiSize, int32_t *piBytesWritten)
  40. {
  41. (void)pvData;
  42. /* This should never fail */
  43. TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_INTERNAL_EVENT_BUFFER));
  44. return xTraceMultiCoreEventBufferAllocCommit(pxInternalEventBuffer, pvData, uiSize, piBytesWritten);
  45. }
  46. traceResult xTraceInternalEventBufferPush(void *pvData, uint32_t uiSize, int32_t *piBytesWritten)
  47. {
  48. /* This should never fail */
  49. TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_INTERNAL_EVENT_BUFFER));
  50. return xTraceMultiCoreEventBufferPush(pxInternalEventBuffer, pvData, uiSize, piBytesWritten);
  51. }
  52. traceResult xTraceInternalEventBufferTransferAll(void)
  53. {
  54. int32_t iBytesWritten = 0;
  55. /* This should never fail */
  56. TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_INTERNAL_EVENT_BUFFER));
  57. return xTraceMultiCoreEventBufferTransferAll(pxInternalEventBuffer, &iBytesWritten);
  58. }
  59. traceResult xTraceInternalEventBufferTransferChunk(void)
  60. {
  61. int32_t iBytesWritten = 0;
  62. int32_t iCounter = 0;
  63. /* This should never fail */
  64. TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_INTERNAL_EVENT_BUFFER));
  65. do
  66. {
  67. if (xTraceMultiCoreEventBufferTransferChunk(pxInternalEventBuffer, TRC_INTERNAL_BUFFER_CHUNK_SIZE, &iBytesWritten) == TRC_FAIL)
  68. {
  69. return TRC_FAIL;
  70. }
  71. iCounter++;
  72. /* This will do another loop if TRC_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_SIZE_LIMIT of data was transferred and we haven't already looped TRC_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_COUNT_LIMIT number of times */
  73. } while (iBytesWritten >= (int32_t)(TRC_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_SIZE_LIMIT) && iCounter < (int32_t)(TRC_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_COUNT_LIMIT));
  74. return TRC_SUCCESS;
  75. }
  76. traceResult xTraceInternalEventBufferClear()
  77. {
  78. /* This should never fail */
  79. TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_INTERNAL_EVENT_BUFFER));
  80. return xTraceMultiCoreEventBufferClear(pxInternalEventBuffer);
  81. }
  82. #endif