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 state machines.
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 #define TRC_STATE_MACHINE_STATE_INDEX 0u
18 #define TRC_STATE_MACHINE_INDEX 0u
19
20 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceStateMachineCreate(const char * szName,TraceStateMachineHandle_t * pxStateMachineHandle)21 traceResult xTraceStateMachineCreate(const char *szName, TraceStateMachineHandle_t *pxStateMachineHandle)
22 {
23 TraceObjectHandle_t xObjectHandle;
24
25 /* This should never fail */
26 TRC_ASSERT(pxStateMachineHandle != (void*)0);
27
28 /* We need to check this */
29 if (xTraceObjectRegister(PSF_EVENT_STATEMACHINE_CREATE , (void*)0, szName, 0u, &xObjectHandle) == TRC_FAIL)
30 {
31 return TRC_FAIL;
32 }
33
34 /* This should never fail */
35 TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions((TraceEntryHandle_t)xObjectHandle, (uint32_t)TRC_ENTRY_OPTION_STATE_MACHINE) == TRC_SUCCESS);
36
37 *pxStateMachineHandle = (TraceStateMachineHandle_t)xObjectHandle;
38
39 return TRC_SUCCESS;
40 }
41
42 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceStateMachineStateCreate(TraceStateMachineHandle_t xStateMachineHandle,const char * szName,TraceStateMachineStateHandle_t * pxStateHandle)43 traceResult xTraceStateMachineStateCreate(TraceStateMachineHandle_t xStateMachineHandle, const char* szName, TraceStateMachineStateHandle_t* pxStateHandle)
44 {
45 TraceObjectHandle_t xObjectHandle;
46
47 /* This should never fail */
48 TRC_ASSERT(xStateMachineHandle != 0);
49
50 /* This should never fail */
51 TRC_ASSERT(pxStateHandle != (void*)0);
52
53 /* We need to check this */
54 if (xTraceObjectRegister(PSF_EVENT_STATEMACHINE_STATE_CREATE, (void*)0, szName, (TraceUnsignedBaseType_t)xStateMachineHandle, &xObjectHandle) == TRC_FAIL) /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
55 {
56 return TRC_FAIL;
57 }
58
59 /* This should never fail */
60 TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions((TraceEntryHandle_t)xObjectHandle, (uint32_t)TRC_ENTRY_OPTION_STATE_MACHINE_STATE) == TRC_SUCCESS);
61
62 *pxStateHandle = (TraceStateMachineHandle_t)xObjectHandle;
63
64 return TRC_SUCCESS;
65 }
66
xTraceStateMachineSetState(TraceStateMachineHandle_t xStateMachineHandle,TraceStateMachineStateHandle_t xStateHandle)67 traceResult xTraceStateMachineSetState(TraceStateMachineHandle_t xStateMachineHandle, TraceStateMachineStateHandle_t xStateHandle)
68 {
69 /* This should never fail */
70 TRC_ASSERT(xStateMachineHandle != 0);
71
72 /* This should never fail */
73 TRC_ASSERT(xStateHandle != 0);
74
75 /* Verify that this state machine state was meant to be used with this state machine */
76 /* This should never fail */
77 TRC_ASSERT(xStateMachineHandle == (TraceStateMachineHandle_t)xTraceEntryGetStateReturn((TraceEntryHandle_t)xStateHandle, TRC_STATE_MACHINE_INDEX));
78
79 /* This should never fail */
80 TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetState((TraceEntryHandle_t)xStateMachineHandle, TRC_STATE_MACHINE_STATE_INDEX, (TraceUnsignedBaseType_t)xStateHandle) == TRC_SUCCESS); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
81
82 (void)xTraceEventCreate2(PSF_EVENT_STATEMACHINE_STATECHANGE, (TraceUnsignedBaseType_t)xStateMachineHandle, (TraceUnsignedBaseType_t)xStateHandle); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
83
84 return TRC_SUCCESS;
85 }
86
87 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
88
89 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
90