1 /*
2 * Trace Recorder for Tracealyzer v4.6.6
3 * Copyright 2021 Percepio AB
4 * www.percepio.com
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Supporting functions for trace streaming, used by the "stream ports"
9 * for reading and writing data to the interface.
10 * This "stream port" sets up the recorder to stream to a Ring Buffer.
11 */
12
13 #include <trcRecorder.h>
14
15 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
16
17 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
18
19 /* Backwards compatibility with plugins */
20 typedef TraceRingBuffer_t RecorderData;
21 RecorderData* RecorderDataPtr = 0;
22
23 TraceStreamPortData_t* pxStreamPortData;
24
xTraceStreamPortInitialize(TraceStreamPortBuffer_t * pxBuffer)25 traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer)
26 {
27 TraceRingBuffer_t* pxRingBuffer;
28
29 TRC_ASSERT_EQUAL_SIZE(TraceStreamPortBuffer_t, TraceStreamPortData_t);
30
31 if (pxBuffer == 0)
32 {
33 return TRC_FAIL;
34 }
35
36 pxStreamPortData = (TraceStreamPortData_t*)pxBuffer;
37 RecorderDataPtr = pxRingBuffer = &pxStreamPortData->xRingBuffer;
38
39 pxRingBuffer->xEventBuffer.uiSize = sizeof(pxRingBuffer->xEventBuffer.uiBuffer);
40
41 #if (TRC_CFG_STREAM_PORT_RINGBUFFER_MODE == TRC_STREAM_PORT_RINGBUFFER_MODE_OVERWRITE_WHEN_FULL)
42 if (xTraceMultiCoreEventBufferInitialize(&pxStreamPortData->xMultiCoreEventBuffer, TRC_EVENT_BUFFER_OPTION_OVERWRITE, pxRingBuffer->xEventBuffer.uiBuffer, sizeof(pxRingBuffer->xEventBuffer.uiBuffer)) == TRC_FAIL)
43 {
44 return TRC_FAIL;
45 }
46 #else
47 if (xTraceMultiCoreEventBufferInitialize(&pxStreamPortData->xMultiCoreEventBuffer, TRC_EVENT_BUFFER_OPTION_SKIP, pxRingBuffer->xEventBuffer.uiBuffer, sizeof(pxRingBuffer->xEventBuffer.uiBuffer)) == TRC_FAIL)
48 {
49 return TRC_FAIL;
50 }
51 #endif
52
53 if (xTraceHeaderInitialize(&pxRingBuffer->xHeaderBuffer) == TRC_FAIL)
54 {
55 return TRC_FAIL;
56 }
57
58 if (xTraceEntryTableInitialize(&pxRingBuffer->xEntryTableBuffer) == TRC_FAIL)
59 {
60 return TRC_FAIL;
61 }
62
63 if (xTraceTimestampInitialize(&pxRingBuffer->xTimestampInfo) == TRC_FAIL)
64 {
65 return TRC_FAIL;
66 }
67
68 pxRingBuffer->END_MARKERS[0] = 0x0A;
69 pxRingBuffer->END_MARKERS[1] = 0x0B;
70 pxRingBuffer->END_MARKERS[2] = 0x0C;
71 pxRingBuffer->END_MARKERS[3] = 0x0D;
72
73 pxRingBuffer->END_MARKERS[4] = 0x71;
74 pxRingBuffer->END_MARKERS[5] = 0x72;
75 pxRingBuffer->END_MARKERS[6] = 0x73;
76 pxRingBuffer->END_MARKERS[7] = 0x74;
77
78 pxRingBuffer->END_MARKERS[8] = 0xF1;
79 pxRingBuffer->END_MARKERS[9] = 0xF2;
80 pxRingBuffer->END_MARKERS[10] = 0xF3;
81 pxRingBuffer->END_MARKERS[11] = 0xF4;
82
83 pxRingBuffer->START_MARKERS[0] = 0x05;
84 pxRingBuffer->START_MARKERS[1] = 0x06;
85 pxRingBuffer->START_MARKERS[2] = 0x07;
86 pxRingBuffer->START_MARKERS[3] = 0x08;
87
88 pxRingBuffer->START_MARKERS[4] = 0x75;
89 pxRingBuffer->START_MARKERS[5] = 0x76;
90 pxRingBuffer->START_MARKERS[6] = 0x77;
91 pxRingBuffer->START_MARKERS[7] = 0x78;
92
93 pxRingBuffer->START_MARKERS[8] = 0xF5;
94 pxRingBuffer->START_MARKERS[9] = 0xF6;
95 pxRingBuffer->START_MARKERS[10] = 0xF7;
96 pxRingBuffer->START_MARKERS[11] = 0xF8;
97
98 return TRC_SUCCESS;
99 }
100
xTraceStreamPortCommit(void * pvData,uint32_t uiSize,int32_t * piBytesCommitted)101 traceResult xTraceStreamPortCommit(void* pvData, uint32_t uiSize, int32_t* piBytesCommitted)
102 {
103 if (pvData == 0)
104 {
105 return TRC_FAIL;
106 }
107
108 xTraceMultiCoreEventBufferPush(&pxStreamPortData->xMultiCoreEventBuffer, pvData, uiSize, piBytesCommitted);
109
110 #if (TRC_CFG_STREAM_PORT_RINGBUFFER_MODE == TRC_STREAM_PORT_RINGBUFFER_MODE_STOP_WHEN_FULL)
111 /* If no bytes was written it means that the buffer is full and we should stop
112 * tracing.
113 */
114 if (uiSize > 0 && *piBytesCommitted == 0) {
115 xTraceDisable();
116 return TRC_FAIL;
117 }
118 #endif
119
120 return TRC_SUCCESS;
121 }
122
xTraceStreamPortOnTraceBegin(void)123 traceResult xTraceStreamPortOnTraceBegin(void)
124 {
125 return xTraceMultiCoreEventBufferClear(&pxStreamPortData->xMultiCoreEventBuffer);
126 }
127
128 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
129
130 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
131