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