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 * Supporting functions for trace streaming, used by the "stream ports"
9 * for reading and writing data to the interface.
10 */
11
12 #include <trcRecorder.h>
13 #include <xscope.h>
14
15 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
16
17 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
18
19 typedef struct TraceStreamPortXS {
20 #if (TRC_USE_INTERNAL_BUFFER == 1)
21 uint8_t uiBufferInternal[TRC_STREAM_PORT_INTERNAL_BUFFER_SIZE];
22 #endif
23 uint8_t uiBuffer[8];
24 } TraceStreamPortXS_t;
25
26 static TraceStreamPortXS_t* pxStreamPortXS TRC_CFG_RECORDER_DATA_ATTRIBUTE;
27
xTraceStreamPortInitialize(TraceStreamPortBuffer_t * pxBuffer)28 traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer)
29 {
30 TRC_ASSERT_EQUAL_SIZE(TraceStreamPortBuffer_t, TraceStreamPortXS_t);
31
32 if (pxBuffer == 0)
33 {
34 return TRC_FAIL;
35 }
36
37 pxStreamPortXS = (TraceStreamPortXS_t*)pxBuffer;
38
39 #if (TRC_USE_INTERNAL_BUFFER == 1)
40 return xTraceInternalEventBufferInitialize(pxStreamPortXS->uiBufferInternal, sizeof(pxStreamPortXS->uiBufferInternal));
41 #else
42 return TRC_SUCCESS;
43 #endif
44 }
45
xTraceStreamPortOnBegin(void)46 traceResult xTraceStreamPortOnBegin(void)
47 {
48 return TRC_SUCCESS;
49 }
50
xTraceStreamPortOnEnd(void)51 traceResult xTraceStreamPortOnEnd(void)
52 {
53 return TRC_SUCCESS;
54 }
55
xTraceStreamPortAllocate(uint32_t uiSize,void ** ppvData)56 traceResult xTraceStreamPortAllocate(uint32_t uiSize, void** ppvData)
57 {
58 (void)uiSize;
59
60 return xTraceStaticBufferGet(ppvData);
61 }
62
xTraceStreamPortCommit(void * pvData,uint32_t uiSize,int32_t * piBytesCommitted)63 traceResult xTraceStreamPortCommit(void* pvData, uint32_t uiSize, int32_t* piBytesCommitted)
64 {
65 if (pvData == 0)
66 {
67 return TRC_FAIL;
68 }
69
70 #if (TRC_USE_INTERNAL_BUFFER == 1)
71 /* Push to internal buffer. It will call on xTraceStreamPortWriteData() periodically. */
72 return xTraceInternalEventBufferPush(pvData, uiSize, piBytesCommitted);
73 #else
74 /* Write directly to file */
75 return xTraceStreamPortWriteData(pvData, uiSize, piBytesCommitted);
76 #endif
77 }
78
xTraceStreamPortWriteData(void * pvData,uint32_t uiSize,int32_t * piBytesWritten)79 traceResult xTraceStreamPortWriteData(void* pvData, uint32_t uiSize, int32_t* piBytesWritten)
80 {
81 /* xscope_bytes is supposed to be thread safe, so we do not bother with any
82 * critical sections here. */
83 xscope_bytes(0, uiSize, (unsigned char*)pvData);
84
85 if (piBytesWritten != 0) {
86 /* Since xScope always write all bytes (not all might be received) we flag this as
87 * a full write */
88 *piBytesWritten = (int32_t)uiSize;
89 }
90
91 return TRC_SUCCESS;
92 }
93
xTraceStreamPortReadData(void * pvData,uint32_t uiSize,int32_t * piBytesRead)94 traceResult xTraceStreamPortReadData(void* pvData, uint32_t uiSize, int32_t* piBytesRead)
95 {
96 return TRC_SUCCESS;
97 }
98
99 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
100
101 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */