1 /*
2 * Trace Recorder for Tracealyzer v4.6.6
3 * Copyright 2021 Percepio AB
4 * www.percepio.com
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * The implementation of extensions.
9 */
10 #include <trcRecorder.h>
11 
12 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
13 
14 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
15 
16 #include <stdio.h>
17 
18 #define TRC_EXTENSION_BASE_EVENT_ID (TRC_EVENT_LAST_ID + 1)
19 uint32_t uiTraceNextFreeExtensionEventId = TRC_EXTENSION_BASE_EVENT_ID;
20 
21 #define TRC_EXTENSION_COMBINE_VERSION(_major, _minor, _patch) \
22 		( \
23 			((0x000000FF & (_major)) << 24) | \
24 			((0x000000FF & (_minor)) << 16) | \
25 			((0x0000FFFF & (_patch)) << 0) \
26 		)
27 
28 /* TODO: INITIALIZE */
29 
xTraceExtensionCreate(const char * szName,uint8_t uiMajor,uint8_t uiMinor,uint16_t uiPatch,uint32_t uiEventCount,TraceExtensionHandle_t * pxExtensionHandle)30 traceResult xTraceExtensionCreate(const char* szName, uint8_t uiMajor, uint8_t uiMinor, uint16_t uiPatch, uint32_t uiEventCount, TraceExtensionHandle_t* pxExtensionHandle)
31 {
32 	TraceObjectHandle_t xObjectHandle;
33 	TraceUnsignedBaseType_t uxStates[3];
34 
35 	/* This should never fail */
36 	TRC_ASSERT(uiEventCount != 0);
37 
38 	/* This should never fail */
39 	TRC_ASSERT(pxExtensionHandle != 0);
40 
41 	uxStates[TRC_EXTENSION_STATE_INDEX_VERSION] = TRC_EXTENSION_COMBINE_VERSION(uiMajor, uiMinor, uiPatch);
42 	uxStates[TRC_EXTENSION_STATE_INDEX_BASE_EVENT_ID] = uiTraceNextFreeExtensionEventId;
43 	uxStates[TRC_EXTENSION_STATE_INDEX_EVENT_COUNT] = uiEventCount;
44 
45 	/* We need to check this */
46 	if (xTraceObjectRegisterInternal(PSF_EVENT_EXTENSION_CREATE, 0, szName, 3, uxStates, TRC_ENTRY_OPTION_EXTENSION, &xObjectHandle) == TRC_FAIL)
47 	{
48 		return TRC_FAIL;
49 	}
50 
51 	uiTraceNextFreeExtensionEventId += uiEventCount;
52 
53 	*pxExtensionHandle = (TraceExtensionHandle_t)xObjectHandle;
54 
55 	return TRC_SUCCESS;
56 }
57 
xTraceExtensionGetBaseEventId(TraceExtensionHandle_t xExtensionHandle,uint32_t * puiBaseEventId)58 traceResult xTraceExtensionGetBaseEventId(TraceExtensionHandle_t xExtensionHandle, uint32_t *puiBaseEventId)
59 {
60 	TraceUnsignedBaseType_t uxBaseEventId;
61 
62 	/* This should never fail */
63 	TRC_ASSERT(puiBaseEventId != 0);
64 
65 	/* This should never fail */
66 	TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetState((TraceEntryHandle_t)xExtensionHandle, TRC_EXTENSION_STATE_INDEX_BASE_EVENT_ID, &uxBaseEventId) == TRC_SUCCESS);
67 
68 	*puiBaseEventId = (uint32_t)uxBaseEventId;
69 
70 	return TRC_SUCCESS;
71 }
72 
xTraceExtensionGetConfigName(TraceExtensionHandle_t xExtensionHandle,const char ** pszName)73 traceResult xTraceExtensionGetConfigName(TraceExtensionHandle_t xExtensionHandle, const char **pszName)
74 {
75 	return xTraceEntryGetSymbol((TraceEntryHandle_t)xExtensionHandle, pszName);
76 }
77 
78 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
79 
80 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
81