]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include/trcRecorder.h
Update to the latest trace recorder library.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace / Include / trcRecorder.h
1 /*******************************************************************************\r
2  * Trace Recorder Library for Tracealyzer v3.1.2\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, 2017.\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 "trcConfig.h"\r
55 #include "trcPortDefines.h"\r
56 \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 /******************************************************************************/\r
89 /*** Common API - both Snapshot and Streaming mode ****************************/\r
90 /******************************************************************************/\r
91 \r
92 /******************************************************************************\r
93 * vTraceEnable(int startOption);\r
94 *\r
95 * Initializes and optionally starts the trace, depending on the start option.\r
96 * To use the trace recorder, the startup must call vTraceEnable before any RTOS\r
97 * calls are made (including "create" calls). Three start options are provided:\r
98\r
99 * TRC_START: Starts the tracing directly. In snapshot mode this allows for \r
100 * starting the trace at any point in your code, assuming vTraceEnable(TRC_INIT)\r
101 * has been called in the startup.\r
102 * Can also be used for streaming without Tracealyzer control, e.g. to a local\r
103 * flash file system (assuming such a "stream port", see trcStreamingPort.h).\r
104\r
105 * TRC_START_AWAIT_HOST: For streaming mode only. Initializes the trace recorder\r
106 * if necessary and waits for a Start command from Tracealyzer ("Start Recording"\r
107 * button). This call is intentionally blocking! By calling vTraceEnable with\r
108 * this option from the startup code, you start tracing at this point and capture\r
109 * the early events.\r
110 *\r
111 * TRC_INIT: Initializes the trace recorder, but does not start the tracing.\r
112 * In snapshot mode, this must be followed by a vTraceEnable(TRC_START) sometime\r
113 * later.\r
114 *\r
115 * Usage examples:\r
116\r
117 * Snapshot trace, from startup:\r
118 *       <board init>\r
119 *       vTraceEnable(TRC_START);\r
120 *       <RTOS init>\r
121 *\r
122 * Snapshot trace, from a later point:\r
123 *       <board init>\r
124 *       vTraceEnable(TRC_INIT);\r
125 *       <RTOS init>\r
126 *       ...\r
127 *       vTraceEnable(TRC_START); // e.g., in task context, at some relevant event\r
128\r
129 * Streaming trace, from startup:\r
130 *       <board init>    \r
131 *       vTraceEnable(TRC_START_AWAIT_HOST); // Blocks!\r
132 *       <RTOS init>\r
133 *\r
134 * Streaming trace, from a later point:\r
135 *       <board startup>\r
136 *       vTraceEnable(TRC_INIT);\r
137 *       <RTOS startup>\r
138 *       \r
139 ******************************************************************************/\r
140 void vTraceEnable(int startOption);\r
141 \r
142 /******************************************************************************\r
143  * vTracePrintF\r
144  *\r
145  * Generates "User Events", with formatted text and data, similar to a "printf".\r
146  * User Events can be used for very efficient logging from your application code.\r
147  * It is very fast since the actual string formatting is done on the host side, \r
148  * when the trace is displayed. The execution time is just some microseconds on\r
149  * a 32-bit MCU.\r
150  *\r
151  * User Events are shown as yellow labels in the main trace view of $PNAME.\r
152  *\r
153  * An advantage of User Events is that data can be plotted in the "User Event\r
154  * Signal Plot" view, visualizing any data you log as User Events, discrete\r
155  * states or control system signals (e.g. system inputs or outputs).\r
156  *\r
157  * You may group User Events into User Event Channels. The yellow User Event \r
158  * labels show the logged string, preceded by the channel name within brackets.\r
159  * \r
160  * Example:\r
161  *\r
162  *  "[MyChannel] Hello World!"\r
163  *\r
164  * The User Event Channels are shown in the View Filter, which makes it easy to\r
165  * select what User Events you wish to display. User Event Channels are created\r
166  * using xTraceRegisterString().\r
167  *\r
168  * Example:\r
169  *\r
170  *       traceString adc_uechannel = xTraceRegisterString("ADC User Events");\r
171  *       ...\r
172  *       vTracePrintF(adc_uechannel,\r
173  *                               "ADC channel %d: %d volts",\r
174  *                               ch, adc_reading);\r
175  *\r
176  * The following format specifiers are supported in both modes:\r
177  * %d - signed integer. \r
178  * %u - unsigned integer.\r
179  * %X - hexadecimal, uppercase. \r
180  * %x - hexadecimal, lowercase.\r
181  * %s - string (see comment below)\r
182  *\r
183  * For integer formats (%d, %u, %x, %X) you may also use width and padding.\r
184  * If using -42 as data argument, two examples are:\r
185  *    "%05d" -> "-0042"\r
186  *     "%5d" -> "  -42".\r
187  *\r
188  * String arguments are supported in both snapshot and streaming, but in streaming\r
189  * mode you need to use xTraceRegisterString and use the returned traceString as\r
190  * the argument. In snapshot you simply provide a char* as argument.\r
191  *\r
192  * Snapshot: vTracePrintF(myChn, "my string: %s", str);\r
193  * Streaming: vTracePrintF(myChn, "my string: %s", xTraceRegisterString(str));\r
194  * \r
195  * In snapshot mode you can specify 8-bit or 16-bit arguments to reduce RAM usage:\r
196  *     %hd -> 16 bit (h) signed integer (d).\r
197  *     %bu -> 8 bit (b) unsigned integer (u).\r
198  *\r
199  * However, in streaming mode all data arguments are assumed to be 32 bit wide. \r
200  * Width specifiers (e.g. %hd) are accepted but ignored (%hd treated like %d).\r
201  *\r
202  * The maximum event size also differs between the modes. In streaming this is\r
203  * limited by a maximum payload size of 52 bytes, including format string and\r
204  * data arguments. So if using one data argument, the format string is limited\r
205  * to 48 byte, etc. If this is exceeded,  the format string is truncated and you\r
206  * get a warning in Tracealyzer.\r
207  *\r
208  * In snapshot mode you are limited to maximum 15 arguments, that must not exceed\r
209  * 32 bytes in total (not counting the format string). If exceeded, the recorder\r
210  * logs an internal error (displayed when opening the trace) and stops recording. \r
211  *\r
212  ******************************************************************************/\r
213 void vTracePrintF(traceString chn, const char* fmt, ...);\r
214 \r
215 /******************************************************************************\r
216 * vTracePrint\r
217 *\r
218 * A faster version of vTracePrintF, that only allows for logging a string.\r
219 *\r
220 * Example:\r
221 *\r
222 *        traceString chn = xTraceRegisterString("MyChannel");\r
223 *        ...\r
224 *        vTracePrint(chn, "Hello World!");\r
225 *\r
226 ******************************************************************************/\r
227 void vTracePrint(traceString chn, const char* str);\r
228 \r
229 /*******************************************************************************\r
230 * xTraceRegisterString\r
231 *\r
232 * Register strings in the recorder, e.g. for names of user event channels.\r
233 *\r
234 * Example:\r
235 *        myEventHandle = xTraceRegisterString("MyUserEvent");\r
236 *        ...\r
237 *        vTracePrintF(myEventHandle, "My value is: %d", myValue);\r
238 *\r
239 ******************************************************************************/\r
240 traceString xTraceRegisterString(const char* name);\r
241 \r
242 /*******************************************************************************\r
243  * vTraceSet...Name(void* object, const char* name)\r
244  *\r
245  * Parameter object: pointer to the kernel object that shall be named\r
246  * Parameter name: the name to set\r
247  *\r
248  * Kernel-specific functions for setting names of kernel objects, for display in\r
249  * Tracealyzer.\r
250  *\r
251  * See trcKernelPort.h for details (since kernel-specific)\r
252  ******************************************************************************/\r
253 \r
254 /*******************************************************************************\r
255  * vTraceExclude... \r
256  *\r
257  * Kernel-specific macros for excluding specified events from the trace. Allows \r
258  * for capturing longer traces in snapshot mode by selective tracing.\r
259  *\r
260  * See trcKernelPort.h for details (kernel-specific)\r
261  ******************************************************************************/ \r
262 \r
263 /*******************************************************************************\r
264  * xTraceSetISRProperties\r
265  *\r
266  * Stores a name and priority level for an Interrupt Service Routine, to allow\r
267  * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin. \r
268  *\r
269  * Example:\r
270  *       #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
271  *       ...\r
272  *       traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
273  *       ...\r
274  *       void ISR_handler()\r
275  *       {\r
276  *               vTraceStoreISRBegin(Timer1Handle);\r
277  *               ...\r
278  *               vTraceStoreISREnd(0);\r
279  *       }\r
280  *\r
281  ******************************************************************************/\r
282 traceHandle xTraceSetISRProperties(const char* name, uint8_t priority);\r
283 \r
284 /*******************************************************************************\r
285  * vTraceStoreISRBegin\r
286  *\r
287  * Registers the beginning of an Interrupt Service Routine, using a traceHandle\r
288  * provided by xTraceSetISRProperties.\r
289  *\r
290  * Example:\r
291  *       #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
292  *       ...\r
293  *       traceHandle Timer1Handle = xTraceSetISRProperties("ISRTimer1", PRIO_ISR_TIMER1);\r
294  *       ...\r
295  *       void ISR_handler()\r
296  *       {\r
297  *               vTraceStoreISRBegin(Timer1Handle);\r
298  *               ...\r
299  *               vTraceStoreISREnd(0);\r
300  *       }\r
301  *\r
302  ******************************************************************************/\r
303 void vTraceStoreISRBegin(traceHandle handle);\r
304 \r
305 /*******************************************************************************\r
306  * vTraceStoreISREnd\r
307  *\r
308  * Registers the end of an Interrupt Service Routine.\r
309  *\r
310  * The parameter pendingISR indicates if the interrupt has requested a\r
311  * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the \r
312  * interrupt is assumed to return to the previous context.\r
313  *\r
314  * Example:\r
315  *       #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt\r
316  *       traceHandle traceHandleIsrTimer1 = 0; // The ID set by the recorder\r
317  *       ...\r
318  *       traceHandleIsrTimer1 = xTraceSetISRProperties("ISRTimer1", PRIO_OF_ISR_TIMER1);\r
319  *       ...\r
320  *       void ISR_handler()\r
321  *       {\r
322  *               vTraceStoreISRBegin(traceHandleIsrTimer1);\r
323  *               ...\r
324  *               vTraceStoreISREnd(0);\r
325  *       }\r
326  *\r
327  ******************************************************************************/\r
328 void vTraceStoreISREnd(int isTaskSwitchRequired);\r
329 \r
330 /*******************************************************************************\r
331  * vTraceInstanceFinishNow\r
332  *\r
333  * Creates an event that ends the current task instance at this very instant.\r
334  * This makes the viewer to splits the current fragment at this point and begin\r
335  * a new actor instance, even if no task-switch has occurred.\r
336  *****************************************************************************/\r
337 void vTraceInstanceFinishedNow(void);\r
338 \r
339 /*******************************************************************************\r
340  * vTraceInstanceFinishedNext\r
341  *\r
342  * Marks the current "task instance" as finished on the next kernel call.\r
343  *\r
344  * If that kernel call is blocking, the instance ends after the blocking event\r
345  * and the corresponding return event is then the start of the next instance.\r
346  * If the kernel call is not blocking, the viewer instead splits the current\r
347  * fragment right before the kernel call, which makes this call the first event\r
348  * of the next instance.\r
349  *****************************************************************************/\r
350 void vTraceInstanceFinishedNext(void);\r
351 \r
352 /*******************************************************************************\r
353  * xTraceGetLastError\r
354  *\r
355  * Returns the last error, if any.\r
356  *****************************************************************************/\r
357 const char* xTraceGetLastError(void);\r
358 \r
359 /*******************************************************************************\r
360  * vTraceClearError\r
361  *\r
362  * Clears any errors.\r
363  *****************************************************************************/\r
364 void vTraceClearError(void);\r
365 \r
366 /*******************************************************************************\r
367 * vTraceStop\r
368 *\r
369 * Stops the recording. Intended for snapshot mode or if streaming without \r
370 * Tracealyzer control (e.g., to a device file system).\r
371 ******************************************************************************/\r
372 void vTraceStop(void);\r
373 \r
374 /******************************************************************************\r
375 * vTraceSetFrequency\r
376 *\r
377 * Registers the clock rate of the time source for the event timestamping.\r
378 * This is normally not required, but if the default value (TRC_HWTC_FREQ_HZ)\r
379 * should be incorrect for your setup, you can override it using this function.\r
380 *\r
381 * Must be called prior to vTraceEnable, and the time source is assumed to\r
382 * have a fixed clock frequency after the startup.\r
383 *\r
384 * Note that, in snapshot mode, the value is divided by the TRC_HWTC_DIVISOR.\r
385 * This is a software "prescaler" that is also applied on the timestamps.\r
386 *****************************************************************************/\r
387 void vTraceSetFrequency(uint32_t frequency);\r
388 \r
389 /*******************************************************************************\r
390 * vTraceSetRecorderDataBuffer\r
391 *\r
392 * The trcConfig.h setting TRC_CFG_RECORDER_BUFFER_ALLOCATION allows for selecting\r
393 * custom allocation (TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), which allows you to\r
394 * control where the recorder trace buffer is allocated.\r
395 *\r
396 * When custom allocation is selected, use TRC_ALLOC_CUSTOM_BUFFER to make the\r
397 * allocation (in global context) and then call vTraceSetRecorderDataBuffer to \r
398 * register the allocated buffer. This supports both snapshot and streaming,\r
399 * and has no effect if using other allocation modes than CUSTOM. \r
400 *\r
401 * NOTE: vTraceSetRecorderDataBuffer must be called before vTraceEnable.\r
402 ******************************************************************************/\r
403 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
404 void vTraceSetRecorderDataBuffer(void* pRecorderData);\r
405 #else\r
406 #define vTraceSetRecorderDataBuffer(pRecorderData)\r
407 #endif\r
408 \r
409 \r
410 /*******************************************************************************\r
411 * TRC_ALLOC_CUSTOM_BUFFER\r
412 *\r
413 * If using custom allocation of the trace buffer (i.e., your trcConfig.h has the\r
414 * setting TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM), this macro allows you to declare\r
415 * the trace buffer in a portable way that works both in snapshot and streaming.\r
416 *\r
417 * This macro has no effect if using another allocation mode, so you can easily \r
418 * switch between different recording modes and configurations, using the same \r
419 * initialization code.\r
420 *\r
421 * This translates to a single static allocation, on which you can apply linker\r
422 * directives to place it in a particular memory region.\r
423 * - Snapshot mode: "RecorderDataType <name>"\r
424 * - Streaming mode: "char <name> [<size>]", with <size> from trcStreamingPort.h.\r
425 *\r
426 * Example:\r
427 *\r
428 *   // GCC example: place myTraceBuffer in section .tz, defined in the .ld file.\r
429 *   TRC_ALLOC_CUSTOM_BUFFER(myTraceBuffer) __attribute__((section(".tz")));\r
430 *   \r
431 *   int main(void)\r
432 *   {\r
433 *      ...\r
434 *      vTraceSetRecorderDataBuffer(&myTraceBuffer); // Note the "&"\r
435 *      ...\r
436 *      vTraceEnable(TRC_INIT); // Initialize the data structure\r
437 *\r
438 ******************************************************************************/\r
439 #ifndef TRC_ALLOC_CUSTOM_BUFFER\r
440 /* Definition for snapshot mode only. Also defined in trcStreamingPort.h */\r
441 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)\r
442 #define TRC_ALLOC_CUSTOM_BUFFER(bufname) RecorderDataType bufname;\r
443 #else\r
444 #define TRC_ALLOC_CUSTOM_BUFFER(bufname)\r
445 #endif\r
446 #endif\r
447 \r
448 \r
449 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)\r
450 \r
451 /******************************************************************************/\r
452 /*** Extended API for Snapshot mode *******************************************/\r
453 /******************************************************************************/\r
454 \r
455 /******************************************************************************\r
456 * TRACE_STOP_HOOK - Hook Pointer Data Type\r
457 *\r
458 * Declares a data type for a call back function that will be invoked whenever\r
459 * the recorder is stopped.\r
460 *\r
461 * Snapshot mode only!\r
462 ******************************************************************************/\r
463 typedef void(*TRACE_STOP_HOOK)(void);\r
464 \r
465 /*******************************************************************************\r
466 * vTraceStopHookPtr\r
467 *\r
468 * Points to a call back function that is called from vTraceStop().\r
469 *\r
470 * Snapshot mode only!\r
471 ******************************************************************************/\r
472 extern TRACE_STOP_HOOK vTraceStopHookPtr;\r
473 \r
474 /*******************************************************************************\r
475 * vTraceSetStopHook\r
476 *\r
477 * Sets a function to be called when the recorder is stopped.\r
478 *\r
479 * Snapshot mode only!\r
480 ******************************************************************************/\r
481 void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction);\r
482 \r
483 /*******************************************************************************\r
484 * uiTraceStart\r
485 *\r
486 * [DEPRECATED] Use vTraceEnable instead.\r
487 *\r
488 * Starts the recorder. The recorder will not be started if an error has been\r
489 * indicated using prvTraceError, e.g. if any of the Nx constants in\r
490 * trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
491 *\r
492 * Returns 1 if the recorder was started successfully.\r
493 * Returns 0 if the recorder start was prevented due to a previous internal\r
494 * error. In that case, check xTraceGetLastError to get the error message.\r
495 * Any error message is also presented when opening a trace file.\r
496 *\r
497 *\r
498 * Snapshot mode only!\r
499 ******************************************************************************/\r
500 uint32_t uiTraceStart(void);\r
501 \r
502 /*******************************************************************************\r
503 * vTraceStart\r
504 *\r
505 * [DEPRECATED] Use vTraceEnable instead.\r
506 *\r
507 * Starts the recorder. The recorder will not be started if an error has been\r
508 * indicated using prvTraceError, e.g. if any of the Nx constants in\r
509 * trcSnapshotConfig.h has a too small value (TRC_CFG_NTASK, TRC_CFG_NQUEUE, etc).\r
510 *\r
511 * Snapshot mode only!\r
512 ******************************************************************************/\r
513 void vTraceStart(void);\r
514 \r
515 /*******************************************************************************\r
516 * vTraceClear\r
517 *\r
518 * Resets the recorder. Only necessary if a restart is desired - this is not\r
519 * needed in the startup initialization.\r
520 *\r
521 * Snapshot mode only!\r
522 ******************************************************************************/\r
523 void vTraceClear(void);\r
524 \r
525 \r
526 /*****************************************************************************/\r
527 /*** INTERNAL SNAPSHOT FUNCTIONS *********************************************/\r
528 /*****************************************************************************/\r
529 \r
530 #undef INCLUDE_xTaskGetSchedulerState\r
531 #define INCLUDE_xTaskGetSchedulerState 1\r
532 \r
533 #undef INCLUDE_xTaskGetCurrentTaskHandle\r
534 #define INCLUDE_xTaskGetCurrentTaskHandle 1\r
535 \r
536 #ifndef TRC_CFG_INCLUDE_OBJECT_DELETE\r
537 #define TRC_CFG_INCLUDE_OBJECT_DELETE 0\r
538 #endif\r
539 \r
540 #ifndef TRC_CFG_INCLUDE_READY_EVENTS\r
541 #define TRC_CFG_INCLUDE_READY_EVENTS 1\r
542 #endif\r
543 \r
544 #ifndef TRC_CFG_INCLUDE_OSTICK_EVENTS\r
545 #define TRC_CFG_INCLUDE_OSTICK_EVENTS 0\r
546 #endif\r
547 \r
548 #define TRC_UNUSED\r
549 \r
550 #if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
551 /* This macro will remove the task and store it in the event buffer */\r
552 #undef trcKERNEL_HOOKS_TASK_DELETE\r
553 #define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB) \\r
554         prvTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
555         prvTraceStoreObjectNameOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
556         prvTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \\r
557         prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
558         prvTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \\r
559         prvTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
560 #else /*(TRC_CFG_INCLUDE_OBJECT_DELETE == 1)*/\r
561 #undef trcKERNEL_HOOKS_TASK_DELETE\r
562 #define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, pxTCB)\r
563 #endif /*(TRC_CFG_INCLUDE_OBJECT_DELETE == 1)*/\r
564 \r
565 #if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
566 /* This macro will remove the object and store it in the event buffer */\r
567 #undef trcKERNEL_HOOKS_OBJECT_DELETE\r
568 #define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject) \\r
569         prvTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
570         prvTraceStoreObjectNameOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
571         prvTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \\r
572         prvTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
573 #else /*TRC_CFG_INCLUDE_OBJECT_DELETE*/\r
574 #undef trcKERNEL_HOOKS_OBJECT_DELETE\r
575 #define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, CLASS, pxObject)\r
576 #endif /*TRC_CFG_INCLUDE_OBJECT_DELETE*/\r
577 \r
578 /* This macro will create a task in the object table */\r
579 #undef trcKERNEL_HOOKS_TASK_CREATE\r
580 #define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \\r
581         TRACE_SET_TASK_NUMBER(pxTCB) \\r
582         prvTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \\r
583         prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \\r
584         prvTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxTCB), TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
585 \r
586 /* This macro will create a failed create call to create a task */\r
587 #undef trcKERNEL_HOOKS_TASK_CREATE_FAILED\r
588 #define trcKERNEL_HOOKS_TASK_CREATE_FAILED(SERVICE, CLASS) \\r
589         prvTraceStoreKernelCall(TRACE_GET_TASK_EVENT_CODE(SERVICE, FAILED, CLASS, 0), TRACE_CLASS_TASK, 0);\r
590 \r
591 /* This macro will setup a task in the object table */\r
592 #undef trcKERNEL_HOOKS_OBJECT_CREATE\r
593 #define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject)\\r
594         TRACE_SET_OBJECT_NUMBER(CLASS, pxObject);\\r
595         prvMarkObjectAsUsed(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject),  TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\\r
596         prvTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, SUCCESS, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \\r
597         prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);\r
598 \r
599 /* This macro will create a failed create call to create an object */\r
600 #undef trcKERNEL_HOOKS_OBJECT_CREATE_FAILED\r
601 #define trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(SERVICE, CLASS, kernelClass) \\r
602         prvTraceStoreKernelCall(TRACE_GET_CLASS_EVENT_CODE(SERVICE, FAILED, CLASS, kernelClass), TRACE_GET_CLASS_TRACE_CLASS(CLASS, kernelClass), 0);\r
603 \r
604 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */\r
605 #undef trcKERNEL_HOOKS_KERNEL_SERVICE\r
606 #define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, RESULT, CLASS, pxObject) \\r
607         prvTraceStoreKernelCall(TRACE_GET_OBJECT_EVENT_CODE(SERVICE, RESULT, CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\r
608 \r
609 /* This macro will set the state for an object */\r
610 #undef trcKERNEL_HOOKS_SET_OBJECT_STATE\r
611 #define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \\r
612         prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), STATE);\r
613 \r
614 /* This macro will flag a certain task as a finished instance */\r
615 #undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED\r
616 #define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \\r
617         prvTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));\r
618 \r
619 #if (TRC_CFG_INCLUDE_READY_EVENTS == 1)\r
620 /* This macro will create an event to indicate that a task became Ready */\r
621 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
622 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \\r
623         prvTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));\r
624 #else /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/\r
625 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE\r
626 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)\r
627 #endif /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/\r
628 \r
629 /* This macro will update the internal tick counter and call prvTracePortGetTimeStamp(0) to update the internal counters */\r
630 #undef trcKERNEL_HOOKS_INCREMENT_TICK\r
631 #define trcKERNEL_HOOKS_INCREMENT_TICK() \\r
632         { extern uint32_t uiTraceTickCount; uiTraceTickCount++; prvTracePortGetTimeStamp(0); }\r
633 \r
634 #if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)\r
635 /* This macro will create an event indicating that the OS tick count has increased */\r
636 #undef trcKERNEL_HOOKS_NEW_TIME\r
637 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \\r
638         prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);\r
639 #else /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/\r
640 #undef trcKERNEL_HOOKS_NEW_TIME\r
641 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)\r
642 #endif /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/\r
643 \r
644 /* This macro will create a task switch event to the currently executing task */\r
645 #undef trcKERNEL_HOOKS_TASK_SWITCH\r
646 #define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \\r
647         prvTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));\r
648 \r
649 /* This macro will create an event to indicate that the task has been suspended */\r
650 #undef trcKERNEL_HOOKS_TASK_SUSPEND\r
651 #define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \\r
652         prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \\r
653         prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
654 \r
655 /* This macro will create an event to indicate that a task has called a wait/delay function */\r
656 #undef trcKERNEL_HOOKS_TASK_DELAY\r
657 #define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \\r
658         prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \\r
659         prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));\r
660 \r
661 /* This macro will create an event to indicate that a task has gotten its priority changed */\r
662 #undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE\r
663 #define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \\r
664         prvTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), prvTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\\r
665         prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority);\r
666 \r
667 /* This macro will create an event to indicate that the task has been resumed */\r
668 #undef trcKERNEL_HOOKS_TASK_RESUME\r
669 #define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \\r
670         prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));\r
671         \r
672 #undef trcKERNEL_HOOKS_TIMER_EVENT\r
673 #define trcKERNEL_HOOKS_TIMER_EVENT(SERVICE, pxTimer) \\r
674         prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
675 \r
676 /* This macro will create a timer in the object table and assign the timer a trace handle (timer number).*/\r
677 #undef trcKERNEL_HOOKS_TIMER_CREATE\r
678 #define trcKERNEL_HOOKS_TIMER_CREATE(SERVICE, pxTimer) \\r
679 TRACE_SET_TIMER_NUMBER(pxTimer); \\r
680 prvTraceSetObjectName(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_GET_TIMER_NAME(pxTimer)); \\r
681 prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
682 \r
683 #undef trcKERNEL_HOOKS_TIMER_DELETE\r
684 #define trcKERNEL_HOOKS_TIMER_DELETE(SERVICE, pxTimer) \\r
685 prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer)); \\r
686 prvTraceStoreObjectNameOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
687 prvTraceStoreObjectPropertiesOnCloseEvent(TRACE_GET_TIMER_NUMBER(pxTimer), TRACE_CLASS_TIMER); \\r
688 prvTraceFreeObjectHandle(TRACE_CLASS_TIMER, TRACE_GET_TIMER_NUMBER(pxTimer));\r
689 \r
690 #if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1\r
691         void prvTraceSetReadyEventsEnabled(int status);\r
692         void prvTraceStoreTaskReady(traceHandle handle);\r
693 #else\r
694         #define prvTraceSetReadyEventsEnabled(status)\r
695 #endif\r
696 \r
697 void prvTraceStoreLowPower(uint32_t flag);\r
698 \r
699 void prvTraceStoreTaskswitch(traceHandle task_handle);\r
700 \r
701 \r
702 #if (TRC_CFG_SCHEDULING_ONLY == 0)\r
703 \r
704 void prvTraceStoreKernelCall(uint32_t eventcode, traceObjectClass objectClass, uint32_t byteParam);\r
705 \r
706 void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param);\r
707 \r
708 void prvTraceStoreKernelCallWithParam(uint32_t evtcode, traceObjectClass objectClass,\r
709                                                                         uint32_t objectNumber, uint32_t param);\r
710 #else\r
711 \r
712 #define prvTraceStoreKernelCall(eventcode, objectClass, byteParam) {}\r
713 #define prvTraceStoreKernelCallWithNumericParamOnly(evtcode, param) {}\r
714 #define prvTraceStoreKernelCallWithParam(evtcode, objectClass, objectNumber, param) {}\r
715 \r
716 #endif\r
717 \r
718 void prvTraceSetTaskInstanceFinished(traceHandle handle);\r
719 \r
720 void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value);\r
721 \r
722 uint8_t prvTraceGetPriorityProperty(uint8_t objectclass, traceHandle id);\r
723 \r
724 void prvTraceSetObjectState(uint8_t objectclass, traceHandle id, uint8_t value);\r
725 \r
726 void prvMarkObjectAsUsed(traceObjectClass objectclass, traceHandle handle);\r
727 \r
728 \r
729 #if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
730 \r
731 void prvTraceStoreObjectNameOnCloseEvent(traceHandle handle,\r
732                                                                                 traceObjectClass objectclass);\r
733 \r
734 void prvTraceStoreObjectPropertiesOnCloseEvent(traceHandle handle,\r
735                                                                                          traceObjectClass objectclass);\r
736 #endif\r
737 \r
738 /* Internal constants for task state */\r
739 #define TASK_STATE_INSTANCE_NOT_ACTIVE 0\r
740 #define TASK_STATE_INSTANCE_ACTIVE 1\r
741 \r
742 \r
743 #if (TRC_CFG_INCLUDE_ISR_TRACING == 0)\r
744 \r
745 //void prvTraceIncreaseISRActive(void);\r
746 \r
747 //void prvTraceDecreaseISRActive(void);\r
748 #undef vTraceSetISRProperties\r
749 #define vTraceSetISRProperties(handle, name, priority)\r
750 \r
751 #undef vTraceStoreISRBegin\r
752 #define vTraceStoreISRBegin(x) (void)x\r
753 \r
754 #undef vTraceStoreISREnd\r
755 #define vTraceStoreISREnd(x) (void)x\r
756 \r
757 #undef xTraceSetISRProperties\r
758 #define xTraceSetISRProperties(name, priority) 0\r
759 \r
760 #endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/\r
761 \r
762 /*******************************************************************************\r
763  * xTraceGetTraceBuffer\r
764  *\r
765  * Returns a pointer to the recorder data structure. Use this together with\r
766  * uiTraceGetTraceBufferSize if you wish to implement an own store/upload\r
767  * solution, e.g., in case a debugger connection is not available for uploading\r
768  * the data.\r
769  ******************************************************************************/\r
770 void* xTraceGetTraceBuffer(void);\r
771 \r
772 /*******************************************************************************\r
773  * uiTraceGetTraceBufferSize\r
774  *\r
775  * Gets the size of the recorder data structure. For use together with\r
776  * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,\r
777  * e.g., in case a debugger connection is not available for uploading the data.\r
778  ******************************************************************************/\r
779 uint32_t uiTraceGetTraceBufferSize(void);\r
780 \r
781 #if (TRC_CFG_SCHEDULING_ONLY == 1)\r
782 #undef TRC_CFG_INCLUDE_USER_EVENTS\r
783 #define TRC_CFG_INCLUDE_USER_EVENTS 0\r
784 #endif /*(TRC_CFG_SCHEDULING_ONLY == 1)*/\r
785 \r
786 #if ((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))\r
787 \r
788 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
789 traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatStr);\r
790 void vTraceUBData(traceUBChannel channel, ...);\r
791 void vTraceUBEvent(traceUBChannel channel);\r
792 #endif /*(TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)*/\r
793 \r
794 #else /*((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0))*/\r
795 \r
796 #undef vTracePrint\r
797 #define vTracePrint(chn, ...) (void)chn\r
798 #undef vTracePrintF\r
799 #define vTracePrintF(chn, ...) (void)chn\r
800 #undef xTraceRegisterString\r
801 #define xTraceRegisterString(x) 0; (void)x;\r
802 #undef xTraceRegisterChannelFormat\r
803 #define xTraceRegisterChannelFormat(eventLabel, formatStr) 0\r
804 #undef vTraceUBData\r
805 #define vTraceUBData(label, ...) {}\r
806 #undef vTraceChannelPrint\r
807 #define vTraceChannelPrint(label) {}\r
808 \r
809 #endif /*(TRC_CFG_INCLUDE_USER_EVENTS == 1)*/\r
810 \r
811 #define NEventCodes 0x100\r
812 \r
813 /* Our local critical sections for the recorder */\r
814 #define trcCRITICAL_SECTION_BEGIN() {TRACE_ENTER_CRITICAL_SECTION(); recorder_busy++;}\r
815 #define trcCRITICAL_SECTION_END() {recorder_busy--; TRACE_EXIT_CRITICAL_SECTION();}\r
816 \r
817 #if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)\r
818         #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY TRACE_ALLOC_CRITICAL_SECTION\r
819         #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_BEGIN\r
820         #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_END\r
821 #else\r
822         #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY() {}\r
823         #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY() recorder_busy++;\r
824         #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY() recorder_busy--;\r
825 #endif\r
826 \r
827 /* Structure to handle the exclude flags for all objects and tasks. We add some extra objects since index 0 is not used for each object class. */\r
828 extern uint8_t trcExcludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1];\r
829 \r
830 /* Structure to handle the exclude flags for all event codes */\r
831 extern uint8_t trcExcludedEventCodes[NEventCodes / 8 + 1];\r
832 \r
833 /******************************************************************************\r
834  * ObjectHandleStack\r
835  * This data-structure is used to provide a mechanism for 1-byte trace object\r
836  * handles. This way, only 1 byte is necessary instead of 4 bytes (a pointer)\r
837  * when storing a reference to an object. This allows for up to 255 objects of\r
838  * each object class active at any given moment. There can be more "historic"\r
839  * objects, that have been deleted - that number is only limited by the size of\r
840  * the symbol table.\r
841  * Note that handle zero (0) is not used, it is a code for an invalid handle.\r
842  *\r
843  * This data structure keeps track of the FREE handles, not the handles in use.\r
844  * This data structure contains one stack per object class. When a handle is\r
845  * allocated to an object, the next free handle is popped from the stack. When\r
846  * a handle is released (on object delete), it is pushed back on the stack.\r
847  * Note that there is no initialization code that pushed the free handles\r
848  * initially, that is not necessary due to the following optimization:\r
849  *\r
850  * The stack of handles (objectHandles) is initially all zeros. Since zero\r
851  * is not a valid handle, that is a signal of additional handles needed.\r
852  * If a zero is received when popping a new handle, it is replaced by the\r
853  * index of the popped handle instead.\r
854  *\r
855  *****************************************************************************/\r
856 typedef struct\r
857 {\r
858         /* For each object class, the index of the next handle to allocate */\r
859         uint16_t indexOfNextAvailableHandle[ TRACE_NCLASSES ];\r
860 \r
861         /* The lowest index of this class (constant) */\r
862         uint16_t lowestIndexOfClass[ TRACE_NCLASSES ];\r
863 \r
864         /* The highest index of this class (constant) */\r
865         uint16_t highestIndexOfClass[ TRACE_NCLASSES ];\r
866 \r
867         /* The highest use count for this class (for statistics) */\r
868         uint16_t handleCountWaterMarksOfClass[ TRACE_NCLASSES ];\r
869 \r
870         /* The free object handles - a set of stacks within this array */\r
871         traceHandle objectHandles[ TRACE_KERNEL_OBJECT_COUNT ];\r
872 \r
873 } objectHandleStackType;\r
874 \r
875 extern objectHandleStackType objectHandleStacks;\r
876 \r
877 /******************************************************************************\r
878  * Object Property Table\r
879  * The Object Table contains name and other properties of the objects (tasks,\r
880  * queues, mutexes, etc). The below data structures defines the properties of\r
881  * each object class and are used to cast the byte buffer into a cleaner format.\r
882  *\r
883  * The values in the object table are continuously overwritten and always\r
884  * represent the current state. If a property is changed during runtime, the OLD\r
885  * value should be stored in the trace buffer, not the new value (since the new\r
886  * value is found in the Object Property Table).\r
887  * For close events this mechanism is the old names are stored in the symbol\r
888  * table), for "priority set" (the old priority is stored in the event data)\r
889  * and for "isActive", where the value decides if the task switch event type\r
890  * should be "new" or "resume".\r
891  ******************************************************************************/\r
892 \r
893 typedef struct\r
894 {\r
895         /* = NCLASSES */\r
896         uint32_t NumberOfObjectClasses;\r
897 \r
898         uint32_t ObjectPropertyTableSizeInBytes;\r
899 \r
900         /* This is used to calculate the index in the dynamic object table\r
901         (handle - 1 - nofStaticObjects = index)*/\r
902 #if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
903         traceHandle NumberOfObjectsPerClass[2*((TRACE_NCLASSES+1)/2)];\r
904 #else\r
905         traceHandle NumberOfObjectsPerClass[4*((TRACE_NCLASSES+3)/4)];\r
906 #endif\r
907 \r
908         /* Allocation size rounded up to the closest multiple of 4 */\r
909         uint8_t NameLengthPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
910 \r
911         uint8_t TotalPropertyBytesPerClass[ 4*((TRACE_NCLASSES+3)/4) ];\r
912 \r
913         /* Allocation size rounded up to the closest multiple of 2 */\r
914         uint16_t StartIndexOfClass[ 2*((TRACE_NCLASSES+1)/2) ];\r
915 \r
916         /* The actual handles issued, should be Initiated to all zeros */\r
917         uint8_t objbytes[ 4*((TRACE_OBJECT_TABLE_SIZE+3)/4) ];\r
918 } ObjectPropertyTableType;\r
919 \r
920 /* Symbol table data structure */\r
921 typedef struct\r
922 {\r
923         /* = SYMBOL_HISTORY_TABLE_SIZE_IN_BYTES */\r
924         uint32_t symTableSize;\r
925 \r
926         /* Entry 0 is reserved. Any reference to entry 0 implies NULL*/\r
927         uint32_t nextFreeSymbolIndex;\r
928 \r
929         /* Size rounded up to closest multiple of 4, to avoid alignment issues*/\r
930         uint8_t symbytes[4*((TRC_CFG_SYMBOL_TABLE_SIZE+3)/4)];\r
931 \r
932         /* Used for lookups - Up to 64 linked lists within the symbol table\r
933         connecting all entries with the same 6 bit checksum.\r
934         This field holds the current list heads. Should be initiated to zeros */\r
935         uint16_t latestEntryOfChecksum[64];\r
936 } symbolTableType;\r
937 \r
938 \r
939 /*******************************************************************************\r
940  * The data structures of the different events, all 4 bytes long\r
941  ******************************************************************************/\r
942 \r
943 typedef struct\r
944 {\r
945         uint8_t type;\r
946         uint8_t objHandle;\r
947         uint16_t dts;   /* differential timestamp - time since last event */\r
948 } TSEvent, TREvent;\r
949 \r
950 typedef struct\r
951 {\r
952         uint8_t type;\r
953         uint8_t dummy;\r
954         uint16_t dts;   /* differential timestamp - time since last event */\r
955 } LPEvent;\r
956 \r
957 typedef struct\r
958 {\r
959         uint8_t type;\r
960         uint8_t objHandle;\r
961         uint16_t dts;   /* differential timestamp - time since last event */\r
962 } KernelCall;\r
963 \r
964 typedef struct\r
965 {\r
966         uint8_t type;\r
967         uint8_t objHandle;\r
968         uint8_t param;\r
969         uint8_t dts;    /* differential timestamp - time since last event */\r
970 } KernelCallWithParamAndHandle;\r
971 \r
972 typedef struct\r
973 {\r
974         uint8_t type;\r
975         uint8_t dts;    /* differential timestamp - time since last event */\r
976         uint16_t param;\r
977 } KernelCallWithParam16;\r
978 \r
979 typedef struct\r
980 {\r
981         uint8_t type;\r
982         uint8_t objHandle;      /* the handle of the closed object */\r
983         uint16_t symbolIndex;            /* the name of the closed object */\r
984 } ObjCloseNameEvent;\r
985 \r
986 typedef struct\r
987 {\r
988         uint8_t type;\r
989         uint8_t arg1;\r
990         uint8_t arg2;\r
991         uint8_t arg3;\r
992 } ObjClosePropEvent;\r
993 \r
994 typedef struct\r
995 {\r
996         uint8_t type;\r
997         uint8_t unused1;\r
998         uint8_t unused2;\r
999         uint8_t dts;\r
1000 } TaskInstanceStatusEvent;\r
1001 \r
1002 typedef struct\r
1003 {\r
1004         uint8_t type;\r
1005         uint8_t dts;\r
1006         uint16_t payload;                /* the name of the user event */\r
1007 } UserEvent;\r
1008 \r
1009 typedef struct\r
1010 {\r
1011         uint8_t type;\r
1012 \r
1013         /* 8 bits extra for storing DTS, if it does not fit in ordinary event\r
1014         (this one is always MSB if used) */\r
1015         uint8_t xts_8;\r
1016 \r
1017         /* 16 bits extra for storing DTS, if it does not fit in ordinary event. */\r
1018         uint16_t xts_16;\r
1019 } XTSEvent;\r
1020 \r
1021 typedef struct\r
1022 {\r
1023         uint8_t type;\r
1024 \r
1025         uint8_t xps_8;\r
1026         uint16_t xps_16;\r
1027 } XPSEvent;\r
1028 \r
1029 typedef struct{\r
1030         uint8_t type;\r
1031         uint8_t dts;\r
1032         uint16_t size;\r
1033 } MemEventSize;\r
1034 \r
1035 typedef struct{\r
1036         uint8_t type;\r
1037         uint8_t addr_high;\r
1038         uint16_t addr_low;\r
1039 } MemEventAddr;\r
1040 \r
1041 /*******************************************************************************\r
1042  * The separate user event buffer structure. Can be enabled in trcConfig.h.\r
1043  ******************************************************************************/\r
1044 \r
1045 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
1046 typedef struct\r
1047 {\r
1048         traceString name;\r
1049         traceString defaultFormat;\r
1050 } ChannelFormatPair;\r
1051 \r
1052 typedef struct\r
1053 {\r
1054         uint16_t bufferID;\r
1055         uint16_t version;\r
1056         uint32_t wraparoundCounter;\r
1057         uint32_t numberOfSlots;\r
1058         uint32_t nextSlotToWrite;\r
1059         uint8_t numberOfChannels;\r
1060         uint8_t padding1;\r
1061         uint8_t padding2;\r
1062         uint8_t padding3;\r
1063         ChannelFormatPair channels[TRC_CFG_UB_CHANNELS+1];\r
1064         uint8_t channelBuffer[(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE + 3) & 0xFFFFFFFC]; /* 1 byte per slot, with padding for 4 byte alignment */\r
1065         uint8_t dataBuffer[TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE * 4]; /* 4 bytes per slot */\r
1066 \r
1067 } UserEventBuffer;\r
1068 #endif\r
1069 \r
1070 /*******************************************************************************\r
1071  * The main data structure, read by Tracealyzer from the RAM dump\r
1072  ******************************************************************************/\r
1073 \r
1074 typedef struct\r
1075 {\r
1076         volatile uint8_t startmarker0; /* Volatile is important, see init code. */\r
1077         volatile uint8_t startmarker1;\r
1078         volatile uint8_t startmarker2;\r
1079         volatile uint8_t startmarker3;\r
1080         volatile uint8_t startmarker4;\r
1081         volatile uint8_t startmarker5;\r
1082         volatile uint8_t startmarker6;\r
1083         volatile uint8_t startmarker7;\r
1084         volatile uint8_t startmarker8;\r
1085         volatile uint8_t startmarker9;\r
1086         volatile uint8_t startmarker10;\r
1087         volatile uint8_t startmarker11;\r
1088 \r
1089         /* Used to determine Kernel and Endianess */\r
1090         uint16_t version;\r
1091 \r
1092         /* Currently 5 */\r
1093         uint8_t minor_version;\r
1094 \r
1095         /* This should be 0 if lower IRQ priority values implies higher priority\r
1096         levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,\r
1097         if higher IRQ priority values means higher priority, this should be 1. */\r
1098         uint8_t irq_priority_order;\r
1099 \r
1100         /* sizeof(RecorderDataType) - just for control */\r
1101         uint32_t filesize;\r
1102 \r
1103         /* Current number of events recorded */\r
1104         uint32_t numEvents;\r
1105 \r
1106         /* The buffer size, in number of event records */\r
1107         uint32_t maxEvents;\r
1108 \r
1109         /* The event buffer index, where to write the next event */\r
1110         uint32_t nextFreeIndex;\r
1111 \r
1112         /* 1 if the buffer is full, 0 otherwise */\r
1113         uint32_t bufferIsFull;\r
1114 \r
1115         /* The frequency of the clock/timer/counter used as time base */\r
1116         uint32_t frequency;\r
1117 \r
1118         /* The absolute timestamp of the last stored event, in the native\r
1119         timebase, modulo frequency! */\r
1120         uint32_t absTimeLastEvent;\r
1121 \r
1122         /* The number of seconds in total - lasts for 136 years */\r
1123         uint32_t absTimeLastEventSecond;\r
1124 \r
1125         /* 1 if the recorder has been started, 0 if not yet started or stopped.\r
1126         This is a 32 bit variable due to alignment issues. */\r
1127         uint32_t recorderActive;\r
1128 \r
1129         /* If > 0, tells the maximum time between two traced ISRs that execute\r
1130         back-to-back. If the time between vTraceStoreISREnd and a directly\r
1131         following vTraceISRBegin is above isrTailchainingThreshold, we assume a\r
1132         return to the previous context in between the ISRs, otherwise we assume\r
1133         the have executed back-to-back and don't show any fragment of the previous\r
1134         context in between. */ \r
1135         uint32_t isrTailchainingThreshold;\r
1136 \r
1137         /* Not used, remains for compatibility and future use */\r
1138         uint8_t notused[24];\r
1139 \r
1140         /* The amount of heap memory remaining at the last malloc or free event */\r
1141         uint32_t heapMemUsage;\r
1142 \r
1143         /* 0xF0F0F0F0 - for control only */\r
1144         int32_t debugMarker0;\r
1145 \r
1146         /* Set to value of TRC_CFG_USE_16BIT_OBJECT_HANDLES */\r
1147         uint32_t isUsing16bitHandles;\r
1148 \r
1149         /* The Object Property Table holds information about currently active\r
1150         tasks, queues, and other recorded objects. This is updated on each\r
1151         create call and includes object name and other properties. */\r
1152         ObjectPropertyTableType ObjectPropertyTable;\r
1153 \r
1154         /* 0xF1F1F1F1 - for control only */\r
1155         int32_t debugMarker1;\r
1156 \r
1157         /* The Symbol Table stores strings for User Events and is also used to\r
1158         store names of deleted objects, which still may be in the trace but no\r
1159         longer are available. */\r
1160         symbolTableType SymbolTable;\r
1161 \r
1162         /* For inclusion of float support, and for endian detection of floats.\r
1163         The value should be (float)1 or (uint32_t)0 */\r
1164 #if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)\r
1165         float exampleFloatEncoding;\r
1166 #else\r
1167         uint32_t exampleFloatEncoding;\r
1168 #endif\r
1169         /* This is non-zero if an internal error occurred in the recorder, e.g., if\r
1170         one of the Nxxx constants was too small. The systemInfo string will then\r
1171         contain an error message that is displayed when attempting to view the\r
1172         trace file. */\r
1173         uint32_t internalErrorOccured;\r
1174 \r
1175         /* 0xF2F2F2F2 - for control only */\r
1176         int32_t debugMarker2;\r
1177 \r
1178         /* Error messages from the recorder. */\r
1179         char systemInfo[80];\r
1180 \r
1181         /* 0xF3F3F3F3 - for control only */\r
1182         int32_t debugMarker3;\r
1183 \r
1184         /* The event data, in 4-byte records */\r
1185         uint8_t eventData[ TRC_CFG_EVENT_BUFFER_SIZE * 4 ];\r
1186 \r
1187 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)\r
1188         UserEventBuffer userEventBuffer;\r
1189 #endif\r
1190 \r
1191         /* This should always be 0 */\r
1192         uint32_t endOfSecondaryBlocks;\r
1193 \r
1194         uint8_t endmarker0;\r
1195         uint8_t endmarker1;\r
1196         uint8_t endmarker2;\r
1197         uint8_t endmarker3;\r
1198         uint8_t endmarker4;\r
1199         uint8_t endmarker5;\r
1200         uint8_t endmarker6;\r
1201         uint8_t endmarker7;\r
1202         uint8_t endmarker8;\r
1203         uint8_t endmarker9;\r
1204         uint8_t endmarker10;\r
1205         uint8_t endmarker11;\r
1206 } RecorderDataType;\r
1207 \r
1208 extern RecorderDataType* RecorderDataPtr;\r
1209 \r
1210 /* Internal functions */\r
1211 \r
1212 /* Signal an error. */\r
1213 void prvTraceError(const char* msg);\r
1214 \r
1215 /*******************************************************************************\r
1216  * prvTracePortGetTimeStamp\r
1217  *\r
1218  * Returns the current time based on the HWTC macros which provide a hardware\r
1219  * isolation layer towards the hardware timer/counter.\r
1220  *\r
1221  * The HWTC macros and prvTracePortGetTimeStamp is the main porting issue\r
1222  * or the trace recorder library. Typically you should not need to change\r
1223  * the code of prvTracePortGetTimeStamp if using the HWTC macros.\r
1224  *\r
1225  ******************************************************************************/\r
1226 void prvTracePortGetTimeStamp(uint32_t *puiTimestamp);\r
1227 \r
1228 traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass);\r
1229 \r
1230 void prvTraceFreeObjectHandle(traceObjectClass objectclass,\r
1231                                                         traceHandle handle);\r
1232 \r
1233 /* Private function. Use the public functions in trcKernelPort.h */\r
1234 void prvTraceSetObjectName(traceObjectClass objectclass,\r
1235                                                         traceHandle handle,\r
1236                                                         const char* name);\r
1237 \r
1238 /* Internal macros */\r
1239 \r
1240 #define TRACE_PROPERTY_NAME_GET(objectclass, objecthandle) \\r
1241 (const char*)(& RecorderDataPtr->ObjectPropertyTable.objbytes \\r
1242 [uiIndexOfObject(objecthandle, objectclass)])\r
1243 \r
1244 #define TRACE_PROPERTY_OBJECT_STATE(objectclass, handle) \\r
1245 RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
1246 + RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass]]\r
1247 \r
1248 #define TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle) \\r
1249 RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \\r
1250 + RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass] + 1]\r
1251 \r
1252 #define TRACE_SET_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] |= (1 << ((bitIndex) & 7))\r
1253 #define TRACE_CLEAR_FLAG_ISEXCLUDED(flags, bitIndex) flags[(bitIndex) >> 3] &= (uint8_t)(~(1 << ((bitIndex) & 7)))\r
1254 #define TRACE_GET_FLAG_ISEXCLUDED(flags, bitIndex) (flags[(bitIndex) >> 3] & (1 << ((bitIndex) & 7)))\r
1255 \r
1256 #define TRACE_SET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_SET_FLAG_ISEXCLUDED(trcExcludedEventCodes, eventCode)\r
1257 #define TRACE_CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_CLEAR_FLAG_ISEXCLUDED(trcExcludedEventCodes, eventCode)\r
1258 #define TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(eventCode) TRACE_GET_FLAG_ISEXCLUDED(trcExcludedEventCodes, eventCode)\r
1259 \r
1260 /* DEBUG ASSERTS */\r
1261 #if defined TRC_CFG_USE_TRACE_ASSERT && TRC_CFG_USE_TRACE_ASSERT != 0\r
1262 #define TRACE_ASSERT(eval, msg, defRetVal) \\r
1263 if (!(eval)) \\r
1264 { \\r
1265         prvTraceError("TRACE_ASSERT: " msg); \\r
1266         return defRetVal; \\r
1267 }\r
1268 #else\r
1269 #define TRACE_ASSERT(eval, msg, defRetVal)\r
1270 #endif\r
1271 \r
1272 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)*/\r
1273 \r
1274 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)\r
1275 \r
1276 /******************************************************************************/\r
1277 /*** INTERNAL STREAMING FUNCTIONS *********************************************/\r
1278 /******************************************************************************/\r
1279 \r
1280 /* Saves a symbol name (task name etc.) in symbol table */\r
1281 void prvTraceSaveSymbol(const void *address, const char *name);\r
1282 \r
1283 /* Deletes a symbol name (task name etc.) from symbol table */\r
1284 void prvTraceDeleteSymbol(void *address);\r
1285 \r
1286 /* Saves an object data entry (task base priority) in object data table */\r
1287 void prvTraceSaveObjectData(const void *address, uint32_t data);\r
1288 \r
1289 /* Removes an object data entry (task base priority) from object data table */\r
1290 void prvTraceDeleteObjectData(void *address);\r
1291 \r
1292 /* Store an event with zero parameters (event ID only) */\r
1293 void prvTraceStoreEvent0(uint16_t eventID);\r
1294 \r
1295 /* Store an event with one 32-bit parameter (pointer address or an int) */\r
1296 void prvTraceStoreEvent1(uint16_t eventID,\r
1297         uint32_t param1);\r
1298 \r
1299 /* Store an event with two 32-bit parameters */\r
1300 void prvTraceStoreEvent2(uint16_t eventID,\r
1301         uint32_t param1,\r
1302         uint32_t param2);\r
1303 \r
1304 /* Store an event with three 32-bit parameters */\r
1305 void prvTraceStoreEvent3(uint16_t eventID,\r
1306         uint32_t param1,\r
1307         uint32_t param2,\r
1308         uint32_t param3);\r
1309 \r
1310 /* Stores an event with <nParam> 32-bit integer parameters */\r
1311 void prvTraceStoreEvent(int nParam, uint16_t EventID, ...);\r
1312 \r
1313 /* Stories an event with a string and <nParam> 32-bit integer parameters */\r
1314 void prvTraceStoreStringEvent(int nArgs, uint16_t eventID, const char* str, ...);\r
1315 \r
1316 /* Initializes the paged event buffer used by certain stream ports */\r
1317 void prvPagedEventBufferInit(char* buffer);\r
1318 \r
1319 /* Retrieve a pointer to the paged event buffer */\r
1320 void* prvPagedEventBufferGetWritePointer(int sizeOfEvent);\r
1321 \r
1322 /* Transfer a full buffer page */\r
1323 int32_t prvPagedEventBufferTransfer(int32_t(*writeFunc)(void* data, uint32_t size, int32_t* ptrBytesWritten), int32_t* nofBytes);\r
1324 \r
1325 /* Resets the paged event buffer */\r
1326 void prvPagedEventBufferReset(void);\r
1327 \r
1328 /* The data structure for commands (a bit overkill) */\r
1329 typedef struct\r
1330 {\r
1331         unsigned char cmdCode;\r
1332         unsigned char param1;\r
1333         unsigned char param2;\r
1334         unsigned char param3;\r
1335         unsigned char param4;\r
1336         unsigned char param5;\r
1337         unsigned char checksumLSB;\r
1338         unsigned char checksumMSB;\r
1339 } TracealyzerCommandType;\r
1340 \r
1341 /* Checks if the provided command is a valid command */\r
1342 int prvIsValidCommand(TracealyzerCommandType* cmd);\r
1343 \r
1344 /* Executed the received command (Start or Stop) */\r
1345 void prvProcessCommand(TracealyzerCommandType* cmd);\r
1346 \r
1347 \r
1348 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/\r
1349 \r
1350 #else /* when TRC_USE_TRACEALYZER_RECORDER == 0 */\r
1351 \r
1352 #define vTraceEnable(x)\r
1353 #define xTraceRegisterString(x) 0; (void)x;\r
1354 #define vTracePrint(chn, ...) (void)chn\r
1355 #define vTracePrintF(chn, ...) (void)chn\r
1356 #define vTraceInstanceFinishedNow()\r
1357 #define vTraceInstanceFinishedNext()\r
1358 #define vTraceStoreISRBegin(x) (void)x\r
1359 #define vTraceStoreISREnd(x) (void)x\r
1360 #define xTraceSetISRProperties(a, b) 0\r
1361 #define vTraceStoreKernelObjectName(a, b)\r
1362 #define xTraceRegisterChannelFormat(eventLabel, formatStr) 0\r
1363 #define vTraceChannelPrint(label)\r
1364 #define vTraceUBData(label, ...)\r
1365 \r
1366 #define prvTraceSetReadyEventsEnabled(status)\r
1367 \r
1368 #define vTraceExcludeTask(handle)\r
1369 \r
1370 #define uiTraceStart() (1)\r
1371 #define vTraceStart()\r
1372 #define vTraceStop()\r
1373 \r
1374 #ifndef vTraceSetRecorderDataBuffer\r
1375 #define vTraceSetRecorderDataBuffer(pRecorderData)\r
1376 #endif\r
1377 \r
1378 #ifndef TRC_ALLOC_CUSTOM_BUFFER\r
1379 #define TRC_ALLOC_CUSTOM_BUFFER(bufname)\r
1380 #endif\r
1381 \r
1382 #endif /*(TRC_USE_TRACEALYZER_RECORDER == 1)*/\r
1383 \r
1384 #ifdef __cplusplus\r
1385 }\r
1386 #endif\r
1387 \r
1388 #endif /* TRC_RECORDER_H */\r