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 strings.
9 */
10 
11 #include <trcRecorder.h>
12 
13 #if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
14 
15 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceStringRegister(const char * szString,TraceStringHandle_t * pString)16 traceResult xTraceStringRegister(const char* szString, TraceStringHandle_t *pString)
17 {
18 	TraceEntryHandle_t xEntryHandle;
19 	int32_t i;
20 	uint32_t uiLength = 0u;
21 
22 	/* This should never fail */
23 	TRC_ASSERT(szString != (void*)0);
24 
25 	/* This should never fail */
26 	TRC_ASSERT(pString != (void*)0);
27 
28 	/* We need to check this */
29 	if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
30 	{
31 		return TRC_FAIL;
32 	}
33 
34 	for (i = 0; (szString[i] != (char)0) && (i < (int32_t)(TRC_ENTRY_TABLE_SLOT_SYMBOL_SIZE)); 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*/
35 
36 	uiLength = (uint32_t)i;
37 
38 	/* The address to the available symbol table slot is the address we use */
39 	/* This should never fail */
40 	TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetSymbol(xEntryHandle, szString, uiLength) == TRC_SUCCESS);
41 
42 	*pString = (TraceStringHandle_t)xEntryHandle;
43 
44 	return xTraceEventCreateData1(PSF_EVENT_OBJ_NAME, (TraceUnsignedBaseType_t)xEntryHandle, (TraceUnsignedBaseType_t*)szString, uiLength + 1);
45 }
46 
47 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceRegisterString(const char * name)48 TraceStringHandle_t xTraceRegisterString(const char *name)
49 {
50 	TraceStringHandle_t trcStr = 0;
51 	(void)xTraceStringRegister(name, &trcStr);
52 
53 	return trcStr;
54 }
55 
56 #endif
57