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 #define TRC_RUNNABLE_STATE_INDEX_OWNER_TASK 0UL
16 
17 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceRunnableRegister(const char * szName,TraceRunnableRegisterMethod_t uxRegisterMethod,TraceRunnableHandle_t * pxRunnableHandle)18 traceResult xTraceRunnableRegister(const char* szName, TraceRunnableRegisterMethod_t uxRegisterMethod, TraceRunnableHandle_t *pxRunnableHandle)
19 {
20 	TraceEntryHandle_t xEntryHandle;
21 	int32_t i;
22 	uint32_t uiLength = 0u;
23 
24 	/* This should never fail */
25 	TRC_ASSERT(szName != (void*)0);
26 
27 	/* This should never fail */
28 	TRC_ASSERT(pxRunnableHandle != (void*)0);
29 
30 	for (i = 0; (szName[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*/
31 
32 	uiLength = (uint32_t)i;
33 
34 	if (uxRegisterMethod == TRC_RUNNABLE_REGISTER_METHOD_USE_ENTRY_TABLE)
35 	{
36 		/* Check if we have already created an entry previously */
37 		if (*pxRunnableHandle == (void*)0)
38 		{
39 			/* We need to check this */
40 			if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
41 			{
42 				return TRC_FAIL;
43 			}
44 
45 			TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions(xEntryHandle, TRC_ENTRY_OPTION_RUNNABLE) == TRC_SUCCESS);
46 
47 			TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetState(xEntryHandle, TRC_RUNNABLE_STATE_INDEX_OWNER_TASK, (TraceUnsignedBaseType_t)xTraceTaskGetCurrentReturn()) == TRC_SUCCESS); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 !MISRAC2012-Rule-11.6 We need the address of the task*/
48 
49 			/* The address to the available symbol table slot is the address we use */
50 			/* This should never fail */
51 			TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetSymbol(xEntryHandle, szName, uiLength) == TRC_SUCCESS);
52 
53 			*pxRunnableHandle = (TraceRunnableHandle_t)xEntryHandle;
54 		}
55 	}
56 	else if (uxRegisterMethod == TRC_RUNNABLE_REGISTER_METHOD_USE_STRING_ADDRESS)
57 	{
58 		*pxRunnableHandle = (TraceRunnableHandle_t)szName; /*cstat !MISRAC2004-11.5 !MISRAC2012-Rule-11.8 We need the address of the string*/
59 	}
60 	else if (uxRegisterMethod == TRC_RUNNABLE_REGISTER_METHOD_USE_HANDLE_ADDRESS)
61 	{
62 		/* The handle address should be a unique value that we can use as handle */
63 		*pxRunnableHandle = (TraceRunnableHandle_t)pxRunnableHandle;
64 	}
65 	else
66 	{
67 		return TRC_FAIL;
68 	}
69 
70 	return xTraceEventCreateData1(PSF_EVENT_RUNNABLE_REGISTER, (TraceUnsignedBaseType_t)*pxRunnableHandle, (TraceUnsignedBaseType_t*)szName, uiLength + 1);
71 }
72 
73 #endif
74