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 strings.
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-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceStringRegister(const char * szString,TraceStringHandle_t * pString)18 traceResult xTraceStringRegister(const char* szString, TraceStringHandle_t *pString)
19 {
20 TraceEntryHandle_t xEntryHandle;
21 TraceEventHandle_t xEventHandle = 0;
22 int32_t i;
23 uint32_t uiLength, uiValue = 0u;
24
25 /* This should never fail */
26 TRC_ASSERT(szString != (void*)0);
27
28 /* This should never fail */
29 TRC_ASSERT(pString != (void*)0);
30
31 /* We need to check this */
32 if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
33 {
34 return TRC_FAIL;
35 }
36
37 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*/
38
39 uiLength = (uint32_t)i;
40
41 /* The address to the available symbol table slot is the address we use */
42 /* This should never fail */
43 TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetSymbol(xEntryHandle, szString, uiLength) == TRC_SUCCESS);
44
45 *pString = (TraceStringHandle_t)xEntryHandle;
46
47 /* We need to check this */
48 if (xTraceEventBegin(PSF_EVENT_OBJ_NAME, sizeof(void*) + uiLength, &xEventHandle) == TRC_SUCCESS)
49 {
50 (void)xTraceEventAddPointer(xEventHandle, (void*)xEntryHandle);
51 (void)xTraceEventAddString(xEventHandle, szString, uiLength);
52
53 /* Check if we can truncate */
54 (void)xTraceEventPayloadRemaining(xEventHandle, &uiValue);
55 if (uiValue > 0u)
56 {
57 (void)xTraceEventAdd8(xEventHandle, 0u);
58 }
59
60 (void)xTraceEventEnd(xEventHandle); /*cstat !MISRAC2012-Rule-17.7 Suppress ignored return value check (inside macro)*/
61 }
62
63 return TRC_SUCCESS;
64 }
65
66 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceRegisterString(const char * name)67 TraceStringHandle_t xTraceRegisterString(const char *name)
68 {
69 TraceStringHandle_t trcStr = 0;
70 (void)xTraceStringRegister(name, &trcStr);
71
72 return trcStr;
73 }
74
75 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
76
77 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
78