1 /*
2 * 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 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 #define TRC_EXTENSION_BASE_EVENT_ID (TRC_EVENT_LAST_ID + 1UL)
17
18 #define TRC_EXTENSION_COMBINE_VERSION(_major, _minor, _patch) \
19 ( \
20 ((0x000000FFUL & (TraceUnsignedBaseType_t)(_major)) << 24) | \
21 ((0x000000FFUL & (TraceUnsignedBaseType_t)(_minor)) << 16) | \
22 ((0x0000FFFFUL & (TraceUnsignedBaseType_t)(_patch)) << 0) \
23 )
24
25 static TraceExtensionData_t *pxExtensionData TRC_CFG_RECORDER_DATA_ATTRIBUTE;
26
xTraceExtensionInitialize(TraceExtensionData_t * const pxBuffer)27 traceResult xTraceExtensionInitialize(TraceExtensionData_t* const pxBuffer)
28 {
29 /* This should never fail */
30 TRC_ASSERT(pxBuffer != (void*)0);
31
32 pxExtensionData = pxBuffer;
33
34 pxExtensionData->uxNextFreeExtensionEventId = TRC_EXTENSION_BASE_EVENT_ID;
35
36 xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_EXTENSION);
37
38 return TRC_SUCCESS;
39 }
40
41 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceExtensionCreate(const char * szName,uint8_t uiMajor,uint8_t uiMinor,uint16_t uiPatch,uint32_t uiEventCount,TraceExtensionHandle_t * pxExtensionHandle)42 traceResult xTraceExtensionCreate(const char* szName, uint8_t uiMajor, uint8_t uiMinor, uint16_t uiPatch, uint32_t uiEventCount, TraceExtensionHandle_t* pxExtensionHandle)
43 {
44 TraceObjectHandle_t xObjectHandle;
45 TraceUnsignedBaseType_t uxStates[3];
46
47 /* This should never fail */
48 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EXTENSION));
49
50 /* This should never fail */
51 TRC_ASSERT(uiEventCount != 0u);
52
53 /* This should never fail */
54 TRC_ASSERT(pxExtensionHandle != (void*)0);
55
56 /* This should never fail */
57 TRC_ASSERT(pxExtensionHandle != (void*)0);
58
59 /* This should never fail */
60 TRC_ASSERT(szName != (void*)0);
61
62 /* This should never fail */
63 TRC_ASSERT(szName[0] != (char)0); /*cstat !MISRAC2004-17.4_b We need to check the first characted*/ /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
64
65 uxStates[TRC_EXTENSION_STATE_INDEX_VERSION] = TRC_EXTENSION_COMBINE_VERSION(uiMajor, uiMinor, uiPatch);
66 uxStates[TRC_EXTENSION_STATE_INDEX_BASE_EVENT_ID] = pxExtensionData->uxNextFreeExtensionEventId;
67 uxStates[TRC_EXTENSION_STATE_INDEX_EVENT_COUNT] = uiEventCount;
68
69 /* We need to check this */
70 if (xTraceObjectRegisterInternal(PSF_EVENT_EXTENSION_CREATE, (void*)0, szName, 3u, uxStates, TRC_ENTRY_OPTION_EXTENSION, &xObjectHandle) == TRC_FAIL)
71 {
72 return TRC_FAIL;
73 }
74
75 pxExtensionData->uxNextFreeExtensionEventId += uiEventCount;
76
77 *pxExtensionHandle = (TraceExtensionHandle_t)xObjectHandle;
78
79 return TRC_SUCCESS;
80 }
81
xTraceExtensionGetBaseEventId(TraceExtensionHandle_t xExtensionHandle,uint32_t * puiBaseEventId)82 traceResult xTraceExtensionGetBaseEventId(TraceExtensionHandle_t xExtensionHandle, uint32_t *puiBaseEventId)
83 {
84 TraceUnsignedBaseType_t uxBaseEventId;
85
86 /* This should never fail */
87 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EXTENSION));
88
89 /* This should never fail */
90 TRC_ASSERT(puiBaseEventId != (void*)0);
91
92 /* This should never fail */
93 TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntryGetState((TraceEntryHandle_t)xExtensionHandle, TRC_EXTENSION_STATE_INDEX_BASE_EVENT_ID, &uxBaseEventId) == TRC_SUCCESS);
94
95 *puiBaseEventId = (uint32_t)uxBaseEventId;
96
97 return TRC_SUCCESS;
98 }
99
100 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceExtensionGetConfigName(TraceExtensionHandle_t xExtensionHandle,const char ** pszName)101 traceResult xTraceExtensionGetConfigName(TraceExtensionHandle_t xExtensionHandle, const char **pszName)
102 {
103 /* This should never fail */
104 TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_EXTENSION));
105
106 return xTraceEntryGetSymbol((TraceEntryHandle_t)xExtensionHandle, pszName);
107 }
108
109 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
110
111 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
112