1 /*
2  * Percepio 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 
9 /**
10  * @file
11  *
12  * @brief Public internal event buffer APIs.
13  */
14 
15 #ifndef TRC_INTERNAL_BUFFER_H
16 #define TRC_INTERNAL_BUFFER_H
17 
18 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
19 
20 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
21 
22 #ifndef TRC_USE_INTERNAL_BUFFER
23 #define TRC_USE_INTERNAL_BUFFER 1
24 #endif
25 
26 #if (TRC_USE_INTERNAL_BUFFER == 1)
27 
28 #include <trcTypes.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * @defgroup trace_internal_event_buffer_apis Trace Internal Event Buffer APIs
36  * @ingroup trace_recorder_apis
37  * @{
38  */
39 
40 /**
41  * @internal Initializes the internal trace event buffer used by certain stream ports.
42  *
43  * @param[in] puiBuffer Pointer to previously allocated memory buffer
44  * @param[in] uiSize Size of buffer
45  *
46  * @retval TRC_FAIL Failure
47  * @retval TRC_SUCCESS Success
48  */
49 traceResult xTraceInternalEventBufferInitialize(uint8_t* puiBuffer, uint32_t uiSize);
50 
51 /**
52  * @brief Pushes data to the internal trace event buffer.
53  *
54  * @param[in] pvData Pointer to data
55  * @param[in] uiSize Size of data
56  * @param[out] piBytesWritten Bytes written.
57  *
58  * @retval TRC_FAIL Failure
59  * @retval TRC_SUCCESS Success
60  */
61 traceResult xTraceInternalEventBufferPush(void *pvData, uint32_t uiSize, int32_t *piBytesWritten);
62 
63 /**
64  * @brief Transfers all internal trace event buffer data using the function
65  * xTraceStreamPortWriteData(...) as defined in trcStreamPort.h.
66  *
67  * This function is intended to be called by the periodic TzCtrl task with a
68  * suitable delay (e.g. 10-100 ms).
69  *
70  * In case of errors from the streaming interface, it registers a warning
71  * (TRC_WARNING_STREAM_PORT_WRITE) provided by xTraceErrorGetLast().
72  *
73  * @param[out] piBytesWritten Bytes written.
74  *
75  * @retval TRC_FAIL Failure
76  * @retval TRC_SUCCESS Success
77  */
78 traceResult xTraceInternalEventBufferTransfer(int32_t *piBytesWritten);
79 
80 /**
81  * @brief Clears all trace events in the internal trace event buffer.
82  *
83  * @retval TRC_FAIL Failure
84  * @retval TRC_SUCCESS Success
85  */
86 traceResult xTraceInternalEventBufferClear(void);
87 
88 /** @} */
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #else /* (TRC_USE_INTERNAL_BUFFER == 1)*/
95 
96 #define xTraceInternalEventBufferInitialize(puiBuffer, uiSize) ((void)uiSize, puiBuffer != 0 ? TRC_SUCCESS : TRC_FAIL)
97 #define xTraceInternalEventBufferPush(pvData, uiSize, piBytesWritten) ((void)uiSize, (void)piBytesWritten, pvData != 0 ? TRC_SUCCESS : TRC_FAIL)
98 #define xTraceInternalEventBufferTransfer(piBytesWritten) ((void)piBytesWritten, TRC_SUCCESS)
99 #define xTraceInternalEventBufferClear() (void)(TRC_SUCCESS)
100 
101 #endif /* (TRC_USE_INTERNAL_BUFFER == 1)*/
102 
103 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
104 
105 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
106 
107 #endif /* TRC_INTERNAL_BUFFER_H */
108