summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcString.c
blob: 6182d20afa156c357935fa14d53af8090702da20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Percepio Trace Recorder for Tracealyzer v4.6.0
* Copyright 2021 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The implementation for strings.
*/

#include <trcRecorder.h>

#if (TRC_USE_TRACEALYZER_RECORDER == 1)

#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)

traceResult xTraceStringRegister(const char* szString, TraceStringHandle_t *pString)
{
	TraceEntryHandle_t xEntryHandle;
	TraceEventHandle_t xEventHandle = 0;
	uint32_t i = 0, uiLength = 0, uiValue = 0;

	/* This should never fail */
	TRC_ASSERT(szString != 0);
	
	/* This should never fail */
	TRC_ASSERT(pString != 0);

	/* We need to check this */
	if (xTraceEntryCreate(&xEntryHandle) == TRC_FAIL)
	{
		return TRC_FAIL;
	}

	/* The address to the available symbol table slot is the address we use */
	/* This should never fail */
	TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetSymbol(xEntryHandle, szString) == TRC_SUCCESS);

	*pString = (TraceStringHandle_t)xEntryHandle;

	for (i = 0; (szString[i] != 0) && (i < (TRC_ENTRY_TABLE_SLOT_SYMBOL_SIZE)); i++) {}

	uiLength = i;

	/* We need to check this */
	if (xTraceEventBegin(PSF_EVENT_OBJ_NAME, sizeof(void*) + uiLength, &xEventHandle) == TRC_SUCCESS)
	{
		xTraceEventAddPointer(xEventHandle, (void*)xEntryHandle);
		xTraceEventAddData(xEventHandle, (void*)szString, uiLength);

		/* Check if we can truncate */
		xTraceEventPayloadRemaining(xEventHandle, &uiValue);
		if (uiValue > 0)
		{
			xTraceEventAdd8(xEventHandle, 0);
		}
		
		xTraceEventEnd(xEventHandle);
	}

	return TRC_SUCCESS;
}

TraceStringHandle_t xTraceRegisterString(const char *name)
{
	TraceStringHandle_t trcStr = 0;
	xTraceStringRegister(name, &trcStr);

	return trcStr;
}

#endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */

#endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */