forked from percepio/TraceRecorderSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcMultiCoreEventBuffer.c
160 lines (121 loc) · 5.37 KB
/
trcMultiCoreEventBuffer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Percepio Trace Recorder for Tracealyzer v4.10.2
* Copyright 2023 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The interface for the multi-core event buffer.
*/
#include <trcRecorder.h>
#if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
traceResult xTraceMultiCoreEventBufferInitialize(TraceMultiCoreEventBuffer_t* const pxTraceMultiCoreEventBuffer, uint32_t uiOptions,
uint8_t* puiBuffer, uint32_t uiSize)
{
uint32_t i;
uint32_t uiBufferSizePerCore;
/* This should never fail */
TRC_ASSERT(pxTraceMultiCoreEventBuffer != (void*)0);
/* This should never fail */
TRC_ASSERT(puiBuffer != (void*)0);
uiBufferSizePerCore = ((uiSize / (uint32_t)(TRC_CFG_CORE_COUNT)) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t); /* BaseType aligned */
/* This should never fail */
TRC_ASSERT(uiBufferSizePerCore != 0u);
for (i = 0u; i < (uint32_t)(TRC_CFG_CORE_COUNT); i++)
{
/* Set the event buffer pointers to point into the allocated space we have been given, this ensures
* a flat memory layout necessary for usage in streaming snaphot. */
pxTraceMultiCoreEventBuffer->xEventBuffer[i] = (TraceEventBuffer_t*)(&puiBuffer[i * uiBufferSizePerCore]); /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress conversion between pointer types checks*/ /*cstat !MISRAC2004-17.4_b We need to access a spcific point in the buffer*/
/* Initialize the event buffer structure with its memory buffer placed following its own structure data. */
/* We need to check this */
if (xTraceEventBufferInitialize(pxTraceMultiCoreEventBuffer->xEventBuffer[i], uiOptions,
&puiBuffer[(i * uiBufferSizePerCore) + sizeof(TraceEventBuffer_t)], /*cstat !MISRAC2004-17.4_b We need to access a specific point in the buffer*/
uiBufferSizePerCore - sizeof(TraceEventBuffer_t)) == TRC_FAIL)
{
return TRC_FAIL;
}
}
return TRC_SUCCESS;
}
#if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
/*cstat !MISRAC2012-Rule-5.1 Yes, these are long names*/
traceResult xTraceMultiCoreEventBufferAlloc(const TraceMultiCoreEventBuffer_t * const pxTraceMultiCoreEventBuffer, uint32_t uiSize,
void **ppvData)
{
/* This should never fail */
TRC_ASSERT(pxTraceMultiCoreEventBuffer != (void*)0);
TRC_ASSERT((TRC_CFG_GET_CURRENT_CORE()) < (TRC_CFG_CORE_COUNT));
return xTraceEventBufferAlloc(pxTraceMultiCoreEventBuffer->xEventBuffer[TRC_CFG_GET_CURRENT_CORE()], uiSize, ppvData);
}
/*cstat !MISRAC2012-Rule-5.1 Yes, these are long names*/
traceResult xTraceMultiCoreEventBufferAllocCommit(const TraceMultiCoreEventBuffer_t * const pxTraceMultiCoreEventBuffer, void *pvData, uint32_t uiSize, int32_t *piBytesWritten)
{
/* This should never fail */
TRC_ASSERT(pxTraceMultiCoreEventBuffer != (void*)0);
TRC_ASSERT((TRC_CFG_GET_CURRENT_CORE()) < (TRC_CFG_CORE_COUNT));
return xTraceEventBufferAllocCommit(pxTraceMultiCoreEventBuffer->xEventBuffer[TRC_CFG_GET_CURRENT_CORE()], pvData, uiSize, piBytesWritten);
}
traceResult xTraceMultiCoreEventBufferPush(const TraceMultiCoreEventBuffer_t* const pxTraceMultiCoreEventBuffer,
void* pvData, uint32_t uiSize, int32_t* piBytesWritten)
{
/* This should never fail */
TRC_ASSERT(pxTraceMultiCoreEventBuffer != (void*)0);
TRC_ASSERT((TRC_CFG_GET_CURRENT_CORE()) < (TRC_CFG_CORE_COUNT));
return xTraceEventBufferPush(pxTraceMultiCoreEventBuffer->xEventBuffer[TRC_CFG_GET_CURRENT_CORE()], pvData, uiSize, piBytesWritten);
}
#endif
/*cstat !MISRAC2012-Rule-5.1 Yes, these are long names*/
traceResult xTraceMultiCoreEventBufferTransferAll(const TraceMultiCoreEventBuffer_t* const pxTraceMultiCoreEventBuffer, int32_t* piBytesWritten)
{
int32_t iBytesWritten = 0;
uint32_t uiCoreId;
/* This should never fail */
TRC_ASSERT(pxTraceMultiCoreEventBuffer != (void*)0);
/* This should never fail */
TRC_ASSERT(piBytesWritten != (void*)0);
*piBytesWritten = 0;
for (uiCoreId = 0u; uiCoreId < (uint32_t)(TRC_CFG_CORE_COUNT); uiCoreId++)
{
/* We need to check this */
if (xTraceEventBufferTransferAll(pxTraceMultiCoreEventBuffer->xEventBuffer[uiCoreId], &iBytesWritten) == TRC_FAIL)
{
return TRC_FAIL;
}
*piBytesWritten += iBytesWritten;
}
return TRC_SUCCESS;
}
/*cstat !MISRAC2012-Rule-5.1 Yes, these are long names*/
traceResult xTraceMultiCoreEventBufferTransferChunk(const TraceMultiCoreEventBuffer_t* const pxTraceMultiCoreEventBuffer, uint32_t uiChunkSize, int32_t* piBytesWritten)
{
int32_t iBytesWritten = 0;
uint32_t uiCoreId;
/* This should never fail */
TRC_ASSERT(pxTraceMultiCoreEventBuffer != (void*)0);
/* This should never fail */
TRC_ASSERT(piBytesWritten != (void*)0);
*piBytesWritten = 0;
for (uiCoreId = 0u; uiCoreId < (uint32_t)(TRC_CFG_CORE_COUNT); uiCoreId++)
{
/* We need to check this */
if (xTraceEventBufferTransferChunk(pxTraceMultiCoreEventBuffer->xEventBuffer[uiCoreId], uiChunkSize, &iBytesWritten) == TRC_FAIL)
{
return TRC_FAIL;
}
*piBytesWritten += iBytesWritten;
}
return TRC_SUCCESS;
}
traceResult xTraceMultiCoreEventBufferClear(const TraceMultiCoreEventBuffer_t* const pxTraceMultiCoreEventBuffer)
{
uint32_t uiCoreId;
/* This should never fail */
TRC_ASSERT(pxTraceMultiCoreEventBuffer != (void*)0);
for (uiCoreId = 0u; uiCoreId < (uint32_t)(TRC_CFG_CORE_COUNT); uiCoreId++)
{
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEventBufferClear(pxTraceMultiCoreEventBuffer->xEventBuffer[uiCoreId]) == TRC_SUCCESS);
}
return TRC_SUCCESS;
}
#endif