1 /*
2 * Percepio 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 * The implementation for events.
9 */
10 
11 #include <trcRecorder.h>
12 
13 #if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
14 
15 #include <string.h>
16 
17 /**
18  * @internal Macro helper for setting trace event parameter count.
19  */
20 #define TRC_EVENT_SET_PARAM_COUNT(id, n) ((uint16_t)(((uint16_t)(id)) | ((((uint16_t)(n)) & 0xF) << 12)))
21 
22 /**
23  * @internal Macro helper for getting trace event parameter count.
24  */
25 #define TRC_EVENT_GET_PARAM_COUNT(id) (((id) >> 12u) & 0xFU)
26 
27 #if (TRC_CFG_CORE_COUNT > 1)
28 #define TRC_EVENT_SET_EVENT_COUNT(c)  ((uint16_t)(((TRC_CFG_GET_CURRENT_CORE() & 0xF) << 12) | ((uint16_t)(c) & 0xFFF)))
29 #else
30 #define TRC_EVENT_SET_EVENT_COUNT(c) ((uint16_t)(c))
31 #endif
32 
33 /**
34  * @internal Macro optimization for getting trace event size.
35  */
36 #define TRC_EVENT_GET_SIZE(pvAddress, puiSize) (*(uint32_t*)(puiSize) = sizeof(TraceEvent0_t) + (TRC_EVENT_GET_PARAM_COUNT(((TraceEvent0_t*)(pvAddress))->EventID)) * sizeof(TraceBaseType_t), TRC_SUCCESS)
37 
38 /**
39  * @internal Macro helper for setting base event data.
40  */
41 #define SET_BASE_EVENT_DATA(pxEvent, eventId, paramCount, eventCount) \
42 	( \
43 		(pxEvent)->EventID = TRC_EVENT_SET_PARAM_COUNT(eventId, paramCount), \
44 		(pxEvent)->EventCount = TRC_EVENT_SET_EVENT_COUNT(eventCount), \
45 		xTraceTimestampGet(&(pxEvent)->TS) \
46 	)
47 
48 #define TRACE_EVENT_BEGIN_OFFLINE(size) 														\
49 	TRACE_ENTER_CRITICAL_SECTION();              										\
50 	pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++; 	\
51 	if (xTraceStreamPortAllocate((uint32_t)(size), (void**)&pxEventData) == TRC_FAIL) /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress pointer checks*/ \
52 	{                                            										\
53 		TRACE_EXIT_CRITICAL_SECTION();              									\
54 		return TRC_FAIL; 																\
55 	} 																					\
56 	SET_BASE_EVENT_DATA(pxEventData, uiEventCode, ((size) - sizeof(TraceEvent0_t)) / sizeof(TraceUnsignedBaseType_t), pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter); /*cstat !MISRAC2012-Rule-11.5 Suppress pointer checks*/
57 
58 #define TRACE_EVENT_BEGIN(size) 														\
59 	/* We need to check this */                  										\
60 	if (!xTraceIsRecorderEnabled())              										\
61 	{ 																					\
62 		return TRC_FAIL;                            									\
63 	} 																					\
64 	TRACE_EVENT_BEGIN_OFFLINE(size)
65 
66 
67 #define TRACE_EVENT_END(size) 															\
68 	(void)xTraceStreamPortCommit(pxEventData, (uint32_t)(size), &iBytesCommitted); 					\
69 	TRACE_EXIT_CRITICAL_SECTION(); 														\
70 	/* We need to use iBytesCommitted for the above call but do not use the value, 		\
71 	 * remove potential warnings */ 													\
72 	(void)iBytesCommitted;
73 
74 #define TRACE_EVENT_ADD_1(__p1)									\
75 	pxEventData->uxParams[0] = __p1;
76 
77 #define TRACE_EVENT_ADD_2(__p1, __p2)							\
78 	TRACE_EVENT_ADD_1(__p1)										\
79 	pxEventData->uxParams[1] = __p2;
80 
81 #define TRACE_EVENT_ADD_3(__p1, __p2, __p3)						\
82 	TRACE_EVENT_ADD_2(__p1, __p2)								\
83 	pxEventData->uxParams[2] = __p3;
84 
85 #define TRACE_EVENT_ADD_4(__p1, __p2, __p3, __p4)				\
86 	TRACE_EVENT_ADD_3(__p1, __p2, __p3)							\
87 	pxEventData->uxParams[3] = __p4;
88 
89 #define TRACE_EVENT_ADD_5(__p1, __p2, __p3, __p4, __p5)			\
90 	TRACE_EVENT_ADD_4(__p1, __p2, __p3, __p4)					\
91 	pxEventData->uxParams[4] = __p5;
92 
93 #define TRACE_EVENT_ADD_6(__p1, __p2, __p3, __p4, __p5, __p6)	\
94 	TRACE_EVENT_ADD_5(__p1, __p2, __p3, __p4, __p5)				\
95 	pxEventData->uxParams[5] = __p6;
96 
97 #define TRACE_EVENT_ADD_0_DATA(__pvData, __uxSize) 											\
98 	memcpy(&((uint8_t*)pxEventData)[sizeof(TraceEvent0_t)], __pvData, __uxSize);
99 
100 #define TRACE_EVENT_ADD_1_DATA(__p1, __pvData, __uxSize)									\
101 	TRACE_EVENT_ADD_1(__p1)																	\
102 	memcpy(&((uint8_t*)pxEventData)[sizeof(TraceEvent1_t)], __pvData, __uxSize);
103 
104 #define TRACE_EVENT_ADD_2_DATA(__p1, __p2, __pvData, __uxSize)								\
105 	TRACE_EVENT_ADD_2(__p1, __p2)															\
106 	memcpy(&((uint8_t*)pxEventData)[sizeof(TraceEvent2_t)], __pvData, __uxSize);
107 
108 #define TRACE_EVENT_ADD_3_DATA(__p1, __p2, __p3, __pvData, __uxSize)						\
109 	TRACE_EVENT_ADD_3(__p1, __p2, __p3)														\
110 	memcpy(&((uint8_t*)pxEventData)[sizeof(TraceEvent3_t)], __pvData, __uxSize);
111 
112 #define TRACE_EVENT_ADD_4_DATA(__p1, __p2, __p3, __p4, __pvData, __uxSize)					\
113 	TRACE_EVENT_ADD_4(__p1, __p2, __p3, __p4)												\
114 	memcpy(&((uint8_t*)pxEventData)[sizeof(TraceEvent4_t)], __pvData, __uxSize);
115 
116 #define TRACE_EVENT_ADD_5_DATA(__p1, __p2, __p3, __p4, __p5, __pvData, __uxSize)			\
117 	TRACE_EVENT_ADD_5(__p1, __p2, __p3, __p4, __p5)											\
118 	memcpy(&((uint8_t*)pxEventData)[sizeof(TraceEvent5_t)], __pvData, __uxSize);
119 
120 #define TRACE_EVENT_ADD_6_DATA(__p1, __p2, __p3, __p4, __p5, __p6, __pvData, __uxSize)		\
121 	TRACE_EVENT_ADD_6(__p1, __p2, __p3, __p4, __p5, __p6)									\
122 	memcpy(&((uint8_t*)pxEventData)[sizeof(TraceEvent6_t)], __pvData, __uxSize);
123 
124 TraceEventDataTable_t *pxTraceEventDataTable TRC_CFG_RECORDER_DATA_ATTRIBUTE;
125 
xTraceEventInitialize(TraceEventDataTable_t * pxBuffer)126 traceResult xTraceEventInitialize(TraceEventDataTable_t* pxBuffer)
127 {
128 	uint32_t i;
129 
130 	/* This should never fail */
131 	TRC_ASSERT(pxBuffer != (void*)0);
132 
133 	pxTraceEventDataTable = pxBuffer;
134 
135 	for (i = 0u; i < (uint32_t)(TRC_CFG_CORE_COUNT); i++)
136 	{
137 		pxTraceEventDataTable->coreEventData[i].eventCounter = 0u;
138 	}
139 
140 	xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_EVENT);
141 
142 	return TRC_SUCCESS;
143 }
144 
xTraceEventCreate0(uint32_t uiEventCode)145 traceResult xTraceEventCreate0(uint32_t uiEventCode)
146 {
147 	TraceEvent0_t* pxEventData = (void*)0;
148 	int32_t iBytesCommitted = 0;
149 
150 	TRACE_ALLOC_CRITICAL_SECTION();
151 
152 	TRACE_EVENT_BEGIN(sizeof(TraceEvent0_t));
153 	TRACE_EVENT_END(sizeof(TraceEvent0_t));
154 
155 	return TRC_SUCCESS;
156 }
157 
xTraceEventCreate1(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1)158 traceResult xTraceEventCreate1(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1)
159 {
160 	TraceEvent1_t* pxEventData = (void*)0;
161 	int32_t iBytesCommitted = 0;
162 
163 	TRACE_ALLOC_CRITICAL_SECTION();
164 
165 	TRACE_EVENT_BEGIN(sizeof(TraceEvent1_t));
166 
167 	TRACE_EVENT_ADD_1(uxParam1);
168 
169 	TRACE_EVENT_END(sizeof(TraceEvent1_t));
170 
171 	return TRC_SUCCESS;
172 }
173 
xTraceEventCreate2(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2)174 traceResult xTraceEventCreate2(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2)
175 {
176 	TraceEvent2_t* pxEventData = (void*)0;
177 	int32_t iBytesCommitted = 0;
178 
179 	TRACE_ALLOC_CRITICAL_SECTION();
180 
181 	TRACE_EVENT_BEGIN(sizeof(TraceEvent2_t));
182 
183 	TRACE_EVENT_ADD_2(uxParam1, uxParam2);
184 
185 	TRACE_EVENT_END(sizeof(TraceEvent2_t));
186 
187 	return TRC_SUCCESS;
188 }
189 
xTraceEventCreate3(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3)190 traceResult xTraceEventCreate3(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2, TraceUnsignedBaseType_t uxParam3)
191 {
192 	TraceEvent3_t* pxEventData = (void*)0;
193 	int32_t iBytesCommitted = 0;
194 
195 	TRACE_ALLOC_CRITICAL_SECTION();
196 
197 	TRACE_EVENT_BEGIN(sizeof(TraceEvent3_t));
198 
199 	TRACE_EVENT_ADD_3(uxParam1, uxParam2, uxParam3);
200 
201 	TRACE_EVENT_END(sizeof(TraceEvent3_t));
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 	TRACE_EVENT_BEGIN(sizeof(TraceEvent4_t));
214 
215 	TRACE_EVENT_ADD_4(uxParam1, uxParam2, uxParam3, uxParam4);
216 
217 	TRACE_EVENT_END(sizeof(TraceEvent4_t));
218 
219 	return TRC_SUCCESS;
220 }
221 
xTraceEventCreate5(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4,TraceUnsignedBaseType_t uxParam5)222 traceResult xTraceEventCreate5(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2, TraceUnsignedBaseType_t uxParam3, TraceUnsignedBaseType_t uxParam4, TraceUnsignedBaseType_t uxParam5)
223 {
224 	TraceEvent5_t* pxEventData = (void*)0;
225 	int32_t iBytesCommitted = 0;
226 
227 	TRACE_ALLOC_CRITICAL_SECTION();
228 
229 	TRACE_EVENT_BEGIN(sizeof(TraceEvent5_t));
230 
231 	TRACE_EVENT_ADD_5(uxParam1, uxParam2, uxParam3, uxParam4, uxParam5);
232 
233 	TRACE_EVENT_END(sizeof(TraceEvent5_t));
234 
235 	return TRC_SUCCESS;
236 }
237 
xTraceEventCreate6(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4,TraceUnsignedBaseType_t uxParam5,TraceUnsignedBaseType_t uxParam6)238 traceResult xTraceEventCreate6(uint32_t uiEventCode, TraceUnsignedBaseType_t uxParam1, TraceUnsignedBaseType_t uxParam2, TraceUnsignedBaseType_t uxParam3, TraceUnsignedBaseType_t uxParam4, TraceUnsignedBaseType_t uxParam5, TraceUnsignedBaseType_t uxParam6)
239 {
240 	TraceEvent6_t* pxEventData = (void*)0;
241 	int32_t iBytesCommitted = 0;
242 
243 	TRACE_ALLOC_CRITICAL_SECTION();
244 
245 	TRACE_EVENT_BEGIN(sizeof(TraceEvent6_t));
246 
247 	TRACE_EVENT_ADD_6(uxParam1, uxParam2, uxParam3, uxParam4, uxParam5, uxParam6);
248 
249 	TRACE_EVENT_END(sizeof(TraceEvent6_t));
250 
251 	return TRC_SUCCESS;
252 }
253 
xTraceEventCreateRawBlocking(const void * pxSource,uint32_t ulSize)254 traceResult xTraceEventCreateRawBlocking(const void* pxSource, uint32_t ulSize)
255 {
256 	int32_t iBytesCommitted = 0;
257 	void* pxBuffer = (void*)0;
258 
259 	TRACE_ALLOC_CRITICAL_SECTION();
260 
261 	ulSize = TRC_ALIGN_CEIL(ulSize, sizeof(TraceUnsignedBaseType_t));
262 
263 	TRACE_ENTER_CRITICAL_SECTION();
264 
265 	pxTraceEventDataTable->coreEventData[TRC_CFG_GET_CURRENT_CORE()].eventCounter++;
266 	while (xTraceStreamPortAllocate(ulSize, (void**)&pxBuffer) == TRC_FAIL) {}
267 
268 	memcpy(pxBuffer, pxSource, ulSize);
269 	while (xTraceStreamPortCommit(pxBuffer, ulSize, &iBytesCommitted) == TRC_FAIL) {}
270 	(void)iBytesCommitted;
271 
272 	TRACE_EXIT_CRITICAL_SECTION();
273 
274 	return TRC_SUCCESS;
275 }
276 
xTraceEventCreateDataOffline0(uint32_t uiEventCode,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)277 traceResult xTraceEventCreateDataOffline0(uint32_t uiEventCode, const TraceUnsignedBaseType_t* const puxData, TraceUnsignedBaseType_t uxSize)
278 {
279 	TraceEvent0_t* pxEventData = (void*)0;
280 	int32_t iBytesCommitted = 0;
281 
282 	TRACE_ALLOC_CRITICAL_SECTION();
283 
284 	/* Align payload size and truncate in case it is too big */
285 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
286 	if (sizeof(TraceEvent0_t) + uxSize > TRC_MAX_BLOB_SIZE)
287 	{
288 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent0_t);
289 	}
290 
291 	TRACE_EVENT_BEGIN_OFFLINE(sizeof(TraceEvent0_t) + uxSize);
292 
293 	TRACE_EVENT_ADD_0_DATA(puxData, uxSize);
294 
295 	TRACE_EVENT_END(sizeof(TraceEvent0_t) + uxSize);
296 
297 	return TRC_SUCCESS;
298 }
299 
xTraceEventCreateData0(uint32_t uiEventCode,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)300 traceResult xTraceEventCreateData0(uint32_t uiEventCode, const TraceUnsignedBaseType_t* const puxData, TraceUnsignedBaseType_t uxSize)
301 {
302 	TraceEvent0_t* pxEventData = (void*)0;
303 	int32_t iBytesCommitted = 0;
304 
305 	TRACE_ALLOC_CRITICAL_SECTION();
306 
307 	/* Align payload size and truncate in case it is too big */
308 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
309 	if (sizeof(TraceEvent0_t) + uxSize > TRC_MAX_BLOB_SIZE)
310 	{
311 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent0_t);
312 	}
313 
314 	TRACE_EVENT_BEGIN(sizeof(TraceEvent0_t) + uxSize);
315 
316 	TRACE_EVENT_ADD_0_DATA(puxData, uxSize);
317 
318 	TRACE_EVENT_END(sizeof(TraceEvent0_t) + uxSize);
319 
320 	return TRC_SUCCESS;
321 }
322 
xTraceEventCreateData1(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)323 traceResult xTraceEventCreateData1(
324 	uint32_t uiEventCode,
325 	TraceUnsignedBaseType_t uxParam1,
326 	const TraceUnsignedBaseType_t* const puxData,
327 	TraceUnsignedBaseType_t uxSize
328 )
329 {
330 	TraceEvent1_t* pxEventData = (void*)0;
331 	int32_t iBytesCommitted = 0;
332 
333 	TRACE_ALLOC_CRITICAL_SECTION();
334 
335 	/* Align payload size and truncate in case it is too big */
336 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
337 	if (sizeof(TraceEvent1_t) + uxSize > TRC_MAX_BLOB_SIZE)
338 	{
339 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent1_t);
340 	}
341 
342 	TRACE_EVENT_BEGIN(sizeof(TraceEvent1_t) + uxSize);
343 
344 	TRACE_EVENT_ADD_1_DATA(uxParam1, puxData, uxSize);
345 
346 	TRACE_EVENT_END(sizeof(TraceEvent1_t) + uxSize);
347 
348 	return TRC_SUCCESS;
349 }
350 
xTraceEventCreateData2(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)351 traceResult xTraceEventCreateData2(
352 	uint32_t uiEventCode,
353 	TraceUnsignedBaseType_t uxParam1,
354 	TraceUnsignedBaseType_t uxParam2,
355 	const TraceUnsignedBaseType_t* const puxData,
356 	TraceUnsignedBaseType_t uxSize
357 )
358 {
359 	TraceEvent2_t* pxEventData = (void*)0;
360 	int32_t iBytesCommitted = 0;
361 
362 	TRACE_ALLOC_CRITICAL_SECTION();
363 
364 	/* Align payload size and truncate in case it is too big */
365 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
366 	if (sizeof(TraceEvent2_t) + uxSize > TRC_MAX_BLOB_SIZE)
367 	{
368 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent2_t);
369 	}
370 
371 	TRACE_EVENT_BEGIN(sizeof(TraceEvent2_t) + uxSize);
372 
373 	TRACE_EVENT_ADD_2_DATA(uxParam1, uxParam2, puxData, uxSize);
374 
375 	TRACE_EVENT_END(sizeof(TraceEvent2_t) + uxSize);
376 
377 	return TRC_SUCCESS;
378 }
379 
xTraceEventCreateData3(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)380 traceResult xTraceEventCreateData3(
381 	uint32_t uiEventCode,
382 	TraceUnsignedBaseType_t uxParam1,
383 	TraceUnsignedBaseType_t uxParam2,
384 	TraceUnsignedBaseType_t uxParam3,
385 	const TraceUnsignedBaseType_t* const puxData,
386 	TraceUnsignedBaseType_t uxSize
387 )
388 {
389 	TraceEvent3_t* pxEventData = (void*)0;
390 	int32_t iBytesCommitted = 0;
391 
392 	TRACE_ALLOC_CRITICAL_SECTION();
393 
394 	/* Align payload size and truncate in case it is too big */
395 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
396 	if (sizeof(TraceEvent3_t) + uxSize > TRC_MAX_BLOB_SIZE)
397 	{
398 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent3_t);
399 	}
400 
401 	TRACE_EVENT_BEGIN(sizeof(TraceEvent3_t) + uxSize);
402 
403 	TRACE_EVENT_ADD_3_DATA(uxParam1, uxParam2, uxParam3, puxData, uxSize);
404 
405 	TRACE_EVENT_END(sizeof(TraceEvent3_t) + uxSize);
406 
407 	return TRC_SUCCESS;
408 }
409 
xTraceEventCreateData4(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)410 traceResult xTraceEventCreateData4(
411 	uint32_t uiEventCode,
412 	TraceUnsignedBaseType_t uxParam1,
413 	TraceUnsignedBaseType_t uxParam2,
414 	TraceUnsignedBaseType_t uxParam3,
415 	TraceUnsignedBaseType_t uxParam4,
416 	const TraceUnsignedBaseType_t* const puxData,
417 	TraceUnsignedBaseType_t uxSize
418 )
419 {
420 	TraceEvent4_t* pxEventData = (void*)0;
421 	int32_t iBytesCommitted = 0;
422 
423 	TRACE_ALLOC_CRITICAL_SECTION();
424 
425 	/* Align payload size and truncate in case it is too big */
426 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
427 	if (sizeof(TraceEvent4_t) + uxSize > TRC_MAX_BLOB_SIZE)
428 	{
429 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent4_t);
430 	}
431 
432 	TRACE_EVENT_BEGIN(sizeof(TraceEvent4_t) + uxSize);
433 
434 	TRACE_EVENT_ADD_4_DATA(uxParam1, uxParam2, uxParam3, uxParam4, puxData, uxSize);
435 
436 	TRACE_EVENT_END(sizeof(TraceEvent4_t) + uxSize);
437 
438 	return TRC_SUCCESS;
439 }
440 
xTraceEventCreateData5(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4,TraceUnsignedBaseType_t uxParam5,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)441 traceResult xTraceEventCreateData5(
442 	uint32_t uiEventCode,
443 	TraceUnsignedBaseType_t uxParam1,
444 	TraceUnsignedBaseType_t uxParam2,
445 	TraceUnsignedBaseType_t uxParam3,
446 	TraceUnsignedBaseType_t uxParam4,
447 	TraceUnsignedBaseType_t uxParam5,
448 	const TraceUnsignedBaseType_t* const puxData,
449 	TraceUnsignedBaseType_t uxSize
450 )
451 {
452 	TraceEvent5_t* pxEventData = (void*)0;
453 	int32_t iBytesCommitted = 0;
454 
455 	TRACE_ALLOC_CRITICAL_SECTION();
456 
457 	/* Align payload size and truncate in case it is too big */
458 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
459 	if (sizeof(TraceEvent5_t) + uxSize > TRC_MAX_BLOB_SIZE)
460 	{
461 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent5_t);
462 	}
463 
464 	TRACE_EVENT_BEGIN(sizeof(TraceEvent5_t) + uxSize);
465 
466 	TRACE_EVENT_ADD_5_DATA(uxParam1, uxParam2, uxParam3, uxParam4, uxParam5, puxData, uxSize);
467 
468 	TRACE_EVENT_END(sizeof(TraceEvent5_t) + uxSize);
469 
470 	return TRC_SUCCESS;
471 }
472 
xTraceEventCreateData6(uint32_t uiEventCode,TraceUnsignedBaseType_t uxParam1,TraceUnsignedBaseType_t uxParam2,TraceUnsignedBaseType_t uxParam3,TraceUnsignedBaseType_t uxParam4,TraceUnsignedBaseType_t uxParam5,TraceUnsignedBaseType_t uxParam6,const TraceUnsignedBaseType_t * const puxData,TraceUnsignedBaseType_t uxSize)473 traceResult xTraceEventCreateData6(
474 	uint32_t uiEventCode,
475 	TraceUnsignedBaseType_t uxParam1,
476 	TraceUnsignedBaseType_t uxParam2,
477 	TraceUnsignedBaseType_t uxParam3,
478 	TraceUnsignedBaseType_t uxParam4,
479 	TraceUnsignedBaseType_t uxParam5,
480 	TraceUnsignedBaseType_t uxParam6,
481 	const TraceUnsignedBaseType_t* const puxData,
482 	TraceUnsignedBaseType_t uxSize
483 )
484 {
485 	TraceEvent6_t* pxEventData = (void*)0;
486 	int32_t iBytesCommitted = 0;
487 
488 	TRACE_ALLOC_CRITICAL_SECTION();
489 
490 	/* Align payload size and truncate in case it is too big */
491 	uxSize = TRC_ALIGN_CEIL(uxSize, sizeof(TraceUnsignedBaseType_t));
492 	if (sizeof(TraceEvent6_t) + uxSize > TRC_MAX_BLOB_SIZE)
493 	{
494 		uxSize = TRC_MAX_BLOB_SIZE - sizeof(TraceEvent6_t);
495 	}
496 
497 	TRACE_EVENT_BEGIN(sizeof(TraceEvent6_t) + uxSize);
498 
499 	TRACE_EVENT_ADD_6_DATA(uxParam1, uxParam2, uxParam3, uxParam4, uxParam5, uxParam6, puxData, uxSize);
500 
501 	TRACE_EVENT_END(sizeof(TraceEvent6_t) + uxSize);
502 
503 	return TRC_SUCCESS;
504 }
505 
xTraceEventGetSize(const void * const pvAddress,uint32_t * puiSize)506 traceResult xTraceEventGetSize(const void* const pvAddress, uint32_t* puiSize)
507 {
508 	/* This should never fail */
509 	TRC_ASSERT(pvAddress != (void*)0);
510 
511 	/* This should never fail */
512 	TRC_ASSERT(puiSize != (void*)0);
513 
514 	/* This should never fail */
515 	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*/
516 
517 	return TRC_EVENT_GET_SIZE(pvAddress, puiSize);
518 }
519 
520 #endif
521