Percepio Trace Recorder  v4.6.6
trcTimestamp.h
Go to the documentation of this file.
1 /*
2 * Percepio 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 
15 #ifndef TRC_TIMESTAMP_H
16 #define TRC_TIMESTAMP_H
17 
18 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
19 
20 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
21 
22 #include <trcTypes.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
37 typedef struct TraceTimestamp
38 {
39  uint32_t type;
40  TraceUnsignedBaseType_t frequency;
41  uint32_t period;
42  uint32_t wraparounds;
43  uint32_t osTickHz;
44  uint32_t latestTimestamp;
45  uint32_t osTickCount;
47 
48 extern TraceTimestamp_t* pxTraceTimestamp;
49 
50 #define TRC_TIMESTAMP_RECORD_SIZE (sizeof(TraceTimestamp_t))
51 
55 typedef struct TraceTimestampBuffer
56 {
57  uint32_t buffer[(TRC_TIMESTAMP_RECORD_SIZE) / sizeof(uint32_t)];
58 } TraceTimestampBuffer_t;
59 
69 traceResult xTraceTimestampInitialize(TraceTimestampBuffer_t *pxBuffer);
70 
71 #if ((TRC_CFG_USE_TRACE_ASSERT) == 1)
72 
81 traceResult xTraceTimestampGet(uint32_t* puiTimestamp);
82 
91 traceResult xTraceTimestampGetWraparounds(uint32_t* puiTimerWraparounds);
92 
101 traceResult xTraceTimestampSetFrequency(TraceUnsignedBaseType_t uxFrequency);
102 
111 traceResult xTraceTimestampGetFrequency(TraceUnsignedBaseType_t* puxFrequency);
112 
121 traceResult xTraceTimestampSetPeriod(uint32_t uiPeriod);
122 
131 traceResult xTraceTimestampGetPeriod(uint32_t* puiPeriod);
132 
141 traceResult xTraceTimestampSetOsTickCount(uint32_t uiOsTickCount);
142 
151 traceResult xTraceTimestampGetOsTickCount(uint32_t *puiOsTickCount);
152 
153 #else /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
154 
163 #if ((TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_INCR) || (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_INCR))
164 #define xTraceTimestampGet(puiTimestamp) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_4(*(puiTimestamp) = TRC_HWTC_COUNT, (*(puiTimestamp) < pxTraceTimestamp->latestTimestamp) ? pxTraceTimestamp->wraparounds++ : 0, pxTraceTimestamp->latestTimestamp = *(puiTimestamp), TRC_SUCCESS)
165 #elif ((TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_DECR) || (TRC_HWTC_TYPE == TRC_CUSTOM_TIMER_DECR))
166 #define xTraceTimestampGet(puiTimestamp) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_4(*(puiTimestamp) = TRC_HWTC_COUNT, (*(puiTimestamp) > pxTraceTimestamp->latestTimestamp) ? pxTraceTimestamp->wraparounds++ : 0, pxTraceTimestamp->latestTimestamp = *(puiTimestamp), TRC_SUCCESS)
167 #elif ((TRC_HWTC_TYPE == TRC_OS_TIMER_INCR) || (TRC_HWTC_TYPE == TRC_OS_TIMER_DECR))
168 #define xTraceTimestampGet(puiTimestamp) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_4(*(puiTimestamp) = ((TRC_HWTC_COUNT) & 0x00FFFFFFU) + ((pxTraceTimestamp->osTickCount & 0x000000FFU) << 24), pxTraceTimestamp->wraparounds = pxTraceTimestamp->osTickCount, pxTraceTimestamp->latestTimestamp = *(puiTimestamp), TRC_SUCCESS)
169 #endif
170 
179 #define xTraceTimestampGetWraparounds(puiTimerWraparounds) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(puiTimerWraparounds) = pxTraceTimestamp->wraparounds, TRC_SUCCESS)
180 
189 #define xTraceTimestampSetFrequency(uxFrequency) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(pxTraceTimestamp->frequency = uxFrequency, TRC_SUCCESS)
190 
199 #define xTraceTimestampSetPeriod(uiPeriod) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(pxTraceTimestamp->period = uiPeriod, TRC_SUCCESS)
200 
209 #define xTraceTimestampSetOsTickCount(uiOsTickCount) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(pxTraceTimestamp->osTickCount = uiOsTickCount, TRC_SUCCESS)
210 
219 #define xTraceTimestampGetFrequency(puxFrequency) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(puxFrequency) = pxTraceTimestamp->frequency, TRC_SUCCESS)
220 
229 #define xTraceTimestampGetPeriod(puiPeriod) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(puiPeriod) = pxTraceTimestamp->period, TRC_SUCCESS)
230 
239 #define xTraceTimestampGetOsTickCount(puiOsTickCount) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(puiOsTickCount) = pxTraceTimestamp->osTickCount, TRC_SUCCESS)
240 
241 #endif /* ((TRC_CFG_USE_TRACE_ASSERT) == 1) */
242 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
250 
251 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
252 
253 #endif /* TRC_TIMESTAMP_H */
TraceTimestamp_t
struct TraceTimestamp TraceTimestamp_t
Trace Timestamp Structure.
TraceTimestamp::period
uint32_t period
Definition: trcTimestamp.h:41
xTraceTimestampGet
#define xTraceTimestampGet(puiTimestamp)
Gets current trace timestamp.
Definition: trcTimestamp.h:164
xTraceTimestampGetPeriod
#define xTraceTimestampGetPeriod(puiPeriod)
Gets trace timestamp period.
Definition: trcTimestamp.h:229
TraceTimestamp::frequency
TraceUnsignedBaseType_t frequency
Definition: trcTimestamp.h:40
TraceTimestamp::wraparounds
uint32_t wraparounds
Definition: trcTimestamp.h:42
xTraceTimestampGetWraparounds
#define xTraceTimestampGetWraparounds(puiTimerWraparounds)
Gets trace timestamp wraparounds.
Definition: trcTimestamp.h:179
TraceTimestamp::type
uint32_t type
Definition: trcTimestamp.h:39
TraceTimestamp
Trace Timestamp Structure.
Definition: trcTimestamp.h:38
TraceTimestamp::osTickHz
uint32_t osTickHz
Definition: trcTimestamp.h:43
xTraceTimestampSetPeriod
#define xTraceTimestampSetPeriod(uiPeriod)
Sets trace timestamp period.
Definition: trcTimestamp.h:199
xTraceTimestampGetFrequency
#define xTraceTimestampGetFrequency(puxFrequency)
Gets trace timestamp frequency.
Definition: trcTimestamp.h:219
TraceTimestamp::osTickCount
uint32_t osTickCount
Definition: trcTimestamp.h:45
xTraceTimestampGetOsTickCount
#define xTraceTimestampGetOsTickCount(puiOsTickCount)
Gets trace timestamp OS tick count.
Definition: trcTimestamp.h:239
xTraceTimestampSetOsTickCount
#define xTraceTimestampSetOsTickCount(uiOsTickCount)
Sets trace timestamp OS tick count.
Definition: trcTimestamp.h:209
xTraceTimestampSetFrequency
#define xTraceTimestampSetFrequency(uxFrequency)
Sets trace timestamp frequency.
Definition: trcTimestamp.h:189
TraceTimestamp::latestTimestamp
uint32_t latestTimestamp
Definition: trcTimestamp.h:44