forked from percepio/TraceRecorderSource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcTimestamp.c
170 lines (127 loc) · 4.34 KB
/
trcTimestamp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Trace Recorder for Tracealyzer v4.10.2
* Copyright 2023 Percepio AB
* www.percepio.com
*
* SPDX-License-Identifier: Apache-2.0
*
* The implementation of timestamps.
*/
#include <trcRecorder.h>
#if (TRC_USE_TRACEALYZER_RECORDER == 1) && (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
TraceTimestampData_t *pxTraceTimestamp TRC_CFG_RECORDER_DATA_ATTRIBUTE;
traceResult xTraceTimestampInitialize(TraceTimestampData_t *pxBuffer)
{
/* This should never fail */
TRC_ASSERT(pxBuffer != (void*)0);
pxTraceTimestamp = pxBuffer;
/* These will be set when tracing is enabled */
pxTraceTimestamp->frequency = 0u;
pxTraceTimestamp->period = 0u;
pxTraceTimestamp->osTickHz = TRC_TICK_RATE_HZ;
pxTraceTimestamp->osTickCount = 0u;
pxTraceTimestamp->wraparounds = 0u;
pxTraceTimestamp->type = TRC_HWTC_TYPE;
#if (TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_INCR || TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_INCR)
pxTraceTimestamp->latestTimestamp = 0u;
#elif (TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_DECR || TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)
pxTraceTimestamp->latestTimestamp = pxTraceTimestamp->period - 1u;
#endif
xTraceSetComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP);
return TRC_SUCCESS;
}
#if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
traceResult xTraceTimestampGet(uint32_t *puiTimestamp)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
/* This should never fail */
TRC_ASSERT(puiTimestamp != (void*)0);
switch (pxTraceTimestamp->type)
{
case TRC_FREE_RUNNING_32BIT_INCR:
case TRC_CUSTOM_TIMER_INCR:
*puiTimestamp = (uint32_t)(TRC_HWTC_COUNT);
if (*puiTimestamp < pxTraceTimestamp->latestTimestamp)
{
pxTraceTimestamp->wraparounds++;
}
break;
case TRC_FREE_RUNNING_32BIT_DECR:
case TRC_CUSTOM_TIMER_DECR:
*puiTimestamp = (uint32_t)(TRC_HWTC_COUNT);
if (*puiTimestamp > pxTraceTimestamp->latestTimestamp)
{
pxTraceTimestamp->wraparounds++;
}
break;
case TRC_OS_TIMER_INCR:
case TRC_OS_TIMER_DECR:
*puiTimestamp = (((uint32_t)(TRC_HWTC_COUNT)) & 0x00FFFFFFUL) + ((pxTraceTimestamp->osTickCount & 0x000000FFUL) << 24);
pxTraceTimestamp->wraparounds = pxTraceTimestamp->osTickCount;
break;
default:
return TRC_FAIL;
}
pxTraceTimestamp->latestTimestamp = *puiTimestamp;
return TRC_SUCCESS;
}
traceResult xTraceTimestampGetWraparounds(uint32_t* puiTimerWraparounds)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
/* This should never fail */
TRC_ASSERT(puiTimerWraparounds != (void*)0);
*puiTimerWraparounds = pxTraceTimestamp->wraparounds;
return TRC_SUCCESS;
}
traceResult xTraceTimestampSetFrequency(TraceUnsignedBaseType_t uxFrequency)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
pxTraceTimestamp->frequency = uxFrequency;
return TRC_SUCCESS;
}
traceResult xTraceTimestampSetPeriod(uint32_t uiPeriod)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
pxTraceTimestamp->period = uiPeriod;
return TRC_SUCCESS;
}
traceResult xTraceTimestampSetOsTickCount(uint32_t uiOsTickCount)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
pxTraceTimestamp->osTickCount = uiOsTickCount;
return TRC_SUCCESS;
}
traceResult xTraceTimestampGetFrequency(TraceUnsignedBaseType_t *puxFrequency)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
/* This should never fail */
TRC_ASSERT(puxFrequency != (void*)0);
*puxFrequency = pxTraceTimestamp->frequency;
return TRC_SUCCESS;
}
traceResult xTraceTimestampGetPeriod(uint32_t *puiPeriod)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
/* This should never fail */
TRC_ASSERT(puiPeriod != (void*)0);
*puiPeriod = pxTraceTimestamp->period;
return TRC_SUCCESS;
}
traceResult xTraceTimestampGetOsTickCount(uint32_t* puiOsTickCount)
{
/* This should never fail */
TRC_ASSERT(xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_TIMESTAMP));
/* This should never fail */
TRC_ASSERT(puiOsTickCount != (void*)0);
*puiOsTickCount = pxTraceTimestamp->osTickCount;
return TRC_SUCCESS;
}
#endif
#endif