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 TCP/IP as streaming channel.
10  * The example is for lwIP.
11  */
12 
13 #ifndef TRC_STREAM_PORT_H
14 #define TRC_STREAM_PORT_H
15 
16 #include <stdint.h>
17 #include <trcTypes.h>
18 #include <trcStreamPortConfig.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #define TRC_USE_INTERNAL_BUFFER (TRC_CFG_STREAM_PORT_USE_INTERNAL_BUFFER)
25 
26 /**
27  * @def TRC_STREAM_PORT_BUFFER_SIZE
28  *
29  * @brief The buffer size, aligned to base type.
30  */
31 #define TRC_STREAM_PORT_BUFFER_SIZE ((((TRC_CFG_STREAM_PORT_BUFFER_SIZE) + sizeof(TraceUnsignedBaseType_t) - 1) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t))
32 
33 typedef struct TraceStreamPortBuffer
34 {
35 #if (TRC_USE_INTERNAL_BUFFER)
36 	uint8_t buffer[(TRC_STREAM_PORT_BUFFER_SIZE)];
37 #else
38 	TraceUnsignedBaseType_t buffer[1];
39 #endif
40 } TraceStreamPortBuffer_t;
41 
42 int32_t prvTraceTcpWrite(void* pvData, uint32_t uiSize, int32_t* piBytesWritten);
43 
44 int32_t prvTraceTcpRead(void* pvData, uint32_t uiSize, int32_t* piBytesRead);
45 
46 traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer);
47 
48 #define xTraceStreamPortAllocate(uiSize, ppvData) ((void)(uiSize), xTraceStaticBufferGet(ppvData))
49 
50 #if (TRC_USE_INTERNAL_BUFFER == 1)
51 /* Push to internal buffer. It will call on xTraceStreamPortWriteData() periodically. */
52 #define xTraceStreamPortCommit xTraceInternalEventBufferPush
53 #else
54 /* Write directly */
55 #define xTraceStreamPortCommit xTraceStreamPortWriteData
56 #endif
57 
58 #define xTraceStreamPortWriteData(pvData, uiSize, piBytesWritten) (prvTraceTcpWrite(pvData, uiSize, piBytesWritten) == 0 ? TRC_SUCCESS : TRC_FAIL)
59 
60 #define xTraceStreamPortReadData(pvData, uiSize, piBytesRead) (prvTraceTcpRead(pvData, uiSize, piBytesRead) == 0 ? TRC_SUCCESS : TRC_FAIL)
61 
62 #define xTraceStreamPortOnEnable(uiStartOption) ((void)(uiStartOption), TRC_SUCCESS)
63 
64 #define xTraceStreamPortOnDisable() (TRC_SUCCESS)
65 
66 #define xTraceStreamPortOnTraceBegin() (TRC_SUCCESS)
67 
68 traceResult xTraceStreamPortOnTraceEnd(void);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* TRC_STREAM_PORT_H */
75 
76