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