]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace(streaming)/trcStreamPort.h
Update FreeRTOS+Trace recorder library to v3.0.2
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace(streaming) / trcStreamPort.h
1 /*******************************************************************************\r
2  * Trace Recorder Library for Tracealyzer v3.0.2\r
3  * Percepio AB, www.percepio.com\r
4  *\r
5  * trcStreamPort.h\r
6  *\r
7  * This file defines the trace streaming interface used by the \r
8  * Trace Recorder Library. It comes preconfigured for use with SEGGER's RTT and\r
9  * a TCP/IP (needs additional configuration in trcTCPIPConfig.h).\r
10  *\r
11  * Terms of Use\r
12  * This software (the "Tracealyzer Recorder Library") is the intellectual\r
13  * property of Percepio AB and may not be sold or in other ways commercially\r
14  * redistributed without explicit written permission by Percepio AB.\r
15  *\r
16  * Separate conditions applies for the SEGGER branded source code included.\r
17  *\r
18  * The recorder library is free for use together with Percepio products.\r
19  * You may distribute the recorder library in its original form, but public\r
20  * distribution of modified versions require approval by Percepio AB.\r
21  *\r
22  * Disclaimer\r
23  * The trace tool and recorder library is being delivered to you AS IS and\r
24  * Percepio AB makes no warranty as to its use or performance. Percepio AB does\r
25  * not and cannot warrant the performance or results you may obtain by using the\r
26  * software or documentation. Percepio AB make no warranties, express or\r
27  * implied, as to noninfringement of third party rights, merchantability, or\r
28  * fitness for any particular purpose. In no event will Percepio AB, its\r
29  * technology partners, or distributors be liable to you for any consequential,\r
30  * incidental or special damages, including any lost profits or lost savings,\r
31  * even if a representative of Percepio AB has been advised of the possibility\r
32  * of such damages, or for any claim by any third party. Some jurisdictions do\r
33  * not allow the exclusion or limitation of incidental, consequential or special\r
34  * damages, or the exclusion of implied warranties or limitations on how long an\r
35  * implied warranty may last, so the above limitations may not apply to you.\r
36  *\r
37  * Tabs are used for indent in this file (1 tab = 4 spaces)\r
38  *\r
39  * Copyright Percepio AB, 2015.\r
40  * www.percepio.com\r
41  ******************************************************************************/\r
42 \r
43 #ifndef _TRC_STREAM_PORT_H\r
44 #define _TRC_STREAM_PORT_H\r
45 \r
46 #ifdef __cplusplus\r
47 extern \93C\94 {\r
48 #endif\r
49 \r
50 #if (USE_TRACEALYZER_RECORDER == 1)\r
51 \r
52 #define TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_BLOCK    (0x01)\r
53 #define TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_NOBLOCK  (0x02)\r
54 #define TRC_RECORDER_TRANSFER_METHOD_TCPIP              (0x03)\r
55 #define TRC_RECORDER_TRANSFER_METHOD_CUSTOM             (0xFF)\r
56 \r
57 #define TRC_RECORDER_BUFFER_ALLOCATION_STATIC   (0x00)\r
58 #define TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC  (0x01)\r
59 \r
60 /*******************************************************************************\r
61  *   TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_BLOCK / NOBLOCK\r
62  ******************************************************************************/\r
63 #if TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_BLOCK || TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_NOBLOCK\r
64 \r
65 #if TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_BLOCK\r
66 #define TRC_STREAM_PORT_BLOCKING_TRANSFER 1\r
67 #define RTT_MODE SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL\r
68 #else\r
69 #define TRC_STREAM_PORT_BLOCKING_TRANSFER 0\r
70 #define RTT_MODE SEGGER_RTT_MODE_NO_BLOCK_SKIP\r
71 #endif\r
72 \r
73 #include "SEGGER_RTT_Conf.h"\r
74 #include "SEGGER_RTT.h"\r
75 \r
76 /* Up-buffer. If index is defined as 0, the internal RTT buffers will be used instead of this. */ \\r
77 #if TRC_RTT_UP_BUFFER_INDEX == 0\r
78 #define TRC_RTT_ALLOC_UP() static char* _TzTraceData = NULL;    /* Not actually used. Ignore allocation method. */\r
79 #define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
80 #else\r
81 #if TRC_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC\r
82 #define TRC_RTT_ALLOC_UP() static char _TzTraceData[BUFFER_SIZE_UP];    /* Static allocation */\r
83 #define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
84 #else\r
85 #define TRC_RTT_ALLOC_UP() static char* _TzTraceData = NULL;    /* Dynamic allocation */\r
86 #define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(BUFFER_SIZE_UP);\r
87 #endif\r
88 #endif\r
89 \r
90 /* Down-buffer. If index is defined as 0, the internal RTT buffers will be used instead of this. */ \\r
91 #if TRC_RTT_DOWN_BUFFER_INDEX == 0\r
92 #define TRC_RTT_ALLOC_DOWN() static char* _TzCtrlData = NULL;           /* Not actually used. Ignore allocation method. */\r
93 #else\r
94 #define TRC_RTT_ALLOC_DOWN() static char _TzCtrlData[BUFFER_SIZE_DOWN]; /* This buffer should be ~32bytes. Ignore allocation method. */\r
95 #endif\r
96   \r
97 #define TRC_STREAM_PORT_ALLOCATE_FIELDS() \\r
98         TRC_RTT_ALLOC_UP() /* Macro that will result in proper UP buffer allocation */ \\r
99         TRC_RTT_ALLOC_DOWN() /* Macro that will result in proper DOWN buffer allocation */\r
100 \r
101 #define TRC_STREAM_PORT_INIT() \\r
102         TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */ \\r
103         SEGGER_RTT_ConfigUpBuffer(TRC_RTT_UP_BUFFER_INDEX, "TzData", _TzTraceData, sizeof(_TzTraceData), RTT_MODE ); \\r
104         SEGGER_RTT_ConfigDownBuffer(TRC_RTT_DOWN_BUFFER_INDEX, "TzCtrl", _TzCtrlData, sizeof(_TzCtrlData), 0);\r
105 \r
106 #define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) uint8_t tmpEvt[_size]; _type* _ptrData = (_type*)tmpEvt;\r
107 #define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) SEGGER_RTT_Write(TRC_RTT_UP_BUFFER_INDEX, (const char*)_ptrData, _size);\r
108 #define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) *_ptrBytesRead = SEGGER_RTT_Read(TRC_RTT_DOWN_BUFFER_INDEX, (char*)_ptrData, _size);\r
109 #define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent)\r
110 \r
111 #define TRC_STREAM_PORT_ON_TRACE_BEGIN() /* Do nothing */\r
112 #define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */\r
113     \r
114 #endif /*TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_BLOCK || TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_JLINK_RTT_NOBLOCK*/\r
115 \r
116 /*******************************************************************************\r
117  *   TRC_RECORDER_TRANSFER_METHOD_TCPIP\r
118  * \r
119  * This TCP/IP implementation is using a secondary buffer consisting of multiple \r
120  * pages to avoid the endless recursive calls that occurr when "socket_send" \r
121  * uses kernel objects such as mutexes and semaphores, which in turn needs to be\r
122  * traced. To use your own TCP/IP stack, modify the functions declared in\r
123  * trcTCPIPConfig.h.\r
124  ******************************************************************************/\r
125 #if TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_TCPIP\r
126 \r
127 #include "trcTCPIP.h"\r
128 #include "trcPagedEventBuffer.h"\r
129 #include "trcPagedEventBufferConfig.h"\r
130 #define TRC_STREAM_PORT_BLOCKING_TRANSFER 0\r
131 \r
132 #if TRC_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC\r
133 #define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char _TzTraceData[TRC_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_PAGED_EVENT_BUFFER_PAGE_SIZE];       /* Static allocation. */\r
134 #define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
135 #else\r
136 #define TRC_STREAM_PORT_ALLOCATE_FIELDS() static char* _TzTraceData = NULL;     /* Dynamic allocation. */\r
137 #define TRC_STREAM_PORT_MALLOC() _TzTraceData = TRC_PORT_MALLOC(TRC_PAGED_EVENT_BUFFER_PAGE_COUNT * TRC_PAGED_EVENT_BUFFER_PAGE_SIZE);\r
138 #endif\r
139 \r
140 #define TRC_STREAM_PORT_INIT() \\r
141         TRC_STREAM_PORT_MALLOC(); /*Dynamic allocation or empty if static */ \\r
142         vPagedEventBufferInit(_TzTraceData);\r
143 \r
144 #define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type* _ptrData; _ptrData = (_type*)vPagedEventBufferGetWritePointer(_size);\r
145 #define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) /* Not needed since we write immediately into the buffer received above by TRC_STREAM_PORT_ALLOCATE_EVENT, and the TRC_STREAM_PORT_PERIODIC_SEND_DATA defined below will take care of the actual trace transfer. */\r
146 #define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) trcTcpRead(_ptrData, _size, _ptrBytesRead);\r
147 #define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent) vPagedEventBufferTransfer(trcTcpWrite, _ptrBytesSent);\r
148 \r
149 #define TRC_STREAM_PORT_ON_TRACE_BEGIN() vPagedEventBufferInit(_TzTraceData);\r
150 #define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */\r
151 \r
152 #endif /*TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_TCPIP*/\r
153 \r
154 /*******************************************************************************\r
155  *   TRC_RECORDER_TRANSFER_METHOD_CUSTOM\r
156  *\r
157  * Implement the following macros in trcConfig.h. If your transfer method uses\r
158  * kernel objects when sending data you will need to use a secondary buffer to \r
159  * store the trace data before sending it. For this reason we provide \r
160  * trcPagedEventBuffer. Look at the TCP/IP macros above to see how to use it.\r
161  ******************************************************************************/\r
162 #if TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_CUSTOM\r
163 \r
164 /* When using the custom transfer method, define TRC_STREAM_CUSTOM_XXXXXXXXXXXXX in trcConfig.h */\r
165 #define TRC_STREAM_PORT_BLOCKING_TRANSFER TRC_STREAM_CUSTOM_BLOCKING_TRANSFER\r
166 #define TRC_STREAM_PORT_ALLOCATE_FIELDS() TRC_STREAM_CUSTOM_ALLOCATE_FIELDS()\r
167 #define TRC_STREAM_PORT_INIT() TRC_STREAM_CUSTOM_INIT()\r
168 #define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptr, _size) TRC_STREAM_CUSTOM_ALLOCATE_EVENT(_type, _ptr, _size)\r
169 #define TRC_STREAM_PORT_COMMIT_EVENT(_ptr, _size) TRC_STREAM_CUSTOM_COMMIT_EVENT(_ptr, _size)\r
170 #define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) TRC_STREAM_CUSTOM_READ_DATA(_ptrData, _size, _ptrBytesRead)\r
171 #define TRC_STREAM_PORT_PERIODIC_SEND_DATA(_ptrBytesSent) TRC_STREAM_CUSTOM_PERIODIC_SEND_DATA(_ptrBytesSent)\r
172 #define TRC_STREAM_PORT_ON_TRACE_BEGIN() TRC_STREAM_CUSTOM_ON_TRACE_BEGIN()\r
173 #define TRC_STREAM_PORT_ON_TRACE_END() TRC_STREAM_CUSTOM_ON_TRACE_END()\r
174 \r
175 #endif /*TRC_RECORDER_TRANSFER_METHOD == TRC_RECORDER_TRANSFER_METHOD_CUSTOM*/\r
176 \r
177 #ifndef TRC_STREAM_PORT_ALLOCATE_FIELDS\r
178 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_ALLOCATE_FIELDS!"\r
179 #endif\r
180 \r
181 #ifndef TRC_STREAM_PORT_ALLOCATE_EVENT\r
182 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_ALLOCATE_EVENT!"\r
183 #endif\r
184 \r
185 #ifndef TRC_STREAM_PORT_COMMIT_EVENT\r
186 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_COMMIT_EVENT!"\r
187 #endif\r
188 \r
189 #ifndef TRC_STREAM_PORT_INIT\r
190 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_INIT!"\r
191 #endif\r
192 \r
193 #ifndef TRC_STREAM_PORT_BLOCKING_TRANSFER\r
194 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_BLOCKING_TRANSFER!"\r
195 #endif\r
196 \r
197 #ifndef TRC_STREAM_PORT_READ_DATA\r
198 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_READ_DATA!"\r
199 #endif\r
200 \r
201 #ifndef TRC_STREAM_PORT_PERIODIC_SEND_DATA\r
202 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_PERIODIC_SEND_DATA!"\r
203 #endif\r
204 \r
205 #ifndef TRC_STREAM_PORT_ON_TRACE_BEGIN\r
206 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_ON_TRACE_BEGIN!"\r
207 #endif\r
208 \r
209 #ifndef TRC_STREAM_PORT_ON_TRACE_END\r
210 #error "Selected TRC_RECORDER_TRANSFER_METHOD does not define TRC_STREAM_PORT_ON_TRACE_END!"\r
211 #endif\r
212 \r
213 #endif /*(USE_TRACEALYZER_RECORDER == 1)*/\r
214 \r
215 #ifdef __cplusplus\r
216 }\r
217 #endif\r
218 \r
219 #endif /* _TRC_STREAM_PORT_H */\r