1 /*
2 * Percepio 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 * The implementation for events.
9 */
10
11 #include <trcRecorder.h>
12
13 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
14
15 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
16
17 /*cstat !MISRAC2004-19.4 Suppress macro check*/
18 #define VERIFY_EVENT_SIZE(i) \
19 if ((TraceUnsignedBaseType_t)(i) > (TraceUnsignedBaseType_t)(TRC_MAX_BLOB_SIZE)) \
20 { \
21 (void)xTraceDiagnosticsSetIfHigher(TRC_DIAGNOSTICS_BLOB_MAX_BYTES_TRUNCATED, (TraceBaseType_t)(i) - (TraceBaseType_t)(TRC_MAX_BLOB_SIZE)); \
22 (i) = (uint32_t)(TRC_MAX_BLOB_SIZE); \
23 }
24
25 TraceEventDataTable_t *pxTraceEventDataTable TRC_CFG_RECORDER_DATA_ATTRIBUTE;
26
xTraceEventInitialize(TraceEventDataTable_t * pxBuffer)27 traceResult xTraceEventInitialize(TraceEventDataTable_t* pxBuffer)
28 {
29 TraceCoreEventData_t* pxCoreEventData;
30 uint32_t i, j;
31
32 /* This should never fail */
33 TRC_ASSERT(pxBuffer != (void*)0);
34
35 pxTraceEventDataTable = pxBuffer;
36
37 for (i = 0u; i < (uint32_t)(TRC_CFG_CORE_COUNT); i++)
38 {
39 pxCoreEventData = &pxTraceEventDataTable->coreEventData[i];
40
41 pxCoreEventData->eventCounter = 0u;
42
43 for (j = 0u; j < ((uint32_t)(TRC_CFG_MAX_ISR_NESTING) + 1u); j++)
44 {
45 RESET_EVENT_DATA(&pxCoreEventData->eventData[j]);
46 }
47 }
48
49 xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_EVENT);
50
51 return TRC_SUCCESS;
52 }
53
xTraceEventCreate0(uint32_t uiEventCode)54 traceResult xTraceEventCreate0(uint32_t uiEventCode)
55 {
56 TraceEvent0_t* pxEventData = (void*)0;
57 int32_t iBytesCommitted = 0;
58 TRACE_ALLOC_CRITICAL_SECTION();
59
60 /* We need to check this */
61 if (!xTraceIsRecorderEnabled())
62 {
63 return TRC_FAIL;
64 }
65
66 TRACE_ENTER_CRITICAL_SECTION();
67
68 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
69
70 if (xTraceStreamPortAllocate(sizeof(TraceEvent0_t), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/
71 {
72 TRACE_EXIT_CRITICAL_SECTION();
73 return TRC_FAIL;
74 }
75
76 SET_BASE_EVENT_DATA(pxEventData, uiEventCode, 0, pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
77
78 (void)xTraceStreamPortCommit(pxEventData, sizeof(TraceEvent0_t), &iBytesCommitted);
79
80 TRACE_EXIT_CRITICAL_SECTION();
81
82 /* We need to use iBytesCommitted for the above call but do not use the value,
83 * remove potential warnings */
84 (void)iBytesCommitted;
85
86 return TRC_SUCCESS;
87 }
88
xTraceEventCreate1(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1)89 traceResult xTraceEventCreate1(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1)
90 {
91 TraceEvent1_t* pxEventData = (void*)0;
92 int32_t iBytesCommitted = 0;
93
94 TRACE_ALLOC_CRITICAL_SECTION();
95
96 /* We need to check this */
97 if (!xTraceIsRecorderEnabled())
98 {
99 return TRC_FAIL;
100 }
101
102 TRACE_ENTER_CRITICAL_SECTION();
103
104 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
105
106 if (xTraceStreamPortAllocate(sizeof(TraceEvent1_t), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/
107 {
108 TRACE_EXIT_CRITICAL_SECTION();
109 return TRC_FAIL;
110 }
111
112 SET_BASE_EVENT_DATA(pxEventData, uiEventCode, 1, pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
113
114 pxEventData->uxParams[0] = uxParam1;
115
116 (void)xTraceStreamPortCommit(pxEventData, sizeof(TraceEvent1_t), &iBytesCommitted);
117
118 TRACE_EXIT_CRITICAL_SECTION();
119
120 /* We need to use iBytesCommitted for the above call but do not use the value,
121 * remove potential warnings */
122 (void)iBytesCommitted;
123
124 return TRC_SUCCESS;
125 }
126
xTraceEventCreate2(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2)127 traceResult xTraceEventCreate2(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2)
128 {
129 TraceEvent2_t* pxEventData = (void*)0;
130 int32_t iBytesCommitted = 0;
131
132 TRACE_ALLOC_CRITICAL_SECTION();
133
134 /* We need to check this */
135 if (!xTraceIsRecorderEnabled())
136 {
137 return TRC_FAIL;
138 }
139
140 TRACE_ENTER_CRITICAL_SECTION();
141
142 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
143
144 if (xTraceStreamPortAllocate(sizeof(TraceEvent2_t), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/
145 {
146 TRACE_EXIT_CRITICAL_SECTION();
147 return TRC_FAIL;
148 }
149
150 SET_BASE_EVENT_DATA(pxEventData, uiEventCode, 2, pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
151
152 pxEventData->uxParams[0] = uxParam1;
153 pxEventData->uxParams[1] = uxParam2;
154
155 (void)xTraceStreamPortCommit(pxEventData, sizeof(TraceEvent2_t), &iBytesCommitted);
156
157 TRACE_EXIT_CRITICAL_SECTION();
158
159 /* We need to use iBytesCommitted for the above call but do not use the value,
160 * remove potential warnings */
161 (void)iBytesCommitted;
162
163 return TRC_SUCCESS;
164 }
165
xTraceEventCreate3(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3)166 traceResult xTraceEventCreate3(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2, TraceUnsignedBaseType_t uxParam3)
167 {
168 TraceEvent3_t* pxEventData = (void*)0;
169 int32_t iBytesCommitted = 0;
170
171 TRACE_ALLOC_CRITICAL_SECTION();
172
173 /* We need to check this */
174 if (!xTraceIsRecorderEnabled())
175 {
176 return TRC_FAIL;
177 }
178
179 TRACE_ENTER_CRITICAL_SECTION();
180
181 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
182
183 if (xTraceStreamPortAllocate(sizeof(TraceEvent3_t), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/
184 {
185 TRACE_EXIT_CRITICAL_SECTION();
186 return TRC_FAIL;
187 }
188
189 SET_BASE_EVENT_DATA(pxEventData, uiEventCode, 3, pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
190
191 pxEventData->uxParams[0] = uxParam1;
192 pxEventData->uxParams[1] = uxParam2;
193 pxEventData->uxParams[2] = uxParam3;
194
195 (void)xTraceStreamPortCommit(pxEventData, sizeof(TraceEvent3_t), &iBytesCommitted);
196
197 TRACE_EXIT_CRITICAL_SECTION();
198
199 /* We need to use iBytesCommitted for the above call but do not use the value,
200 * remove potential warnings */
201 (void)iBytesCommitted;
202
203 return TRC_SUCCESS;
204 }
205
xTraceEventCreate4(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4)206 traceResult xTraceEventCreate4(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2, TraceUnsignedBaseType_t uxParam3, TraceUnsignedBaseType_t uxParam4)
207 {
208 TraceEvent4_t* pxEventData = (void*)0;
209 int32_t iBytesCommitted = 0;
210
211 TRACE_ALLOC_CRITICAL_SECTION();
212
213 /* We need to check this */
214 if (!xTraceIsRecorderEnabled())
215 {
216 return TRC_FAIL;
217 }
218
219 TRACE_ENTER_CRITICAL_SECTION();
220
221 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
222
223 if (xTraceStreamPortAllocate(sizeof(TraceEvent4_t), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/
224 {
225 TRACE_EXIT_CRITICAL_SECTION();
226 return TRC_FAIL;
227 }
228
229 SET_BASE_EVENT_DATA(pxEventData, uiEventCode, 4, pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
230
231 pxEventData->uxParams[0] = uxParam1;
232 pxEventData->uxParams[1] = uxParam2;
233 pxEventData->uxParams[2] = uxParam3;
234 pxEventData->uxParams[3] = uxParam4;
235
236 (void)xTraceStreamPortCommit(pxEventData, sizeof(TraceEvent4_t), &iBytesCommitted);
237
238 TRACE_EXIT_CRITICAL_SECTION();
239
240 /* We need to use iBytesCommitted for the above call but do not use the value,
241 * remove potential warnings */
242 (void)iBytesCommitted;
243
244 return TRC_SUCCESS;
245 }
246
xTraceEventCreate5(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4,TraceUnsignedBaseType_t uxParam5)247 traceResult xTraceEventCreate5(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2, TraceUnsignedBaseType_t uxParam3, TraceUnsignedBaseType_t uxParam4, TraceUnsignedBaseType_t uxParam5)
248 {
249 TraceEvent5_t* pxEventData = (void*)0;
250 int32_t iBytesCommitted = 0;
251
252 TRACE_ALLOC_CRITICAL_SECTION();
253
254 /* We need to check this */
255 if (!xTraceIsRecorderEnabled())
256 {
257 return TRC_FAIL;
258 }
259
260 TRACE_ENTER_CRITICAL_SECTION();
261
262 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
263
264 if (xTraceStreamPortAllocate(sizeof(TraceEvent5_t), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/
265 {
266 TRACE_EXIT_CRITICAL_SECTION();
267 return TRC_FAIL;
268 }
269
270 SET_BASE_EVENT_DATA(pxEventData, uiEventCode, 5, pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
271
272 pxEventData->uxParams[0] = uxParam1;
273 pxEventData->uxParams[1] = uxParam2;
274 pxEventData->uxParams[2] = uxParam3;
275 pxEventData->uxParams[3] = uxParam4;
276 pxEventData->uxParams[4] = uxParam5;
277
278 (void)xTraceStreamPortCommit(pxEventData, sizeof(TraceEvent5_t), &iBytesCommitted);
279
280 TRACE_EXIT_CRITICAL_SECTION();
281
282 /* We need to use iBytesCommitted for the above call but do not use the value,
283 * remove potential warnings */
284 (void)iBytesCommitted;
285
286 return TRC_SUCCESS;
287 }
288
xTraceEventCreate6(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4,TraceUnsignedBaseType_t uxParam5,TraceUnsignedBaseType_t uxParam6)289 traceResult xTraceEventCreate6(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2, TraceUnsignedBaseType_t uxParam3, TraceUnsignedBaseType_t uxParam4, TraceUnsignedBaseType_t uxParam5, TraceUnsignedBaseType_t uxParam6)
290 {
291 TraceEvent6_t* pxEventData = (void*)0;
292 int32_t iBytesCommitted = 0;
293
294 TRACE_ALLOC_CRITICAL_SECTION();
295
296 /* We need to check this */
297 if (!xTraceIsRecorderEnabled())
298 {
299 return TRC_FAIL;
300 }
301
302 TRACE_ENTER_CRITICAL_SECTION();
303
304 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
305
306 if (xTraceStreamPortAllocate(sizeof(TraceEvent6_t), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/
307 {
308 TRACE_EXIT_CRITICAL_SECTION();
309 return TRC_FAIL;
310 }
311
312 SET_BASE_EVENT_DATA(pxEventData, uiEventCode, 6, pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
313
314 pxEventData->uxParams[0] = uxParam1;
315 pxEventData->uxParams[1] = uxParam2;
316 pxEventData->uxParams[2] = uxParam3;
317 pxEventData->uxParams[3] = uxParam4;
318 pxEventData->uxParams[4] = uxParam5;
319 pxEventData->uxParams[5] = uxParam6;
320
321 (void)xTraceStreamPortCommit(pxEventData, sizeof(TraceEvent6_t), &iBytesCommitted);
322
323 TRACE_EXIT_CRITICAL_SECTION();
324
325 /* We need to use iBytesCommitted for the above call but do not use the value,
326 * remove potential warnings */
327 (void)iBytesCommitted;
328
329 return TRC_SUCCESS;
330 }
331
xTraceEventBeginRawOffline(uint32_t uiSize,TraceEventHandle_t * pxEventHandle)332 traceResult xTraceEventBeginRawOffline(uint32_t uiSize, TraceEventHandle_t* pxEventHandle)
333 {
334 int32_t ISR_nesting = 0;
335 TraceEventData_t* pxEventData;
336 TraceCoreEventData_t* pxCoreEventData;
337
338 TRACE_ALLOC_CRITICAL_SECTION();
339
340 /* We need to check this */
341 if (xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT) == 0U)
342 {
343 return TRC_FAIL;
344 }
345
346 /* This should never fail */
347 TRC_ASSERT(pxEventHandle != (void*)0);
348
349 TRACE_ENTER_CRITICAL_SECTION();
350
351 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
352
353 pxCoreEventData = &pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()];
354
355 /* We backup the local variable to the CORE specific variable */
356 pxCoreEventData->TRACE_ALLOC_CRITICAL_SECTION_NAME = TRACE_ALLOC_CRITICAL_SECTION_NAME;
357
358 (void)xTraceISRGetCurrentNesting(&ISR_nesting);
359
360 /* We add 1 since xTraceISRGetCurrentNesting(...) returns -1 if no ISR is active */
361 pxEventData = &pxCoreEventData->eventData[ISR_nesting + 1];
362
363 /* This should never fail */
364 TRC_ASSERT_CUSTOM_ON_FAIL(pxEventData->pvBlob == 0, TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
365
366 VERIFY_EVENT_SIZE(uiSize); /*cstat !MISRAC2012-Rule-17.8 Suppress modified function parameter check*/
367
368 pxEventData->size = ((uiSize + (sizeof(TraceUnsignedBaseType_t) - 1u)) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t); /* BaseType align */
369
370 pxEventData->offset = 0u;
371
372 /* This can fail and we should handle it */
373 if (xTraceStreamPortAllocate(pxEventData->size, &pxEventData->pvBlob) == TRC_FAIL)
374 {
375 TRACE_EXIT_CRITICAL_SECTION();
376 return TRC_FAIL;
377 }
378
379 *pxEventHandle = (TraceEventHandle_t)pxEventData;
380
381 return TRC_SUCCESS;
382 }
383
xTraceEventBeginRawOfflineBlocking(uint32_t uiSize,TraceEventHandle_t * pxEventHandle)384 traceResult xTraceEventBeginRawOfflineBlocking(uint32_t uiSize, TraceEventHandle_t* pxEventHandle)
385 {
386 TraceEventData_t* pxEventData;
387 TraceCoreEventData_t* pxCoreEventData;
388 int32_t ISR_nesting = 0;
389 uint32_t uiAttempts = 0u;
390
391 TRACE_ALLOC_CRITICAL_SECTION();
392
393 /* We need to check this */
394 if (xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT) == 0U)
395 {
396 return TRC_FAIL;
397 }
398
399 /* This should never fail */
400 TRC_ASSERT(pxEventHandle != (void*)0);
401
402 TRACE_ENTER_CRITICAL_SECTION();
403
404 pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
405
406 pxCoreEventData = &pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()];
407
408 /* We backup the local variable to the CORE specific variable */
409 pxCoreEventData->TRACE_ALLOC_CRITICAL_SECTION_NAME = TRACE_ALLOC_CRITICAL_SECTION_NAME;
410
411 (void)xTraceGetCurrentISRNesting(&ISR_nesting);
412
413 /* We add 1 since xTraceISRGetCurrentNesting(...) returns -1 if no ISR is active */
414 pxEventData = &pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventData[ISR_nesting + 1];
415
416 /* This should never fail */
417 TRC_ASSERT_CUSTOM_ON_FAIL(pxEventData->pvBlob == 0, TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
418
419 VERIFY_EVENT_SIZE(uiSize); /*cstat !MISRAC2012-Rule-17.8 Suppress modified function parameter check*/
420
421 pxEventData->size = ((uiSize + (sizeof(TraceUnsignedBaseType_t) - 1u)) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t); /* BaseType align */
422
423 pxEventData->offset = 0u;
424
425 /* This can fail and we should handle it */
426 while (xTraceStreamPortAllocate(pxEventData->size, &pxEventData->pvBlob) != TRC_SUCCESS)
427 {
428 uiAttempts++;
429 }
430
431 *pxEventHandle = (TraceEventHandle_t)pxEventData;
432
433 return TRC_SUCCESS;
434 }
435
xTraceEventEndOffline(TraceEventHandle_t xEventHandle)436 traceResult xTraceEventEndOffline(TraceEventHandle_t xEventHandle)
437 {
438 TraceEventData_t* pxEventData = (TraceEventData_t*)xEventHandle;
439 const TraceCoreEventData_t* pxCoreEventData;
440 int32_t iBytesCommitted = 0;
441
442 TRACE_ALLOC_CRITICAL_SECTION()
443
444 pxCoreEventData = &pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()];
445
446 /* We restore the CORE specific variable to the local variable before any EXIT */
447 TRACE_ALLOC_CRITICAL_SECTION_NAME = pxCoreEventData->TRACE_ALLOC_CRITICAL_SECTION_NAME;
448
449 /* This should never fail */
450 TRC_ASSERT_CUSTOM_ON_FAIL(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT), TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
451
452 /* This should never fail */
453 TRC_ASSERT_CUSTOM_ON_FAIL(pxEventData != (void*)0, TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
454
455 /* This should never fail */
456 TRC_ASSERT_CUSTOM_ON_FAIL(pxEventData->pvBlob != (void*)0, TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
457
458 (void)xTraceStreamPortCommit(pxEventData->pvBlob, pxEventData->size, &iBytesCommitted);
459
460 /* We need to use iBytesCommitted for the above call but do not use the value,
461 * remove potential warnings */
462 (void)iBytesCommitted;
463
464 RESET_EVENT_DATA(pxEventData);
465
466 TRACE_EXIT_CRITICAL_SECTION();
467
468 return TRC_SUCCESS;
469 }
470
xTraceEventEndOfflineBlocking(TraceEventHandle_t xEventHandle)471 traceResult xTraceEventEndOfflineBlocking(TraceEventHandle_t xEventHandle)
472 {
473 TraceEventData_t* pxEventData = (TraceEventData_t*)xEventHandle;
474 const TraceCoreEventData_t* pxCoreEventData;
475 int32_t iBytesCommitted;
476 uint32_t uiByteOffset = 0u;
477 uint8_t *pubBlob;
478
479 TRACE_ALLOC_CRITICAL_SECTION()
480
481 pxCoreEventData = &pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()];
482
483 /* We restore the CORE specific variable to the local variable before any EXIT */
484 TRACE_ALLOC_CRITICAL_SECTION_NAME = pxCoreEventData->TRACE_ALLOC_CRITICAL_SECTION_NAME;
485
486 /* This should never fail */
487 TRC_ASSERT_CUSTOM_ON_FAIL(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT), TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
488
489 /* This should never fail */
490 TRC_ASSERT_CUSTOM_ON_FAIL(pxEventData != (void*)0, TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
491
492 /* This should never fail */
493 TRC_ASSERT_CUSTOM_ON_FAIL(pxEventData->pvBlob != (void*)0, TRACE_EXIT_CRITICAL_SECTION(); return TRC_FAIL; );
494
495 pubBlob = (uint8_t*)pxEventData->pvBlob; /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
496
497 while (pxEventData->size > uiByteOffset)
498 {
499 iBytesCommitted = 0;
500 (void)xTraceStreamPortCommit((void*)&pubBlob[uiByteOffset], pxEventData->size - uiByteOffset, &iBytesCommitted); /*cstat !MISRAC2004-17.4_b We need to access a specific part of the buffer*/
501
502 uiByteOffset += (uint32_t)iBytesCommitted;
503 }
504
505 RESET_EVENT_DATA(pxEventData);
506
507 TRACE_EXIT_CRITICAL_SECTION();
508
509 return TRC_SUCCESS;
510 }
511
xTraceEventAddData(TraceEventHandle_t xEventHandle,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)512 traceResult xTraceEventAddData(TraceEventHandle_t xEventHandle, const TraceUnsignedBaseType_t* const puxData, TraceUnsignedBaseType_t uxSize)
513 {
514 TraceUnsignedBaseType_t i;
515
516 /* This should never fail */
517 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
518
519 /* This should never fail */
520 TRC_ASSERT(xEventHandle != 0);
521
522 /* This should never fail */
523 TRC_ASSERT(puxData != (void*)0);
524
525 /* This should never fail */
526 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset + (uint32_t)(uxSize * sizeof(TraceUnsignedBaseType_t))) <= ((TraceEventData_t*)xEventHandle)->size);
527
528 for (i = 0u; i < uxSize; i++)
529 {
530 TRC_EVENT_ADD_UNSIGNED_BASE_TYPE(xEventHandle, puxData[i]); /*cstat !MISRAC2004-17.4_b We need to access a specific part of the buffer*/
531 }
532
533 return TRC_SUCCESS;
534 }
535
536 #if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
537
xTraceEventGetSize(const void * const pvAddress,uint32_t * puiSize)538 traceResult xTraceEventGetSize(const void* const pvAddress, uint32_t* puiSize)
539 {
540 /* This should never fail */
541 TRC_ASSERT(pvAddress != (void*)0);
542
543 /* This should never fail */
544 TRC_ASSERT(puiSize != (void*)0);
545
546 /* This should never fail */
547 TRC_ASSERT((sizeof(TraceEvent0_t) + ((uint32_t)(uint16_t)(TRC_EVENT_GET_PARAM_COUNT(((const TraceEvent0_t*)pvAddress)->EventID)) * sizeof(uint32_t))) <= (uint32_t)(TRC_MAX_BLOB_SIZE)); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
548
549 return TRC_EVENT_GET_SIZE(pvAddress, puiSize);
550 }
551
xTraceEventGetRawData(TraceEventHandle_t xEventHandle,uint32_t uiOffset,uint32_t uiSize,void ** ppvData)552 traceResult xTraceEventGetRawData(TraceEventHandle_t xEventHandle, uint32_t uiOffset, uint32_t uiSize, void** ppvData)
553 {
554 /* This should never fail */
555 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
556
557 /* This should never fail */
558 TRC_ASSERT(xEventHandle != 0);
559
560 /* This should never fail */
561 TRC_ASSERT(ppvData != (void*)0);
562
563 /* This should never fail */
564 TRC_ASSERT((uiOffset + uiSize) <= ((TraceEventData_t*)xEventHandle)->size);
565
566 return TRC_EVENT_GET_RAW_DATA(xEventHandle, uiOffset, uiSize, ppvData);
567 }
568
xTraceEventGetPayload(const TraceEventHandle_t xEventHandle,uint32_t uiOffset,uint32_t uiSize,void ** ppvData)569 traceResult xTraceEventGetPayload(const TraceEventHandle_t xEventHandle, uint32_t uiOffset, uint32_t uiSize, void** ppvData)
570 {
571 /* This should never fail */
572 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
573
574 /* This should never fail */
575 TRC_ASSERT(xEventHandle != 0);
576
577 /* This should never fail */
578 TRC_ASSERT(ppvData != (void*)0);
579
580 /* This should never fail */
581 TRC_ASSERT((uiOffset + uiSize) <= ((const TraceEventData_t*)xEventHandle)->size);
582
583 return TRC_EVENT_GET_PAYLOAD(xEventHandle, uiOffset, uiSize, ppvData);
584 }
585
xTraceEventPayloadRemaining(const TraceEventHandle_t xEventHandle,uint32_t * puiValue)586 traceResult xTraceEventPayloadRemaining(const TraceEventHandle_t xEventHandle, uint32_t* puiValue)
587 {
588 /* This should never fail */
589 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
590
591 /* This should never fail */
592 TRC_ASSERT(xEventHandle != 0);
593
594 /* This should never fail */
595 TRC_ASSERT(puiValue != (void*)0);
596
597 /* This should never fail */
598 TRC_ASSERT(((const TraceEventData_t*)xEventHandle)->pvBlob != (void*)0);
599
600 return TRC_EVENT_PAYLOAD_REMAINING(xEventHandle, puiValue);
601 }
602
xTraceEventPayloadUsed(const TraceEventHandle_t xEventHandle,uint32_t * puiValue)603 traceResult xTraceEventPayloadUsed(const TraceEventHandle_t xEventHandle, uint32_t* puiValue)
604 {
605 /* This should never fail */
606 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
607
608 /* This should never fail */
609 TRC_ASSERT(xEventHandle != 0);
610
611 /* This should never fail */
612 TRC_ASSERT(puiValue != (void*)0);
613
614 /* This should never fail */
615 TRC_ASSERT(((const TraceEventData_t*)xEventHandle)->pvBlob != (void*)0);
616
617 return TRC_EVENT_PAYLOAD_USED(xEventHandle, puiValue);
618 }
619
xTraceEventPayloadSize(const TraceEventHandle_t xEventHandle,uint32_t * puiValue)620 traceResult xTraceEventPayloadSize(const TraceEventHandle_t xEventHandle, uint32_t* puiValue)
621 {
622 /* This should never fail */
623 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
624
625 /* This should never fail */
626 TRC_ASSERT(xEventHandle != 0);
627
628 /* This should never fail */
629 TRC_ASSERT(puiValue != (void*)0);
630
631 /* This should never fail */
632 TRC_ASSERT(((const TraceEventData_t*)xEventHandle)->pvBlob != (void*)0);
633
634 return TRC_EVENT_PAYLOAD_SIZE(xEventHandle, puiValue);
635 }
636
xTraceEventAddPointer(TraceEventHandle_t xEventHandle,void * pvAddress)637 traceResult xTraceEventAddPointer(TraceEventHandle_t xEventHandle, void* pvAddress)
638 {
639 /* This should never fail */
640 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
641
642 /* This should never fail */
643 TRC_ASSERT(xEventHandle != 0);
644
645 /* This should never fail */
646 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset + sizeof(void*)) <= ((TraceEventData_t*)xEventHandle)->size);
647
648 /* Make sure we are writing at void* aligned offset */
649 /* This should never fail */
650 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset & (sizeof(void*) - 1u)) == 0u);
651
652 return TRC_EVENT_ADD_POINTER(xEventHandle, pvAddress);
653 }
654
xTraceEventAddUnsignedBaseType(TraceEventHandle_t xEventHandle,TraceUnsignedBaseType_t uxValue)655 traceResult xTraceEventAddUnsignedBaseType(TraceEventHandle_t xEventHandle, TraceUnsignedBaseType_t uxValue)
656 {
657 /* This should never fail */
658 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
659
660 /* This should never fail */
661 TRC_ASSERT(xEventHandle != 0);
662
663 /* This should never fail */
664 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset + sizeof(TraceUnsignedBaseType_t)) <= ((TraceEventData_t*)xEventHandle)->size);
665
666 /* Make sure we are writing at TraceUnsignedBaseType_t aligned offset */
667 /* This should never fail */
668 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset & (sizeof(TraceUnsignedBaseType_t) - 1u)) == 0u);
669
670 return TRC_EVENT_ADD_UNSIGNED_BASE_TYPE(xEventHandle, uxValue);
671 }
672
xTraceEventAdd32(TraceEventHandle_t xEventHandle,uint32_t value)673 traceResult xTraceEventAdd32(TraceEventHandle_t xEventHandle, uint32_t value)
674 {
675 /* This should never fail */
676 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
677
678 /* This should never fail */
679 TRC_ASSERT(xEventHandle != 0);
680
681 /* This should never fail */
682 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset + sizeof(uint32_t)) <= ((TraceEventData_t*)xEventHandle)->size);
683
684 /* Make sure we are writing at 32-bit aligned offset */
685 /* This should never fail */
686 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset & 3u) == 0u);
687
688 return TRC_EVENT_ADD_32(xEventHandle, value);
689 }
690
xTraceEventAdd16(TraceEventHandle_t xEventHandle,uint16_t value)691 traceResult xTraceEventAdd16(TraceEventHandle_t xEventHandle, uint16_t value)
692 {
693 /* This should never fail */
694 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
695
696 /* This should never fail */
697 TRC_ASSERT(xEventHandle != 0);
698
699 /* This should never fail */
700 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset + sizeof(uint16_t)) <= ((TraceEventData_t*)xEventHandle)->size);
701
702 /* Make sure we are writing at 16-bit aligned offset */
703 /* This should never fail */
704 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset & 1u) == 0u);
705
706 return TRC_EVENT_ADD_16(xEventHandle, value);
707 }
708
xTraceEventAdd8(TraceEventHandle_t xEventHandle,uint8_t value)709 traceResult xTraceEventAdd8(TraceEventHandle_t xEventHandle, uint8_t value)
710 {
711 /* This should never fail */
712 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EVENT));
713
714 /* This should never fail */
715 TRC_ASSERT(xEventHandle != 0);
716
717 /* This should never fail */
718 TRC_ASSERT((((TraceEventData_t*)xEventHandle)->offset + sizeof(uint8_t)) <= ((TraceEventData_t*)xEventHandle)->size);
719
720 return TRC_EVENT_ADD_8(xEventHandle, value);
721 }
722
723 #endif /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
724
725 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
726
727 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
728