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 /******************************************************************************
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 0
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  * The unit depends on the delay function used for the specific kernel port (trcKernelPort.c).
210  * For example, FreeRTOS uses ticks while Zephyr uses ms.
211  */
212 #define TRC_CFG_CTRL_TASK_DELAY 10
213 
214 /**
215  * @def TRC_CFG_CTRL_TASK_STACK_SIZE
216  * @brief The stack size of the Tracealyzer Control (TzCtrl) task.
217  * See TRC_CFG_CTRL_TASK_PRIORITY for further information about TzCtrl.
218  */
219 #define TRC_CFG_CTRL_TASK_STACK_SIZE 1024
220 
221 /**
222  * @def TRC_CFG_RECORDER_BUFFER_ALLOCATION
223  * @brief Specifies how the recorder buffer is allocated (also in case of streaming, in
224  * port using the recorder's internal temporary buffer)
225  *
226  * Values:
227  * TRC_RECORDER_BUFFER_ALLOCATION_STATIC  - Static allocation (internal)
228  * TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC - Malloc in vTraceEnable
229  * TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM  - Use vTraceSetRecorderDataBuffer
230  *
231  * Static and dynamic mode does the allocation for you, either in compile time
232  * (static) or in runtime (malloc).
233  * The custom mode allows you to control how and where the allocation is made,
234  * for details see TRC_ALLOC_CUSTOM_BUFFER and vTraceSetRecorderDataBuffer().
235  */
236 #define TRC_CFG_RECORDER_BUFFER_ALLOCATION TRC_RECORDER_BUFFER_ALLOCATION_STATIC
237 
238 /**
239  * @def TRC_CFG_MAX_ISR_NESTING
240  * @brief Defines how many levels of interrupt nesting the recorder can handle, in
241  * case multiple ISRs are traced and ISR nesting is possible. If this
242  * is exceeded, the particular ISR will not be traced and the recorder then
243  * logs an error message. This setting is used to allocate an internal stack
244  * for keeping track of the previous execution context (4 byte per entry).
245  *
246  * This value must be a non-zero positive constant, at least 1.
247  *
248  * Default value: 8
249  */
250 #define TRC_CFG_MAX_ISR_NESTING 8
251 
252 /**
253  * @def TRC_CFG_ISR_TAILCHAINING_THRESHOLD
254  * @brief Macro which should be defined as an integer value.
255  *
256  * If tracing multiple ISRs, this setting allows for accurate display of the
257  * context-switching also in cases when the ISRs execute in direct sequence.
258  *
259  * vTraceStoreISREnd normally assumes that the ISR returns to the previous
260  * context, i.e., a task or a preempted ISR. But if another traced ISR
261  * executes in direct sequence, Tracealyzer may incorrectly display a minimal
262  * fragment of the previous context in between the ISRs.
263  *
264  * By using TRC_CFG_ISR_TAILCHAINING_THRESHOLD you can avoid this. This is
265  * however a threshold value that must be measured for your specific setup.
266  * See http://percepio.com/2014/03/21/isr_tailchaining_threshold/
267  *
268  * The default setting is 0, meaning "disabled" and that you may get an
269  * extra fragments of the previous context in between tail-chained ISRs.
270  *
271  * Note: This setting has separate definitions in trcSnapshotConfig.h and
272  * trcStreamingConfig.h, since it is affected by the recorder mode.
273  */
274 #define TRC_CFG_ISR_TAILCHAINING_THRESHOLD 0
275 
276 /**
277  * @def TRC_CFG_RECORDER_DATA_INIT
278  * @brief Macro which states wether the recorder data should have an initial value.
279  *
280  * In very specific cases where traced objects are created before main(),
281  * the recorder will need to be started even before that. In these cases,
282  * the recorder data would be initialized by vTraceEnable(TRC_INIT) but could
283  * then later be overwritten by the initialization value.
284  * If this is an issue for you, set TRC_CFG_RECORDER_DATA_INIT to 0.
285  * The following code can then be used before any traced objects are created:
286  *
287  *	extern uint32_t RecorderInitialized;
288  *	RecorderInitialized = 0;
289  *	xTraceInitialize();
290  *
291  * After the clocks are properly initialized, use vTraceEnable(...) to start
292  * the tracing.
293  *
294  * Default value is 1.
295  */
296 #define TRC_CFG_RECORDER_DATA_INIT 1
297 
298 /**
299  * @def TRC_CFG_RECORDER_DATA_ATTRIBUTE
300  * @brief When setting TRC_CFG_RECORDER_DATA_INIT to 0, you might also need to make
301  * sure certain recorder data is placed in a specific RAM section to avoid being
302  * zeroed out after initialization. Define TRC_CFG_RECORDER_DATA_ATTRIBUTE as
303  * that attribute.
304  *
305  * Example:
306  * #define TRC_CFG_RECORDER_DATA_ATTRIBUTE __attribute__((section(".bss.trace_recorder_data")))
307  *
308  * Default value is empty.
309  */
310 #define TRC_CFG_RECORDER_DATA_ATTRIBUTE
311 
312 /**
313  * @def TRC_CFG_USE_TRACE_ASSERT
314  * @brief Enable or disable debug asserts. Information regarding any assert that is
315  * triggered will be in trcAssert.c.
316  */
317 #define TRC_CFG_USE_TRACE_ASSERT 0
318 
319 #ifdef __cplusplus
320 }
321 #endif
322 
323 #endif /* _TRC_CONFIG_H */
324