1 /*
2 * Trace Recorder for Tracealyzer v4.8.1
3 * Copyright 2023 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 TRC_CFG_RECORDER_DATA_ATTRIBUTE; /*cstat !MISRAC2004-8.7 !MISRAC2004-8.10 !MISRAC2012-Rule-8.4 !MISRAC2012-Rule-8.7 !MISRAC2012-Rule-8.9_b Suppress global object check*/
22 
23 TraceStreamPortData_t* pxStreamPortData TRC_CFG_RECORDER_DATA_ATTRIBUTE;
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 == (void*)0)
32 	{
33 		return TRC_FAIL;
34 	}
35 
36 	pxStreamPortData = (TraceStreamPortData_t*)pxBuffer; /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress conversion between pointer types checks*/
37 	pxRingBuffer = &pxStreamPortData->xRingBuffer;
38 	RecorderDataPtr = pxRingBuffer;
39 
40 	pxRingBuffer->xEventBuffer.uxSize = sizeof(pxRingBuffer->xEventBuffer.uiBuffer);
41 
42 #if (TRC_CFG_STREAM_PORT_RINGBUFFER_MODE == TRC_STREAM_PORT_RINGBUFFER_MODE_OVERWRITE_WHEN_FULL)
43 	if (xTraceMultiCoreEventBufferInitialize(&pxStreamPortData->xMultiCoreEventBuffer, TRC_EVENT_BUFFER_OPTION_OVERWRITE, pxRingBuffer->xEventBuffer.uiBuffer, sizeof(pxRingBuffer->xEventBuffer.uiBuffer)) == TRC_FAIL)
44 	{
45 		return TRC_FAIL;
46 	}
47 #else
48 	if (xTraceMultiCoreEventBufferInitialize(&pxStreamPortData->xMultiCoreEventBuffer, TRC_EVENT_BUFFER_OPTION_SKIP, pxRingBuffer->xEventBuffer.uiBuffer, sizeof(pxRingBuffer->xEventBuffer.uiBuffer)) == TRC_FAIL)
49 	{
50 		return TRC_FAIL;
51 	}
52 #endif
53 
54 	if (xTraceHeaderInitialize(&pxRingBuffer->xHeaderBuffer) == TRC_FAIL)
55 	{
56 		return TRC_FAIL;
57 	}
58 
59 	if (xTraceEntryTableInitialize(&pxRingBuffer->xEntryTable) == TRC_FAIL)
60 	{
61 		return TRC_FAIL;
62 	}
63 
64 	if (xTraceTimestampInitialize(&pxRingBuffer->xTimestampInfo) == TRC_FAIL)
65 	{
66 		return TRC_FAIL;
67 	}
68 
69 	pxRingBuffer->END_MARKERS[0] = 0x0AU;
70 	pxRingBuffer->END_MARKERS[1] = 0x0BU;
71 	pxRingBuffer->END_MARKERS[2] = 0x0CU;
72 	pxRingBuffer->END_MARKERS[3] = 0x0DU;
73 
74 	pxRingBuffer->END_MARKERS[4] = 0x71U;
75 	pxRingBuffer->END_MARKERS[5] = 0x72U;
76 	pxRingBuffer->END_MARKERS[6] = 0x73U;
77 	pxRingBuffer->END_MARKERS[7] = 0x74U;
78 
79 	pxRingBuffer->END_MARKERS[8] = 0xF1U;
80 	pxRingBuffer->END_MARKERS[9] = 0xF2U;
81 	pxRingBuffer->END_MARKERS[10] = 0xF3U;
82 	pxRingBuffer->END_MARKERS[11] = 0xF4U;
83 
84 	pxRingBuffer->START_MARKERS[0] = 0x05U;
85 	pxRingBuffer->START_MARKERS[1] = 0x06U;
86 	pxRingBuffer->START_MARKERS[2] = 0x07U;
87 	pxRingBuffer->START_MARKERS[3] = 0x08U;
88 
89 	pxRingBuffer->START_MARKERS[4] = 0x75U;
90 	pxRingBuffer->START_MARKERS[5] = 0x76U;
91 	pxRingBuffer->START_MARKERS[6] = 0x77U;
92 	pxRingBuffer->START_MARKERS[7] = 0x78U;
93 
94 	pxRingBuffer->START_MARKERS[8] = 0xF5U;
95 	pxRingBuffer->START_MARKERS[9] = 0xF6U;
96 	pxRingBuffer->START_MARKERS[10] = 0xF7U;
97 	pxRingBuffer->START_MARKERS[11] = 0xF8U;
98 
99 	return TRC_SUCCESS;
100 }
101 
xTraceStreamPortOnTraceBegin(void)102 traceResult xTraceStreamPortOnTraceBegin(void)
103 {
104 	return xTraceMultiCoreEventBufferClear(&pxStreamPortData->xMultiCoreEventBuffer);
105 }
106 
107 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
108 
109 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
110