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 intervals.
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 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceIntervalChannelSetCreate(const char * szName,TraceIntervalChannelSetHandle_t * pxIntervalChannelSetHandle)18 traceResult xTraceIntervalChannelSetCreate(const char* szName, TraceIntervalChannelSetHandle_t* pxIntervalChannelSetHandle)
19 {
20 	TraceObjectHandle_t xObjectHandle;
21 
22 	/* This should never fail */
23 	TRC_ASSERT(pxIntervalChannelSetHandle != (void*)0);
24 
25 	/* We need to check this */
26 	if (xTraceObjectRegister(PSF_EVENT_INTERVAL_CHANNEL_SET_CREATE, (void*)0, szName, 0u, &xObjectHandle) == TRC_FAIL)
27 	{
28 		return TRC_FAIL;
29 	}
30 
31 	/* This should never fail */
32 	TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions((TraceEntryHandle_t)xObjectHandle, TRC_ENTRY_OPTION_INTERVAL_CHANNEL_SET) == TRC_SUCCESS);
33 
34 	*pxIntervalChannelSetHandle = (TraceIntervalChannelSetHandle_t)xObjectHandle;
35 
36 	return TRC_SUCCESS;
37 }
38 
39 /*cstat !MISRAC2004-6.3 !MISRAC2012-Dir-4.6_a Suppress basic char type usage*/
xTraceIntervalChannelCreate(const char * szName,TraceIntervalChannelSetHandle_t xIntervalChannelSetHandle,TraceIntervalChannelHandle_t * pxIntervalChannelHandle)40 traceResult xTraceIntervalChannelCreate(const char *szName, TraceIntervalChannelSetHandle_t xIntervalChannelSetHandle, TraceIntervalChannelHandle_t *pxIntervalChannelHandle)
41 {
42 	TraceObjectHandle_t xObjectHandle;
43 
44 	/* This should never fail */
45 	TRC_ASSERT(pxIntervalChannelHandle != (void*)0);
46 
47 	/* This should never fail */
48 	TRC_ASSERT(xIntervalChannelSetHandle != 0);
49 
50 	/* We need to check this */
51 	if (xTraceObjectRegister(PSF_EVENT_INTERVAL_CHANNEL_CREATE, (void*)0, szName, (TraceUnsignedBaseType_t)xIntervalChannelSetHandle, &xObjectHandle) == TRC_FAIL) /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
52 	{
53 		return TRC_FAIL;
54 	}
55 
56 	/* This should never fail */
57 	TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions((TraceEntryHandle_t)xObjectHandle, TRC_ENTRY_OPTION_INTERVAL_CHANNEL) == TRC_SUCCESS);
58 
59 	*pxIntervalChannelHandle = (TraceIntervalChannelHandle_t)xObjectHandle;
60 
61 	return TRC_SUCCESS;
62 }
63 
xTraceIntervalStart(TraceIntervalChannelHandle_t xIntervalChannelHandle,TraceUnsignedBaseType_t uxValue,TraceIntervalInstanceHandle_t * pxIntervalInstanceHandle)64 traceResult xTraceIntervalStart(TraceIntervalChannelHandle_t xIntervalChannelHandle, TraceUnsignedBaseType_t uxValue, TraceIntervalInstanceHandle_t *pxIntervalInstanceHandle)
65 {
66 	TRC_ASSERT(xIntervalChannelHandle != 0);
67 
68 	TRC_ASSERT(pxIntervalInstanceHandle != (void*)0);
69 
70 	/* We null all of it first in case it's 64-bit and we only write 32-bit */
71 	*pxIntervalInstanceHandle = 0;
72 
73 	TRC_ASSERT_ALWAYS_EVALUATE(xTraceTimestampGet((uint32_t*)pxIntervalInstanceHandle) == TRC_SUCCESS); /*cstat !MISRAC2004-11.4 !MISRAC2012-Rule-11.3 Suppress conversion between pointer types checks*/
74 
75 	(void)xTraceEventCreate3(PSF_EVENT_INTERVAL_START, (TraceUnsignedBaseType_t)xIntervalChannelHandle, (TraceUnsignedBaseType_t)*pxIntervalInstanceHandle, uxValue); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
76 
77 	return TRC_SUCCESS;
78 }
79 
xTraceIntervalStop(TraceIntervalChannelHandle_t xIntervalChannelHandle,TraceIntervalInstanceHandle_t xIntervalInstanceHandle)80 traceResult xTraceIntervalStop(TraceIntervalChannelHandle_t xIntervalChannelHandle, TraceIntervalInstanceHandle_t xIntervalInstanceHandle)
81 {
82 	TRC_ASSERT(xIntervalChannelHandle != 0);
83 
84 	(void)xTraceEventCreate2(PSF_EVENT_INTERVAL_STOP, (TraceUnsignedBaseType_t)xIntervalChannelHandle, (TraceUnsignedBaseType_t)xIntervalInstanceHandle); /*cstat !MISRAC2004-11.3 !MISRAC2012-Rule-11.4 Suppress conversion from pointer to integer check*/
85 
86 	return TRC_SUCCESS;
87 }
88 
89 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
90 
91 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
92