forked from percepio/TraceRecorderSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcObject.c
302 lines (224 loc) · 9.49 KB
/
trcObject.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* Percepio Trace Recorder for Tracealyzer v4.10.2
* Copyright 2023 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The implementation for strings.
*/
#include <trcRecorder.h>
#if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
#include <trcTypes.h>
#ifndef TRC_SEND_NAME_ONLY_ON_DELETE
#define TRC_SEND_NAME_ONLY_ON_DELETE 0
#endif
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceObjectRegisterInternal(uint32_t uiEventCode, void* const pvObject, const char* szName, TraceUnsignedBaseType_t uxStateCount, const TraceUnsignedBaseType_t uxStates[], TraceUnsignedBaseType_t uxOptions, TraceObjectHandle_t* pxObjectHandle)
{
TraceEntryHandle_t xEntryHandle;
TraceUnsignedBaseType_t i;
void *pvAddress;
TRACE_ALLOC_CRITICAL_SECTION();
/* This should never fail */
TRC_ASSERT(pxObjectHandle != (void*)0);
/* This should never fail */
TRC_ASSERT(uxStateCount <= (uint32_t)(TRC_ENTRY_TABLE_STATE_COUNT));
TRACE_ENTER_CRITICAL_SECTION();
if (pvObject != (void*)0)
{
/* An address was supplied */
if (xTraceEntryCreateWithAddress(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
pvAddress = pvObject;
}
else
{
/* No address was supplied */
if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress(xEntryHandle, &pvAddress) == TRC_SUCCESS);
}
for (i = 0u; i < uxStateCount; i++)
{
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetState(xEntryHandle, (uint32_t)i, uxStates[i]) == TRC_SUCCESS);
}
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions(xEntryHandle, (uint32_t)uxOptions) == TRC_SUCCESS);
*pxObjectHandle = (TraceObjectHandle_t)xEntryHandle;
TRACE_EXIT_CRITICAL_SECTION();
if ((szName != (void*)0) && (szName[0] != (char)0)) /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/ /*cstat !MISRAC2004-17.4_b We need to access every character in the string*/
{
/* Not a null or empty string */
/* This will set the symbol and create an event for it */
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceObjectSetName((TraceObjectHandle_t)xEntryHandle, szName) == TRC_SUCCESS);
}
switch (uxStateCount)
{
case 0:
xTraceEventCreate1(uiEventCode, (TraceUnsignedBaseType_t)pvAddress);
break;
case 1:
xTraceEventCreate2(uiEventCode, (TraceUnsignedBaseType_t)pvAddress, uxStates[0]);
break;
case 2:
xTraceEventCreate3(uiEventCode, (TraceUnsignedBaseType_t)pvAddress, uxStates[0], uxStates[1]);
break;
case 3:
xTraceEventCreate4(uiEventCode, (TraceUnsignedBaseType_t)pvAddress, uxStates[0], uxStates[1], uxStates[2]);
break;
default:
return TRC_FAIL;
break;
}
return TRC_SUCCESS;
}
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceObjectRegister(uint32_t uiEventCode, void* const pvObject, const char* szName, TraceUnsignedBaseType_t uxState, TraceObjectHandle_t *pxObjectHandle)
{
return xTraceObjectRegisterInternal(uiEventCode, pvObject, szName, 1u, &uxState, 0u, pxObjectHandle);
}
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceObjectRegister2(uint32_t uiEventCode, void* const pvObject, const char* szName, TraceUnsignedBaseType_t uxState1, TraceUnsignedBaseType_t uxState2, TraceObjectHandle_t *pxObjectHandle)
{
TraceUnsignedBaseType_t auxStates[2] = { uxState1, uxState2 };
return xTraceObjectRegisterInternal(uiEventCode, pvObject, szName, 2u, auxStates, 0u, pxObjectHandle);
}
traceResult xTraceObjectUnregister(TraceObjectHandle_t xObjectHandle, uint32_t uiEventCode, TraceUnsignedBaseType_t uxState)
{
void* pvObject = (void*)0;
const char *szName = (void*)0; /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
#if (TRC_SEND_NAME_ONLY_ON_DELETE == 1)
uint32_t uiLength;
uint32_t i;
#endif
/* If asserts are disabled this variable will not get used, this stops warnings. */
(void)szName;
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress((TraceEntryHandle_t)xObjectHandle, &pvObject) == TRC_SUCCESS);
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetSymbol((TraceEntryHandle_t)xObjectHandle, &szName) == TRC_SUCCESS);
#if (TRC_SEND_NAME_ONLY_ON_DELETE == 1)
/* Send name event because this is a delete */
for (i = 0u; (szName[i] != (char)0) && (i < 128u); i++) {} /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/ /*cstat !MISRAC2004-17.4_b We need to access every character in the string*/
uiLength = i;
/* Send the name event, if possible */
(void)xTraceEventCreateData1(PSF_EVENT_OBJ_NAME, (TraceUnsignedBaseType_t)pvObject, (TraceUnsignedBaseType_t*)szName, uiLength + 1); /* +1 for termination */
#endif /* (TRC_SEND_NAME_ONLY_ON_DELETE == 1) */
/* Send the delete event, if possible */
(void)xTraceEventCreate2(uiEventCode, (TraceUnsignedBaseType_t)(pvObject), uxState); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 !MISRAC2012-Rule-11.6 Suppress conversion from pointer to integer check*/
return xTraceEntryDelete(xObjectHandle);
}
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceObjectSetName(TraceObjectHandle_t xObjectHandle, const char* szName)
{
void* pvObject = (void*)0;
uint32_t uiLength;
uint32_t i;
/* If asserts are disabled this variable will not get used, this stops warnings. */
(void)pvObject;
if (szName == (void*)0)
{
szName = ""; /*cstat !MISRAC2012-Rule-17.8 Suppress modified function parameter check*/
}
/* This should never fail */
TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetAddress((TraceEntryHandle_t)xObjectHandle, &pvObject) == TRC_SUCCESS);
for (i = 0u; (szName[i] != (char)0) && (i < 128u); i++) {} /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/ /*cstat !MISRAC2004-17.4_b We need to access every character in the string*/
uiLength = i;
#if (TRC_SEND_NAME_ONLY_ON_DELETE == 0)
/* Attempt to send name event now since we don't do it on delete events */
(void)xTraceEventCreateData1(PSF_EVENT_OBJ_NAME, (TraceUnsignedBaseType_t)pvObject, (TraceUnsignedBaseType_t*)szName, uiLength + 1); /* +1 for termination */
#endif /* (TRC_SEND_NAME_ONLY_ON_DELETE == 0) */
return xTraceEntrySetSymbol((TraceEntryHandle_t)xObjectHandle, szName, uiLength);
}
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceObjectRegisterWithoutHandle(uint32_t uiEventCode, void* pvObject, const char* szName, TraceUnsignedBaseType_t uxState)
{
TraceObjectHandle_t xObjectHandle;
return xTraceObjectRegisterInternal(uiEventCode, pvObject, szName, 1u, &uxState, 0u, &xObjectHandle);
}
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceObjectRegisterWithoutHandle2(uint32_t uiEventCode, void* pvObject, const char* szName, TraceUnsignedBaseType_t uxState1, TraceUnsignedBaseType_t uxState2)
{
TraceObjectHandle_t xObjectHandle;
TraceUnsignedBaseType_t auxStates[2] = { uxState1, uxState2 };
return xTraceObjectRegisterInternal(uiEventCode, pvObject, szName, 2u, auxStates, 0u, &xObjectHandle);
}
traceResult xTraceObjectUnregisterWithoutHandle(uint32_t uiEventCode, void* pvObject, TraceUnsignedBaseType_t uxState)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
xResult = xTraceObjectUnregister((TraceObjectHandle_t)xEntryHandle, uiEventCode, uxState);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
/*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
traceResult xTraceObjectSetNameWithoutHandle(void* pvObject, const char* szName)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
/* No previous entry found. Create one. */
if (xTraceEntryCreateWithAddress(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
}
xResult = xTraceObjectSetName((TraceObjectHandle_t)xEntryHandle, szName);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
traceResult xTraceObjectSetSpecificStateWithoutHandle(void* pvObject, uint32_t uiIndex, TraceUnsignedBaseType_t uxState)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
xResult = xTraceObjectSetSpecificState((TraceObjectHandle_t)xEntryHandle, uiIndex, uxState);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
traceResult xTraceObjectSetOptionsWithoutHandle(void* pvObject, uint32_t uiMask)
{
TraceEntryHandle_t xEntryHandle;
traceResult xResult;
TRACE_ALLOC_CRITICAL_SECTION();
TRACE_ENTER_CRITICAL_SECTION();
if (xTraceEntryFind(pvObject, &xEntryHandle) == TRC_FAIL)
{
/* No previous entry found. Create one. */
if (xTraceEntryCreateWithAddress(pvObject, &xEntryHandle) == TRC_FAIL)
{
TRACE_EXIT_CRITICAL_SECTION();
return TRC_FAIL;
}
}
xResult = xTraceObjectSetOptions((TraceObjectHandle_t)xEntryHandle, uiMask);
TRACE_EXIT_CRITICAL_SECTION();
return xResult;
}
#endif