]> git.sur5r.net Git - freertos/blob - FreeRTOS-Labs/Source/FreeRTOS-Plus-Trace/Include/trcRecorder.h
Add the Labs projects provided in the V10.2.1_191129 zip file.
[freertos] / FreeRTOS-Labs / Source / FreeRTOS-Plus-Trace / Include / trcRecorder.h
1 /*******************************************************************************\r
2  * Trace Recorder Library for Tracealyzer v4.1.5\r
3  * Percepio AB, www.percepio.com\r
4  *\r
5  * trcRecorder.h\r
6  *\r
7  * The public API of the trace recorder.\r
8  *\r
9  * Terms of Use\r
10  * This file is part of the trace recorder library (RECORDER), which is the \r
11  * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
12  * license as follows.\r
13  * The RECORDER may be used free of charge for the purpose of recording data\r
14  * intended for analysis in PERCEPIO products. It may not be used or modified\r
15  * for other purposes without explicit permission from PERCEPIO.\r
16  * You may distribute the RECORDER in its original source code form, assuming\r
17  * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
18  * allowed to distribute the RECORDER with minor modifications intended for\r
19  * configuration or porting of the RECORDER, e.g., to allow using it on a \r
20  * specific processor, processor family or with a specific communication\r
21  * interface. Any such modifications should be documented directly below\r
22  * this comment block.  \r
23  *\r
24  * Disclaimer\r
25  * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
26  * as to its use or performance. PERCEPIO does not and cannot warrant the \r
27  * performance or results you may obtain by using the RECORDER or documentation.\r
28  * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
29  * third party rights, merchantability, or fitness for any particular purpose.\r
30  * In no event will PERCEPIO, its technology partners, or distributors be liable\r
31  * to you for any consequential, incidental or special damages, including any\r
32  * lost profits or lost savings, even if a representative of PERCEPIO has been\r
33  * advised of the possibility of such damages, or for any claim by any third\r
34  * party. Some jurisdictions do not allow the exclusion or limitation of\r
35  * incidental, consequential or special damages, or the exclusion of implied\r
36  * warranties or limitations on how long an implied warranty may last, so the\r
37  * above limitations may not apply to you. \r
38  *\r
39  * Tabs are used for indent in this file (1 tab = 4 spaces)\r
40  *\r
41  * Copyright Percepio AB, 2018.\r
42  * www.percepio.com\r
43  ******************************************************************************/\r
44 \r
45 #ifndef TRC_RECORDER_H\r
46 #define TRC_RECORDER_H\r
47 \r
48 #ifdef __cplusplus\r
49 extern "C" {\r
50 #endif\r
51 \r
52 #include <stdint.h>\r
53 #include <stddef.h>\r
54 \r
55 #include "trcConfig.h"\r
56 #include "trcPortDefines.h"\r
57 \r
58 \r
59 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
60 typedef uint16_t traceString;\r
61 typedef uint8_t traceUBChannel;\r
62 typedef uint8_t traceObjectClass;\r
63 \r
64 #if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
65 typedef uint16_t traceHandle;\r
66 #else\r
67 typedef uint8_t traceHandle;\r
68 #endif\r
69         \r
70 #include "trcHardwarePort.h"\r
71 #include "trcKernelPort.h"\r
72 \r
73 // Not available in snapshot mode\r
74 #define vTraceConsoleChannelPrintF(fmt, ...)\r
75 \r
76 #endif\r
77         \r
78 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
79 \r
80 typedef const char* traceString;\r
81 typedef const void* traceHandle;\r
82 \r
83 #include "trcHardwarePort.h"\r
84 #include "trcStreamingPort.h"\r
85 #include "trcKernelPort.h"\r
86 \r
87 #endif\r
88 \r
89 #if (TRC_USE_TRACEALYZER_RECORDER == 1)\r
90 \r
91 /* The user event channel for recorder warnings, must be defined in trcKernelPort.c */\r
92 extern traceString trcWarningChannel;\r
93 \r
94 #define TRACE_GET_LOW16(value) ((uint16_t)((value) & 0x0000FFFF))\r
95 #define TRACE_GET_HIGH16(value) ((uint16_t)(((value) >> 16) & 0x0000FFFF))\r
96 #define TRACE_SET_LOW16(current, value)  (((current) & 0xFFFF0000) | (value))\r
97 #define TRACE_SET_HIGH16(current, value) (((current) & 0x0000FFFF) | (((uint32_t)(value)) << 16))\r
98 \r
99 /******************************************************************************/\r
100 /*** Common API - both Snapshot and Streaming mode ****************************/\r
101 /******************************************************************************/\r
102 \r
103 /******************************************************************************\r
104 * vTraceEnable(int startOption);\r
105 *\r
106 * Initializes and optionally starts the trace, depending on the start option.\r
107 * To use the trace recorder, the startup must call vTraceEnable before any RTOS\r
108 * calls are made (including "create" calls). Three start options are provided:\r
109\r
110 * TRC_START: Starts the tracing directly. In snapshot mode this allows for \r
111 * starting the trace at any point in your code, assuming vTraceEnable(TRC_INIT)\r
112 * has been called in the startup.\r
113 * Can also be used for streaming without Tracealyzer control, e.g. to a local\r
114 * flash file system (assuming such a "stream port", see trcStreamingPort.h).\r
115\r
116 * TRC_START_AWAIT_HOST: For streaming mode only. Initializes the trace recorder\r
117 * if necessary and waits for a Start command from Tracealyzer ("Start Recording"\r
118 * button). This call is intentionally blocking! By calling vTraceEnable with\r
119 * this option from the startup code, you start tracing at this point and capture\r
120 * the early events.\r
121 *\r
122 * TRC_INIT: Initializes the trace recorder, but does not start the tracing.\r
123 * In snapshot mode, this must be followed by a vTraceEnable(TRC_START) sometime\r
124 * later.\r
125 *\r
126 * Usage examples:\r
127\r
128 * Snapshot trace, from startup:\r
129 *       <board init>\r
130 *       vTraceEnable(TRC_START);\r
131 *       <RTOS init>\r
132 *\r
133 * Snapshot trace, from a later point:\r
134 *       <board init>\r
135 *       vTraceEnable(TRC_INIT);\r
136 *       <RTOS init>\r
137 *       ...\r
138 *       vTraceEnable(TRC_START); // e.g., in task context, at some relevant event\r
139\r
140 * Streaming trace, from startup:\r
141 *       <board init>    \r
142 *       vTraceEnable(TRC_START_AWAIT_HOST); // Blocks!\r
143 *       <RTOS init>\r
144 *\r
145 * Streaming trace, from a later point:\r
146 *       <board startup>\r
147 *       vTraceEnable(TRC_INIT);\r
148 *       <RTOS startup>\r
149 *       \r
150 ******************************************************************************/\r
151 void vTraceEnable(int startOption);\r
152 \r
153 /******************************************************************************\r
154  * vTracePrintF\r
155  *\r
156  * Generates "User Events", with formatted text and data, similar to a "printf".\r
157  * User Events can be used for very efficient logging from your application code.\r
158  * It is very fast since the actual string formatting is done on the host side, \r
159  * when the trace is displayed. The execution time is just some microseconds on\r
160  * a 32-bit MCU.\r
161  *\r
162  * User Events are shown as yellow labels in the main trace view of $PNAME.\r
163  *\r
164  * An advantage of User Events is that data can be plotted in the "User Event\r
165  * Signal Plot" view, visualizing any data you log as User Events, discrete\r
166  * states or control system signals (e.g. system inputs or outputs).\r
167  *\r
168  * You may group User Events into User Event Channels. The yellow User Event \r
169  * labels show the logged string, preceded by the channel name within brackets.\r
170  * \r
171  * Example:\r
172  *\r
173  *  "[MyChannel] Hello World!"\r
174  *\r
175  * The User Event Channels are shown in the View Filter, which makes it easy to\r
176  * select what User Events you wish to display. User Event Channels are created\r
177  * using xTraceRegisterString().\r
178  *\r
179  * Example:\r
180  *\r
181  *       traceString adc_uechannel = xTraceRegisterString("ADC User Events");\r
182  *       ...\r
183  *       vTracePrintF(adc_uechannel,\r
184  *                               "ADC channel %d: %d volts",\r
185  *                               ch, adc_reading);\r
186  *\r
187  * The following format specifiers are supported in both modes:\r
188  * %d - signed integer. \r
189  * %u - unsigned integer.\r
190  * %X - hexadecimal, uppercase. \r
191  * %x - hexadecimal, lowercase.\r
192  * %s - string (see comment below)\r
193  *\r
194  * For integer formats (%d, %u, %x, %X) you may also use width and padding.\r
195  * If using -42 as data argument, two examples are:\r
196  *    "%05d" -> "-0042"\r
197  *     "%5d" -> "  -42".\r
198  *\r
199  * String arguments are supported in both snapshot and streaming, but in streaming\r
200  * mode you need to use xTraceRegisterString and use the returned traceString as\r
201  * the argument. In snapshot you simply provide a char* as argument.\r
202  *\r
203  * Snapshot: vTracePrintF(myChn, "my string: %s", str);\r
204  * Streaming: vTracePrintF(myChn, "my string: %s", xTraceRegisterString(str));\r
205  * \r
206  * In snapshot mode you can specify 8-bit or 16-bit arguments to reduce RAM usage:\r
207  *     %hd -> 16 bit (h) signed integer (d).\r
208  *     %bu -> 8 bit (b) unsigned integer (u).\r
209  *\r
210  * However, in streaming mode all data arguments are assumed to be 32 bit wide. \r
211  * Width specifiers (e.g. %hd) are accepted but ignored (%hd treated like %d).\r
212  *\r
213  * The maximum event size also differs between the modes. In streaming this is\r
214  * limited by a maximum payload size of 52 bytes, including format string and\r
215  * data arguments. So if using one data argument, the format string is limited\r
216  * to 48 byte, etc. If this is exceeded,  the format string is truncated and you\r
217  * get a warning in Tracealyzer.\r
218  *\r
219  * In snapshot mode you are limited to maximum 15 arguments, that must not exceed\r
220  * 32 bytes in total (not counting the format string). If exceeded, the recorder\r
221  * logs an internal error (displayed when opening the trace) and stops recording. \r
222  ******************************************************************************/\r
223 #if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)\r
224 void vTracePrintF(traceString chn, const char* fmt, ...);\r
225 #else\r
226 #define vTracePrintF(chn, ...) (void)chn\r
227 #endif\r
228 \r
229  /******************************************************************************\r
230 * vTracePrint\r
231 *\r
232 * A faster version of vTracePrintF, that only allows for logging a string.\r
233 *\r
234 * Example:\r
235 *\r
236 *        traceString chn = xTraceRegisterString("MyChannel");\r
237 *        ...\r
238 *        vTracePrint(chn, "Hello World!");\r
239 ******************************************************************************/\r
240 #if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)\r
241 void vTracePrint(traceString chn, const char* str);\r
242 #else\r
243 #define vTracePrint(chn, ...) (void)chn\r
244 #endif\r
245 \r
246 \r
247 /*******************************************************************************\r
248 * vTraceConsoleChannelPrintF\r
249 *\r
250 * Wrapper for vTracePrint, using the default channel. Can be used as a drop-in\r
251 * replacement for printf and similar functions, e.g. in a debug logging macro.\r
252 *\r
253 * Example:\r
254 *\r
255 *        // Old: #define LogString debug_console_printf\r
256 *\r
257 *    // New, log to Tracealyzer instead:\r
258 *        #define LogString vTraceConsoleChannelPrintF \r
259 *        ...\r
260 *        LogString("My value is: %d", myValue);\r
261 ******************************************************************************/\r
262 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
263 void vTraceConsoleChannelPrintF(const char* fmt, ...);\r
264 #endif\r
265 \r
266 /*******************************************************************************\r
267 * xTraceRegisterString\r
268 *\r
269 * Register strings in the recorder, e.g. for names of user event channels.\r
270 *\r
271 * Example:\r
272 *        myEventHandle = xTraceRegisterString("MyUserEvent");\r
273 *        ...\r
274 *        vTracePrintF(myEventHandle, "My value is: %d", myValue);\r
275 ******************************************************************************/\r
276 #if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)\r
277 traceString xTraceRegisterString(const char* name);\r
278 #else\r
279 #define xTraceRegisterString(x) (x)\r
280 #endif\r
281 \r
282 /*******************************************************************************\r
283  * vTraceSet...Name(void* object, const char* name)\r
284  *\r
285  * Parameter object: pointer to the kernel object that shall be named\r
286  * Parameter name: the name to set\r
287  *\r
288  * Kernel-specific functions for setting names of kernel objects, for display in\r
289  * Tracealyzer.\r
290  ******************************************************************************/\r
291 /* See trcKernelPort.h for details (kernel-specific) */\r
292 \r
293 /*******************************************************************************\r
294  * xTraceSetISRProperties\r
295  *\r
296  * Stores a name and priority level for an Interrupt Service Routine, to allow\r
297  * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin. \r
298  *\r
299  * Example:\r
300  *       #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
301  *       ...\r
302  *       traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
303  *       ...\r
304  *       void ISR_handler()\r
305  *       {\r
306  *               vTraceStoreISRBegin(Timer1Handle);\r
307  *               ...\r
308  *               vTraceStoreISREnd(0);\r
309  *       }\r
310  ******************************************************************************/\r
311 traceHandle xTraceSetISRProperties(const char* name, uint8_t priority);\r
312 \r
313 /*******************************************************************************\r
314  * vTraceStoreISRBegin\r
315  *\r
316  * Registers the beginning of an Interrupt Service Routine, using a traceHandle\r
317  * provided by xTraceSetISRProperties.\r
318  *\r
319  * Example:\r
320  *       #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
321  *       ...\r
322  *       traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
323  *       ...\r
324  *       void ISR_handler()\r
325  *       {\r
326  *               vTraceStoreISRBegin(Timer1Handle);\r
327  *               ...\r
328  *               vTraceStoreISREnd(0);\r
329  *       }\r
330  ******************************************************************************/\r
331 void vTraceStoreISRBegin(traceHandle handle);\r
332 \r
333 /*******************************************************************************\r
334  * vTraceStoreISREnd\r
335  *\r
336  * Registers the end of an Interrupt Service Routine.\r
337  *\r
338  * The parameter pendingISR indicates if the interrupt has requested a\r
339  * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the \r
340  * interrupt is assumed to return to the previous context.\r
341  *\r
342  * Example:\r
343  *       #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
344  *       traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder\r
345  *       ...\r
346  *       traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);\r
347  *       ...\r
348  *       void ISR_handler()\r
349  *       {\r
350  *               vTraceStoreISRBegin(traceHandleIsrTimer1);\r
351  *               ...\r
352  *               vTraceStoreISREnd(0);\r
353  *       }\r
354  ******************************************************************************/\r
355 void vTraceStoreISREnd(int isTaskSwitchRequired);\r
356 \r
357 /*******************************************************************************\r
358  * vTraceInstanceFinishNow\r
359  *\r
360  * Creates an event that ends the current task instance at this very instant.\r
361  * This makes the viewer to splits the current fragment at this point and begin\r
362  * a new actor instance, even if no task-switch has occurred.\r
363  *****************************************************************************/\r
364 void vTraceInstanceFinishedNow(void);\r
365 \r
366 /*******************************************************************************\r
367  * vTraceInstanceFinishedNext\r
368  *\r
369  * Marks the current "task instance" as finished on the next kernel call.\r
370  *\r
371  * If that kernel call is blocking, the instance ends after the blocking event\r
372  * and the corresponding return event is then the start of the next instance.\r
373  * If the kernel call is not blocking, the viewer instead splits the current\r
374  * fragment right before the kernel call, which makes this call the first event\r
375  * of the next instance.\r
376  *****************************************************************************/\r
377 void vTraceInstanceFinishedNext(void);\r
378 \r
379 /*******************************************************************************\r
380  * xTraceGetLastError\r
381  *\r
382  * Returns the last error or warning as a string, or NULL if none.\r
383  *****************************************************************************/\r
384 const char* xTraceGetLastError(void);\r
385 \r
386 /*******************************************************************************\r
387  * vTraceClearError\r
388  *\r
389  * Clears any errors.\r
390  *****************************************************************************/\r
391 void vTraceClearError(void);\r
392 \r
393 /*******************************************************************************\r
394 * vTraceStop\r
395 *\r
396 * Stops the recording. Intended for snapshot mode or if streaming without \r
397 * Tracealyzer control (e.g., to a device file system).\r
398 ******************************************************************************/\r
399 void vTraceStop(void);\r
400 \r
401 /******************************************************************************\r
402 * vTraceSetFrequency\r
403 *\r
404 * Registers the clock rate of the time source for the event timestamping.\r
405 * This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)\r
406 * should be incorrect for your setup, you can override it using this function.\r
407 *\r
408 * Must be called prior to vTraceEnable, and the time source is assumed to\r
409 * have a fixed clock frequency after the startup.\r
410 *\r
411 * Note that, in snapshot mode, the value is divided by the TRC_HWTC_DIVISOR.\r
412 * This is a software "prescaler" that is also applied on the timestamps.\r
413 *****************************************************************************/\r
414 void vTraceSetFrequency(uint32_t frequency);\r
415 \r
416 /*******************************************************************************\r
417 * vTraceSetRecorderDataBuffer\r
418 *\r
419 * The trcConfig.h setting TRC_CFG_RECORDER_BUFFER_ALLOCATION allows for selecting\r
420 * custom allocation (TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), which allows you to\r
421 * control where the recorder trace buffer is allocated.\r
422 *\r
423 * When custom allocation is selected, use TRC_ALLOC_CUSTOM_BUFFER to make the\r
424 * allocation (in global context) and then call vTraceSetRecorderDataBuffer to \r
425 * register the allocated buffer. This supports both snapshot and streaming,\r
426 * and has no effect if using other allocation modes than CUSTOM. \r
427 *\r
428 * NOTE: vTraceSetRecorderDataBuffer must be called before vTraceEnable.\r
429 ******************************************************************************/\r
430 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
431 void vTraceSetRecorderDataBuffer(void* pRecorderData);\r
432 #else\r
433 #define vTraceSetRecorderDataBuffer(pRecorderData)\r
434 #endif\r
435 \r
436 \r
437 /*******************************************************************************\r
438 * TRC_ALLOC_CUSTOM_BUFFER\r
439 *\r
440 * If using custom allocation of the trace buffer (i.e., your trcConfig.h has the\r
441 * setting TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), this macro allows you to declare\r
442 * the trace buffer in a portable way that works both in snapshot and streaming.\r
443 *\r
444 * This macro has no effect if using another allocation mode, so you can easily \r
445 * switch between different recording modes and configurations, using the same \r
446 * initialization code.\r
447 *\r
448 * This translates to a single static allocation, on which you can apply linker\r
449 * directives to place it in a particular memory region.\r
450 *\r
451 * - Snapshot mode: "RecorderDataType <name>"\r
452 *\r
453 * - Streaming mode: "char <name> [<size>]", \r
454 *   where <size> is defined in trcStreamingConfig.h.\r
455 *\r
456 * Example:\r
457 *\r
458 *   // GCC example: place myTraceBuffer in section .tz, defined in the .ld file.\r
459 *   TRC_ALLOC_CUSTOM_BUFFER(myTraceBuffer) __attribute__((section(".tz")));\r
460 *   \r
461 *   int main(void)\r
462 *   {\r
463 *      ...\r
464 *      vTraceSetRecorderDataBuffer(&myTraceBuffer); // Note the "&"\r
465 *      ...\r
466 *      vTraceEnable(TRC_INIT); // Initialize the data structure\r
467 ******************************************************************************/\r
468 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
469         #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
470                 #define TRC_ALLOC_CUSTOM_BUFFER(bufname) RecorderDataType bufname;\r
471         #elif (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
472                 #ifdef TRC_CFG_RTT_BUFFER_SIZE_UP /* J-Link RTT */\r
473                         #define TRC_ALLOC_CUSTOM_BUFFER(bufname) char bufname [TRC_CFG_RTT_BUFFER_SIZE_UP];  /* Not static in this case, since declared in user code */\r
474                 #else\r
475                         #define TRC_ALLOC_CUSTOM_BUFFER(bufname) char bufname [(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];\r
476                 #endif\r
477         #endif\r
478 #else\r
479         #define TRC_ALLOC_CUSTOM_BUFFER(bufname)\r
480 #endif\r
481 \r
482 /******************************************************************************\r
483 * xTraceIsRecordingEnabled\r
484 *\r
485 * Returns true (1) if the recorder is enabled (i.e. is recording), otherwise 0.\r
486 ******************************************************************************/\r
487 int xTraceIsRecordingEnabled(void);\r
488 \r
489 /*******************************************************************************\r
490 * vTraceSetFilterGroup\r
491 *\r
492 * Sets the "filter group" to assign when creating RTOS objects, such as tasks,\r
493 * queues, semaphores and mutexes. This together with vTraceSetFilterMask \r
494 * allows you to control what events that are recorded, based on the \r
495 * objects they refer to.\r
496 *\r
497 * There are 16 filter groups named FilterGroup0 .. FilterGroup15.\r
498 *\r
499 * Note: We don't recommend filtering out the Idle task, so make sure to call \r
500 * vTraceSetFilterGroup just before initializing the RTOS, in order to assign\r
501 * such "default" objects to the right Filter Group (typically group 0).\r
502 *\r
503 * Example:\r
504 *  \r
505 *               // Assign tasks T1 to FilterGroup0 (default)\r
506 *               <Create Task T1>  \r
507 *\r
508 *               // Assign Q1 and Q2 to FilterGroup1\r
509 *               vTraceSetFilterGroup(FilterGroup1);\r
510 *               <Create Queue Q1> \r
511 *               <Create Queue Q2>\r
512 *\r
513 *               // Assigns Q3 to FilterGroup2\r
514 *               vTraceSetFilterGroup(FilterGroup2);\r
515 *               <Create Queue Q3>\r
516 *\r
517 *               // Only include FilterGroup0 and FilterGroup2, exclude FilterGroup1 (Q1 and Q2) from the trace\r
518 *               vTraceSetFilterMask( FilterGroup0 | FilterGroup2 );\r
519 *\r
520 *               // Assign the default RTOS objects (e.g. Idle task) to FilterGroup0\r
521 *               vTraceSetFilterGroup(FilterGroup0);\r
522 *               <Start the RTOS scheduler>\r
523 *\r
524 * Note that you may define your own names for the filter groups using\r
525 * preprocessor definitions, to make the code easier to understand.\r
526 *\r
527 * Example:\r
528 *\r
529 *               #define BASE FilterGroup0\r
530 *               #define USB_EVENTS FilterGroup1\r
531 *               #define CAN_EVENTS FilterGroup2\r
532 *\r
533 * Note that filtering per event type (regardless of object) is also available\r
534 * in trcConfig.h.\r
535 ******************************************************************************/\r
536 void vTraceSetFilterGroup(uint16_t filterGroup);\r
537 \r
538 /******************************************************************************\r
539 * vTraceSetFilterMask\r
540 *\r
541 * Sets the "filter mask" that is used to filter the events by object. This can\r
542 * be used to reduce the trace data rate, i.e., if your streaming interface is\r
543 * a bottleneck or if you want longer snapshot traces without increasing the\r
544 * buffer size.\r
545 *\r
546 * Note: There are two kinds of filters in the recorder. The other filter type\r
547 * excludes all events of certain kinds (e.g., OS ticks). See trcConfig.h.\r
548 *\r
549 * The filtering is based on bitwise AND with the Filter Group ID, assigned\r
550 * to RTOS objects such as tasks, queues, semaphores and mutexes. \r
551 * This together with vTraceSetFilterGroup allows you to control what\r
552 * events that are recorded, based on the objects they refer to.\r
553 *\r
554 * See example for vTraceSetFilterGroup.\r
555 ******************************************************************************/\r
556 void vTraceSetFilterMask(uint16_t filterMask);\r
557 \r
558 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
559 \r
560 /******************************************************************************/\r
561 /*** Extended API for Snapshot mode *******************************************/\r
562 /******************************************************************************/\r
563 \r
564 /******************************************************************************\r
565 * TRACE_STOP_HOOK - Hook Pointer Data Type\r
566 *\r
567 * Declares a data type for a call back function that will be invoked whenever\r
568 * the recorder is stopped.\r
569 *\r
570 * Snapshot mode only!\r
571 ******************************************************************************/\r
572 typedef void(*TRACE_STOP_HOOK)(void);\r
573 \r
574 /*******************************************************************************\r
575 * vTraceStopHookPtr\r
576 *\r
577 * Points to a call back function that is called from vTraceStop().\r
578 *\r
579 * Snapshot mode only!\r
580 ******************************************************************************/\r
581 extern TRACE_STOP_HOOK vTraceStopHookPtr;\r
582 \r
583 /*******************************************************************************\r
584 * vTraceSetStopHook\r
585 *\r
586 * Sets a function to be called when the recorder is stopped.\r
587 *\r
588 * Snapshot mode only!\r
589 ******************************************************************************/\r
590 void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction);\r
591 \r
592 /*******************************************************************************\r
593 * uiTraceStart\r
594 *\r
595 * [DEPRECATED] Use vTraceEnable instead.\r
596 *\r
597 * Starts the recorder. The recorder will not be started if an error has been\r
598 * indicated using prvTraceError, e.g. if any of the Nx constants in\r
599 * trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
600 *\r
601 * Returns 1 if the recorder was started successfully.\r
602 * Returns 0 if the recorder start was prevented due to a previous internal\r
603 * error. In that case, check xTraceGetLastError to get the error message.\r
604 * Any error message is also presented when opening a trace file.\r
605 *\r
606 * Snapshot mode only!\r
607 ******************************************************************************/\r
608 uint32_t uiTraceStart(void);\r
609 \r
610 /*******************************************************************************\r
611 * vTraceStart\r
612 *\r
613 * [DEPRECATED] Use vTraceEnable instead.\r
614 *\r
615 * Starts the recorder. The recorder will not be started if an error has been\r
616 * indicated using prvTraceError, e.g. if any of the Nx constants in\r
617 * trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
618 *\r
619 * Snapshot mode only!\r
620 ******************************************************************************/\r
621 void vTraceStart(void);\r
622 \r
623 /*******************************************************************************\r
624 * vTraceClear\r
625 *\r
626 * Resets the recorder. Only necessary if a restart is desired - this is not\r
627 * needed in the startup initialization.\r
628 *\r
629 * Snapshot mode only!\r
630 ******************************************************************************/\r
631 void vTraceClear(void);\r
632 \r
633 \r
634 /*****************************************************************************/\r
635 /*** INTERNAL SNAPSHOT FUNCTIONS *********************************************/\r
636 /*****************************************************************************/\r
637 \r
638 #define TRC_UNUSED\r
639 \r
640 #ifndef TRC_CFG_INCLUDE_OBJECT_DELETE\r
641 #define TRC_CFG_INCLUDE_OBJECT_DELETE 0\r
642 #endif\r
643 \r
644 #ifndef TRC_CFG_INCLUDE_READY_EVENTS\r
645 #define TRC_CFG_INCLUDE_READY_EVENTS 1\r
646 #endif\r
647 \r
648 #ifndef TRC_CFG_INCLUDE_OSTICK_EVENTS\r
649 #define TRC_CFG_INCLUDE_OSTICK_EVENTS 0\r
650 #endif\r
651 \r
652 /* This macro will create a task in the object table */\r
653 #undef trcKERNEL_HOOKS_TASK_CREATE\r
654 #define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \\r
655         TRACE_SET_OBJECT_NUMBER(TASK, pxTCB); \\r
656         TRACE_SET_OBJECT_FILTER(TASK, pxTCB, CurrentFilterGroup); \\r
657         prvTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \\r
658         prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
659         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
660                 if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
661                         prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
662 \r
663 /* This macro will remove the task and store it in the event buffer */\r
664 #undef trcKERNEL_HOOKS_TASK_DELETE\r
665 #define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, SERVICE_NAME, SERVICE_PROP, pxTCB) \\r
666         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
667                 if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
668                         prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
669         prvTraceStoreObjectNameOnCloseEvent(SERVICE_NAME, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
670         prvTraceStoreObjectPropertiesOnCloseEvent(SERVICE_PROP, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
671         prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
672         prvTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \\r
673         prvTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
674 \r
675 \r
676 /* This macro will setup a task in the object table */\r
677 #undef trcKERNEL_HOOKS_OBJECT_CREATE\r
678 #define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject)\\r
679         TRACE_SET_OBJECT_NUMBER(CLASS, pxObject);\\r
680         TRACE_SET_OBJECT_FILTER(CLASS, pxObject, CurrentFilterGroup); \\r
681         prvMarkObjectAsUsed(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject),  TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\\r
682         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
683                 if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \\r
684                         prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
685         prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);\r
686 \r
687 /* This macro will remove the object and store it in the event buffer */\r
688 #undef trcKERNEL_HOOKS_OBJECT_DELETE\r
689 #define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, SERVICE_NAME, SERVICE_PROP, CLASS, pxObject) \\r
690         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
691                 if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \\r
692                         prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
693         prvTraceStoreObjectNameOnCloseEvent(SERVICE_NAME, TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
694         prvTraceStoreObjectPropertiesOnCloseEvent(SERVICE_PROP, TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
695         prvTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
696 \r
697 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
698 #undef trcKERNEL_HOOKS_KERNEL_SERVICE\r
699 #define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, CLASS, pxObject) \\r
700         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
701                 if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \\r
702                         prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
703 \r
704 /* This macro will create a call to a kernel service with a certain result, with a null object as parameter */\r
705 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT\r
706 #define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT(SERVICE, TRACECLASS) \\r
707         if (TRACE_GET_TASK_FILTER(TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
708                 prvTraceStoreKernelCall(SERVICE, TRACECLASS, 0);\r
709 \r
710 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
711 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM\r
712 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(SERVICE, CLASS, pxObject, param) \\r
713         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
714                 if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \\r
715                         prvTraceStoreKernelCallWithParam(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint32_t)param);\r
716 \r
717 /* This macro will create a call to a kernel service with a certain result, with a null object and other value as parameter */\r
718 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM\r
719 #define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM(SERVICE, TRACECLASS, param) \\r
720         if (TRACE_GET_TASK_FILTER(TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
721                 prvTraceStoreKernelCallWithParam(SERVICE, TRACECLASS, 0, param);\r
722 \r
723 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
724 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY\r
725 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(SERVICE, param) \\r
726         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
727                 prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, (uint32_t)param);\r
728 \r
729 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
730 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR\r
731 #define trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(SERVICE, CLASS, pxObject) \\r
732         if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \\r
733                 prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
734 \r
735 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
736 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR\r
737 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR(SERVICE, CLASS, pxObject, param) \\r
738         if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \\r
739                 prvTraceStoreKernelCallWithParam(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint32_t)param);\r
740 \r
741 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
742 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY_FROM_ISR\r
743 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY_FROM_ISR(SERVICE, param) \\r
744         prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, (uint32_t)param);\r
745 \r
746 /* This macro will set the state for an object */\r
747 #undef trcKERNEL_HOOKS_SET_OBJECT_STATE\r
748 #define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \\r
749         prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint8_t)STATE);\r
750 \r
751 /* This macro will flag a certain task as a finished instance */\r
752 #undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED\r
753 #define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \\r
754         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
755                 prvTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));\r
756 \r
757 #if (TRC_CFG_INCLUDE_READY_EVENTS == 1)\r
758 /* This macro will create an event to indicate that a task became Ready */\r
759 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
760 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \\r
761         if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
762                 prvTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));\r
763 #else /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/\r
764 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
765 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)\r
766 #endif /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/\r
767 \r
768 /* This macro will update the internal tick counter and call prvTracePortGetTimeStamp(0) to update the internal counters */\r
769 #undef trcKERNEL_HOOKS_INCREMENT_TICK\r
770 #define trcKERNEL_HOOKS_INCREMENT_TICK() \\r
771         { \\r
772                 extern uint32_t uiTraceTickCount; \\r
773                 uiTraceTickCount++; \\r
774                 prvTracePortGetTimeStamp(0); \\r
775         }\r
776 \r
777 #if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)\r
778 /* This macro will create an event indicating that the OS tick count has increased */\r
779 #undef trcKERNEL_HOOKS_NEW_TIME\r
780 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \\r
781         prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);\r
782 #else /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/\r
783 #undef trcKERNEL_HOOKS_NEW_TIME\r
784 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)\r
785 #endif /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/\r
786 \r
787 /* This macro will create a task switch event to the currently executing task */\r
788 #undef trcKERNEL_HOOKS_TASK_SWITCH\r
789 #define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \\r
790         if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
791                 prvTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));\r
792 \r
793 /* This macro will create an event to indicate that the task has been suspended */\r
794 #undef trcKERNEL_HOOKS_TASK_SUSPEND\r
795 #define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \\r
796         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
797                 if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
798                         prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
799         prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
800 \r
801 /* This macro will create an event to indicate that a task has called a wait/delay function */\r
802 #undef trcKERNEL_HOOKS_TASK_DELAY\r
803 #define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \\r
804         if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
805         { \\r
806                 prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \\r
807                 prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB)); \\r
808         }\r
809 \r
810 /* This macro will create an event to indicate that a task has gotten its priority changed */\r
811 #undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE\r
812 #define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \\r
813         if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
814         { \\r
815                 prvTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), prvTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\\r
816                 prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority); \\r
817         }\r
818 \r
819 /* This macro will create an event to indicate that the task has been resumed */\r
820 #undef trcKERNEL_HOOKS_TASK_RESUME\r
821 #define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \\r
822         if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \\r
823                 if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
824                         prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
825 \r
826 #undef trcKERNEL_HOOKS_TASK_RESUME_FROM_ISR\r
827 #define trcKERNEL_HOOKS_TASK_RESUME_FROM_ISR(SERVICE, pxTCB) \\r
828         if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \\r
829                 prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
830 \r
831 #if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1\r
832         void prvTraceSetReadyEventsEnabled(int status);\r
833         void prvTraceStoreTaskReady(traceHandle handle);\r
834 #else\r
835         #define prvTraceSetReadyEventsEnabled(status)\r
836 #endif\r
837 \r
838 void prvTraceStoreLowPower(uint32_t flag);\r
839 \r
840 void prvTraceStoreTaskswitch(traceHandle task_handle);\r
841 \r
842 \r
843 #if (TRC_CFG_SCHEDULING_ONLY == 0)\r
844 \r
845 void prvTraceStoreKernelCall(uint32_t eventcode, traceObjectClass objectClass, uint32_t byteParam);\r
846 \r
847 void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param);\r
848 \r
849 void prvTraceStoreKernelCallWithParam(uint32_t evtcode, traceObjectClass objectClass,\r
850                                                                         uint32_t objectNumber, uint32_t param);\r
851 #else\r
852 \r
853 #define prvTraceStoreKernelCall(eventcode, objectClass, byteParam) {}\r
854 #define prvTraceStoreKernelCallWithNumericParamOnly(evtcode, param) {}\r
855 #define prvTraceStoreKernelCallWithParam(evtcode, objectClass, objectNumber, param) {}\r
856 \r
857 #endif\r
858 \r
859 void prvTraceSetTaskInstanceFinished(traceHandle handle);\r
860 \r
861 void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value);\r
862 \r
863 uint8_t prvTraceGetPriorityProperty(uint8_t objectclass, traceHandle id);\r
864 \r
865 void prvTraceSetObjectState(uint8_t objectclass, traceHandle id, uint8_t value);\r
866 \r
867 void prvMarkObjectAsUsed(traceObjectClass objectclass, traceHandle handle);\r
868 \r
869 void prvTraceStoreObjectNameOnCloseEvent(uint8_t evtcode, traceHandle handle,\r
870                                                                                 traceObjectClass objectclass);\r
871 \r
872 void prvTraceStoreObjectPropertiesOnCloseEvent(uint8_t evtcode, traceHandle handle,\r
873                                                                                          traceObjectClass objectclass);\r
874 \r
875 /* Internal constants for task state */\r
876 #define TASK_STATE_INSTANCE_NOT_ACTIVE 0\r
877 #define TASK_STATE_INSTANCE_ACTIVE 1\r
878 \r
879 \r
880 #if (TRC_CFG_INCLUDE_ISR_TRACING == 0)\r
881 \r
882 #undef vTraceSetISRProperties\r
883 #define vTraceSetISRProperties(handle, name, priority)\r
884 \r
885 #undef vTraceStoreISRBegin\r
886 #define vTraceStoreISRBegin(x) (void)x\r
887 \r
888 #undef vTraceStoreISREnd\r
889 #define vTraceStoreISREnd(x) (void)x\r
890 \r
891 #undef xTraceSetISRProperties\r
892 #define xTraceSetISRProperties(name, priority) 0\r
893 \r
894 #endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/\r
895 \r
896 /*******************************************************************************\r
897  * xTraceGetTraceBuffer\r
898  *\r
899  * Returns a pointer to the recorder data structure. Use this together with\r
900  * uiTraceGetTraceBufferSize if you wish to implement an own store/upload\r
901  * solution, e.g., in case a debugger connection is not available for uploading\r
902  * the data.\r
903  ******************************************************************************/\r
904 void* xTraceGetTraceBuffer(void);\r
905 \r
906 /*******************************************************************************\r
907  * uiTraceGetTraceBufferSize\r
908  *\r
909  * Gets the size of the recorder data structure. For use together with\r
910  * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,\r
911  * e.g., in case a debugger connection is not available for uploading the data.\r
912  ******************************************************************************/\r
913 uint32_t uiTraceGetTraceBufferSize(void);\r
914 \r
915 #if (TRC_CFG_SCHEDULING_ONLY == 1)\r
916 #undef TRC_CFG_INCLUDE_USER_EVENTS\r
917 #define TRC_CFG_INCLUDE_USER_EVENTS 0\r
918 #endif /*(TRC_CFG_SCHEDULING_ONLY == 1)*/\r
919 \r
920 #if ((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))\r
921 \r
922 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
923 traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatStr);\r
924 void vTraceUBData(traceUBChannel channel, ...);\r
925 void vTraceUBEvent(traceUBChannel channel);\r
926 #endif /*(TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)*/\r
927 \r
928 #else /*((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))*/\r
929 \r
930 #undef vTracePrint\r
931 #define vTracePrint(chn, ...) (void)chn\r
932 #undef vTracePrintF\r
933 #define vTracePrintF(chn, ...) (void)chn\r
934 #undef xTraceRegisterString\r
935 #define xTraceRegisterString(x) 0; (void)x;\r
936 #undef xTraceRegisterChannelFormat\r
937 #define xTraceRegisterChannelFormat(eventLabel, formatStr) 0\r
938 #undef vTraceUBData\r
939 #define vTraceUBData(label, ...) {}\r
940 #undef vTraceChannelPrint\r
941 #define vTraceChannelPrint(label) {}\r
942 \r
943 #endif /*(TRC_CFG_INCLUDE_USER_EVENTS == 1)*/\r
944 \r
945 #define NEventCodes 0x100\r
946 \r
947 /* Our local critical sections for the recorder */\r
948 #define trcCRITICAL_SECTION_BEGIN() {TRACE_ENTER_CRITICAL_SECTION(); recorder_busy++;}\r
949 #define trcCRITICAL_SECTION_END() {recorder_busy--; TRACE_EXIT_CRITICAL_SECTION();}\r
950 \r
951 #if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)\r
952         #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY TRACE_ALLOC_CRITICAL_SECTION\r
953         #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_BEGIN\r
954         #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_END\r
955 #else\r
956         #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY() {}\r
957         #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY() recorder_busy++;\r
958         #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY() recorder_busy--;\r
959 #endif\r
960 \r
961 /******************************************************************************\r
962  * ObjectHandleStack\r
963  * This data-structure is used to provide a mechanism for 1-byte trace object\r
964  * handles. This way, only 1 byte is necessary instead of 4 bytes (a pointer)\r
965  * when storing a reference to an object. This allows for up to 255 objects of\r
966  * each object class active at any given moment. There can be more "historic"\r
967  * objects, that have been deleted - that number is only limited by the size of\r
968  * the symbol table.\r
969  *\r
970  * Note that handle zero (0) is not used, it is a code for an invalid handle.\r
971  *\r
972  * This data structure keeps track of the FREE handles, not the handles in use.\r
973  * This data structure contains one stack per object class. When a handle is\r
974  * allocated to an object, the next free handle is popped from the stack. When\r
975  * a handle is released (on object delete), it is pushed back on the stack.\r
976  * Note that there is no initialization code that pushed the free handles\r
977  * initially, that is not necessary due to the following optimization:\r
978  *\r
979  * The stack of handles (objectHandles) is initially all zeros. Since zero\r
980  * is not a valid handle, that is a signal of additional handles needed.\r
981  * If a zero is received when popping a new handle, it is replaced by the\r
982  * index of the popped handle instead.\r
983  *****************************************************************************/\r
984 typedef struct\r
985 {\r
986         /* For each object class, the index of the next handle to allocate */\r
987         uint16_t indexOfNextAvailableHandle[ TRACE_NCLASSES ];\r
988 \r
989         /* The lowest index of this class (constant) */\r
990         uint16_t lowestIndexOfClass[ TRACE_NCLASSES ];\r
991 \r
992         /* The highest index of this class (constant) */\r
993         uint16_t highestIndexOfClass[ TRACE_NCLASSES ];\r
994 \r
995         /* The highest use count for this class (for statistics) */\r
996         uint16_t handleCountWaterMarksOfClass[ TRACE_NCLASSES ];\r
997 \r
998         /* The free object handles - a set of stacks within this array */\r
999         traceHandle objectHandles[ TRACE_KERNEL_OBJECT_COUNT ];\r
1000 \r
1001 } objectHandleStackType;\r
1002 \r
1003 extern objectHandleStackType objectHandleStacks;\r
1004 \r
1005 /******************************************************************************\r
1006  * Object Property Table\r
1007  * The Object Table contains name and other properties of the objects (tasks,\r
1008  * queues, mutexes, etc). The below data structures defines the properties of\r
1009  * each object class and are used to cast the byte buffer into a cleaner format.\r
1010  *\r
1011  * The values in the object table are continuously overwritten and always\r
1012  * represent the current state. If a property is changed during runtime, the OLD\r
1013  * value should be stored in the trace buffer, not the new value (since the new\r
1014  * value is found in the Object Property Table).\r
1015  *\r
1016  * For close events this mechanism is the old names are stored in the symbol\r
1017  * table), for "priority set" (the old priority is stored in the event data)\r
1018  * and for "isActive", where the value decides if the task switch event type\r
1019  * should be "new" or "resume".\r
1020  ******************************************************************************/\r
1021 \r
1022 typedef struct\r
1023 {\r
1024         /* = NCLASSES */\r
1025         uint32_t NumberOfObjectClasses;\r
1026 \r
1027         uint32_t ObjectPropertyTableSizeInBytes;\r
1028 \r
1029         /* This is used to calculate the index in the dynamic object table\r
1030         (handle - 1 - nofStaticObjects = index)*/\r
1031 #if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
1032         traceHandle NumberOfObjectsPerClass[2*((TRACE_NCLASSES+1)/2)];\r
1033 #else\r
1034         traceHandle NumberOfObjectsPerClass[4*((TRACE_NCLASSES+3)/4)];\r
1035 #endif\r
1036 \r
1037         /* Allocation size rounded up to the closest multiple of 4 */\r
1038         uint8_t NameLengthPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
1039 \r
1040         uint8_t TotalPropertyBytesPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
1041 \r
1042         /* Allocation size rounded up to the closest multiple of 2 */\r
1043         uint16_t StartIndexOfClass[ 2*((TRACE_NCLASSES+1)/2) ];\r
1044 \r
1045         /* The actual handles issued, should be Initiated to all zeros */\r
1046         uint8_t objbytes[ 4*((TRACE_OBJECT_TABLE_SIZE+3)/4) ];\r
1047 } ObjectPropertyTableType;\r
1048 \r
1049 /* Symbol table data structure */\r
1050 typedef struct\r
1051 {\r
1052         /* = SYMBOL_HISTORY_TABLE_SIZE_IN_BYTES */\r
1053         uint32_t symTableSize;\r
1054 \r
1055         /* Entry 0 is reserved. Any reference to entry 0 implies NULL*/\r
1056         uint32_t nextFreeSymbolIndex;\r
1057 \r
1058         /* Size rounded up to closest multiple of 4, to avoid alignment issues*/\r
1059         uint8_t symbytes[4*(((TRC_CFG_SYMBOL_TABLE_SIZE)+3)/4)];\r
1060 \r
1061         /* Used for lookups - Up to 64 linked lists within the symbol table\r
1062         connecting all entries with the same 6 bit checksum.\r
1063         This field holds the current list heads. Should be initiated to zeros */\r
1064         uint16_t latestEntryOfChecksum[64];\r
1065 } symbolTableType;\r
1066 \r
1067 \r
1068 /*******************************************************************************\r
1069  * The data structures of the different events, all 4 bytes long\r
1070  ******************************************************************************/\r
1071 \r
1072 typedef struct\r
1073 {\r
1074         uint8_t type;\r
1075         uint8_t objHandle;\r
1076         uint16_t dts;   /* differential timestamp - time since last event */\r
1077 } TSEvent, TREvent;\r
1078 \r
1079 typedef struct\r
1080 {\r
1081         uint8_t type;\r
1082         uint8_t dummy;\r
1083         uint16_t dts;   /* differential timestamp - time since last event */\r
1084 } LPEvent;\r
1085 \r
1086 typedef struct\r
1087 {\r
1088         uint8_t type;\r
1089         uint8_t objHandle;\r
1090         uint16_t dts;   /* differential timestamp - time since last event */\r
1091 } KernelCall;\r
1092 \r
1093 typedef struct\r
1094 {\r
1095         uint8_t type;\r
1096         uint8_t objHandle;\r
1097         uint8_t param;\r
1098         uint8_t dts;    /* differential timestamp - time since last event */\r
1099 } KernelCallWithParamAndHandle;\r
1100 \r
1101 typedef struct\r
1102 {\r
1103         uint8_t type;\r
1104         uint8_t dts;    /* differential timestamp - time since last event */\r
1105         uint16_t param;\r
1106 } KernelCallWithParam16;\r
1107 \r
1108 typedef struct\r
1109 {\r
1110         uint8_t type;\r
1111         uint8_t objHandle;              /* the handle of the closed object */\r
1112         uint16_t symbolIndex;   /* the name of the closed object */\r
1113 } ObjCloseNameEvent;\r
1114 \r
1115 typedef struct\r
1116 {\r
1117         uint8_t type;\r
1118         uint8_t arg1;\r
1119         uint8_t arg2;\r
1120         uint8_t arg3;\r
1121 } ObjClosePropEvent;\r
1122 \r
1123 typedef struct\r
1124 {\r
1125         uint8_t type;\r
1126         uint8_t unused1;\r
1127         uint8_t unused2;\r
1128         uint8_t dts;\r
1129 } TaskInstanceStatusEvent;\r
1130 \r
1131 typedef struct\r
1132 {\r
1133         uint8_t type;\r
1134         uint8_t dts;\r
1135         uint16_t payload;                /* the name of the user event */\r
1136 } UserEvent;\r
1137 \r
1138 typedef struct\r
1139 {\r
1140         uint8_t type;\r
1141 \r
1142         /* 8 bits extra for storing DTS, if it does not fit in ordinary event\r
1143         (this one is always MSB if used) */\r
1144         uint8_t xts_8;\r
1145 \r
1146         /* 16 bits extra for storing DTS, if it does not fit in ordinary event. */\r
1147         uint16_t xts_16;\r
1148 } XTSEvent;\r
1149 \r
1150 typedef struct\r
1151 {\r
1152         uint8_t type;\r
1153 \r
1154         uint8_t xps_8;\r
1155         uint16_t xps_16;\r
1156 } XPSEvent;\r
1157 \r
1158 typedef struct{\r
1159         uint8_t type;\r
1160         uint8_t dts;\r
1161         uint16_t size;\r
1162 } MemEventSize;\r
1163 \r
1164 typedef struct{\r
1165         uint8_t type;\r
1166         uint8_t addr_high;\r
1167         uint16_t addr_low;\r
1168 } MemEventAddr;\r
1169 \r
1170 /*******************************************************************************\r
1171  * The separate user event buffer structure. Can be enabled in trcConfig.h.\r
1172  ******************************************************************************/\r
1173 \r
1174 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
1175 typedef struct\r
1176 {\r
1177         traceString name;\r
1178         traceString defaultFormat;\r
1179 } ChannelFormatPair;\r
1180 \r
1181 typedef struct\r
1182 {\r
1183         uint16_t bufferID;\r
1184         uint16_t version;\r
1185         uint32_t wraparoundCounter;\r
1186         uint32_t numberOfSlots;\r
1187         uint32_t nextSlotToWrite;\r
1188         uint8_t numberOfChannels;\r
1189         uint8_t padding1;\r
1190         uint8_t padding2;\r
1191         uint8_t padding3;\r
1192         ChannelFormatPair channels[(TRC_CFG_UB_CHANNELS)+1];\r
1193         uint8_t channelBuffer[((TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) + 3) & 0xFFFFFFFC]; /* 1 byte per slot, with padding for 4 byte alignment */\r
1194         uint8_t dataBuffer[(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) * 4]; /* 4 bytes per slot */\r
1195 \r
1196 } UserEventBuffer;\r
1197 #endif\r
1198 \r
1199 /*******************************************************************************\r
1200  * The main data structure, read by Tracealyzer from the RAM dump\r
1201  ******************************************************************************/\r
1202 \r
1203 typedef struct\r
1204 {\r
1205         volatile uint8_t startmarker0; /* Volatile is important, see init code. */\r
1206         volatile uint8_t startmarker1;\r
1207         volatile uint8_t startmarker2;\r
1208         volatile uint8_t startmarker3;\r
1209         volatile uint8_t startmarker4;\r
1210         volatile uint8_t startmarker5;\r
1211         volatile uint8_t startmarker6;\r
1212         volatile uint8_t startmarker7;\r
1213         volatile uint8_t startmarker8;\r
1214         volatile uint8_t startmarker9;\r
1215         volatile uint8_t startmarker10;\r
1216         volatile uint8_t startmarker11;\r
1217 \r
1218         /* Used to determine Kernel and Endianess */\r
1219         uint16_t version;\r
1220 \r
1221         /* Currently 5 */\r
1222         uint8_t minor_version;\r
1223 \r
1224         /* This should be 0 if lower IRQ priority values implies higher priority\r
1225         levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,\r
1226         if higher IRQ priority values means higher priority, this should be 1. */\r
1227         uint8_t irq_priority_order;\r
1228 \r
1229         /* sizeof(RecorderDataType) - just for control */\r
1230         uint32_t filesize;\r
1231 \r
1232         /* Current number of events recorded */\r
1233         uint32_t numEvents;\r
1234 \r
1235         /* The buffer size, in number of event records */\r
1236         uint32_t maxEvents;\r
1237 \r
1238         /* The event buffer index, where to write the next event */\r
1239         uint32_t nextFreeIndex;\r
1240 \r
1241         /* 1 if the buffer is full, 0 otherwise */\r
1242         uint32_t bufferIsFull;\r
1243 \r
1244         /* The frequency of the clock/timer/counter used as time base */\r
1245         uint32_t frequency;\r
1246 \r
1247         /* The absolute timestamp of the last stored event, in the native\r
1248         timebase, modulo frequency! */\r
1249         uint32_t absTimeLastEvent;\r
1250 \r
1251         /* The number of seconds in total - lasts for 136 years */\r
1252         uint32_t absTimeLastEventSecond;\r
1253 \r
1254         /* 1 if the recorder has been started, 0 if not yet started or stopped.\r
1255         This is a 32 bit variable due to alignment issues. */\r
1256         uint32_t recorderActive;\r
1257 \r
1258         /* If > 0, tells the maximum time between two traced ISRs that execute\r
1259         back-to-back. If the time between vTraceStoreISREnd and a directly\r
1260         following vTraceISRBegin is above isrTailchainingThreshold, we assume a\r
1261         return to the previous context in between the ISRs, otherwise we assume\r
1262         the have executed back-to-back and don't show any fragment of the previous\r
1263         context in between. */ \r
1264         uint32_t isrTailchainingThreshold;\r
1265 \r
1266         /* Not used, remains for compatibility and future use */\r
1267         uint8_t notused[24];\r
1268 \r
1269         /* The amount of heap memory remaining at the last malloc or free event */\r
1270         uint32_t heapMemUsage;\r
1271 \r
1272         /* 0xF0F0F0F0 - for control only */\r
1273         int32_t debugMarker0;\r
1274 \r
1275         /* Set to value of TRC_CFG_USE_16BIT_OBJECT_HANDLES */\r
1276         uint32_t isUsing16bitHandles;\r
1277 \r
1278         /* The Object Property Table holds information about currently active\r
1279         tasks, queues, and other recorded objects. This is updated on each\r
1280         create call and includes object name and other properties. */\r
1281         ObjectPropertyTableType ObjectPropertyTable;\r
1282 \r
1283         /* 0xF1F1F1F1 - for control only */\r
1284         int32_t debugMarker1;\r
1285 \r
1286         /* The Symbol Table stores strings for User Events and is also used to\r
1287         store names of deleted objects, which still may be in the trace but no\r
1288         longer are available. */\r
1289         symbolTableType SymbolTable;\r
1290 \r
1291         /* For inclusion of float support, and for endian detection of floats.\r
1292         The value should be (float)1 or (uint32_t)0 */\r
1293 #if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)\r
1294         float exampleFloatEncoding;\r
1295 #else\r
1296         uint32_t exampleFloatEncoding;\r
1297 #endif\r
1298         /* This is non-zero if an internal error occurred in the recorder, e.g., if\r
1299         one of the Nxxx constants was too small. The systemInfo string will then\r
1300         contain an error message that is displayed when attempting to view the\r
1301         trace file. */\r
1302         uint32_t internalErrorOccured;\r
1303 \r
1304         /* 0xF2F2F2F2 - for control only */\r
1305         int32_t debugMarker2;\r
1306 \r
1307         /* Error messages from the recorder. */\r
1308         char systemInfo[80];\r
1309 \r
1310         /* 0xF3F3F3F3 - for control only */\r
1311         int32_t debugMarker3;\r
1312 \r
1313         /* The event data, in 4-byte records */\r
1314         uint8_t eventData[ (TRC_CFG_EVENT_BUFFER_SIZE) * 4 ];\r
1315 \r
1316 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
1317         UserEventBuffer userEventBuffer;\r
1318 #endif\r
1319 \r
1320         /* This should always be 0 */\r
1321         uint32_t endOfSecondaryBlocks;\r
1322 \r
1323         uint8_t endmarker0;\r
1324         uint8_t endmarker1;\r
1325         uint8_t endmarker2;\r
1326         uint8_t endmarker3;\r
1327         uint8_t endmarker4;\r
1328         uint8_t endmarker5;\r
1329         uint8_t endmarker6;\r
1330         uint8_t endmarker7;\r
1331         uint8_t endmarker8;\r
1332         uint8_t endmarker9;\r
1333         uint8_t endmarker10;\r
1334         uint8_t endmarker11;\r
1335 } RecorderDataType;\r
1336 \r
1337 extern RecorderDataType* RecorderDataPtr;\r
1338 \r
1339 /* Internal functions */\r
1340 \r
1341 /* Signal an error. */\r
1342 void prvTraceError(const char* msg);\r
1343 \r
1344 /*******************************************************************************\r
1345  * prvTracePortGetTimeStamp\r
1346  *\r
1347  * Returns the current time based on the HWTC macros which provide a hardware\r
1348  * isolation layer towards the hardware timer/counter.\r
1349  *\r
1350  * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue\r
1351  * or the trace recorder library. Typically you should not need to change\r
1352  * the code of prvTracePortGetTimeStamp if using the HWTC macros.\r
1353  *\r
1354  ******************************************************************************/\r
1355 void prvTracePortGetTimeStamp(uint32_t *puiTimestamp);\r
1356 \r
1357 traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass);\r
1358 \r
1359 void prvTraceFreeObjectHandle(traceObjectClass objectclass,\r
1360                                                         traceHandle handle);\r
1361 \r
1362 /* Private function. Use the public functions in trcKernelPort.h */\r
1363 void prvTraceSetObjectName(traceObjectClass objectclass,\r
1364                                                         traceHandle handle,\r
1365                                                         const char* name);\r
1366 \r
1367 /* Internal macros */\r
1368 \r
1369 #define TRACE_PROPERTY_NAME_GET(objectclass, objecthandle) \\r
1370 (const char*)(& RecorderDataPtr->ObjectPropertyTable.objbytes \\r
1371 [uiIndexOfObject(objecthandle, objectclass)])\r
1372 \r
1373 #define TRACE_PROPERTY_OBJECT_STATE(objectclass, handle) \\r
1374 RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
1375 + RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass]]\r
1376 \r
1377 #define TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle) \\r
1378 RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
1379 + RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass] + 1]\r
1380 \r
1381 /* DEBUG ASSERTS */\r
1382 #if defined TRC_CFG_USE_TRACE_ASSERT && TRC_CFG_USE_TRACE_ASSERT != 0\r
1383 #define TRACE_ASSERT(eval, msg, defRetVal) \\r
1384 if (!(eval)) \\r
1385 { \\r
1386         prvTraceError("TRACE_ASSERT: " msg); \\r
1387         return defRetVal; \\r
1388 }\r
1389 #else\r
1390 #define TRACE_ASSERT(eval, msg, defRetVal)\r
1391 #endif\r
1392 \r
1393 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)*/\r
1394 \r
1395 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
1396 \r
1397 /******************************************************************************\r
1398  * Default values for STREAM PORT macros\r
1399  *\r
1400  * As a normal user, this is nothing you don't need to bother about. This is\r
1401  * only important if you want to define your own custom streaming interface.\r
1402  *\r
1403  * You may override these in your own trcStreamingPort.h to create a custom\r
1404  * stream port, and thereby stream the trace on any host-target interface.\r
1405  * These default values are suitable for most cases, except the J-Link port. \r
1406  ******************************************************************************/\r
1407 \r
1408 /******************************************************************************\r
1409  * TRC_STREAM_PORT_USE_INTERNAL_BUFFER\r
1410  *\r
1411  * There are two kinds of stream ports, those that store the event to the \r
1412  * internal buffer (with periodic flushing by the TzCtrl task) and those that\r
1413  * write directly to the streaming interface. Most stream ports use the \r
1414  * recorder's internal buffer, except for the SEGGER J-Link port (also uses a\r
1415  * RAM buffer, but one defined in the SEGGER code).\r
1416  *\r
1417  * If the stream port (trcStreamingPort.h) defines this as zero (0), it is \r
1418  * expected to transmit the data directly using TRC_STREAM_PORT_COMMIT_EVENT.\r
1419  * Otherwise it is expected that the trace data is stored in the internal buffer\r
1420  * and the TzCtrl task will then send the buffer pages when they become full.\r
1421  ******************************************************************************/\r
1422 #ifndef TRC_STREAM_PORT_USE_INTERNAL_BUFFER\r
1423 #define TRC_STREAM_PORT_USE_INTERNAL_BUFFER 1\r
1424 #endif\r
1425 \r
1426  /******************************************************************************\r
1427  * TRC_STREAM_PORT_ON_TRACE_BEGIN\r
1428  *\r
1429  * Defining any actions needed in the stream port when the recording is activated.\r
1430  *******************************************************************************/\r
1431 #ifndef TRC_STREAM_PORT_ON_TRACE_BEGIN\r
1432         #define TRC_STREAM_PORT_ON_TRACE_BEGIN() /* Do nothing */\r
1433 #endif\r
1434 \r
1435  /******************************************************************************\r
1436  * TRC_STREAM_PORT_ON_TRACE_BEGIN\r
1437  *\r
1438  * Defining any actions needed in the stream port when the tracing stops.\r
1439  * Empty by default.\r
1440  *******************************************************************************/\r
1441 #ifndef TRC_STREAM_PORT_ON_TRACE_END\r
1442 #define TRC_STREAM_PORT_ON_TRACE_END() /* Do nothing */\r
1443 #endif\r
1444 \r
1445  /******************************************************************************\r
1446  * TRC_STREAM_PORT_ALLOCATE_EVENT\r
1447  *\r
1448  * This macro is used to allocate memory for each event record, just before\r
1449  * assigning the record fields.\r
1450  * Depending on "TRC_STREAM_PORT_USE_INTERNAL_BUFFER", this either allocates\r
1451  * space in the paged event buffer, or on the local stack. In the latter case,\r
1452  * the COMMIT event is used to write the data to the streaming interface.\r
1453  ******************************************************************************/\r
1454 #ifndef TRC_STREAM_PORT_ALLOCATE_EVENT\r
1455 #if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)\r
1456         #define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type* _ptrData; _ptrData = (_type*)prvPagedEventBufferGetWritePointer(_size);\r
1457 #else\r
1458         #define TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) _type _tmpArray[_size / sizeof(_type)]; _type* _ptrData = _tmpArray;\r
1459 #endif\r
1460 #endif\r
1461 \r
1462  /******************************************************************************\r
1463  * TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT\r
1464  *\r
1465  * This macro is used to allocate memory for each event record, just before\r
1466  * assigning the record fields. \r
1467  * This has the same purpose as TRC_STREAM_PORT_ALLOCATE_EVENT and by default\r
1468  * it has the same definition as TRC_STREAM_PORT_ALLOCATE_EVENT. This is used\r
1469  * for events carrying variable-sized payload, such as strings.\r
1470  * In the SEGGER RTT port, we need this in order to make a worst-case\r
1471  * allocation on the stack. \r
1472  ******************************************************************************/\r
1473 #ifndef TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT\r
1474 #if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)\r
1475         #define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) TRC_STREAM_PORT_ALLOCATE_EVENT(_type, _ptrData, _size) /* We do the same thing as for non-dynamic event sizes */\r
1476 #else\r
1477         #define TRC_STREAM_PORT_ALLOCATE_DYNAMIC_EVENT(_type, _ptrData, _size) _type _tmpArray[sizeof(largestEventType) / sizeof(_type)]; _type* _ptrData = _tmpArray;\r
1478 #endif\r
1479 #endif\r
1480 \r
1481  /******************************************************************************\r
1482  * TRC_STREAM_PORT_COMMIT_EVENT\r
1483  *\r
1484  * The COMMIT macro is used to write a single event record directly to the \r
1485  * streaming inteface, without first storing the event in the internal buffer.\r
1486  * This is currently only used in the SEGGER J-Link RTT port. \r
1487  *\r
1488  * This relies on the TRC_STREAM_PORT_WRITE_DATA macro, defined in by the \r
1489  * stream port in trcStreamingPort.h. The COMMIT macro calls \r
1490  * prvTraceWarning(TRC_STREAM_PORT_WRITE_DATA) if a non-zero value is returned\r
1491  * from TRC_STREAM_PORT_WRITE_DATA. If zero (0) is returned, it is assumed \r
1492  * that all data was successfully written.\r
1493  *\r
1494  * In ports using the internal buffer, this macro has no purpose as the events\r
1495  * are written to the internal buffer instead. They are then flushed to the\r
1496  * streaming interface in the TzCtrl task using TRC_STREAM_PORT_WRITE_DATA.\r
1497  ******************************************************************************/\r
1498 #ifndef TRC_STREAM_PORT_COMMIT_EVENT\r
1499 #if (TRC_STREAM_PORT_USE_INTERNAL_BUFFER == 1)\r
1500         #define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) /* Not used */\r
1501 #else\r
1502         #define TRC_STREAM_PORT_COMMIT_EVENT(_ptrData, _size) \\r
1503         { \\r
1504          if (TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, 0) != 0)\\r
1505                 prvTraceWarning(PSF_WARNING_STREAM_PORT_WRITE); \\r
1506         }\r
1507 #endif\r
1508 #endif\r
1509 \r
1510 /******************************************************************************\r
1511  * TRC_STREAM_PORT_READ_DATA (defined in trcStreamingPort.h)\r
1512  *\r
1513  * Defining how to read data from host (commands from Tracealyzer).\r
1514  *\r
1515  * If there is no direct interface to host (e.g., if streaming to a file\r
1516  * system) this should be defined as 0. Instead use vTraceEnable(TRC_START) and\r
1517  * vTraceStop() to control the recording from target.\r
1518  *\r
1519  * Parameters:\r
1520  *\r
1521  * - _ptrData: a pointer to a data buffer, where the received data shall be \r
1522  *             stored (TracealyzerCommandType*).\r
1523  *\r
1524  * - _size: the number of bytes to read (int).\r
1525  *\r
1526  * - _ptrBytesRead: a pointer to an integer (int), that should be assigned\r
1527  *                                      with the number of bytes that was received.\r
1528  *\r
1529  * Example:\r
1530  * \r
1531  *      int32_t myRead(void* ptrData, uint32_t size, int32_t* ptrBytesRead);\r
1532  * \r
1533  *      #define TRC_STREAM_PORT_READ_DATA(_ptrData, _size, _ptrBytesRead) \\r
1534  *          myRead(_ptrData, _size, _ptrBytesRead)\r
1535  *\r
1536  * Your "myRead" function should return 0 if successful, i.e. if at least some \r
1537  * bytes were received. A non-zero value should be returned if the streaming\r
1538  * interface returned an error (e.g. a closed socket), which results in the\r
1539  * recorder calling prvTraceWarning with the error code \r
1540  * PSF_WARNING_STREAM_PORT_WRITE.\r
1541  *\r
1542  * If developing your own custom stream port and using the default internal\r
1543  * buffer, it is important that the _ptrBytesRead parameter is assigned\r
1544  * correctly by "myRead", i.e. with the number of bytes actually written. \r
1545  * Otherwise the data stream may get out of sync in case the streaming interface\r
1546  * can't swallow all data at once. \r
1547  ******************************************************************************/\r
1548 #ifndef TRC_STREAM_PORT_READ_DATA\r
1549 #error "No definition for TRC_STREAM_PORT_READ_DATA (should be in trcStreamingPort.h)"\r
1550 #endif\r
1551 \r
1552 /******************************************************************************\r
1553  * TRC_STREAM_PORT_WRITE_DATA (defined in trcStreamingPort.h)\r
1554  *\r
1555  * Defining how to write trace data to the streaming interface. \r
1556  *\r
1557  * Parameters:\r
1558  *\r
1559  * - _ptrData: a pointer (void*) to the data to write.\r
1560  *\r
1561  * - _size: the number of bytes to write (uint32_t).\r
1562  *\r
1563  * - _ptrBytesWritten: a pointer to an integer (int32_t), that should be\r
1564  *                                              assigned with the number of bytes actually written.\r
1565  *\r
1566  * Example:\r
1567  *\r
1568  *      int32_t myWrite(void* ptrData, uint32_t size, int32_t* ptrBytesWritten);\r
1569  *\r
1570  *      #define TRC_STREAM_PORT_WRITE_DATA(_ptrData, _size, _ptrBytesWritten) \\r
1571  *                      myWrite(_ptrData, _size, _ptrBytesWritten) \r
1572  *  \r
1573  * Your "myWrite" function should return 0 if successful, i.e. if at least some \r
1574  * bytes were sent. A non-zero value should be returned if the streaming interface\r
1575  * returned an error (e.g. a closed socket), which results in the recorder calling\r
1576  * prvTraceWarning with the error code PSF_WARNING_STREAM_PORT_WRITE.\r
1577  * \r
1578  * If developing your own custom stream port and using the default internal\r
1579  * buffer, it is important that the _ptrBytesWritten parameter is assigned\r
1580  * correctly by "myWrite", i.e. with the number of bytes actually written. \r
1581  * Otherwise the data stream may get out of sync in case the streaming interface\r
1582  * can't swallow all data at once.\r
1583  *\r
1584  * Assuming TRC_STREAM_PORT_USE_INTERNAL_BUFFER is 1 (default), the TzCtrl task\r
1585  * will use this macro to send one buffer page at a time. In case all data can't\r
1586  * be written at once (if _ptrBytesWritten is less than _size), the TzCtrl task\r
1587  * is smart enough to make repeated calls (with updated parameters) in order to \r
1588  * send the remaining data.\r
1589  * \r
1590  * However, if TRC_STREAM_PORT_USE_INTERNAL_BUFFER is 0, this is used from the\r
1591  * COMMIT macro, directly in the "event functions". In that case, the\r
1592  * _ptrBytesWritten parameter will be NULL and should be ignored by the write\r
1593  * function. In this case, it is assumed that all data can be sent in a single\r
1594  * call, otherwise the write function should return a non-zero error code.\r
1595  ******************************************************************************/\r
1596 #ifndef TRC_STREAM_PORT_WRITE_DATA\r
1597 #error "No definition for TRC_STREAM_PORT_WRITE_DATA (should be in trcStreamingPort.h)"\r
1598 #endif\r
1599 \r
1600 /******************************************************************************\r
1601 * Data structure declaration, depending on  TRC_CFG_RECORDER_BUFFER_ALLOCATION\r
1602 *******************************************************************************/\r
1603 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC)\r
1604         \r
1605         /* Static allocation. */\r
1606         \r
1607         /* If not defined in trcStreamingPort.h */\r
1608         #ifndef TRC_STREAM_PORT_ALLOCATE_FIELDS\r
1609                 #define TRC_STREAM_PORT_ALLOCATE_FIELDS() \\r
1610                 char _TzTraceData[(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];            \r
1611                 extern char _TzTraceData[(TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE)];\r
1612         #endif\r
1613         \r
1614         /* If not defined in trcStreamingPort.h */\r
1615         #ifndef TRC_STREAM_PORT_MALLOC\r
1616                 #define TRC_STREAM_PORT_MALLOC() /* Static allocation. Not used. */\r
1617         #endif\r
1618 #else\r
1619         /* For Dynamic or Custom Allocation mode */\r
1620         \r
1621         /* If not defined in trcStreamingPort.h */\r
1622         #ifndef TRC_STREAM_PORT_ALLOCATE_FIELDS\r
1623                 #define TRC_STREAM_PORT_ALLOCATE_FIELDS() char* _TzTraceData = NULL;\r
1624                 extern char* _TzTraceData;\r
1625         #endif\r
1626         \r
1627         /* If not defined in trcStreamingPort.h */\r
1628         #ifndef TRC_STREAM_PORT_MALLOC\r
1629                 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_DYNAMIC)\r
1630                         #define TRC_STREAM_PORT_MALLOC() \\r
1631                         _TzTraceData = TRC_PORT_MALLOC((TRC_CFG_PAGED_EVENT_BUFFER_PAGE_COUNT) * (TRC_CFG_PAGED_EVENT_BUFFER_PAGE_SIZE));\r
1632                         extern char* _TzTraceData;\r
1633                 #else\r
1634                         #define TRC_STREAM_PORT_MALLOC()  /* Custom allocation. Not used. */\r
1635                 #endif\r
1636         #endif\r
1637 #endif\r
1638 \r
1639 #ifndef TRC_STREAM_PORT_INIT\r
1640         #define TRC_STREAM_PORT_INIT() \\r
1641                         TRC_STREAM_PORT_MALLOC(); /* Empty if static allocation mode */ \\r
1642                         prvPagedEventBufferInit(_TzTraceData);\r
1643 #endif\r
1644 \r
1645 \r
1646 /* Signal an error. */\r
1647 void prvTraceError(int errCode);\r
1648 \r
1649 /* Signal an warning (does not stop the recorder). */\r
1650 void prvTraceWarning(int errCode);\r
1651 \r
1652 /******************************************************************************/\r
1653 /*** ERROR AND WARNING CODES (check using xTraceGetLastError) *****************/\r
1654 /******************************************************************************/\r
1655 \r
1656 #define PSF_ERROR_NONE 0\r
1657 #define PSF_ERROR_EVENT_CODE_TOO_LARGE 1\r
1658 #define PSF_ERROR_ISR_NESTING_OVERFLOW 2\r
1659 #define PSF_ERROR_DWT_NOT_SUPPORTED 3\r
1660 #define PSF_ERROR_DWT_CYCCNT_NOT_SUPPORTED 4\r
1661 #define PSF_ERROR_TZCTRLTASK_NOT_CREATED 5\r
1662 \r
1663 #define PSF_WARNING_SYMBOL_TABLE_SLOTS 101\r
1664 #define PSF_WARNING_SYMBOL_MAX_LENGTH 102\r
1665 #define PSF_WARNING_OBJECT_DATA_SLOTS 103\r
1666 #define PSF_WARNING_STRING_TOO_LONG 104\r
1667 #define PSF_WARNING_STREAM_PORT_READ 105\r
1668 #define PSF_WARNING_STREAM_PORT_WRITE 106\r
1669 \r
1670 /******************************************************************************/\r
1671 /*** INTERNAL STREAMING FUNCTIONS *********************************************/\r
1672 /******************************************************************************/\r
1673 \r
1674 /* Saves a symbol name (task name etc.) in symbol table */\r
1675 void prvTraceSaveSymbol(const void *address, const char *name);\r
1676 \r
1677 /* Deletes a symbol name (task name etc.) from symbol table */\r
1678 void prvTraceDeleteSymbol(void *address);\r
1679 \r
1680 /* Saves an object data entry (task base priority) in object data table */\r
1681 void prvTraceSaveObjectData(const void *address, uint32_t data);\r
1682 \r
1683 /* Removes an object data entry (task base priority) from object data table */\r
1684 void prvTraceDeleteObjectData(void *address);\r
1685 \r
1686 /* Store an event with zero parameters (event ID only) */\r
1687 void prvTraceStoreEvent0(uint16_t eventID);\r
1688 \r
1689 /* Store an event with one 32-bit parameter (pointer address or an int) */\r
1690 void prvTraceStoreEvent1(uint16_t eventID,\r
1691         uint32_t param1);\r
1692 \r
1693 /* Store an event with two 32-bit parameters */\r
1694 void prvTraceStoreEvent2(uint16_t eventID,\r
1695         uint32_t param1,\r
1696         uint32_t param2);\r
1697 \r
1698 /* Store an event with three 32-bit parameters */\r
1699 void prvTraceStoreEvent3(uint16_t eventID,\r
1700         uint32_t param1,\r
1701         uint32_t param2,\r
1702         uint32_t param3);\r
1703 \r
1704 /* Stores an event with <nParam> 32-bit integer parameters */\r
1705 void prvTraceStoreEvent(int nParam, uint16_t EventID, ...);\r
1706 \r
1707 /* Stories an event with a string and <nParam> 32-bit integer parameters */\r
1708 void prvTraceStoreStringEvent(int nArgs, uint16_t eventID, const char* str, ...);\r
1709 \r
1710 /* Initializes the paged event buffer used by certain stream ports */\r
1711 void prvPagedEventBufferInit(char* buffer);\r
1712 \r
1713 /* Retrieve a pointer to the paged event buffer */\r
1714 void* prvPagedEventBufferGetWritePointer(int sizeOfEvent);\r
1715 \r
1716 /* Transfer a full buffer page */\r
1717 uint32_t prvPagedEventBufferTransfer(void);\r
1718 \r
1719 /* The data structure for commands (a bit overkill) */\r
1720 typedef struct\r
1721 {\r
1722         unsigned char cmdCode;\r
1723         unsigned char param1;\r
1724         unsigned char param2;\r
1725         unsigned char param3;\r
1726         unsigned char param4;\r
1727         unsigned char param5;\r
1728         unsigned char checksumLSB;\r
1729         unsigned char checksumMSB;\r
1730 } TracealyzerCommandType;\r
1731 \r
1732 /* Checks if the provided command is a valid command */\r
1733 int prvIsValidCommand(TracealyzerCommandType* cmd);\r
1734 \r
1735 /* Executed the received command (Start or Stop) */\r
1736 void prvProcessCommand(TracealyzerCommandType* cmd);\r
1737 \r
1738 #define vTraceSetStopHook(x)\r
1739 \r
1740 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r
1741 \r
1742 #else /* when TRC_USE_TRACEALYZER_RECORDER == 0 */\r
1743 \r
1744 #define vTraceEnable(x)\r
1745 #define xTraceRegisterString(x) 0; (void)x;\r
1746 #define vTracePrint(chn, ...) (void)chn\r
1747 #define vTracePrintF(chn, ...) (void)chn\r
1748 #define vTraceInstanceFinishedNow()\r
1749 #define vTraceInstanceFinishedNext()\r
1750 #define vTraceStoreISRBegin(x) (void)x\r
1751 #define vTraceStoreISREnd(x) (void)x\r
1752 #define xTraceSetISRProperties(a, b) 0\r
1753 #define vTraceStoreKernelObjectName(a, b)\r
1754 #define xTraceRegisterChannelFormat(eventLabel, formatStr) 0\r
1755 #define vTraceChannelPrint(label)\r
1756 #define vTraceUBData(label, ...)\r
1757 \r
1758 #define vTraceSetFilterGroup(x)\r
1759 #define vTraceSetFilterMask(x)\r
1760 \r
1761 #define prvTraceSetReadyEventsEnabled(status)\r
1762 \r
1763 #define vTraceExcludeTask(handle)\r
1764 \r
1765 #define uiTraceStart() (1)\r
1766 #define vTraceStart()\r
1767 #define vTraceStop()\r
1768 \r
1769 #ifndef vTraceSetRecorderDataBuffer\r
1770 #define vTraceSetRecorderDataBuffer(pRecorderData)\r
1771 #endif\r
1772 \r
1773 #define vTraceConsoleChannelPrintF(fmt, ...)\r
1774 \r
1775 #ifndef TRC_ALLOC_CUSTOM_BUFFER\r
1776 #define TRC_ALLOC_CUSTOM_BUFFER(bufname)\r
1777 #endif\r
1778 \r
1779 #define xTraceIsRecordingEnabled() (0)\r
1780 \r
1781 #define vTraceSetStopHook(x)\r
1782 \r
1783 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
1784 \r
1785 #ifdef __cplusplus\r
1786 }\r
1787 #endif\r
1788 \r
1789 #endif /* TRC_RECORDER_H */\r