Percepio Trace Recorder v4.12.0
Loading...
Searching...
No Matches
trcRecorder.h
Go to the documentation of this file.
1/*
2 * Percepio TraceRecorder for Tracealyzer v4.12.0
3 * Copyright 2025 Percepio AB
4 * www.percepio.com
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9#ifndef TRC_RECORDER_H
10#define TRC_RECORDER_H
11
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
28
29#define TRC_ACKNOWLEDGED (0xABC99123)
30
31#include <trcDefines.h>
32#include <trcConfig.h>
33
34#ifndef TRC_CFG_ENTRY_SLOTS
35#error TRC_CFG_ENTRY_SLOTS not defined. Please ensure you are using updated config files.
36#endif
37
38#include <trcKernelPortConfig.h>
39
40#include <trcTypes.h>
41
42#ifndef TRC_CFG_TEST_MODE
43#define TRC_CFG_TEST_MODE 0
44#endif
45
46/* Unless specified in trcConfig.h we assume this is a single core target */
47#ifndef TRC_CFG_CORE_COUNT
48#define TRC_CFG_CORE_COUNT 1
49#endif
50
51/* Unless specified in trcConfig.h we assume this is a single core target */
52#ifndef TRC_CFG_GET_CURRENT_CORE
53#define TRC_CFG_GET_CURRENT_CORE() 0
54#endif
55
56/* Unless specified in trcConfig.h or trcKernelPortConfig.h we assume
57 * GCC statement expressions aren't supported. */
58#ifndef TRC_CFG_USE_GCC_STATEMENT_EXPR
59#define TRC_CFG_USE_GCC_STATEMENT_EXPR 0
60#endif
61
62/* Backwards compatibility */
63#undef traceHandle
64#define traceHandle TraceISRHandle_t
65
66/* Maximum event size */
67#define TRC_MAX_BLOB_SIZE (16UL * sizeof(TraceUnsignedBaseType_t))
68
69/* Platform name length */
70#define TRC_PLATFORM_CFG_LENGTH 8UL
71
72/* Header size */
73#define TRC_HEADER_BUFFER_SIZE (sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint8_t) + sizeof(uint8_t) + (sizeof(char) * (TRC_PLATFORM_CFG_LENGTH)))
74
75typedef struct TraceHeaderBuffer /* Aligned */
76{
77 uint8_t buffer[TRC_HEADER_BUFFER_SIZE];
78} TraceHeaderBuffer_t;
79
80#include <trcHardwarePort.h>
81#include <trcKernelPort.h>
82#include <trcString.h>
83#include <trcStaticBuffer.h>
84#include <trcError.h>
85#include <trcEvent.h>
86#include <trcEventBuffer.h>
88#include <trcTimestamp.h>
89#include <trcEntryTable.h>
90#include <trcStreamPort.h>
91#include <trcISR.h>
92#include <trcTask.h>
93#include <trcObject.h>
94#include <trcPrint.h>
95#include <trcHeap.h>
96#include <trcExtension.h>
97#include <trcUtility.h>
98#include <trcStackMonitor.h>
100#include <trcDiagnostics.h>
101#include <trcAssert.h>
102#include <trcRunnable.h>
103#include <trcDependency.h>
104#include <trcProcess.h>
105#include <trcThread.h>
106#include <trcInterval.h>
107#include <trcStateMachine.h>
108#include <trcCounter.h>
109#include <trcTaskMonitor.h>
110
111#if (TRC_USE_TRACEALYZER_RECORDER == 1)
112
127traceResult xTraceInitialize(void);
128
200traceResult xTraceEnable(uint32_t uiStartOption);
201
208traceResult xTraceDisable(void);
209
210#ifndef TRC_EXTERNAL_BUFFERS
211#define TRC_EXTERNAL_BUFFERS 0
212#endif
213
214/* Empty default define */
215#ifndef TRC_CFG_PRINTF
216#define TRC_CFG_PRINTF(...)
217#endif
218
219typedef struct TraceRecorderData /* Aligned */
220{
221 uint32_t uiSessionCounter;
222 uint32_t uiRecorderEnabled;
223 TraceUnsignedBaseType_t uxTraceSystemStates[TRC_CFG_CORE_COUNT];
224 uint32_t reserved; /* alignment */
225
226 TraceAssertData_t xAssertBuffer; /* aligned */
227 TraceEntryIndexTable_t xEntryIndexTableBuffer; /* aligned */
228#if (TRC_EXTERNAL_BUFFERS == 0)
229 TraceHeaderBuffer_t xHeaderBuffer; /* aligned */
230 TraceEntryTable_t xEntryTable; /* aligned */
231 TraceTimestampData_t xTimestampBuffer; /* aligned */
232#endif
233#if (TRC_USE_INTERNAL_BUFFER == 1)
234 TraceInternalEventBufferData_t xInternalEventBuffer; /* aligned */
235#endif
236 TraceStreamPortBuffer_t xStreamPortBuffer; /* verify alignment in xTraceInitialize() */
237 TraceStaticBufferTable_t xStaticBufferBuffer; /* aligned */
238 TraceEventDataTable_t xEventDataBuffer; /* verify alignment in xTraceInitialize() */
239 TracePrintData_t xPrintBuffer; /* aligned */
240 TraceErrorData_t xErrorBuffer; /* aligned */
241 TraceISRData_t xISRBuffer; /* aligned */
242 TraceKernelPortDataBuffer_t xKernelPortBuffer; /* verify alignment in xTraceInitialize() */
243 TraceTaskData_t xTaskInfoBuffer; /* aligned */
244 TraceStackMonitorData_t xStackMonitorBuffer; /* aligned */
245 TraceDiagnosticsData_t xDiagnosticsBuffer; /* aligned */
246 TraceExtensionData_t xExtensionBuffer; /* aligned */
247 TraceCounterData_t xCounterBuffer; /* aligned */
248 TraceTaskMonitorData_t xTaskMonitorBuffer; /* aligned */
249} TraceRecorderData_t;
250
251extern TraceRecorderData_t* pxTraceRecorderData;
252extern uint32_t RecorderInitialized;
253
262traceResult xTraceHeaderInitialize(TraceHeaderBuffer_t* pxBuffer);
263
270#define xTraceIsRecorderEnabled() (xTraceIsRecorderInitialized() && pxTraceRecorderData->uiRecorderEnabled)
271
278#define xTraceIsRecorderInitialized() xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_CORE)
279
288#define xTraceSetComponentInitialized(uiComponentBit) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(RecorderInitialized |= (uiComponentBit), TRC_SUCCESS)
289
298#define xTraceIsComponentInitialized(uiComponentBit) (RecorderInitialized & (uiComponentBit))
299
308#define xTraceStateSet(uxState) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(pxTraceRecorderData->uxTraceSystemStates[TRC_CFG_GET_CURRENT_CORE()] = (uxState), TRC_SUCCESS)
309
318#define xTraceStateGet(puxState) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(puxState) = pxTraceRecorderData->uxTraceSystemStates[TRC_CFG_GET_CURRENT_CORE()], TRC_SUCCESS)
319
326traceResult xTraceTzCtrl(void);
327
328/******************************************************************************/
329/*** INTERNAL STREAMING FUNCTIONS *********************************************/
330/******************************************************************************/
331
332#if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)
341traceResult xTraceSetBuffer(TraceRecorderData_t *pxBuffer);
342#else
343#define xTraceSetBuffer(p) (TRC_SUCCESS)
344#endif
345
355traceResult xTraceGetEventBuffer(void** ppvBuffer, TraceUnsignedBaseType_t * puiSize);
356
357#else /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
358
359#define xTraceInitialize() (TRC_SUCCESS)
360#define xTraceEnable(x) ((void)(x), TRC_SUCCESS)
361#define xTraceDisable() (TRC_SUCCESS)
362
363#define prvTraceSetReadyEventsEnabled(status) (void)(status)
364
365#define vTraceExcludeTask(handle) (void)(handle)
366
367#define vTraceConsoleChannelPrintF(fmt, ...) (void)(fmt)
368
369#ifndef TRC_ALLOC_CUSTOM_BUFFER
370#define TRC_ALLOC_CUSTOM_BUFFER(bufname)
371#endif
372
373#define xTraceIsRecorderEnabled() (0)
374#define xTraceIsRecorderInitialized() (0)
375
376#define xTraceSetBuffer(p) (TRC_SUCCESS)
377#define xTraceGetEventBuffer(p) (TRC_FAIL)
378
379#define vTraceSetStopHook(x) (void)(x)
380
381#define TraceRecorderData_t uint32_t
382
383#endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
384
388#define vTraceInitialize (void)xTraceInitialize
389
393#define vTraceEnable (void)xTraceEnable
394
398#define vTraceStop (void)xTraceDisable
399
403#define vTraceInstanceFinishedNow (void)xTraceTaskInstanceFinishedNow
404
408#define vTraceInstanceFinishedNext (void)xTraceTaskInstanceFinishedNext
409
413#define vTracePrintF (void)xTracePrintF
414
418#define vTraceVPrintF (void)xTraceVPrintF
419
423#define vTracePrint (void)xTracePrint
424
428#define vTraceSetRecorderDataBuffer(pxBuffer) xTraceSetBuffer((TraceRecorderData_t*)(pxBuffer))
429
430#ifdef __cplusplus
431}
432#endif
433
434#endif
struct TraceTimestampData TraceTimestampData_t
Trace Timestamp Structure.
Public trace assert APIs.
Public trace counter APIs.
Public trace dependency APIs.
Public trace diagnostic APIs.
Public trace entry table APIs.
Public trace error APIs.
Public trace event buffer APIs.
Public trace event APIs.
Public trace extension APIs.
Public trace heap APIs.
Public trace ISR APIs.
Public internal event buffer APIs.
struct TraceInternalEventBufferData TraceInternalEventBufferData_t
A structure representing the trace stream port buffer.
Public trace interval APIs.
Public trace object APIs.
Public trace print APIs.
Public trace process APIs.
traceResult xTraceTzCtrl(void)
Call this function periodically.
Definition trcStreamingRecorder.c:452
traceResult xTraceHeaderInitialize(TraceHeaderBuffer_t *pxBuffer)
Initializes the header data.
Definition trcStreamingRecorder.c:281
traceResult xTraceInitialize(void)
Initializes the recorder data. xTraceInitialize() or xTraceEnable(...) must be called before any atte...
Definition trcStreamingRecorder.c:136
traceResult xTraceDisable(void)
Disables tracing.
Definition trcStreamingRecorder.c:415
traceResult xTraceGetEventBuffer(void **ppvBuffer, TraceUnsignedBaseType_t *puiSize)
Retrieve the event buffer and event buffer size.
Definition trcStreamingRecorder.c:438
Public trace runnable APIs.
Public trace stack monitor APIs.
Public trace state machine APIs.
Public trace static buffer APIs.
Public trace string APIs.
Public trace task monitor APIs.
Public trace task APIs.
Public trace thread APIs.
Public trace timestamp APIs.