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 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
25 extern "C" {
26 #endif
27 
28 #define TRC_USE_INTERNAL_BUFFER (TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER)
29 
30 /* Default file name */
31 #ifndef TRC_CFG_STREAM_PORT_TRACE_FILE
32 #define TRC_CFG_STREAM_PORT_TRACE_FILE "trace.psf"
33 #endif
34 
35 typedef struct TraceStreamPortFile
36 {
37 	FILE* pxFile;
38 #if (TRC_USE_INTERNAL_BUFFER)
39 	uint8_t buffer[TRC_STREAM_PORT_BUFFER_SIZE];
40 #endif
41 } TraceStreamPortFile_t;
42 
43 extern TraceStreamPortFile_t* pxStreamPortFile;
44 
45 #define TRC_STREAM_PORT_BUFFER_SIZE (sizeof(TraceStreamPortFile_t))
46 
47 typedef struct TraceStreamPortBuffer
48 {
49 	uint8_t buffer[TRC_STREAM_PORT_BUFFER_SIZE];
50 } TraceStreamPortBuffer_t;
51 
52 traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer);
53 
54 #define xTraceStreamPortAllocate(uiSize, ppvData) ((void)(uiSize), xTraceStaticBufferGet(ppvData))
55 
56 #if (TRC_USE_INTERNAL_BUFFER == 1)
57 /* Push to internal buffer. It will call on xTraceStreamPortWriteData() periodically. */
58 #define xTraceStreamPortCommit(pvData, uiSize, piBytesCommitted) xTraceInternalEventBufferPush(pvData, uiSize, piBytesCommitted)
59 #else
60 /* Write directly to file */
61 #define xTraceStreamPortCommit(pvData, uiSize, piBytesCommitted) xTraceStreamPortWriteData(pvData, uiSize, piBytesCommitted)
62 #endif
63 
64 #define xTraceStreamPortWriteData(pvData, uiSize, piBytesWritten) (*(piBytesWritten) = fwrite(pvData, 1, uiSize, pxStreamPortFile->pxFile), TRC_SUCCESS)
65 
66 #define xTraceStreamPortReadData(pvData, uiSize, piBytesRead) ((void)(pvData), (void)(uiSize), (void)(piBytesRead), TRC_SUCCESS)
67 
68 #define xTraceStreamPortOnEnable(uiStartOption) ((void)(uiStartOption), TRC_SUCCESS)
69 
70 #define xTraceStreamPortOnDisable() (TRC_SUCCESS)
71 
72 traceResult xTraceStreamPortOnTraceBegin(void);
73 
74 traceResult xTraceStreamPortOnTraceEnd(void);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
81 
82 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
83 
84 #endif /* TRC_STREAM_PORT_H */
85