Percepio Trace Recorder v4.8.0.hotfix1
Loading...
Searching...
No Matches
trcStreamPort.h
1/*
2 * Trace Recorder for Tracealyzer v4.8.0.hotfix1
3 * Copyright 2023 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 stream the trace to file.
10 */
11
12#ifndef TRC_STREAM_PORT_H
13#define TRC_STREAM_PORT_H
14
15#if (TRC_USE_TRACEALYZER_RECORDER == 1)
16
17#if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
18
19#include <stdint.h>
20#include <trcTypes.h>
21#include <trcStreamPortConfig.h>
22#include <stdio.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define TRC_ALIGNED_STREAM_PORT_BUFFER_SIZE ((((TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_SIZE) + sizeof(TraceUnsignedBaseType_t) - 1) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t))
29
30#define TRC_USE_INTERNAL_BUFFER (TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER)
31
32#define TRC_INTERNAL_EVENT_BUFFER_WRITE_MODE (TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_WRITE_MODE)
33
34#define TRC_INTERNAL_EVENT_BUFFER_TRANSFER_MODE (TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_TRANSFER_MODE)
35
36#define TRC_INTERNAL_BUFFER_CHUNK_SIZE (TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_CHUNK_SIZE)
37
38#define TRC_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_SIZE_LIMIT (TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_SIZE_LIMIT)
39
40#define TRC_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_COUNT_LIMIT (TRC_CFG_STREAM_PORT_INTERNAL_BUFFER_CHUNK_TRANSFER_AGAIN_COUNT_LIMIT)
41
42/* Default file name */
43#ifndef TRC_CFG_STREAM_PORT_TRACE_FILE
44#define TRC_CFG_STREAM_PORT_TRACE_FILE "trace.psf"
45#endif
46
47typedef struct TraceStreamPortFile /* Aligned */
48{
49 FILE* pxFile;
50#if (TRC_USE_INTERNAL_BUFFER)
51 uint8_t buffer[TRC_ALIGNED_STREAM_PORT_BUFFER_SIZE];
52#endif
53} TraceStreamPortFile_t;
54
55extern TraceStreamPortFile_t* pxStreamPortFile;
56
57#define TRC_STREAM_PORT_BUFFER_SIZE (sizeof(TraceStreamPortFile_t))
58
59typedef struct TraceStreamPortBuffer
60{
61 uint8_t buffer[TRC_STREAM_PORT_BUFFER_SIZE];
63
74traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer);
75
85#if (TRC_USE_INTERNAL_BUFFER == 1)
86 #if (TRC_INTERNAL_EVENT_BUFFER_WRITE_MODE == TRC_INTERNAL_EVENT_BUFFER_OPTION_WRITE_MODE_COPY)
87 #define xTraceStreamPortAllocate(uiSize, ppvData) ((void)(uiSize), xTraceStaticBufferGet(ppvData))
88 #else
89 #define xTraceStreamPortAllocate(uiSize, ppvData) ((void)(uiSize), xTraceInternalEventBufferAlloc(uiSize, ppvData))
90 #endif
91#else
92 #define xTraceStreamPortAllocate(uiSize, ppvData) ((void)(uiSize), xTraceStaticBufferGet(ppvData))
93#endif
94
107#if (TRC_USE_INTERNAL_BUFFER == 1)
108 #if (TRC_INTERNAL_EVENT_BUFFER_WRITE_MODE == TRC_INTERNAL_EVENT_BUFFER_OPTION_WRITE_MODE_COPY)
109 #define xTraceStreamPortCommit xTraceInternalEventBufferPush
110 #else
111 #define xTraceStreamPortCommit xTraceInternalEventBufferAllocCommit
112 #endif
113#else
114 #define xTraceStreamPortCommit xTraceStreamPortWriteData
115#endif
116
127#define xTraceStreamPortWriteData(pvData, uiSize, piBytesWritten) (*(piBytesWritten) = (int32_t)fwrite(pvData, 1, uiSize, pxStreamPortFile->pxFile), TRC_SUCCESS)
128
139#define xTraceStreamPortReadData(pvData, uiSize, piBytesRead) ((void)(pvData), (void)(uiSize), (void)(piBytesRead), TRC_SUCCESS)
140
141#define xTraceStreamPortOnEnable(uiStartOption) ((void)(uiStartOption), TRC_SUCCESS)
142
143#define xTraceStreamPortOnDisable() (TRC_SUCCESS)
144
145traceResult xTraceStreamPortOnTraceBegin(void);
146
147traceResult xTraceStreamPortOnTraceEnd(void);
148
149#ifdef __cplusplus
150}
151#endif
152
153#endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
154
155#endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
156
157#endif /* TRC_STREAM_PORT_H */
A structure representing the trace stream port buffer.
Definition: trcStreamPort.h:93