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 Windows sockets (Winsock), for use with Windows ports.
11  */
12 
13 #ifndef TRC_STREAM_PORT_H
14 #define TRC_STREAM_PORT_H
15 
16 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
17 
18 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
19 
20 #include <stdint.h>
21 #include <trcTypes.h>
22 #include <trcStreamPortConfig.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 /**
31  * @def TRC_STREAM_PORT_BUFFER_SIZE
32  *
33  * @brief The buffer size, aligned to base type.
34  */
35 #define TRC_STREAM_PORT_BUFFER_SIZE ((((TRC_CFG_STREAM_PORT_BUFFER_SIZE) + sizeof(TraceUnsignedBaseType_t) - 1) / sizeof(TraceUnsignedBaseType_t)) * sizeof(TraceUnsignedBaseType_t))
36 
37 typedef struct TraceStreamPortBuffer
38 {
39 #if (TRC_USE_INTERNAL_BUFFER)
40 	uint8_t buffer[(TRC_STREAM_PORT_BUFFER_SIZE)];
41 #else
42 	TraceUnsignedBaseType_t buffer[1];
43 #endif
44 } TraceStreamPortBuffer_t;
45 
46 int32_t prvTraceWriteToSocket(void* data, uint32_t size, int32_t* ptrBytesWritten);
47 int32_t prvTraceReadFromSocket(void* data, uint32_t bufsize, int32_t* ptrBytesRead);
48 
49 traceResult xTraceStreamPortInitialize(TraceStreamPortBuffer_t* pxBuffer);
50 
51 #define xTraceStreamPortAllocate(uiSize, ppvData) ((void)(uiSize), xTraceStaticBufferGet(ppvData))
52 
53 #if (TRC_USE_INTERNAL_BUFFER == 1)
54 /* Push to internal buffer. It will call on xTraceStreamPortWriteData() periodically. */
55 #define xTraceStreamPortCommit xTraceInternalEventBufferPush
56 #else
57 /* Write directly */
58 #define xTraceStreamPortCommit xTraceStreamPortWriteData
59 #endif
60 
61 #define xTraceStreamPortWriteData(pvData, uiSize, piBytesWritten) (prvTraceWriteToSocket(pvData, uiSize, piBytesWritten) == 0 ? TRC_SUCCESS : TRC_FAIL)
62 
63 #define xTraceStreamPortReadData(pvData, uiSize, piBytesRead) (prvTraceReadFromSocket(pvData, uiSize, piBytesRead) == 0 ? TRC_SUCCESS : TRC_FAIL)
64 
65 #define xTraceStreamPortOnEnable(uiStartOption) ((void)(uiStartOption), TRC_SUCCESS)
66 
67 #define xTraceStreamPortOnDisable() (TRC_SUCCESS)
68 
69 #define xTraceStreamPortOnTraceBegin() (TRC_SUCCESS)
70 
71 traceResult xTraceStreamPortOnTraceEnd(void);
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
78 
79 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/
80 
81 #endif /* TRC_STREAM_PORT_H */
82