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