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 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
xTraceIntervalChannelSetCreate(const char * szName,TraceIntervalChannelSetHandle_t * pxIntervalChannelSetHandle)17 traceResult xTraceIntervalChannelSetCreate(const char* szName, TraceIntervalChannelSetHandle_t* pxIntervalChannelSetHandle)
18 {
19 TraceObjectHandle_t xObjectHandle;
20
21 /* This should never fail */
22 TRC_ASSERT(pxIntervalChannelSetHandle != 0);
23
24 /* We need to check this */
25 if (xTraceObjectRegister(PSF_EVENT_INTERVAL_CHANNEL_SET_CREATE, 0, szName, 0, &xObjectHandle) == TRC_FAIL)
26 {
27 return TRC_FAIL;
28 }
29
30 /* This should never fail */
31 TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions((TraceEntryHandle_t)xObjectHandle, TRC_ENTRY_OPTION_INTERVAL_CHANNEL_SET) == TRC_SUCCESS);
32
33 *pxIntervalChannelSetHandle = (TraceIntervalChannelSetHandle_t)xObjectHandle;
34
35 return TRC_SUCCESS;
36 }
37
xTraceIntervalChannelCreate(const char * szName,TraceIntervalChannelSetHandle_t xIntervalChannelSetHandle,TraceIntervalChannelHandle_t * pxIntervalChannelHandle)38 traceResult xTraceIntervalChannelCreate(const char *szName, TraceIntervalChannelSetHandle_t xIntervalChannelSetHandle, TraceIntervalChannelHandle_t *pxIntervalChannelHandle)
39 {
40 TraceObjectHandle_t xObjectHandle;
41
42 /* This should never fail */
43 TRC_ASSERT(pxIntervalChannelHandle != 0);
44
45 /* This should never fail */
46 TRC_ASSERT(xIntervalChannelSetHandle != 0);
47
48 /* We need to check this */
49 if (xTraceObjectRegister(PSF_EVENT_INTERVAL_CHANNEL_CREATE, 0, szName, xIntervalChannelSetHandle, &xObjectHandle) == TRC_FAIL)
50 {
51 return TRC_FAIL;
52 }
53
54 /* This should never fail */
55 TRC_ASSERT_ALWAYS_EVALUATE(xTraceEntrySetOptions((TraceEntryHandle_t)xObjectHandle, TRC_ENTRY_OPTION_INTERVAL_CHANNEL) == TRC_SUCCESS);
56
57 *pxIntervalChannelHandle = (TraceIntervalChannelHandle_t)xObjectHandle;
58
59 return TRC_SUCCESS;
60 }
61
xTraceIntervalStart(TraceIntervalChannelHandle_t xIntervalChannelHandle,TraceUnsignedBaseType_t uxValue,TraceIntervalInstanceHandle_t * pxIntervalInstanceHandle)62 traceResult xTraceIntervalStart(TraceIntervalChannelHandle_t xIntervalChannelHandle, TraceUnsignedBaseType_t uxValue, TraceIntervalInstanceHandle_t *pxIntervalInstanceHandle)
63 {
64 TraceEventHandle_t xEventHandle = 0;
65
66 TRC_ASSERT(xIntervalChannelHandle != 0);
67
68 TRC_ASSERT_ALWAYS_EVALUATE(xTraceTimestampGet((uint32_t*)pxIntervalInstanceHandle) == TRC_SUCCESS);
69
70 /* We need to check this */
71 if (xTraceEventBegin(PSF_EVENT_INTERVAL_START, sizeof(void*) + sizeof(TraceUnsignedBaseType_t) + sizeof(TraceUnsignedBaseType_t), &xEventHandle) == TRC_SUCCESS)
72 {
73 xTraceEventAddPointer(xEventHandle, (void*)xIntervalChannelHandle);
74 xTraceEventAddUnsignedBaseType(xEventHandle, (TraceUnsignedBaseType_t)*pxIntervalInstanceHandle);
75 xTraceEventAddUnsignedBaseType(xEventHandle, uxValue);
76 xTraceEventEnd(xEventHandle);
77 }
78
79 return TRC_SUCCESS;
80 }
81
xTraceIntervalStop(TraceIntervalChannelHandle_t xIntervalChannelHandle,TraceIntervalInstanceHandle_t xIntervalInstanceHandle)82 traceResult xTraceIntervalStop(TraceIntervalChannelHandle_t xIntervalChannelHandle, TraceIntervalInstanceHandle_t xIntervalInstanceHandle)
83 {
84 TraceEventHandle_t xEventHandle = 0;
85
86 TRC_ASSERT(xIntervalChannelHandle != 0);
87
88 /* We need to check this */
89 if (xTraceEventBegin(PSF_EVENT_INTERVAL_STOP, sizeof(void*) + sizeof(TraceUnsignedBaseType_t), &xEventHandle) == TRC_SUCCESS)
90 {
91 xTraceEventAddPointer(xEventHandle, (void*)xIntervalChannelHandle);
92 xTraceEventAddUnsignedBaseType(xEventHandle, (TraceUnsignedBaseType_t)xIntervalInstanceHandle);
93 xTraceEventEnd(xEventHandle);
94 }
95
96 return TRC_SUCCESS;
97 }
98
99 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
100
101 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
102