Percepio Trace Recorder  v4.6.6
trcStreamPort.h
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 interface definitions for trace streaming ("stream ports").
9  * This "stream port" sets up the recorder to use SEGGER RTT as streaming channel.
10  *
11  * Note that this stream port is more complex than the typical case, since
12  * the J-Link interface uses a separate RAM buffer in SEGGER_RTT.c, instead
13  * of the default buffer included in the recorder core. The other stream ports
14  * offer more typical examples of how to define a custom streaming interface.
15  */
16 
17 #ifndef TRC_STREAM_PORT_H
18 #define TRC_STREAM_PORT_H
19 
20 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
21 
22 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include <trcTypes.h>
29 #include <trcStreamPortConfig.h>
30 
31 #include <SEGGER_RTT_Conf.h>
32 #include <SEGGER_RTT.h>
33 
34 #define TRC_USE_INTERNAL_BUFFER (TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER)
35 
36 /* Aligned */
37 #define TRC_STREAM_PORT_INTERNAL_BUFFER_SIZE ((((TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_SIZE) + sizeof(TraceUnsignedBaseType_t) - 1) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t))
38 
39 /* Aligned */
40 #define TRC_STREAM_PORT_RTT_UP_BUFFER_SIZE ((((TRC_CFG_STREAM_PORT_RTT_UP_BUFFER_SIZE) + sizeof(TraceUnsignedBaseType_t) - 1) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t))
41 
42 /* Aligned */
43 #define TRC_STREAM_PORT_RTT_DOWN_BUFFER_SIZE ((((TRC_CFG_STREAM_PORT_RTT_DOWN_BUFFER_SIZE) + sizeof(TraceUnsignedBaseType_t) - 1) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t))
44 
45 
49 typedef struct TraceStreamPortBuffer
50 {
51 #if (TRC_USE_INTERNAL_BUFFER == 1)
52  uint8_t bufferInternal[TRC_STREAM_PORT_INTERNAL_BUFFER_SIZE];
53 #endif
54  uint8_t bufferUp[TRC_STREAM_PORT_RTT_UP_BUFFER_SIZE];
55  uint8_t bufferDown[TRC_STREAM_PORT_RTT_DOWN_BUFFER_SIZE];
57 
68 traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer);
69 
79 #define xTraceStreamPortAllocate(uiSize, ppvData) ((void)(uiSize), xTraceStaticBufferGet(ppvData))
80 
93 #if (TRC_USE_INTERNAL_BUFFER == 1)
94 #define xTraceStreamPortCommit xTraceInternalEventBufferPush
95 #else
96 #define xTraceStreamPortCommit xTraceStreamPortWriteData
97 #endif
98 
109 #if (defined(TRC_CFG_STREAM_PORT_RTT_NO_LOCK_WRITE) && TRC_CFG_STREAM_PORT_RTT_NO_LOCK_WRITE == 1)
110 #define xTraceStreamPortWriteData(pvData, uiSize, piBytesWritten) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(piBytesWritten) = (int32_t)SEGGER_RTT_WriteNoLock((TRC_CFG_STREAM_PORT_RTT_UP_BUFFER_INDEX), (const char*)pvData, uiSize), TRC_SUCCESS)
111 #else
112 #define xTraceStreamPortWriteData(pvData, uiSize, piBytesWritten) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(piBytesWritten) = (int32_t)SEGGER_RTT_Write((TRC_CFG_STREAM_PORT_RTT_UP_BUFFER_INDEX), (const char*)pvData, uiSize), TRC_SUCCESS)
113 #endif
114 
125 #define xTraceStreamPortReadData(pvData, uiSize, piBytesRead) ((SEGGER_RTT_HASDATA(TRC_CFG_STREAM_PORT_RTT_DOWN_BUFFER_INDEX)) ? (*(piBytesRead) = (int32_t)SEGGER_RTT_Read((TRC_CFG_STREAM_PORT_RTT_DOWN_BUFFER_INDEX), (char*)(pvData), uiSize), TRC_SUCCESS) : TRC_SUCCESS)
126 
127 traceResult xTraceStreamPortOnEnable(uint32_t uiStartOption);
128 
129 #define xTraceStreamPortOnDisable() (void)(TRC_SUCCESS)
130 
131 #define xTraceStreamPortOnTraceBegin() (void)(TRC_SUCCESS)
132 
133 #define xTraceStreamPortOnTraceEnd() (void)(TRC_SUCCESS)
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
140 
141 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
142 
143 #endif /* TRC_STREAM_PORT_H */
TraceStreamPortBuffer
A structure representing the trace stream port buffer.
Definition: trcStreamPort.h:80