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  * Main configuration parameters for the trace recorder library.
9  * More settings can be found in trcStreamingConfig.h and trcSnapshotConfig.h.
10  */
11 
12 #ifndef TRC_CONFIG_H
13 #define TRC_CONFIG_H
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /******************************************************************************
20  * Include of processor header file
21  *
22  * Here you may need to include the header file for your processor. This is
23  * required at least for the ARM Cortex-M port, that uses the ARM CMSIS API.
24  * Try that in case of build problems. Otherwise, remove the #error line below.
25  *****************************************************************************/
26 #error "Trace Recorder: Please include your processor's header file here and remove this line."
27 
28 /**
29  * @def TRC_CFG_HARDWARE_PORT
30  * @brief Specify what hardware port to use (i.e., the "timestamping driver").
31  *
32  * All ARM Cortex-M MCUs are supported by "TRC_HARDWARE_PORT_ARM_Cortex_M".
33  * This port uses the DWT cycle counter for Cortex-M3/M4/M7 devices, which is
34  * available on most such devices. In case your device don't have DWT support,
35  * you will get an error message opening the trace. In that case, you may
36  * force the recorder to use SysTick timestamping instead, using this define:
37  *
38  * #define TRC_CFG_ARM_CM_USE_SYSTICK
39  *
40  * For ARM Cortex-M0/M0+ devices, SysTick mode is used automatically.
41  *
42  * See trcHardwarePort.h for available ports and information on how to
43  * define your own port, if not already present.
44  */
45 #define TRC_CFG_HARDWARE_PORT TRC_HARDWARE_PORT_NOT_SET
46 
47 /**
48  * @def TRC_CFG_SCHEDULING_ONLY
49  * @brief Macro which should be defined as an integer value.
50  *
51  * If this setting is enabled (= 1), only scheduling events are recorded.
52  * If disabled (= 0), all events are recorded (unless filtered in other ways).
53  *
54  * Default value is 0 (= include additional events).
55  */
56 #define TRC_CFG_SCHEDULING_ONLY 0
57 
58 /**
59  * @def TRC_CFG_INCLUDE_MEMMANG_EVENTS
60  * @brief Macro which should be defined as either zero (0) or one (1).
61  *
62  * This controls if malloc and free calls should be traced. Set this to zero (0)
63  * to exclude malloc/free calls, or one (1) to include such events in the trace.
64  *
65  * Default value is 1.
66  */
67 #define TRC_CFG_INCLUDE_MEMMANG_EVENTS 1
68 
69 /**
70  * @def TRC_CFG_INCLUDE_USER_EVENTS
71  * @brief Macro which should be defined as either zero (0) or one (1).
72  *
73  * If this is zero (0), all code related to User Events is excluded in order
74  * to reduce code size. Any attempts of storing User Events are then silently
75  * ignored.
76  *
77  * User Events are application-generated events, like "printf" but for the
78  * trace log, generated using vTracePrint and vTracePrintF.
79  * The formatting is done on host-side, by Tracealyzer. User Events are
80  * therefore much faster than a console printf and can often be used
81  * in timing critical code without problems.
82  *
83  * Note: In streaming mode, User Events are used to provide error messages
84  * and warnings from the recorder (in case of incorrect configuration) for
85  * display in Tracealyzer. Disabling user events will also disable these
86  * warnings. You can however still catch them by calling xTraceErrorGetLast
87  * or by putting breakpoints in xTraceError and xTraceWarning.
88  *
89  * Default value is 1.
90  */
91 #define TRC_CFG_INCLUDE_USER_EVENTS 1
92 
93 /**
94  * @def TRC_CFG_INCLUDE_ISR_TRACING
95  * @brief Macro which should be defined as either zero (0) or one (1).
96  *
97  * If this is zero (0), the code for recording Interrupt Service Routines is
98  * excluded, in order to reduce code size. This means that any calls to
99  * vTraceStoreISRBegin/vTraceStoreISREnd will be ignored.
100  * This does not completely disable ISR tracing, in cases where an ISR is
101  * calling a traced kernel service. These events will still be recorded and
102  * show up in anonymous ISR instances in Tracealyzer, with names such as
103  * "ISR sending to <queue name>".
104  * To disable such tracing, please refer to vTraceSetFilterGroup and
105  * vTraceSetFilterMask.
106  *
107  * Default value is 1.
108  *
109  * Note: tracing ISRs requires that you insert calls to vTraceStoreISRBegin
110  * and vTraceStoreISREnd in your interrupt handlers.
111  */
112 #define TRC_CFG_INCLUDE_ISR_TRACING 1
113 
114 /**
115  * @def TRC_CFG_INCLUDE_READY_EVENTS
116  * @brief Macro which should be defined as either zero (0) or one (1).
117  *
118  * If one (1), events are recorded when tasks enter scheduling state "ready".
119  * This allows Tracealyzer to show the initial pending time before tasks enter
120  * the execution state, and present accurate response times.
121  * If zero (0), "ready events" are not created, which allows for recording
122  * longer traces in the same amount of RAM.
123  *
124  * Default value is 1.
125  */
126 #define TRC_CFG_INCLUDE_READY_EVENTS 1
127 
128 /**
129  * @def TRC_CFG_INCLUDE_OSTICK_EVENTS
130  * @brief Macro which should be defined as either zero (0) or one (1).
131  *
132  * If this is one (1), events will be generated whenever the OS clock is
133  * increased. If zero (0), OS tick events are not generated, which allows for
134  * recording longer traces in the same amount of RAM.
135  *
136  * Default value is 1.
137  */
138 #define TRC_CFG_INCLUDE_OSTICK_EVENTS 1
139 
140 /**
141  * @def TRC_CFG_ENABLE_STACK_MONITOR
142  * @brief If enabled (1), the recorder periodically reports the unused stack space of
143  * all active tasks.
144  * The stack monitoring runs in the Tracealyzer Control task, TzCtrl. This task
145  * is always created by the recorder when in streaming mode.
146  * In snapshot mode, the TzCtrl task is only used for stack monitoring and is
147  * not created unless this is enabled.
148  */
149 #define TRC_CFG_ENABLE_STACK_MONITOR 1
150 
151 /**
152  * @def TRC_CFG_STACK_MONITOR_MAX_TASKS
153  * @brief Macro which should be defined as a non-zero integer value.
154  *
155  * This controls how many tasks that can be monitored by the stack monitor.
156  * If this is too small, some tasks will be excluded and a warning is shown.
157  *
158  * Default value is 10.
159  */
160 #define TRC_CFG_STACK_MONITOR_MAX_TASKS 10
161 
162 /**
163  * @def TRC_CFG_STACK_MONITOR_MAX_REPORTS
164  * @brief Macro which should be defined as a non-zero integer value.
165  *
166  * This defines how many tasks that will be subject to stack usage analysis for
167  * each execution of the Tracealyzer Control task (TzCtrl). Note that the stack
168  * monitoring cycles between the tasks, so this does not affect WHICH tasks that
169  * are monitored, but HOW OFTEN each task stack is analyzed.
170  *
171  * This setting can be combined with TRC_CFG_CTRL_TASK_DELAY to tune the
172  * frequency of the stack monitoring. This is motivated since the stack analysis
173  * can take some time to execute.
174  * However, note that the stack analysis runs in a separate task (TzCtrl) that
175  * can be executed on low priority. This way, you can avoid that the stack
176  * analysis disturbs any time-sensitive tasks.
177  *
178  * Default value is 1.
179  */
180 #define TRC_CFG_STACK_MONITOR_MAX_REPORTS 1
181 
182 /**
183  * @def TRC_CFG_CTRL_TASK_PRIORITY
184  * @brief The scheduling priority of the Tracealyzer Control (TzCtrl) task.
185  *
186  * In streaming mode, TzCtrl is used to receive start/stop commands from
187  * Tracealyzer and in some cases also to transmit the trace data (for stream
188  * ports that uses the internal buffer, like TCP/IP). For such stream ports,
189  * make sure the TzCtrl priority is high enough to ensure reliable periodic
190  * execution and transfer of the data, but low enough to avoid disturbing any
191  * time-sensitive functions.
192  *
193  * In Snapshot mode, TzCtrl is only used for the stack usage monitoring and is
194  * not created if stack monitoring is disabled. TRC_CFG_CTRL_TASK_PRIORITY should
195  * be low, to avoid disturbing any time-sensitive tasks.
196  */
197 #define TRC_CFG_CTRL_TASK_PRIORITY 1
198 
199 /**
200  * @def TRC_CFG_CTRL_TASK_DELAY
201  * @brief The delay between loops of the TzCtrl task (see TRC_CFG_CTRL_TASK_PRIORITY),
202  * which affects the frequency of the stack monitoring.
203  *
204  * In streaming mode, this also affects the trace data transfer if you are using
205  * a stream port leveraging the internal buffer (like TCP/IP). A shorter delay
206  * increases the CPU load of TzCtrl somewhat, but may improve the performance of
207  * of the trace streaming, especially if the trace buffer is small.
208  */
209 #define TRC_CFG_CTRL_TASK_DELAY 2
210 
211 /**
212  * @def TRC_CFG_CTRL_TASK_STACK_SIZE
213  * @brief The stack size of the Tracealyzer Control (TzCtrl) task.
214  * See TRC_CFG_CTRL_TASK_PRIORITY for further information about TzCtrl.
215  */
216 #define TRC_CFG_CTRL_TASK_STACK_SIZE 1024
217 
218 /**
219  * @def TRC_CFG_RECORDER_BUFFER_ALLOCATION
220  * @brief Specifies how the recorder buffer is allocated (also in case of streaming, in
221  * port using the recorder's internal temporary buffer)
222  *
223  * Values:
224  * TRC_RECORDER_BUFFER_ALLOCATION_STATIC  - Static allocation (internal)
225  * TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC - Malloc in vTraceEnable
226  * TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM  - Use vTraceSetRecorderDataBuffer
227  *
228  * Static and dynamic mode does the allocation for you, either in compile time
229  * (static) or in runtime (malloc).
230  * The custom mode allows you to control how and where the allocation is made,
231  * for details see TRC_ALLOC_CUSTOM_BUFFER and vTraceSetRecorderDataBuffer().
232  */
233 #define TRC_CFG_RECORDER_BUFFER_ALLOCATION TRC_RECORDER_BUFFER_ALLOCATION_STATIC
234 
235 /**
236  * @def TRC_CFG_MAX_ISR_NESTING
237  * @brief Defines how many levels of interrupt nesting the recorder can handle, in
238  * case multiple ISRs are traced and ISR nesting is possible. If this
239  * is exceeded, the particular ISR will not be traced and the recorder then
240  * logs an error message. This setting is used to allocate an internal stack
241  * for keeping track of the previous execution context (4 byte per entry).
242  *
243  * This value must be a non-zero positive constant, at least 1.
244  *
245  * Default value: 8
246  */
247 #define TRC_CFG_MAX_ISR_NESTING 8
248 
249 /**
250  * @def TRC_CFG_ISR_TAILCHAINING_THRESHOLD
251  * @brief Macro which should be defined as an integer value.
252  *
253  * If tracing multiple ISRs, this setting allows for accurate display of the
254  * context-switching also in cases when the ISRs execute in direct sequence.
255  *
256  * vTraceStoreISREnd normally assumes that the ISR returns to the previous
257  * context, i.e., a task or a preempted ISR. But if another traced ISR
258  * executes in direct sequence, Tracealyzer may incorrectly display a minimal
259  * fragment of the previous context in between the ISRs.
260  *
261  * By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is
262  * however a threshold value that must be measured for your specific setup.
263  * See http://percepio.com/2014/03/21/isr_tailchaining_threshold/
264  *
265  * The default setting is 0, meaning "disabled" and that you may get an
266  * extra fragments of the previous context in between tail-chained ISRs.
267  *
268  * Note: This setting has separate definitions in trcSnapshotConfig.h and
269  * trcStreamingConfig.h, since it is affected by the recorder mode.
270  */
271 #define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0
272 
273 /**
274  * @def TRC_CFG_RECORDER_DATA_INIT
275  * @brief Macro which states wether the recorder data should have an initial value.
276  *
277  * In very specific cases where traced objects are created before main(),
278  * the recorder will need to be started even before that. In these cases,
279  * the recorder data would be initialized by vTraceEnable(TRC_INIT) but could
280  * then later be overwritten by the initialization value.
281  * If this is an issue for you, set TRC_CFG_RECORDER_DATA_INIT to 0.
282  * The following code can then be used before any traced objects are created:
283  *
284  *	extern uint32_t RecorderEnabled;
285  *	RecorderEnabled = 0;
286  *	xTraceInitialize();
287  *
288  * After the clocks are properly initialized, use vTraceEnable(...) to start
289  * the tracing.
290  *
291  * Default value is 1.
292  */
293 #define TRC_CFG_RECORDER_DATA_INIT 1
294 
295 /**
296  * @def TRC_CFG_RECORDER_DATA_ATTRIBUTE
297  * @brief When setting TRC_CFG_RECORDER_DATA_INIT to 0, you might also need to make
298  * sure certain recorder data is placed in a specific RAM section to avoid being
299  * zeroed out after initialization. Define TRC_CFG_RECORDER_DATA_ATTRIBUTE as
300  * that attribute.
301  *
302  * Example:
303  * #define TRC_CFG_RECORDER_DATA_ATTRIBUTE __attribute__((section(".bss.trace_recorder_data")))
304  *
305  * Default value is empty.
306  */
307 #define TRC_CFG_RECORDER_DATA_ATTRIBUTE
308 
309 /**
310  * @def TRC_CFG_USE_TRACE_ASSERT
311  * @brief Enable or disable debug asserts. Information regarding any assert that is
312  * triggered will be in trcAssert.c.
313  */
314 #define TRC_CFG_USE_TRACE_ASSERT 0
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 
320 #endif /* _TRC_CONFIG_H */
321