Percepio Trace Recorder v4.11.0
Loading...
Searching...
No Matches
trcStreamPort.h
1/*
2 * Trace Recorder for Tracealyzer v4.11.0
3 * Copyright 2025 Percepio AB
4 * www.percepio.com
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * The interface definitions for trace streaming ("stream ports").
9 * This "stream port" sets up the recorder to use ARM ITM as streaming channel.
10 *
11 * To setup Keil uVision for ITM tracing with a Keil ULINKpro (or ULINKplus),
12 * see Percepio Application Note PA-021, available at
13 * https://percepio.com/2018/05/04/keil-itm-support/
14 *
15 * To setup IAR Embedded Workbench for ITM tracing with an IAR I-Jet,
16 * see Percepio Application Note PA-023, https://percepio.com/iar
17 *
18 * NOTE: This stream port may block the application in case the ITM port
19 * is not ready for more data (the TPIU FIFO has become full). This is
20 * necessary to avoid data loss, as the TPIU FIFO is often quite small.
21 *
22 * --- Direct vs. Indirect ITM streaming ---
23 * Direct streaming: By default, this stream port writes directly to the ITM
24 * register mode without any RAM buffer. This assumes you have a fast debug
25 * probe, like aKeil ULINKpro or IAR I-Jet, to avoid excessive blocking.
26 * In case the ITM blocking appears to disturb your application, make sure your
27 * debugger is configured for maximum performance, as described in the above
28 * Application Nodes.
29 *
30 * Indirect streaming: If direct streaming gives too much overhead, you may
31 * instead try indirect ITM streaming. This is done by enabling the internal
32 * RAM buffer, like below. This reconfigures the recorder to store the events
33 * in the internal RAM buffer instead of writing them directly to the ITM port.
34 *
35 * Set TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER to 1 to use the indirect mode.
36 *
37 * This increases RAM usage but eliminates peaks in the trace data rate.
38 * Moreover, the ITM writes are then performed in a separate task (TzCtrl).
39 * You find relevant settings (buffer size etc.) in trcConfig.h.
40 *
41 * See also https://percepio.com/2018/10/11/tuning-your-custom-trace-streaming
42 *
43 * --- One-way vs. Two-way Communication ---
44 * The ITM port only provides one-way communication, from target to host.
45 * This is sufficient if you start the tracing from the target application,
46 * using vTraceEnable(TRC_START). Just make sure to start the Tracealyzer
47 * recording before you start the target system.
48 *
49 * In case you prefer to interactively start and stop the tracing from the host
50 * computer, you need two-way communication to send commands to the recorder.
51 * This is possible by writing such "start" and "stop" commands to a special
52 * buffer, monitored by the recorder library, using the debugger IDE.
53 * See trcStreamPort.c and also the example macro for Keil uVision
54 * (Keil-uVision-Tracealyzer-ITM-Exporter.ini).
55 */
56
57#ifndef TRC_STREAM_PORT_H
58#define TRC_STREAM_PORT_H
59
60#if (TRC_USE_TRACEALYZER_RECORDER == 1)
61
62#include <stdint.h>
63#include <trcTypes.h>
64#include <trcStreamPortConfig.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70#if (!defined(TRC_CFG_STREAM_PORT_ITM_PORT) || (TRC_CFG_STREAM_PORT_ITM_PORT) < 0) || ((TRC_CFG_STREAM_PORT_ITM_PORT) > 31)
71#error "Invalid ITM port defined in trcStreamPortConfig.h."
72#endif
73
74/* For now we disable multistream support for this streamport.
75#define TRC_STREAM_PORT_MULTISTREAM_SUPPORT
76*/
77
78#ifndef TRC_STREAM_PORT_MULTISTREAM_SUPPORT
79/* Multistream support is disabled */
80#define TRC_STREAM_PORT_MULTISTREAM_GET_CHANNEL(uiChannel) 0
81#else
82#define TRC_STREAM_PORT_MULTISTREAM_GET_CHANNEL(uiChannel) uiChannel
83#endif
84
85typedef struct TraceStreamPortBuffer /* Aligned */
86{
87 TraceUnsignedBaseType_t dummy;
88} TraceStreamPortBuffer_t;
89
93traceResult prvTraceItmWrite(void* ptrData, uint32_t size, uint32_t uiChannel, int32_t* ptrBytesWritten);
94
98traceResult prvTraceItmRead(void* ptrData, uint32_t uiSize, int32_t* piBytesRead);
99
103traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer);
104
116#define xTraceStreamPortWriteData(pvData, uiSize, uiChannel, piBytesWritten) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(prvTraceItmWrite(pvData, uiSize, TRC_STREAM_PORT_MULTISTREAM_GET_CHANNEL(uiChannel), piBytesWritten), TRC_SUCCESS)
117
118#define xTraceStreamPortReadData(pvData, uiSize, piBytesRead) prvTraceItmRead(pvData, uiSize, piBytesRead)
119
120#define xTraceStreamPortOnEnable(uiStartOption) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2((void)(uiStartOption), TRC_SUCCESS)
121
122#define xTraceStreamPortOnDisable() TRC_COMMA_EXPR_TO_STATEMENT_EXPR_1(TRC_SUCCESS)
123
124#define xTraceStreamPortOnTraceBegin() TRC_COMMA_EXPR_TO_STATEMENT_EXPR_1(TRC_SUCCESS)
125
126#define xTraceStreamPortOnTraceEnd() TRC_COMMA_EXPR_TO_STATEMENT_EXPR_1(TRC_SUCCESS)
127
128#ifdef __cplusplus
129}
130#endif
131
132#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
133
134#endif /* TRC_STREAM_PORT_H */
A structure representing the trace stream port buffer.
Definition trcStreamPort.h:71