1 /*******************************************************************************
\r
2 * FreeRTOS+Trace v2.3.0 Recorder Library
\r
3 * Percepio AB, www.percepio.com
\r
7 * The public API of the trace recorder library.
\r
10 * This software is copyright Percepio AB. The recorder library is free for
\r
11 * use together with Percepio products. You may distribute the recorder library
\r
12 * in its original form, including modifications in trcPort.c and trcPort.h
\r
13 * given that these modification are clearly marked as your own modifications
\r
14 * and documented in the initial comment section of these source files.
\r
15 * This software is the intellectual property of Percepio AB and may not be
\r
16 * sold or in other ways commercially redistributed without explicit written
\r
17 * permission by Percepio AB.
\r
20 * The trace tool and recorder library is being delivered to you AS IS and
\r
21 * Percepio AB makes no warranty as to its use or performance. Percepio AB does
\r
22 * not and cannot warrant the performance or results you may obtain by using the
\r
23 * software or documentation. Percepio AB make no warranties, express or
\r
24 * implied, as to noninfringement of third party rights, merchantability, or
\r
25 * fitness for any particular purpose. In no event will Percepio AB, its
\r
26 * technology partners, or distributors be liable to you for any consequential,
\r
27 * incidental or special damages, including any lost profits or lost savings,
\r
28 * even if a representative of Percepio AB has been advised of the possibility
\r
29 * of such damages, or for any claim by any third party. Some jurisdictions do
\r
30 * not allow the exclusion or limitation of incidental, consequential or special
\r
31 * damages, or the exclusion of implied warranties or limitations on how long an
\r
32 * implied warranty may last, so the above limitations may not apply to you.
\r
34 * FreeRTOS+Trace is available as Free Edition and in two premium editions.
\r
35 * You may use the premium features during 30 days for evaluation.
\r
36 * Download FreeRTOS+Trace at http://www.percepio.com/products/downloads/
\r
38 * Copyright Percepio AB, 2012.
\r
40 ******************************************************************************/
\r
45 #include "trcUser.h"
\r
49 #if (configUSE_TRACE_FACILITY == 1)
\r
51 extern uint8_t inExcludedTask;
\r
52 extern uint8_t nISRactive;
\r
53 extern uint8_t handle_of_last_logged_task;
\r
54 extern uint32_t dts_min;
\r
55 extern uint32_t hwtc_count_max_after_tick;
\r
56 extern uint32_t hwtc_count_sum_after_tick;
\r
57 extern uint32_t hwtc_count_sum_after_tick_counter;
\r
58 extern unsigned char ucQueueGetQueueType(void*);
\r
59 extern unsigned char ucQueueGetQueueNumber(void*);
\r
60 extern char* traceErrorMessage;
\r
61 static void vTraceMonitorTask(void);
\r
62 static void prvTraceExcludeOrIncludeKernelServiceFromTrace(traceKernelService, uint8_t);
\r
64 /*******************************************************************************
\r
67 * A task which periodically reports the recorder status to the console.
\r
68 * This is included depending on USE_TRACE_PROGRESS_MONITOR_TASK.
\r
69 ******************************************************************************/
\r
70 static void vTraceMonitorTask(void)
\r
72 portTickType xNextWakeTime;
\r
73 char localsprintbuffer[90];
\r
75 char* lastErr = NULL;
\r
76 #define STATE_INIT 0
\r
77 #define STATE_STARTED 1
\r
78 #define STATE_STOPPED 2
\r
79 int state = STATE_INIT;
\r
81 vTraceConsoleMessage("\n\r[FreeRTOS+Trace] Monitor task started...\n\r");
\r
83 /* Initialise xNextWakeTime - this only needs to be done once. */
\r
84 xNextWakeTime = xTaskGetTickCount();
\r
89 err = xTraceGetLastError();
\r
92 sprintf(localsprintbuffer, "\n\r[FreeRTOS+Trace] Error: %s\n\r", err);
\r
93 vTraceConsoleMessage(localsprintbuffer);
\r
96 if (state == STATE_STOPPED || state == STATE_INIT)
\r
98 if (RecorderDataPtr->recorderActive == 1)
\r
100 state = STATE_STARTED;
\r
101 vTraceConsoleMessage("\n\r[FreeRTOS+Trace] Recorder started.\n\r");
\r
105 if (state == STATE_INIT)
\r
108 vTraceConsoleMessage("\n\r[FreeRTOS+Trace] Recorder not started.\n\r");
\r
109 state = STATE_STOPPED;
\r
114 if (state == STATE_STARTED)
\r
116 if (RecorderDataPtr->frequency > 0)
\r
118 sprintf(localsprintbuffer,
\r
119 "\n\r[FreeRTOS+Trace] Event count: %d, Duration: %d ms. [%d ticks]\n\r",
\r
120 (int)RecorderDataPtr->numEvents,
\r
121 (int)(RecorderDataPtr->absTimeLastEventSecond*1000 + (RecorderDataPtr->absTimeLastEvent*1000)/ RecorderDataPtr->frequency), (int)xTaskGetTickCount());
\r
122 vTraceConsoleMessage(localsprintbuffer);
\r
125 if (RecorderDataPtr->recorderActive == 0)
\r
127 state = STATE_STOPPED;
\r
128 vTraceConsoleMessage("\n\r[FreeRTOS+Trace] Recorder stopped.\n\r");
\r
135 /* Place this task in the blocked state until it is time to run again. */
\r
136 vTaskDelayUntil( &xNextWakeTime, TRACE_PROGRESS_MONITOR_TASK_PERIOD);
\r
141 /*******************************************************************************
\r
144 * Resets the recorder. Only necessary if a restart is desired - this is not
\r
145 * needed in the startup initialization.
\r
146 ******************************************************************************/
\r
147 void vTraceClear(void)
\r
149 trcCRITICAL_SECTION_BEGIN();
\r
151 RecorderDataPtr->absTimeLastEvent = 0;
\r
152 RecorderDataPtr->nextFreeIndex = 0;
\r
153 RecorderDataPtr->numEvents = 0;
\r
154 RecorderDataPtr->bufferIsFull = 0;
\r
156 trcCRITICAL_SECTION_END();
\r
160 /*******************************************************************************
\r
161 * vTraceStartStatusMonitor
\r
163 * This starts a task to monitor the state of½ the recorder.
\r
164 * This task periodically prints a line to the console window, which shows the
\r
165 * number of events recorded and the latest timestamp. This task
\r
166 * calls vTracePortEnd when the recorder has been stopped, where custom
\r
167 * actions can be added, e.g., to store the trace to a file
\r
168 * if a file system is available on the device.
\r
169 ******************************************************************************/
\r
170 void vTraceStartStatusMonitor(void)
\r
172 vTraceConsoleMessage("\n\r[FreeRTOS+Trace] Starting Trace Status Monitor...\n\r");
\r
173 (void)xTaskCreate( (pdTASK_CODE)vTraceMonitorTask, (const signed char*)"TraceMon", TRACE_PROGRESS_MONITOR_TASK_STACKSIZE, NULL, TRACE_PROGRESS_MONITOR_TASK_PRIORITY, NULL );
\r
176 /*******************************************************************************
\r
179 * Starts the recorder. The recorder will not be started if an error has been
\r
180 * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h
\r
181 * has a too small value (NTASK, NQUEUE, etc).
\r
183 * Returns 1 if the recorder was started successfully.
\r
184 * Returns 0 if the recorder start was prevented due to a previous internal
\r
185 * error. In that case, check vTraceGetLastError to get the error message.
\r
186 * Any error message is also presented when opening a trace file in
\r
187 * FreeRTOS+Trace v2.2.2 or later.
\r
188 ******************************************************************************/
\r
190 uint32_t uiTraceStart(void)
\r
192 if (traceErrorMessage == NULL)
\r
194 trcCRITICAL_SECTION_BEGIN();
\r
195 RecorderDataPtr->recorderActive = 1;
\r
196 vTraceStoreTaskswitch(); /* Register the currently running task */
\r
197 trcCRITICAL_SECTION_END();
\r
200 return RecorderDataPtr->recorderActive;
\r
203 /*******************************************************************************
\r
206 * Starts the recorder. The recorder will not be started if an error has been
\r
207 * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h
\r
208 * has a too small value (NTASK, NQUEUE, etc).
\r
210 * This function is obsolete, but has been saved for backwards compatibility.
\r
211 * We recommend using uiTraceStart instead.
\r
212 ******************************************************************************/
\r
213 void vTraceStart(void)
\r
215 (void)uiTraceStart();
\r
218 /*******************************************************************************
\r
221 * Stops the recorder. The recording can be resumed by calling vTraceStart.
\r
222 * This does not reset the recorder. Use vTraceClear is that is desired.
\r
223 ******************************************************************************/
\r
224 void vTraceStop(void)
\r
226 RecorderDataPtr->recorderActive = 0;
\r
229 /*******************************************************************************
\r
230 * xTraceGetLastError
\r
232 * Gives the last error message, if any. NULL if no error message is stored.
\r
233 * The message is cleared on read.
\r
234 * Any error message is also presented when opening a trace file in
\r
235 * FreeRTOS+Trace v2.2.2 or later.
\r
236 ******************************************************************************/
\r
237 char* xTraceGetLastError(void)
\r
239 return traceErrorMessage;
\r
242 /*******************************************************************************
\r
243 * vTraceGetTraceBuffer
\r
245 * Returns a pointer to the recorder data structure. Use this together with
\r
246 * uiTraceGetTraceBufferSize if you wish to implement an own store/upload
\r
247 * solution, e.g., in case a debugger connection is not available for uploading
\r
249 ******************************************************************************/
\r
250 void* vTraceGetTraceBuffer(void)
\r
252 return RecorderDataPtr;
\r
255 /*******************************************************************************
\r
256 * uiTraceGetTraceBufferSize
\r
258 * Gets the size of the recorder data structure. For use together with
\r
259 * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,
\r
260 * e.g., in case a debugger connection is not available for uploading the data.
\r
261 ******************************************************************************/
\r
262 uint32_t uiTraceGetTraceBufferSize(void)
\r
264 return sizeof(RecorderDataType);
\r
267 /*******************************************************************************
\r
268 * prvTraceExcludeOrIncludeKernelServiceFromTrace
\r
270 * Includes or excludes all events that is related to the kernel service.
\r
271 ******************************************************************************/
\r
272 static void prvTraceExcludeOrIncludeKernelServiceFromTrace(traceKernelService kernelService, uint8_t flag)
\r
274 switch(kernelService)
\r
276 case TRACE_KERNEL_SERVICE_TASK_CREATE:
\r
279 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_TASK);
\r
280 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_TASK);
\r
284 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_TASK);
\r
285 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_TASK);
\r
288 case TRACE_KERNEL_SERVICE_TASK_DELETE:
\r
291 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_TASK);
\r
295 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_TASK);
\r
298 case TRACE_KERNEL_SERVICE_TASK_DELAY:
\r
301 SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY);
\r
302 SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY_UNTIL);
\r
306 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY);
\r
307 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_DELAY_UNTIL);
\r
310 case TRACE_KERNEL_SERVICE_PRIORITY_SET:
\r
313 SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_PRIORITY_SET);
\r
317 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_PRIORITY_SET);
\r
320 case TRACE_KERNEL_SERVICE_TASK_SUSPEND:
\r
323 SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_SUSPEND);
\r
327 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_SUSPEND);
\r
330 case TRACE_KERNEL_SERVICE_TASK_RESUME:
\r
333 SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_RESUME);
\r
334 SET_EVENT_CODE_FLAG_ISEXCLUDED(TASK_RESUME_FROM_ISR);
\r
338 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_RESUME);
\r
339 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(TASK_RESUME_FROM_ISR);
\r
342 case TRACE_KERNEL_SERVICE_QUEUE_CREATE:
\r
345 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_QUEUE);
\r
346 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_QUEUE);
\r
350 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_QUEUE);
\r
351 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_QUEUE);
\r
354 case TRACE_KERNEL_SERVICE_QUEUE_DELETE:
\r
357 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_QUEUE);
\r
361 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_QUEUE);
\r
364 case TRACE_KERNEL_SERVICE_QUEUE_SEND:
\r
367 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND + TRACE_CLASS_QUEUE);
\r
368 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND + TRACE_CLASS_QUEUE);
\r
369 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_SEND + TRACE_CLASS_QUEUE);
\r
370 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR + TRACE_CLASS_QUEUE);
\r
371 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND_FROM_ISR + TRACE_CLASS_QUEUE);
\r
377 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND + TRACE_CLASS_QUEUE);
\r
378 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND + TRACE_CLASS_QUEUE);
\r
379 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_SEND + TRACE_CLASS_QUEUE);
\r
380 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR + TRACE_CLASS_QUEUE);
\r
381 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND_FROM_ISR + TRACE_CLASS_QUEUE);
\r
384 case TRACE_KERNEL_SERVICE_QUEUE_RECEIVE:
\r
387 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE + TRACE_CLASS_QUEUE);
\r
388 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE + TRACE_CLASS_QUEUE);
\r
389 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_RECEIVE + TRACE_CLASS_QUEUE);
\r
390 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR + TRACE_CLASS_QUEUE);
\r
391 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE_FROM_ISR + TRACE_CLASS_QUEUE);
\r
395 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE + TRACE_CLASS_QUEUE);
\r
396 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE + TRACE_CLASS_QUEUE);
\r
397 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_RECEIVE + TRACE_CLASS_QUEUE);
\r
398 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR + TRACE_CLASS_QUEUE);
\r
399 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE_FROM_ISR + TRACE_CLASS_QUEUE);
\r
402 case TRACE_KERNEL_SERVICE_QUEUE_PEEK:
\r
405 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_PEEK + TRACE_CLASS_QUEUE);
\r
406 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_PEEK + TRACE_CLASS_SEMAPHORE);
\r
407 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_PEEK + TRACE_CLASS_MUTEX);
\r
411 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_PEEK + TRACE_CLASS_QUEUE);
\r
412 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_PEEK + TRACE_CLASS_SEMAPHORE);
\r
413 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_PEEK + TRACE_CLASS_MUTEX);
\r
416 case TRACE_KERNEL_SERVICE_MUTEX_CREATE:
\r
419 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_MUTEX);
\r
420 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_MUTEX);
\r
424 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_MUTEX);
\r
425 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_MUTEX);
\r
428 case TRACE_KERNEL_SERVICE_MUTEX_DELETE:
\r
431 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_MUTEX);
\r
435 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_MUTEX);
\r
438 case TRACE_KERNEL_SERVICE_MUTEX_GIVE:
\r
441 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND + TRACE_CLASS_MUTEX);
\r
442 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND + TRACE_CLASS_MUTEX);
\r
443 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_SEND + TRACE_CLASS_MUTEX);
\r
444 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR + TRACE_CLASS_MUTEX);
\r
445 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND_FROM_ISR + TRACE_CLASS_MUTEX);
\r
449 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND + TRACE_CLASS_MUTEX);
\r
450 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND + TRACE_CLASS_MUTEX);
\r
451 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_SEND + TRACE_CLASS_MUTEX);
\r
452 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR + TRACE_CLASS_MUTEX);
\r
453 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND_FROM_ISR + TRACE_CLASS_MUTEX);
\r
456 case TRACE_KERNEL_SERVICE_MUTEX_TAKE:
\r
459 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE + TRACE_CLASS_MUTEX);
\r
460 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE + TRACE_CLASS_MUTEX);
\r
461 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_RECEIVE + TRACE_CLASS_MUTEX);
\r
462 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR + TRACE_CLASS_MUTEX);
\r
463 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE_FROM_ISR + TRACE_CLASS_MUTEX);
\r
467 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE + TRACE_CLASS_MUTEX);
\r
468 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE + TRACE_CLASS_MUTEX);
\r
469 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_RECEIVE + TRACE_CLASS_MUTEX);
\r
470 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR + TRACE_CLASS_MUTEX);
\r
471 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE_FROM_ISR + TRACE_CLASS_MUTEX);
\r
474 case TRACE_KERNEL_SERVICE_SEMAPHORE_CREATE:
\r
477 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_SEMAPHORE);
\r
478 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_SEMAPHORE);
\r
482 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_CREATE + TRACE_CLASS_SEMAPHORE);
\r
483 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_CREATE + TRACE_CLASS_SEMAPHORE);
\r
486 case TRACE_KERNEL_SERVICE_SEMAPHORE_DELETE:
\r
489 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_SEMAPHORE);
\r
493 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_DELETE + TRACE_CLASS_SEMAPHORE);
\r
496 case TRACE_KERNEL_SERVICE_SEMAPHORE_GIVE:
\r
499 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND + TRACE_CLASS_SEMAPHORE);
\r
500 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND + TRACE_CLASS_SEMAPHORE);
\r
501 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_SEND + TRACE_CLASS_SEMAPHORE);
\r
502 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
503 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
507 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND + TRACE_CLASS_SEMAPHORE);
\r
508 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND + TRACE_CLASS_SEMAPHORE);
\r
509 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_SEND + TRACE_CLASS_SEMAPHORE);
\r
510 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_SEND_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
511 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_SEND_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
514 case TRACE_KERNEL_SERVICE_SEMAPHORE_TAKE:
\r
517 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE + TRACE_CLASS_SEMAPHORE);
\r
518 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE + TRACE_CLASS_SEMAPHORE);
\r
519 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_RECEIVE + TRACE_CLASS_SEMAPHORE);
\r
520 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
521 SET_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
525 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE + TRACE_CLASS_SEMAPHORE);
\r
526 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE + TRACE_CLASS_SEMAPHORE);
\r
527 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_BLOCK_ON_RECEIVE + TRACE_CLASS_SEMAPHORE);
\r
528 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_RECEIVE_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
529 CLEAR_EVENT_CODE_FLAG_ISEXCLUDED(EVENTGROUP_FAILED_RECEIVE_FROM_ISR + TRACE_CLASS_SEMAPHORE);
\r
535 /******************************************************************************
\r
536 * vTraceExclude______FromTrace
\r
538 * Excludes a task or object from the trace.
\r
539 * This can be useful if some irrelevant task is very frequent and is "eating
\r
540 * up the buffer". This should be called after the task has been created, but
\r
541 * before starting the FreeRTOS scheduler.
\r
542 *****************************************************************************/
\r
543 void vTraceExcludeQueueFromTrace(void* handle)
\r
545 SET_QUEUE_FLAG_ISEXCLUDED(ucQueueGetQueueNumber(handle));
\r
548 void vTraceExcludeSemaphoreFromTrace(void* handle)
\r
550 SET_SEMAPHORE_FLAG_ISEXCLUDED(ucQueueGetQueueNumber(handle));
\r
553 void vTraceExcludeMutexFromTrace(void* handle)
\r
555 SET_MUTEX_FLAG_ISEXCLUDED(ucQueueGetQueueNumber(handle));
\r
558 void vTraceExcludeTaskFromTrace(void* handle)
\r
560 SET_TASK_FLAG_ISEXCLUDED(uxTaskGetTaskNumber(handle));
\r
563 void vTraceExcludeKernelServiceFromTrace(traceKernelService kernelService)
\r
565 prvTraceExcludeOrIncludeKernelServiceFromTrace(kernelService, 1);
\r
568 /******************************************************************************
\r
569 * vTraceInclude______InTrace
\r
571 * Includes a task, object or kernel service in the trace. This is only
\r
572 * necessary if the task or object has been previously exluded.
\r
573 *****************************************************************************/
\r
574 void vTraceIncludeQueueInTrace(void* handle)
\r
576 CLEAR_QUEUE_FLAG_ISEXCLUDED(ucQueueGetQueueNumber(handle));
\r
579 void vTraceIncludeSemaphoreInTrace(void* handle)
\r
581 CLEAR_SEMAPHORE_FLAG_ISEXCLUDED(ucQueueGetQueueNumber(handle));
\r
584 void vTraceIncludeMutexInTrace(void* handle)
\r
586 CLEAR_MUTEX_FLAG_ISEXCLUDED(ucQueueGetQueueNumber(handle));
\r
589 void vTraceIncludeTaskInTrace(void* handle)
\r
591 CLEAR_TASK_FLAG_ISEXCLUDED(uxTaskGetTaskNumber(handle));
\r
594 void vTraceIncludeKernelServiceInTrace(traceKernelService kernelService)
\r
596 prvTraceExcludeOrIncludeKernelServiceFromTrace(kernelService, 0);
\r
599 /*******************************************************************************
\r
600 * vTraceSetQueueName
\r
602 * Assigns a name to a FreeRTOS Queue, Semaphore or Mutex. This function should
\r
603 * be called right after creation of the queue/mutex/semaphore. If not using
\r
604 * this function, the queues/mutexes/semaphores will be presented by their
\r
605 * numeric handle only.
\r
608 * actuatorQ = xQueueCreate(3, sizeof(QueueMessage));
\r
609 * vTraceSetQueueName(actuatorQ, "ActuatorQueue");
\r
610 ******************************************************************************/
\r
611 void vTraceSetQueueName(void* queue, const char* name)
\r
613 int t = ucQueueGetQueueType(queue);
\r
614 vTraceSetObjectName(TraceObjectClassTable[t],
\r
615 (objectHandleType)ucQueueGetQueueNumber(queue), name);
\r
619 /******************************************************************************
\r
620 * vTraceTaskInstanceIsFinished
\r
622 * This defines an explicit Instance Finish Event for the current task. It tells
\r
623 * the recorder that the current instance of this task is finished at the next
\r
624 * kernel call of the task, e.g., a taskDelay or a queue receive. This function
\r
625 * should be called right before the api function call considered to be the end
\r
626 * of the current task instance, i.e., the Instance Finish Event.
\r
627 *****************************************************************************/
\r
628 void vTraceTaskInstanceIsFinished()
\r
630 if (handle_of_last_logged_task)
\r
632 SET_TASK_FLAG_MARKIFE(handle_of_last_logged_task);
\r
636 /*******************************************************************************
\r
637 * vvTraceTaskSkipDefaultInstanceFinishedEvents
\r
639 * This is useful if there are implicit Instance Finish Events, such as
\r
640 * vTaskDelayUntil or xQueueReceive, in a task where an explicit Instance Finish
\r
641 * Event has been defined. This function tells the recorder that only the
\r
642 * explicitly defined functions, using vTraceTaskInstanceIsFinished, should be
\r
643 * treated as Instance Finish Events for this task. The implicit Instance Finish
\r
644 * Events are thus disregarded for the calling task.
\r
645 ******************************************************************************/
\r
646 void vTraceTaskSkipDefaultInstanceFinishedEvents()
\r
648 if (handle_of_last_logged_task)
\r
650 PROPERTY_TASK_IFE_SERVICECODE(handle_of_last_logged_task) =
\r
651 RESERVED_DUMMY_CODE;
\r
655 /*******************************************************************************
\r
656 * Interrupt recording functions
\r
657 ******************************************************************************/
\r
659 #if (INCLUDE_ISR_TRACING == 1)
\r
661 #define MAX_ISR_NESTING 16
\r
662 static uint8_t isrstack[MAX_ISR_NESTING];
\r
664 /*******************************************************************************
\r
665 * vTraceSetISRProperties
\r
667 * Registers an Interrupt Service Routine in the recorder library, This must be
\r
668 * called before using vTraceStoreISRBegin to store ISR events. This is
\r
669 * typically called in the startup of the system, before the scheduler is
\r
673 * #define ID_ISR_TIMER1 1 // lowest valid ID is 1
\r
674 * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
\r
676 * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
\r
678 * void ISR_handler()
\r
680 * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
\r
682 * vTraceStoreISREnd();
\r
685 * NOTE: To safely record ISRs, you need to make sure that all traced
\r
686 * interrupts actually are disabled by trcCRITICAL_SECTION_BEGIN(), which
\r
687 * typically is mapped to portENTER_CRITICAL(), which uses the macro
\r
688 * portDISABLE_INTERRUPTS. However, in some ports of FreeRTOS and depending on
\r
689 * FreeRTOS configuration, this does not disable high priority interrupts!
\r
690 * If an ISR calls vTraceStoreISRBegin while the recorder is busy, it will
\r
691 * stop the recording and give an error message.
\r
692 ******************************************************************************/
\r
693 void vTraceSetISRProperties(objectHandleType handle, const char* name, char priority)
\r
695 vTraceSetObjectName(TRACE_CLASS_ISR, handle, name);
\r
696 vTraceSetPriorityProperty(TRACE_CLASS_ISR, handle, priority);
\r
699 /*******************************************************************************
\r
700 * vTraceStoreISRBegin
\r
702 * Registers the beginning of an Interrupt Service Routine.
\r
705 * #define ID_ISR_TIMER1 1 // lowest valid ID is 1
\r
706 * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
\r
708 * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
\r
710 * void ISR_handler()
\r
712 * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
\r
714 * vTraceStoreISREnd();
\r
717 * NOTE: You need to make sure that any traced interrupts actually are
\r
718 * disabled by trcCRITICAL_SECTION_BEGIN(), i.e., taskENTER_CRITICAL() which
\r
719 * uses portDISABLE_INTERRUPTS().
\r
720 * In some ports of FreeRTOS, this does not disable high-priority interrupts,
\r
721 * i.e., with priorities above configMAX_SYSCALL_INTERRUPT_PRIORITY.
\r
722 * If an invalid call to vTraceStoreISRBegin is detected (i.e., that preempted
\r
723 * a critical section of the recorder) this will generate a recorder error
\r
724 * using vTraceError.
\r
725 ******************************************************************************/
\r
726 void vTraceStoreISRBegin(objectHandleType handle)
\r
729 TSEvent* ts = NULL;
\r
733 vTraceError("Illegal call to vTraceStoreISRBegin/End");
\r
736 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
738 trcCRITICAL_SECTION_BEGIN();
\r
739 dts4 = (uint16_t)prvTraceGetDTS(0xFFFF);
\r
741 if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
\r
744 if (nISRactive < MAX_ISR_NESTING)
\r
746 isrstack[nISRactive] = handle;
\r
748 ts = (TSEvent*)xTraceNextFreeEventBufferSlot();
\r
751 ts->type = TS_ISR_BEGIN;
\r
753 ts->objHandle = handle;
\r
754 prvTraceUpdateCounters();
\r
759 /* This should not occur unless something is very wrong */
\r
760 vTraceError("Too many nested interrupts!");
\r
763 trcCRITICAL_SECTION_END();
\r
768 #if (SELECTED_PORT == PORT_ARM_CortexM)
\r
770 int tailchain_irq_pending(void);
\r
772 /*******************************************************************************
\r
773 * tailchain_irq_pending
\r
775 * For Cortex-M chips only. Returns 1 if an interrupt is pending, by checking
\r
776 * the 8 NVIC IRQ pend registers at 0xE000E200 to 0xE000E21C. Returns 0 if no
\r
777 * interrupt is pending. This is used to predict tailchaining of ISRs.
\r
778 ******************************************************************************/
\r
779 int tailchain_irq_pending(void)
\r
781 uint32_t* pend_reg = ((uint32_t*)0xE000E200);
\r
784 for (i=0; i<8; i++)
\r
786 if (pend_reg[i] != 0)
\r
796 /*******************************************************************************
\r
797 * vTraceStoreISREnd
\r
799 * Registers the end of an Interrupt Service Routine.
\r
802 * #define ID_ISR_TIMER1 1 // lowest valid ID is 1
\r
803 * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
\r
805 * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
\r
807 * void ISR_handler()
\r
809 * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
\r
811 * vTraceStoreISREnd();
\r
814 * NOTE: You need to make sure that any traced interrupts actually are
\r
815 * disabled by trcCRITICAL_SECTION_BEGIN(), i.e., taskENTER_CRITICAL() which
\r
816 * uses portDISABLE_INTERRUPTS().
\r
817 * In some ports of FreeRTOS, this does not disable high-priority interrupts,
\r
818 * i.e., with priorities above configMAX_SYSCALL_INTERRUPT_PRIORITY.
\r
819 * If an invalid call to vTraceStoreISREnd is detected (i.e., that preempted
\r
820 * a critical section of the recorder) this will generate a recorder error
\r
821 * using vTraceError.
\r
822 ******************************************************************************/
\r
823 void vTraceStoreISREnd(void)
\r
830 vTraceError("Illegal call to vTraceStoreISRBegin/End");
\r
834 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
836 #if (SELECTED_PORT == PORT_ARM_CortexM)
\r
837 if (tailchain_irq_pending() > 0)
\r
839 nISRactive--; /* If an IRQ strikes exactly here, the resulting
\r
840 ISR tailchaining is not detected. The trace instead shows a very
\r
841 short fragment of the earlier preempted task/ISR, and then the new
\r
847 trcCRITICAL_SECTION_BEGIN();
\r
848 dts5 = (uint16_t)prvTraceGetDTS(0xFFFF);
\r
850 if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
\r
852 ts = (TSEvent*)xTraceNextFreeEventBufferSlot();
\r
855 if (nISRactive > 1)
\r
857 /* return to another isr */
\r
858 ts->type = TS_ISR_RESUME;
\r
859 ts->objHandle = isrstack[nISRactive];
\r
863 /* return to task */
\r
864 ts->type = TS_TASK_RESUME;
\r
865 ts->objHandle = handle_of_last_logged_task;
\r
869 prvTraceUpdateCounters();
\r
872 trcCRITICAL_SECTION_END();
\r
878 /* ISR tracing is turned off */
\r
879 void vTraceIncreaseISRActive(void)
\r
881 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
885 void vTraceDecreaseISRActive(objectHandleType handle)
\r
887 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
893 /*******************************************************************************
\r
894 * User Event functions
\r
895 ******************************************************************************/
\r
897 #if (INCLUDE_USER_EVENTS == 1)
\r
899 /******************************************************************************
\r
902 * Basic user event (Standard and Professional Edition only)
\r
904 * Generates a User Event with a text label. The label is created/looked up
\r
905 * in the symbol table using xTraceOpenLabel.
\r
906 ******************************************************************************/
\r
907 void vTraceUserEvent(traceLabel eventLabel)
\r
912 if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive ) && handle_of_last_logged_task)
\r
914 trcCRITICAL_SECTION_BEGIN();
\r
916 dts1 = (uint8_t)prvTraceGetDTS(0xFF);
\r
918 if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
\r
920 ue = (UserEvent*) xTraceNextFreeEventBufferSlot();
\r
924 ue->type = USER_EVENT;
\r
925 ue->payload = eventLabel;
\r
926 prvTraceUpdateCounters();
\r
929 trcCRITICAL_SECTION_END();
\r
933 /*** Locally used in vTracePrintF ***/
\r
935 /* one word (32 bit) is required for the USER_EVENT entry, 8 words
\r
936 (8*32 bit = 32 byte) available for argument data */
\r
937 #define MAX_ARG_SIZE (4+32)
\r
939 static uint8_t writeInt8(void * buffer, uint8_t i, uint8_t value);
\r
940 static uint8_t writeInt16(void * buffer, uint8_t i, uint16_t value);
\r
941 static uint8_t writeInt32(void * buffer, uint8_t i, uint32_t value);
\r
943 #if (INCLUDE_FLOAT_SUPPORT)
\r
944 static uint8_t writeFloat(void * buffer, uint8_t i, float value);
\r
945 static uint8_t writeDouble(void * buffer, uint8_t i, double value);
\r
948 /*** Locally used in vTracePrintF ***/
\r
949 static uint8_t writeInt8(void * buffer, uint8_t i, uint8_t value)
\r
952 if (i >= MAX_ARG_SIZE)
\r
957 ((uint8_t*)buffer)[i] = value;
\r
959 if (i + 1 > MAX_ARG_SIZE)
\r
967 /*** Locally used in vTracePrintF ***/
\r
968 static uint8_t writeInt16(void * buffer, uint8_t i, uint16_t value)
\r
970 /* Align to multiple of 2 */
\r
971 while ((i % 2) != 0)
\r
973 if (i >= MAX_ARG_SIZE)
\r
978 ((uint8_t*)buffer)[i] = 0;
\r
982 if (i + 2 > MAX_ARG_SIZE)
\r
987 ((uint16_t*)buffer)[i/2] = value;
\r
992 /*** Locally used in vTracePrintF ***/
\r
993 static uint8_t writeInt32(void * buffer, uint8_t i, uint32_t value)
\r
996 /* A 32 bit value should begin at an even 4-byte address */
\r
997 while ((i % 4) != 0)
\r
999 if (i >= MAX_ARG_SIZE)
\r
1004 ((uint8_t*)buffer)[i] = 0;
\r
1008 if (i + 4 > MAX_ARG_SIZE)
\r
1013 ((uint32_t*)buffer)[i/4] = value;
\r
1018 #if (INCLUDE_FLOAT_SUPPORT)
\r
1020 /*** Locally used in vTracePrintF ***/
\r
1021 static uint8_t writeFloat(void * buffer, uint8_t i, float value)
\r
1023 /* A 32 bit value should begin at an even 4-byte address */
\r
1024 while ((i % 4) != 0)
\r
1026 if (i >= MAX_ARG_SIZE)
\r
1031 ((uint8_t*)buffer)[i] = 0;
\r
1035 if (i + 4 > MAX_ARG_SIZE)
\r
1040 ((float*)buffer)[i/4] = value;
\r
1045 /*** Locally used in vTracePrintF ***/
\r
1046 static uint8_t writeDouble(void * buffer, uint8_t i, double value)
\r
1048 uint32_t * dest = buffer;
\r
1049 uint32_t * src = (void*)&value;
\r
1050 /* The double is written as two 32 bit values, and should begin at an even
\r
1051 4-byte address (to avoid having to align with 8 byte) */
\r
1052 while (i % 4 != 0)
\r
1054 if (i >= MAX_ARG_SIZE)
\r
1059 ((uint8_t*)buffer)[i] = 0;
\r
1063 if (i + 8 > MAX_ARG_SIZE)
\r
1068 dest[i/4+0] = src[0];
\r
1069 dest[i/4+1] = src[1];
\r
1076 /******************************************************************************
\r
1079 * Advanced user events (Professional Edition only)
\r
1081 * Generates User Event with formatted text and data, similar to a "printf".
\r
1082 * It is very fast compared to a normal "printf" since this function only
\r
1083 * stores the arguments. The actual formatting is done
\r
1084 * on the host PC when the trace is displayed in the viewer tool.
\r
1086 * User Event labels are created using xTraceOpenLabel.
\r
1089 * traceLabel adc_uechannel = xTraceOpenLabel("ADC User Events");
\r
1091 * vTracePrint(adc_uechannel,
\r
1092 * "ADC channel %d: %lf volts",
\r
1093 * ch, (double)adc_reading/(double)scale);
\r
1095 * This can be combined into one line, if desired, but this is slower:
\r
1097 * vTracePrint(xTraceOpenLabel("ADC User Events"),
\r
1098 * "ADC channel %d: %lf volts",
\r
1099 * ch, (double)adc_reading/(double)scale);
\r
1101 * Calling xTraceOpenLabel multiple times will not create duplicate entries, but
\r
1102 * it is of course faster to just do it once, and then keep the handle for later
\r
1103 * use. If you don´t have any data arguments, only a text label/string, it is
\r
1104 * better to use vTraceUserEvent - it is faster.
\r
1106 * Format specifiers supported:
\r
1107 * %d - 32 bit signed integer
\r
1108 * %u - 32 bit unsigned integer
\r
1109 * %f - 32 bit float
\r
1110 * %s - string (is copied to the recorder symbol table)
\r
1111 * %hd - 16 bit signed integer
\r
1112 * %hu - 16 bit unsigned integer
\r
1113 * %bd - 8 bit signed integer
\r
1114 * %bu - 8 bit unsigned integer
\r
1115 * %lf - double-precision float
\r
1117 * Up to 15 data arguments are allowed, with a total size of maximum 32 byte.
\r
1118 * In case this is exceeded, the user event is changed into an error message.
\r
1120 * The data is stored in trace buffer, and is packed to allow storing multiple
\r
1121 * smaller data entries in the same 4-byte record, e.g., four 8-bit values.
\r
1122 * A string requires two bytes, as the symbol table is limited to 64K. Storing a
\r
1123 * double (%lf) uses two records, so this is quite costly. Use float (%f) unless
\r
1124 * the higher precision is really necessary.
\r
1125 ******************************************************************************/
\r
1126 void vTracePrintF(traceLabel eventLabel, const char* formatStr, ...)
\r
1130 uint8_t argCounter = 0;
\r
1132 uint8_t nofEventEntries = 0;
\r
1133 uint16_t formatStrIndex = 0;
\r
1135 /**************************************************************************
\r
1136 * The array tempDataBuffer is a local buffer used in a two-phase commit of
\r
1137 * the event data, since a vTracePrintF may span over multiple slots in the
\r
1139 * This buffer can be made larger, of course, but remember the risk for
\r
1140 * stack overflow. Note: This should be a LOCAL buffer, must not be made
\r
1141 * global. That would cause data corruption when two calls to vTracePrintF
\r
1142 * from different tasks overlaps (interrupts are only disabled in a small
\r
1143 * part of this function, otherwise enabled)
\r
1144 ***************************************************************************/
\r
1146 uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];
\r
1149 if ((inExcludedTask == 0) &&
\r
1150 (nISRactive == 0) &&
\r
1151 (RecorderDataPtr->recorderActive == 1) &&
\r
1152 (handle_of_last_logged_task > 0))
\r
1154 /* First, write the "primary" user event entry in the local buffer, but
\r
1155 let the event type be "EVENT_BEING_WRITTEN" for now...*/
\r
1157 ue1 = (UserEvent*)(&tempDataBuffer[0]);
\r
1158 ue1->type = EVENT_BEING_WRITTEN; /* Update this as the last step */
\r
1161 formatStrIndex = 0;
\r
1162 va_start(vl, formatStr); /* Begin reading the arguments list */
\r
1164 while (formatStr[formatStrIndex] != '\0')
\r
1166 if (formatStr[formatStrIndex] == '%')
\r
1170 if (argCounter > 15)
\r
1172 vTraceError("vTracePrintF - Too many arguments, max 15 allowed!");
\r
1174 formatStr = "[vTracePrintF error] Too many arguments, max 15 allowed!";
\r
1179 /*******************************************************************************
\r
1180 * These below code writes raw data (primitive datatypes) in the event buffer,
\r
1181 * instead of the normal event structs (where byte 0 is event type).
\r
1182 * These data entries must never be interpreted as real event data, as the type
\r
1183 * field would be misleading since used for payload data.
\r
1185 * The correctness of this encoding depends on two mechanisms:
\r
1187 * 1. An initial USER_EVENT, which type code tells the number of 32-bit data
\r
1188 * entires that follows. (code - USER_EVENT = number of data entries).
\r
1189 * Note that a data entry corresponds to the slots that normally corresponds to
\r
1190 * one (1) event, i.e., 32 bits. vTracePrintF may encode several pieces of data
\r
1191 * in one data entry, e.g., two 16-bit values or four 8-bit values, one 16-bit
\r
1192 * value followes by two 8-bit values, etc.
\r
1194 * 2. A two-phase commit procedure, where the USER_EVENT and data entries are
\r
1195 * written to a local buffer at first, and when all checks are OK then copied to
\r
1196 * the main event buffer using a fast memcpy. The event code is finalized as the
\r
1197 * very last step. Before that that step, the event code indicates an unfinished
\r
1198 * event, which causes it to be ignored and stop the loading of the file (since
\r
1199 * an unfinished event is the last event in the trace).
\r
1200 *******************************************************************************/
\r
1202 switch (formatStr[formatStrIndex])
\r
1204 case 'd': i = writeInt32((uint8_t*)tempDataBuffer,
\r
1206 (uint32_t)va_arg(vl, uint32_t));
\r
1208 case 'u': i = writeInt32((uint8_t*)tempDataBuffer,
\r
1210 (uint32_t)va_arg(vl, uint32_t));
\r
1212 case 's': i = writeInt16((uint8_t*)tempDataBuffer,
\r
1214 (uint16_t)xTraceOpenLabel((char*)va_arg(vl, char*)));
\r
1217 #if (INCLUDE_FLOAT_SUPPORT)
\r
1218 /* Yes, "double" as type also in the float
\r
1219 case. This since "float" is promoted into "double"
\r
1220 by the va_arg stuff. */
\r
1221 case 'f': i = writeFloat((uint8_t*)tempDataBuffer,
\r
1223 (float)va_arg(vl, double));
\r
1226 /* No support for floats, but attempt to store a float user event
\r
1227 avoid a possible crash due to float reference. Instead store the
\r
1228 data on uint_32 format (will not be displayed anyway). This is just
\r
1229 to keep va_arg and i consistent. */
\r
1231 case 'f': i = writeInt32((uint8_t*)tempDataBuffer,
\r
1233 (uint32_t)va_arg(vl, double));
\r
1237 switch (formatStr[formatStrIndex])
\r
1239 #if (INCLUDE_FLOAT_SUPPORT)
\r
1240 case 'f': i = writeDouble((uint8_t*)tempDataBuffer,
\r
1242 (double)va_arg(vl, double));
\r
1245 /* No support for floats, but attempt to store a float user event
\r
1246 avoid a possible crash due to float reference. Instead store the
\r
1247 data on uint_32 format (will not be displayed anyway). This is just
\r
1248 to keep va_arg and i consistent. */
\r
1249 case 'f': i = writeInt32((uint8_t*)tempDataBuffer, /* In this case, the value will not be shown anyway */
\r
1251 (uint32_t)va_arg(vl, double));
\r
1252 i = writeInt32((uint8_t*)tempDataBuffer, /* Do it twice, to write in total 8 bytes */
\r
1254 (uint32_t)va_arg(vl, double));
\r
1261 switch (formatStr[formatStrIndex])
\r
1263 case 'd': i = writeInt16((uint8_t*)tempDataBuffer,
\r
1265 (uint16_t)va_arg(vl, uint32_t));
\r
1267 case 'u': i = writeInt16((uint8_t*)tempDataBuffer,
\r
1269 (uint16_t)va_arg(vl, uint32_t));
\r
1275 switch (formatStr[formatStrIndex])
\r
1277 case 'd': i = writeInt8((uint8_t*)tempDataBuffer,
\r
1279 (uint8_t)va_arg(vl, uint32_t));
\r
1281 case 'u': i = writeInt8((uint8_t*)tempDataBuffer,
\r
1283 (uint8_t)va_arg(vl, uint32_t));
\r
1289 formatStrIndex++;
\r
1293 //vTraceError("vTracePrintF - Too large arguments, max 32 byte allowed!");
\r
1294 formatStr = "[vTracePrintF error] Too large arguments, max 32 byte allowed!";
\r
1302 /* Store the format string, with a reference to the channel symbol */
\r
1303 ue1->payload = prvTraceOpenSymbol(formatStr, eventLabel);
\r
1305 trcCRITICAL_SECTION_BEGIN();
\r
1307 ue1->dts = (uint8_t)prvTraceGetDTS(0xFF);
\r
1308 if (! RecorderDataPtr->recorderActive)
\r
1311 /* Abort, since an XTS event (created by prvTraceGetDTS) filled the
\r
1312 buffer, and the recorder stopped since not circular buffer. */
\r
1313 trcCRITICAL_SECTION_END();
\r
1318 nofEventEntries = (i+3)/4;
\r
1320 /* If the data does not fit in the remaining main buffer, wrap around to
\r
1321 0 if allowed, otherwise stop the recorder and quit). */
\r
1322 if (RecorderDataPtr->nextFreeIndex + nofEventEntries > RecorderDataPtr->maxEvents)
\r
1324 #if (RECORDER_STORE_MODE == STORE_MODE_RING_BUFFER)
\r
1325 (void)memset(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],
\r
1327 (RecorderDataPtr->maxEvents - RecorderDataPtr->nextFreeIndex)*4);
\r
1328 RecorderDataPtr->nextFreeIndex = 0;
\r
1329 RecorderDataPtr->bufferIsFull = 1;
\r
1331 /* Abort and stop recorder, since the event data will not fit in the
\r
1332 buffer and not circular buffer in this case... */
\r
1333 trcCRITICAL_SECTION_END();
\r
1341 #if (RECORDER_STORE_MODE == STORE_MODE_RING_BUFFER)
\r
1342 /* Check that the buffer to be overwritten does not contain any user
\r
1343 events that would be partially overwritten. If so, they must be "killed"
\r
1344 by replacing the user event and following data with NULL events (i.e.,
\r
1345 using a memset to zero).*/
\r
1346 prvCheckDataToBeOverwrittenForMultiEntryUserEvents(nofEventEntries);
\r
1348 /* Copy the local buffer to the main buffer */
\r
1349 (void)memcpy(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],
\r
1353 /* Update the event type, i.e., number of data entries following the
\r
1354 main USER_EVENT entry (Note: important that this is after the memcpy,
\r
1355 but within the critical section!)*/
\r
1356 RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4] =
\r
1357 (uint8_t) USER_EVENT + nofEventEntries - 1;
\r
1359 /* Update the main buffer event index (already checked that it fits in
\r
1360 the buffer, so no need to check for wrapping)*/
\r
1362 RecorderDataPtr->nextFreeIndex += nofEventEntries;
\r
1363 RecorderDataPtr->numEvents += nofEventEntries;
\r
1365 if (RecorderDataPtr->nextFreeIndex >= EVENT_BUFFER_SIZE)
\r
1368 #if (RECORDER_STORE_MODE == STORE_MODE_RING_BUFFER)
\r
1369 RecorderDataPtr->nextFreeIndex = 0;
\r
1370 RecorderDataPtr->bufferIsFull = 1;
\r
1376 trcCRITICAL_SECTION_END();
\r
1380 /*******************************************************************************
\r
1383 * Creates user event labels for user event channels or for individual events.
\r
1384 * User events can be used to log application events and data for display in
\r
1385 * the visualization tool. A user event is identified by a label, i.e., a string,
\r
1386 * which is stored in the recorder's symbol table.
\r
1387 * When logging a user event, a numeric handle (reference) to this string is
\r
1388 * used to identify the event. This is obtained by calling
\r
1390 * xTraceOpenLabel()
\r
1392 * which adds the string to the symbol table (if not already present)
\r
1393 * and returns the corresponding handle.
\r
1395 * This can be used in two ways:
\r
1397 * 1. The handle is looked up every time, when storing the user event.
\r
1400 * vTraceUserEvent(xTraceOpenLabel("MyUserEvent"));
\r
1402 * 2. The label is registered just once, with the handle stored in an
\r
1403 * application variable - much like using a file handle.
\r
1406 * myEventHandle = xTraceOpenLabel("MyUserEvent");
\r
1408 * vTraceUserEvent(myEventHandle);
\r
1410 * The second option is faster since no lookup is required on each event, and
\r
1411 * therefore recommended for user events that are frequently
\r
1412 * executed and/or located in time-critical code. The lookup operation is
\r
1413 * however fairly fast due to the design of the symbol table.
\r
1414 ******************************************************************************/
\r
1415 traceLabel xTraceOpenLabel(const char* label)
\r
1417 return prvTraceOpenSymbol(label, 0);
\r