1 /*******************************************************************************
\r
2 * Tracealyzer v2.6.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 trcHardwarePort.c/.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 * Copyright Percepio AB, 2013.
\r
36 ******************************************************************************/
\r
37 #include "FreeRTOS.h"
\r
40 #include "trcUser.h"
\r
42 #if (USE_TRACEALYZER_RECORDER == 1)
\r
48 TRACE_STOP_HOOK vTraceStopHookPtr = (TRACE_STOP_HOOK)0;
\r
50 extern uint8_t inExcludedTask;
\r
51 extern uint8_t nISRactive;
\r
52 extern objectHandleType handle_of_last_logged_task;
\r
53 extern uint32_t dts_min;
\r
54 extern uint32_t hwtc_count_max_after_tick;
\r
55 extern uint32_t hwtc_count_sum_after_tick;
\r
56 extern uint32_t hwtc_count_sum_after_tick_counter;
\r
57 extern char* traceErrorMessage;
\r
59 /*** private functions *******************************************************/
\r
60 void vTracePrintF_Helper(traceLabel eventLabel, const char* formatStr, va_list vl);
\r
62 #if (USE_SEPARATE_USER_EVENT_BUFFER == 1)
\r
63 void vTraceChannelPrintF_Helper(UserEventChannel channelPair, va_list vl);
\r
64 static void prvTraceUserEventHelper1(UserEventChannel channel, traceLabel eventLabel, traceLabel formatLabel, va_list vl);
\r
65 static void prvTraceUserEventHelper2(UserEventChannel channel, uint32_t* data, uint32_t noOfSlots);
\r
67 /*****************************************************************************/
\r
71 /*******************************************************************************
\r
72 * vTraceInitTraceData
\r
74 * Allocates, if necessary, and initializes the recorder data structure, based
\r
75 * on the constants in trcConfig.h.
\r
76 ******************************************************************************/
\r
77 void vTraceInitTraceData(void)
\r
79 prvTraceInitTraceData();
\r
82 /*******************************************************************************
\r
83 * vTraceSetRecorderData
\r
85 * If custom allocation is used, this function must be called so the recorder
\r
86 * library knows where to save the trace data.
\r
87 ******************************************************************************/
\r
88 #if TRACE_DATA_ALLOCATION == TRACE_DATA_ALLOCATION_CUSTOM
\r
89 void vTraceSetRecorderData(void* pRecorderData)
\r
91 TRACE_ASSERT(pRecorderData != NULL, "vTraceSetTraceData, pRecorderData == NULL", );
\r
92 RecorderDataPtr = pRecorderData;
\r
96 /*******************************************************************************
\r
99 * Resets the recorder. Only necessary if a restart is desired - this is not
\r
100 * needed in the startup initialization.
\r
101 ******************************************************************************/
\r
102 void vTraceClear(void)
\r
104 TRACE_SR_ALLOC_CRITICAL_SECTION();
\r
105 trcCRITICAL_SECTION_BEGIN();
\r
107 RecorderDataPtr->absTimeLastEvent = 0;
\r
108 RecorderDataPtr->nextFreeIndex = 0;
\r
109 RecorderDataPtr->numEvents = 0;
\r
110 RecorderDataPtr->bufferIsFull = 0;
\r
111 traceErrorMessage = NULL;
\r
112 RecorderDataPtr->internalErrorOccured = 0;
\r
114 trcCRITICAL_SECTION_END();
\r
118 /*******************************************************************************
\r
121 * Starts the recorder. The recorder will not be started if an error has been
\r
122 * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h
\r
123 * has a too small value (NTASK, NQUEUE, etc).
\r
125 * Returns 1 if the recorder was started successfully.
\r
126 * Returns 0 if the recorder start was prevented due to a previous internal
\r
127 * error. In that case, check vTraceGetLastError to get the error message.
\r
128 * Any error message is also presented when opening a trace file.
\r
129 ******************************************************************************/
\r
131 uint32_t uiTraceStart(void)
\r
133 objectHandleType handle;
\r
134 TRACE_SR_ALLOC_CRITICAL_SECTION();
\r
138 if (RecorderDataPtr == NULL)
\r
140 vTraceError("RecorderDataPtr is NULL. Call vTraceInitTraceData() before starting trace.");
\r
143 if (traceErrorMessage == NULL)
\r
145 trcCRITICAL_SECTION_BEGIN();
\r
146 RecorderDataPtr->recorderActive = 1;
\r
148 handle = TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK());
\r
151 /* This occurs if the scheduler is not yet started.
\r
152 This creates a dummy "(startup)" task entry internally in the
\r
154 handle = xTraceGetObjectHandle(TRACE_CLASS_TASK);
\r
155 vTraceSetObjectName(TRACE_CLASS_TASK, handle, "(startup)");
\r
157 vTraceSetPriorityProperty(TRACE_CLASS_TASK, handle, 0);
\r
160 vTraceStoreTaskswitch(handle); /* Register the currently running task */
\r
161 trcCRITICAL_SECTION_END();
\r
164 return RecorderDataPtr->recorderActive;
\r
167 /*******************************************************************************
\r
170 * Starts the recorder. The recorder will not be started if an error has been
\r
171 * indicated using vTraceError, e.g. if any of the Nx constants in trcConfig.h
\r
172 * has a too small value (NTASK, NQUEUE, etc).
\r
174 * This function is obsolete, but has been saved for backwards compatibility.
\r
175 * We recommend using uiTraceStart instead.
\r
176 ******************************************************************************/
\r
177 void vTraceStart(void)
\r
179 (void)uiTraceStart();
\r
182 /*******************************************************************************
\r
185 * Stops the recorder. The recording can be resumed by calling vTraceStart.
\r
186 * This does not reset the recorder. Use vTraceClear if that is desired.
\r
187 ******************************************************************************/
\r
188 void vTraceStop(void)
\r
190 RecorderDataPtr->recorderActive = 0;
\r
192 if (vTraceStopHookPtr != (TRACE_STOP_HOOK)0)
\r
194 (*vTraceStopHookPtr)(); /* Call an application level call back function. */
\r
198 /*******************************************************************************
\r
199 * xTraceGetLastError
\r
201 * Gives the last error message, if any. NULL if no error message is stored.
\r
202 * Any error message is also presented when opening a trace file.
\r
203 ******************************************************************************/
\r
204 char* xTraceGetLastError(void)
\r
206 return traceErrorMessage;
\r
209 /*******************************************************************************
\r
212 * Removes any previous error message generated by recorder calling vTraceError.
\r
213 * By calling this function, it may be possible to start/restart the trace
\r
214 * despite errors in the recorder, but there is no guarantee that the trace
\r
215 * recorder will work correctly in that case, depending on the type of error.
\r
216 ******************************************************************************/
\r
217 void vTraceClearError(int resetErrorMessage)
\r
219 ( void ) resetErrorMessage;
\r
220 traceErrorMessage = NULL;
\r
221 RecorderDataPtr->internalErrorOccured = 0;
\r
224 /*******************************************************************************
\r
225 * vTraceGetTraceBuffer
\r
227 * Returns a pointer to the recorder data structure. Use this together with
\r
228 * uiTraceGetTraceBufferSize if you wish to implement an own store/upload
\r
229 * solution, e.g., in case a debugger connection is not available for uploading
\r
231 ******************************************************************************/
\r
232 void* vTraceGetTraceBuffer(void)
\r
234 return RecorderDataPtr;
\r
237 /*******************************************************************************
\r
238 * uiTraceGetTraceBufferSize
\r
240 * Gets the size of the recorder data structure. For use together with
\r
241 * vTraceGetTraceBuffer if you wish to implement an own store/upload solution,
\r
242 * e.g., in case a debugger connection is not available for uploading the data.
\r
243 ******************************************************************************/
\r
244 uint32_t uiTraceGetTraceBufferSize(void)
\r
246 return sizeof(RecorderDataType);
\r
249 /******************************************************************************
\r
250 * vTraceTaskInstanceIsFinished
\r
252 * This defines an explicit Instance Finish Event for the current task. It tells
\r
253 * the recorder that the current instance of this task is finished at the
\r
254 * context-switch. This function should be called right before the API function
\r
255 * call considered to be the Instance Finish Event.
\r
256 *****************************************************************************/
\r
257 void vTraceTaskInstanceIsFinished()
\r
259 if (handle_of_last_logged_task)
\r
261 TRACE_PROPERTY_OBJECT_STATE(TRACE_CLASS_TASK, handle_of_last_logged_task) = 0;
\r
265 /*******************************************************************************
\r
266 * Interrupt recording functions
\r
267 ******************************************************************************/
\r
269 #if (INCLUDE_ISR_TRACING == 1)
\r
271 #define MAX_ISR_NESTING 16
\r
272 static uint8_t isrstack[MAX_ISR_NESTING];
\r
274 /*******************************************************************************
\r
275 * vTraceSetISRProperties
\r
277 * Registers an Interrupt Service Routine in the recorder library, This must be
\r
278 * called before using vTraceStoreISRBegin to store ISR events. This is
\r
279 * typically called in the startup of the system, before the scheduler is
\r
283 * #define ID_ISR_TIMER1 1 // lowest valid ID is 1
\r
284 * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
\r
286 * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
\r
288 * void ISR_handler()
\r
290 * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
\r
292 * vTraceStoreISREnd();
\r
295 * NOTE: To safely record ISRs, you need to make sure that all traced
\r
296 * interrupts actually are disabled by trcCRITICAL_SECTION_BEGIN(). However,
\r
297 * in some ports this does not disable high priority interrupts!
\r
298 * If an ISR calls vTraceStoreISRBegin while the recorder is busy, it will
\r
299 * stop the recording and give an error message.
\r
300 ******************************************************************************/
\r
301 void vTraceSetISRProperties(objectHandleType handle, const char* name, char priority)
\r
303 TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceSetISRProperties: Invalid value for handle", );
\r
304 TRACE_ASSERT(name != NULL, "vTraceSetISRProperties: name == NULL", );
\r
305 TRACE_ASSERT(priority >= 0, "vTraceSetISRProperties: Invalid value for priority", );
\r
307 vTraceSetObjectName(TRACE_CLASS_ISR, handle, name);
\r
308 vTraceSetPriorityProperty(TRACE_CLASS_ISR, handle, priority);
\r
311 #if (SELECTED_PORT == PORT_ARM_CortexM)
\r
312 /******************************************************************************
\r
315 * ISR_TAILCHAINING_THRESHOLD (For Cortex-M devices only)
\r
317 * ARM Cortex-M devices may execute ISRs back-to-back (tail-chained) without
\r
318 * resuming the previous context in between. Since this is decided in
\r
319 * hardware, we can only detect this indirectly, in the following manner:
\r
321 * When entering vTraceStoreISRBegin, we check the number of CPU cycles since
\r
322 * the last return of vTraceStoreISREnd. If less or equal to the constant
\r
323 * ISR_TAILCHAINING_THRESHOLD it is assumed that the ISRs executed back-to-back
\r
324 * (tail-chained). In that case, the previously stored RESUME event
\r
325 * (pointed to by ptrLastISRExitEvent) is then deleted to avoid showing a
\r
326 * fragment of the previous context in between the ISR events. The delete is
\r
327 * made by replacing the event code with a XTS16L event, that serves to keep
\r
328 * the differential timestamp from the earlier event.
\r
330 * The value of ISR_TAILCHAINING_THRESHOLD depends on the interrupt latency of
\r
331 * the processor, on the compiler and on the compiler settings, but should be
\r
332 * around 70 cycles. The default value is 66 cycles, which should be correct when
\r
333 * using GCC with optimizations disabled (-O0) and Cortex-M3/M4.
\r
335 * To measure this value, see MEASURE_ISR_TAILCHAINING_THRESHOLD below.
\r
337 * If this value set too low, tail-chained ISRs will incorrectly be shown
\r
338 * separated, with a short fragment of the previous task or ISR in between.
\r
339 * If this value is set too high, you get the opposite effect - separate ISRs
\r
340 * will appear to execute tail-chained and will appear to have higher execution
\r
341 * time and response time (maximum ISR_TAILCHAINING_THRESHOLD cycles more).
\r
342 *****************************************************************************/
\r
343 #define ISR_TAILCHAINING_THRESHOLD 66
\r
345 uint8_t* ptrLastISRExitEvent = NULL;
\r
346 uint32_t DWTCycleCountAtLastISRExit = 0;
\r
348 /******************************************************************************
\r
351 * MEASURE_ISR_TAILCHAINING_THRESHOLD (For Cortex-M devices only)
\r
353 * Allows for measuring the value of ISR_TAILCHAINING_THRESHOLD (see above).
\r
355 * This is intended to measure the minimum number of clock cycles from the end
\r
356 * of vTraceStoreISREnd to the beginning of the following vTraceStoreISRBegin.
\r
357 * For this purpose, we assume a test setup using the SysTick interrupt, which
\r
358 * is available on most Cortex-M devices and typically used by the RTOS kernel.
\r
359 * To do the measurement, follow these steps:
\r
361 * 1. Make sure MEASURE_ISR_TAILCHAINING_THRESHOLD is enabled (defined as 1)
\r
363 * 2. Temporarily replace your SysTick handler with the following:
\r
365 * void xPortSysTickHandler( void )
\r
367 * vTraceStoreISRBegin(1);
\r
368 * vTraceStoreISREnd();
\r
371 * 3. To make sure that the ISRs execute back-to-back, increase the OS tick
\r
372 * frequency to a very high level so that the OS tick interrupt execute
\r
373 * continuously with no application tasks in between. A tick frequency of
\r
374 * 1 MHz (1.000.000) should be sufficient.
\r
376 * 4. Put a breakpoint in the highest priority task and make sure it is not
\r
377 * reached. This means that the SysTick handler is executing at maximum rate
\r
378 * and thereby tail-chained, where the interrupt latency is 6 cycles.
\r
380 * 5. Let the system run without breakpoints and inspect the value of
\r
381 * threshold_low_watermark. This is the minimum total latency observed.
\r
382 * The hardware latency is 6 clock cycles due to the tail-chaining, so the
\r
383 * software latency (SL) is then SL = threshold_low_watermark - 6.
\r
385 * The threshold value ISR_TAILCHAINING_THRESHOLD should be SL + 2 * HL, where
\r
386 * HL is the normal hardware interrupt latency, i.e., the number of CPU
\r
387 * cycles to enter or exit the exception handler for an exception in task
\r
388 * context. The HL value is 12-16 depending on core, as shown below.
\r
390 * Values for ISR_TAILCHAINING_THRESHOLD, assuming SL = 42
\r
391 * Cortex-M3 and M4 (HL = 12): 66 cycles
\r
392 * Cortex-M0 (HL = 16): 74 cycles
\r
393 * Cortex-M0+ (HL = 15): 72 cycles
\r
395 * If the ISR_TAILCHAINING_THRESHOLD value is set too low, some tail-chained
\r
396 * ISRs be shown separated, with a short fragment of the previous actor. If
\r
397 * the value is set too high, separate ISRs will appear to execute tail-chained
\r
398 * and for too long time.
\r
399 *****************************************************************************/
\r
400 #define MEASURE_ISR_TAILCHAINING_THRESHOLD 1
\r
402 #if (MEASURE_ISR_TAILCHAINING_THRESHOLD == 1)
\r
403 volatile uint32_t threshold_low_watermark = 2000000000;
\r
408 /*******************************************************************************
\r
409 * vTraceStoreISRBegin
\r
411 * Registers the beginning of an Interrupt Service Routine.
\r
414 * #define ID_ISR_TIMER1 1 // lowest valid ID is 1
\r
415 * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
\r
417 * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
\r
419 * void ISR_handler()
\r
421 * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
\r
423 * vTraceStoreISREnd();
\r
426 ******************************************************************************/
\r
427 void vTraceStoreISRBegin(objectHandleType handle)
\r
430 #if (SELECTED_PORT == PORT_ARM_CortexM)
\r
431 uint32_t CPUCyclesSinceLastISRExit = DWT_CYCLE_COUNTER - DWTCycleCountAtLastISRExit;
\r
434 TRACE_SR_ALLOC_CRITICAL_SECTION();
\r
438 #if (SELECTED_PORT == PORT_ARM_CortexM)
\r
439 if (DWTCycleCountAtLastISRExit > 0)
\r
441 #if (MEASURE_ISR_TAILCHAINING_THRESHOLD == 1)
\r
442 /* Allows for verifying the value of ISR_TAILCHAINING_THRESHOLD */
\r
443 if (CPUCyclesSinceLastISRExit < threshold_low_watermark)
\r
445 threshold_low_watermark = CPUCyclesSinceLastISRExit;
\r
449 if (CPUCyclesSinceLastISRExit <= ISR_TAILCHAINING_THRESHOLD)
\r
451 /* This is judged to be a case of ISR tail-chaining since the
\r
452 number of cycles since the last vTraceStoreISREnd is shorter or equal to
\r
453 the threshold (ISR_TAILCHAINING_THRESHOLD) */
\r
455 if (ptrLastISRExitEvent != NULL)
\r
457 /* Overwrite the last ISR exit event with a "neutral" event that only
\r
458 accounts for the time passed */
\r
459 *ptrLastISRExitEvent = XTS16L;
\r
468 vTraceError("Illegal call to vTraceStoreISRBegin, recorder busy!");
\r
471 trcCRITICAL_SECTION_BEGIN();
\r
472 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
475 TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceStoreISRBegin: Invalid value for handle", );
\r
477 dts4 = (uint16_t)prvTraceGetDTS(0xFFFF);
\r
479 if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
\r
481 if (nISRactive < MAX_ISR_NESTING)
\r
483 uint8_t hnd8 = prvTraceGet8BitHandle(handle);
\r
484 isrstack[nISRactive] = handle;
\r
486 ts = (TSEvent*)xTraceNextFreeEventBufferSlot();
\r
489 ts->type = TS_ISR_BEGIN;
\r
491 ts->objHandle = hnd8;
\r
492 prvTraceUpdateCounters();
\r
497 /* This should not occur unless something is very wrong */
\r
498 vTraceError("Too many nested interrupts!");
\r
502 trcCRITICAL_SECTION_END();
\r
505 /*******************************************************************************
\r
506 * vTraceStoreISREnd
\r
508 * Registers the end of an Interrupt Service Routine.
\r
511 * #define ID_ISR_TIMER1 1 // lowest valid ID is 1
\r
512 * #define PRIO_OF_ISR_TIMER1 3 // the hardware priority of the interrupt
\r
514 * vTraceSetISRProperties(ID_ISR_TIMER1, "ISRTimer1", PRIO_OF_ISR_TIMER1);
\r
516 * void ISR_handler()
\r
518 * vTraceStoreISRBegin(ID_OF_ISR_TIMER1);
\r
520 * vTraceStoreISREnd();
\r
523 ******************************************************************************/
\r
524 void vTraceStoreISREnd(void)
\r
528 TRACE_SR_ALLOC_CRITICAL_SECTION();
\r
532 vTraceError("Illegal call to vTraceStoreISREnd, recorder busy!");
\r
536 trcCRITICAL_SECTION_BEGIN();
\r
537 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
539 dts5 = (uint16_t)prvTraceGetDTS(0xFFFF);
\r
541 if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
\r
543 uint8_t hnd8, type;
\r
545 if (nISRactive > 1)
\r
547 /* return to another isr */
\r
548 type = TS_ISR_RESUME;
\r
549 hnd8 = prvTraceGet8BitHandle(isrstack[nISRactive]);
\r
553 /* return to task */
\r
554 type = TS_TASK_RESUME;
\r
555 hnd8 = prvTraceGet8BitHandle(handle_of_last_logged_task);
\r
558 ts = (TSEvent*)xTraceNextFreeEventBufferSlot();
\r
563 ts->objHandle = hnd8;
\r
566 prvTraceUpdateCounters();
\r
571 #if (SELECTED_PORT == PORT_ARM_CortexM)
\r
572 /* Remember the last ISR exit event, as the event needs to be modified in case of a following ISR entry (if tail-chained ISRs) */
\r
573 ptrLastISRExitEvent = (uint8_t*)ts;
\r
574 DWTCycleCountAtLastISRExit = DWT_CYCLE_COUNTER;
\r
577 trcCRITICAL_SECTION_END();
\r
582 /* ISR tracing is turned off */
\r
583 void vTraceIncreaseISRActive(void)
\r
585 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
589 void vTraceDecreaseISRActive(void)
\r
591 if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)
\r
597 /*******************************************************************************
\r
598 * User Event functions
\r
599 ******************************************************************************/
\r
601 #if (INCLUDE_USER_EVENTS == 1)
\r
603 #define MAX_ARG_SIZE (4+32)
\r
604 /*** Locally used in vTracePrintF ***/
\r
605 static uint8_t writeInt8(void * buffer, uint8_t i, uint8_t value)
\r
607 TRACE_ASSERT(buffer != NULL, "writeInt8: buffer == NULL", 0);
\r
609 if (i >= MAX_ARG_SIZE)
\r
614 ((uint8_t*)buffer)[i] = value;
\r
616 if (i + 1 > MAX_ARG_SIZE)
\r
624 /*** Locally used in vTracePrintF ***/
\r
625 static uint8_t writeInt16(void * buffer, uint8_t i, uint16_t value)
\r
627 TRACE_ASSERT(buffer != NULL, "writeInt16: buffer == NULL", 0);
\r
629 /* Align to multiple of 2 */
\r
630 while ((i % 2) != 0)
\r
632 if (i >= MAX_ARG_SIZE)
\r
637 ((uint8_t*)buffer)[i] = 0;
\r
641 if (i + 2 > MAX_ARG_SIZE)
\r
646 ((uint16_t*)buffer)[i/2] = value;
\r
651 /*** Locally used in vTracePrintF ***/
\r
652 static uint8_t writeInt32(void * buffer, uint8_t i, uint32_t value)
\r
654 TRACE_ASSERT(buffer != NULL, "writeInt32: buffer == NULL", 0);
\r
656 /* A 32 bit value should begin at an even 4-byte address */
\r
657 while ((i % 4) != 0)
\r
659 if (i >= MAX_ARG_SIZE)
\r
664 ((uint8_t*)buffer)[i] = 0;
\r
668 if (i + 4 > MAX_ARG_SIZE)
\r
673 ((uint32_t*)buffer)[i/4] = value;
\r
678 #if (INCLUDE_FLOAT_SUPPORT)
\r
680 /*** Locally used in vTracePrintF ***/
\r
681 static uint8_t writeFloat(void * buffer, uint8_t i, float value)
\r
683 TRACE_ASSERT(buffer != NULL, "writeFloat: buffer == NULL", 0);
\r
685 /* A 32 bit value should begin at an even 4-byte address */
\r
686 while ((i % 4) != 0)
\r
688 if (i >= MAX_ARG_SIZE)
\r
693 ((uint8_t*)buffer)[i] = 0;
\r
697 if (i + 4 > MAX_ARG_SIZE)
\r
702 ((float*)buffer)[i/4] = value;
\r
707 /*** Locally used in vTracePrintF ***/
\r
708 static uint8_t writeDouble(void * buffer, uint8_t i, double value)
\r
710 TRACE_ASSERT(buffer != NULL, "writeDouble: buffer == NULL", 0);
\r
713 uint32_t * src = (void*)&value;
\r
714 /* The double is written as two 32 bit values, and should begin at an even
\r
715 4-byte address (to avoid having to align with 8 byte) */
\r
718 if (i >= MAX_ARG_SIZE)
\r
723 ((uint8_t*)buffer)[i] = 0;
\r
727 if (i + 8 > MAX_ARG_SIZE)
\r
732 dest = &(((uint32_t *)buffer)[i]);
\r
742 /*******************************************************************************
\r
743 * prvTraceUserEventFormat
\r
745 * Parses the format string and stores the arguments in the buffer.
\r
746 ******************************************************************************/
\r
747 static uint8_t prvTraceUserEventFormat(const char* formatStr, va_list vl, uint8_t* buffer, uint8_t byteOffset)
\r
749 uint16_t formatStrIndex = 0;
\r
750 uint8_t argCounter = 0;
\r
751 uint8_t i = byteOffset;
\r
753 while (formatStr[formatStrIndex] != '\0')
\r
755 if (formatStr[formatStrIndex] == '%')
\r
759 if (argCounter > 15)
\r
761 vTraceError("vTracePrintF - Too many arguments, max 15 allowed!");
\r
765 /*******************************************************************************
\r
766 * These below code writes raw data (primitive datatypes) in the event buffer,
\r
767 * instead of the normal event structs (where byte 0 is event type).
\r
768 * These data entries must never be interpreted as real event data, as the type
\r
769 * field would be misleading since used for payload data.
\r
771 * The correctness of this encoding depends on two mechanisms:
\r
773 * 1. An initial USER_EVENT, which type code tells the number of 32-bit data
\r
774 * entires that follows. (code - USER_EVENT = number of data entries).
\r
775 * Note that a data entry corresponds to the slots that normally corresponds to
\r
776 * one (1) event, i.e., 32 bits. vTracePrintF may encode several pieces of data
\r
777 * in one data entry, e.g., two 16-bit values or four 8-bit values, one 16-bit
\r
778 * value followed by two 8-bit values, etc.
\r
780 * 2. A two-phase commit procedure, where the USER_EVENT and data entries are
\r
781 * written to a local buffer at first, and when all checks are OK then copied to
\r
782 * the main event buffer using a fast memcpy. The event code is finalized as the
\r
783 * very last step. Before that step, the event code indicates an unfinished
\r
784 * event, which causes it to be ignored and stop the loading of the file (since
\r
785 * an unfinished event is the last event in the trace).
\r
786 *******************************************************************************/
\r
789 while ((formatStr[formatStrIndex] >= '0' && formatStr[formatStrIndex] <= '9') || formatStr[formatStrIndex] == '#' || formatStr[formatStrIndex] == '.')
\r
792 if (formatStr[formatStrIndex] != '\0')
\r
794 switch (formatStr[formatStrIndex])
\r
796 case 'd': i = writeInt32(buffer,
\r
798 (uint32_t)va_arg(vl, uint32_t));
\r
802 case 'u': i = writeInt32(buffer,
\r
804 (uint32_t)va_arg(vl, uint32_t));
\r
806 case 's': i = writeInt16(buffer,
\r
808 (uint16_t)xTraceOpenLabel((char*)va_arg(vl, char*)));
\r
811 #if (INCLUDE_FLOAT_SUPPORT)
\r
812 /* Yes, "double" as type also in the float
\r
813 case. This since "float" is promoted into "double"
\r
814 by the va_arg stuff. */
\r
815 case 'f': i = writeFloat(buffer,
\r
817 (float)va_arg(vl, double));
\r
820 /* No support for floats, but attempt to store a float user event
\r
821 avoid a possible crash due to float reference. Instead store the
\r
822 data on uint_32 format (will not be displayed anyway). This is just
\r
823 to keep va_arg and i consistent. */
\r
825 case 'f': i = writeInt32(buffer,
\r
827 (uint32_t)va_arg(vl, double));
\r
832 switch (formatStr[formatStrIndex])
\r
834 #if (INCLUDE_FLOAT_SUPPORT)
\r
835 case 'f': i = writeDouble(buffer,
\r
837 (double)va_arg(vl, double));
\r
840 /* No support for floats, but attempt to store a float user event
\r
841 avoid a possible crash due to float reference. Instead store the
\r
842 data on uint_32 format (will not be displayed anyway). This is just
\r
843 to keep va_arg and i consistent. */
\r
844 case 'f': i = writeInt32(buffer, /* In this case, the value will not be shown anyway */
\r
846 (uint32_t)va_arg(vl, double));
\r
847 i = writeInt32(buffer, /* Do it twice, to write in total 8 bytes */
\r
849 (uint32_t)va_arg(vl, double));
\r
857 switch (formatStr[formatStrIndex])
\r
859 case 'd': i = writeInt16(buffer,
\r
861 (uint16_t)va_arg(vl, uint32_t));
\r
863 case 'u': i = writeInt16(buffer,
\r
865 (uint16_t)va_arg(vl, uint32_t));
\r
871 switch (formatStr[formatStrIndex])
\r
873 case 'd': i = writeInt8(buffer,
\r
875 (uint8_t)va_arg(vl, uint32_t));
\r
877 case 'u': i = writeInt8(buffer,
\r
879 (uint8_t)va_arg(vl, uint32_t));
\r
891 vTraceError("vTracePrintF - Too large arguments, max 32 byte allowed!");
\r
898 #if (USE_SEPARATE_USER_EVENT_BUFFER == 1)
\r
900 /*******************************************************************************
\r
901 * prvTraceClearChannelBuffer
\r
903 * Clears a number of items in the channel buffer, starting from nextSlotToWrite.
\r
904 ******************************************************************************/
\r
905 static void prvTraceClearChannelBuffer(uint32_t count)
\r
909 TRACE_ASSERT(USER_EVENT_BUFFER_SIZE >= count, "prvTraceClearChannelBuffer: USER_EVENT_BUFFER_SIZE is too small to handle this event.", );
\r
911 /* Check if we're close to the end of the buffer */
\r
912 if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > USER_EVENT_BUFFER_SIZE)
\r
914 slots = USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */
\r
915 (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, slots);
\r
916 (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[0], 0, (count - slots));
\r
919 (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, count);
\r
922 /*******************************************************************************
\r
923 * prvTraceCopyToDataBuffer
\r
925 * Copies a number of items to the data buffer, starting from nextSlotToWrite.
\r
926 ******************************************************************************/
\r
927 static void prvTraceCopyToDataBuffer(uint32_t* data, uint32_t count)
\r
929 TRACE_ASSERT(data != NULL, "prvTraceCopyToDataBuffer: data == NULL.", );
\r
930 TRACE_ASSERT(count <= USER_EVENT_BUFFER_SIZE, "prvTraceCopyToDataBuffer: USER_EVENT_BUFFER_SIZE is too small to handle this event.", );
\r
933 /* Check if we're close to the end of the buffer */
\r
934 if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > USER_EVENT_BUFFER_SIZE)
\r
936 slots = USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */
\r
937 (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, slots * 4);
\r
938 (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[0], data + slots, (count - slots) * 4);
\r
942 (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, count * 4);
\r
946 /*******************************************************************************
\r
947 * prvTraceUserEventHelper1
\r
949 * Calls on prvTraceUserEventFormat() to do the actual formatting, then goes on to the next helper function.
\r
950 ******************************************************************************/
\r
951 static void prvTraceUserEventHelper1(UserEventChannel channel, traceLabel eventLabel, traceLabel formatLabel, va_list vl)
\r
953 uint32_t data[(3 + MAX_ARG_SIZE) / 4];
\r
954 uint8_t byteOffset = 4; /* Need room for timestamp */
\r
959 /* We are dealing with an unknown channel format pair */
\r
960 byteOffset += 4; /* Also need room for channel and format */
\r
961 ((uint16_t*)data)[2] = eventLabel;
\r
962 ((uint16_t*)data)[3] = formatLabel;
\r
965 noOfSlots = prvTraceUserEventFormat((char*)&(RecorderDataPtr->SymbolTable.symbytes[formatLabel+4]), vl, (uint8_t*)data, byteOffset);
\r
967 prvTraceUserEventHelper2(channel, data, noOfSlots);
\r
970 /*******************************************************************************
\r
971 * prvTraceUserEventHelper2
\r
973 * This function simply copies the data buffer to the actual user event buffer.
\r
974 ******************************************************************************/
\r
975 static void prvTraceUserEventHelper2(UserEventChannel channel, uint32_t* data, uint32_t noOfSlots)
\r
977 static uint32_t old_timestamp = 0;
\r
978 uint32_t old_nextSlotToWrite = 0;
\r
980 TRACE_ASSERT(USER_EVENT_BUFFER_SIZE >= noOfSlots, "vTracePrintF: USER_EVENT_BUFFER_SIZE is too small to handle this event.", );
\r
982 trcCRITICAL_SECTION_BEGIN();
\r
983 /* Store the timestamp */
\r
984 vTracePortGetTimeStamp(data);
\r
986 if (*data < old_timestamp)
\r
987 RecorderDataPtr->userEventBuffer.wraparoundCounter++;
\r
988 old_timestamp = *data;
\r
990 /* Start by erasing any information in the channel buffer */
\r
991 prvTraceClearChannelBuffer(noOfSlots);
\r
993 prvTraceCopyToDataBuffer(data, noOfSlots); /* Will wrap around the data if necessary */
\r
995 old_nextSlotToWrite = RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Save the index that we want to write the channel data at when we're done */
\r
996 RecorderDataPtr->userEventBuffer.nextSlotToWrite = (RecorderDataPtr->userEventBuffer.nextSlotToWrite + noOfSlots) % USER_EVENT_BUFFER_SIZE; /* Make sure we never end up outside the buffer */
\r
998 /* Write to the channel buffer to indicate that this user event is ready to be used */
\r
1000 RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = channel;
\r
1002 RecorderDataPtr->userEventBuffer.channelBuffer[old_nextSlotToWrite] = (UserEventChannel)0xFF; /* 0xFF indicates that this is not a normal channel id */
\r
1003 trcCRITICAL_SECTION_END();
\r
1006 /*******************************************************************************
\r
1007 * xTraceRegisterChannelFormat
\r
1009 * Attempts to create a pair of the channel and format string.
\r
1011 * Note: This is only available if USE_SEPARATE_USER_EVENT_BUFFER is enabled in
\r
1013 ******************************************************************************/
\r
1014 UserEventChannel xTraceRegisterChannelFormat(traceLabel channel, traceLabel formatStr)
\r
1017 UserEventChannel retVal = 0;
\r
1019 TRACE_ASSERT(formatStr != 0, "vTraceRegisterChannelFormat: formatStr == 0", (UserEventChannel)0);
\r
1021 trcCRITICAL_SECTION_BEGIN();
\r
1022 for (i = 1; i <= CHANNEL_FORMAT_PAIRS; i++) /* Size of the channels buffer is CHANNEL_FORMAT_PAIRS + 1. Index 0 is unused. */
\r
1024 if(RecorderDataPtr->userEventBuffer.channels[i].name == 0 && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == 0)
\r
1026 /* Found empty slot */
\r
1027 RecorderDataPtr->userEventBuffer.channels[i].name = channel;
\r
1028 RecorderDataPtr->userEventBuffer.channels[i].defaultFormat = formatStr;
\r
1029 retVal = (UserEventChannel)i;
\r
1033 if (RecorderDataPtr->userEventBuffer.channels[i].name == channel && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == formatStr)
\r
1035 /* Found a match */
\r
1036 retVal = (UserEventChannel)i;
\r
1040 trcCRITICAL_SECTION_END();
\r
1044 /******************************************************************************
\r
1045 * vTraceChannelPrintF
\r
1047 * Slightly faster version of vTracePrintF() due to no lookups.
\r
1049 * Note: This is only available if USE_SEPARATE_USER_EVENT_BUFFER is enabled in
\r
1052 ******************************************************************************/
\r
1053 void vTraceChannelPrintF(UserEventChannel channelPair, ...)
\r
1057 va_start(vl, channelPair);
\r
1058 vTraceChannelPrintF_Helper(channelPair, vl);
\r
1062 void vTraceChannelPrintF_Helper(UserEventChannel channelPair, va_list vl)
\r
1064 traceLabel channel;
\r
1065 traceLabel formatStr;
\r
1067 TRACE_ASSERT(channelPair != 0, "vTraceChannelPrintF: channelPair == 0", );
\r
1068 TRACE_ASSERT(channelPair <= CHANNEL_FORMAT_PAIRS, "vTraceChannelPrintF: ", );
\r
1070 channel = RecorderDataPtr->userEventBuffer.channels[channelPair].name;
\r
1071 formatStr = RecorderDataPtr->userEventBuffer.channels[channelPair].defaultFormat;
\r
1073 prvTraceUserEventHelper1(channelPair, channel, formatStr, vl);
\r
1076 /******************************************************************************
\r
1077 * vTraceChannelUserEvent
\r
1079 * Slightly faster version of vTraceUserEvent() due to no lookups.
\r
1080 ******************************************************************************/
\r
1081 void vTraceChannelUserEvent(UserEventChannel channelPair)
\r
1083 uint32_t data[(3 + MAX_ARG_SIZE) / 4];
\r
1085 TRACE_ASSERT(channelPair != 0, "vTraceChannelPrintF: channelPair == 0", );
\r
1086 TRACE_ASSERT(channelPair <= CHANNEL_FORMAT_PAIRS, "vTraceChannelPrintF: ", );
\r
1088 prvTraceUserEventHelper2(channelPair, data, 1); /* Only need one slot for timestamp */
\r
1090 #endif /* USE_SEPARATE_USER_EVENT_BUFFER == 1 */
\r
1092 /******************************************************************************
\r
1095 * Advanced user events (Professional Edition only)
\r
1097 * Generates User Event with formatted text and data, similar to a "printf".
\r
1098 * It is very fast compared to a normal "printf" since this function only
\r
1099 * stores the arguments. The actual formatting is done
\r
1100 * on the host PC when the trace is displayed in the viewer tool.
\r
1102 * User Event labels are created using xTraceOpenLabel.
\r
1105 * traceLabel adc_uechannel = xTraceOpenLabel("ADC User Events");
\r
1107 * vTracePrint(adc_uechannel,
\r
1108 * "ADC channel %d: %lf volts",
\r
1109 * ch, (double)adc_reading/(double)scale);
\r
1111 * This can be combined into one line, if desired, but this is slower:
\r
1113 * vTracePrint(xTraceOpenLabel("ADC User Events"),
\r
1114 * "ADC channel %d: %lf volts",
\r
1115 * ch, (double)adc_reading/(double)scale);
\r
1117 * Calling xTraceOpenLabel multiple times will not create duplicate entries, but
\r
1118 * it is of course faster to just do it once, and then keep the handle for later
\r
1119 * use. If you don´t have any data arguments, only a text label/string, it is
\r
1120 * better to use vTraceUserEvent - it is faster.
\r
1122 * Format specifiers supported:
\r
1123 * %d - 32 bit signed integer
\r
1124 * %u - 32 bit unsigned integer
\r
1125 * %f - 32 bit float
\r
1126 * %s - string (is copied to the recorder symbol table)
\r
1127 * %hd - 16 bit signed integer
\r
1128 * %hu - 16 bit unsigned integer
\r
1129 * %bd - 8 bit signed integer
\r
1130 * %bu - 8 bit unsigned integer
\r
1131 * %lf - double-precision float
\r
1133 * Up to 15 data arguments are allowed, with a total size of maximum 32 byte.
\r
1134 * In case this is exceeded, the user event is changed into an error message.
\r
1136 * The data is stored in trace buffer, and is packed to allow storing multiple
\r
1137 * smaller data entries in the same 4-byte record, e.g., four 8-bit values.
\r
1138 * A string requires two bytes, as the symbol table is limited to 64K. Storing a
\r
1139 * double (%lf) uses two records, so this is quite costly. Use float (%f) unless
\r
1140 * the higher precision is really necessary.
\r
1141 ******************************************************************************/
\r
1143 void vTracePrintF(traceLabel eventLabel, const char* formatStr, ...)
\r
1147 va_start(vl, formatStr);
\r
1148 vTracePrintF_Helper(eventLabel, formatStr, vl);
\r
1152 void vTracePrintF_Helper(traceLabel eventLabel, const char* formatStr, va_list vl)
\r
1154 #if (USE_SEPARATE_USER_EVENT_BUFFER == 0)
\r
1155 uint32_t noOfSlots;
\r
1157 uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];
\r
1158 TRACE_SR_ALLOC_CRITICAL_SECTION();
\r
1160 /**************************************************************************
\r
1161 * The array tempDataBuffer is a local buffer used in a two-phase commit of
\r
1162 * the event data, since a vTracePrintF may span over multiple slots in the
\r
1164 * This buffer can be made larger, of course, but remember the risk for
\r
1165 * stack overflow. Note: This should be a LOCAL buffer, must not be made
\r
1166 * global. That would cause data corruption when two calls to vTracePrintF
\r
1167 * from different tasks overlaps (interrupts are only disabled in a small
\r
1168 * part of this function, otherwise enabled)
\r
1169 ***************************************************************************/
\r
1171 TRACE_ASSERT(formatStr != NULL, "vTracePrintF: formatStr == NULL", );
\r
1173 trcCRITICAL_SECTION_BEGIN();
\r
1175 if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)
\r
1177 /* First, write the "primary" user event entry in the local buffer, but
\r
1178 let the event type be "EVENT_BEING_WRITTEN" for now...*/
\r
1180 ue1 = (UserEvent*)(&tempDataBuffer[0]);
\r
1182 ue1->type = EVENT_BEING_WRITTEN; /* Update this as the last step */
\r
1184 noOfSlots = prvTraceUserEventFormat(formatStr, vl, (uint8_t*)tempDataBuffer, 4);
\r
1186 /* Store the format string, with a reference to the channel symbol */
\r
1187 ue1->payload = prvTraceOpenSymbol(formatStr, eventLabel);
\r
1189 ue1->dts = (uint8_t)prvTraceGetDTS(0xFF);
\r
1191 /* prvTraceGetDTS might stop the recorder in some cases... */
\r
1192 if (RecorderDataPtr->recorderActive)
\r
1195 /* If the data does not fit in the remaining main buffer, wrap around to
\r
1196 0 if allowed, otherwise stop the recorder and quit). */
\r
1197 if (RecorderDataPtr->nextFreeIndex + noOfSlots > RecorderDataPtr->maxEvents)
\r
1199 #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)
\r
1200 (void)memset(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],
\r
1202 (RecorderDataPtr->maxEvents - RecorderDataPtr->nextFreeIndex)*4);
\r
1203 RecorderDataPtr->nextFreeIndex = 0;
\r
1204 RecorderDataPtr->bufferIsFull = 1;
\r
1207 /* Stop recorder, since the event data will not fit in the
\r
1208 buffer and not circular buffer in this case... */
\r
1213 /* Check if recorder has been stopped (i.e., vTraceStop above) */
\r
1214 if (RecorderDataPtr->recorderActive)
\r
1216 /* Check that the buffer to be overwritten does not contain any user
\r
1217 events that would be partially overwritten. If so, they must be "killed"
\r
1218 by replacing the user event and following data with NULL events (i.e.,
\r
1219 using a memset to zero).*/
\r
1220 #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)
\r
1221 prvCheckDataToBeOverwrittenForMultiEntryEvents((uint8_t)noOfSlots);
\r
1223 /* Copy the local buffer to the main buffer */
\r
1224 (void)memcpy(& RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4],
\r
1228 /* Update the event type, i.e., number of data entries following the
\r
1229 main USER_EVENT entry (Note: important that this is after the memcpy,
\r
1230 but within the critical section!)*/
\r
1231 RecorderDataPtr->eventData[RecorderDataPtr->nextFreeIndex * 4] =
\r
1232 (uint8_t) ( USER_EVENT + noOfSlots - 1 );
\r
1234 /* Update the main buffer event index (already checked that it fits in
\r
1235 the buffer, so no need to check for wrapping)*/
\r
1237 RecorderDataPtr->nextFreeIndex += noOfSlots;
\r
1238 RecorderDataPtr->numEvents += noOfSlots;
\r
1240 if (RecorderDataPtr->nextFreeIndex >= EVENT_BUFFER_SIZE)
\r
1242 #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)
\r
1243 /* We have reached the end, but this is a ring buffer. Start from the beginning again. */
\r
1244 RecorderDataPtr->bufferIsFull = 1;
\r
1245 RecorderDataPtr->nextFreeIndex = 0;
\r
1247 /* We have reached the end so we stop. */
\r
1252 #if (STOP_AFTER_N_EVENTS > -1)
\r
1253 /* Check if we have reached the desired number of events */
\r
1254 if (RecorderDataPtr->numEvents >= STOP_AFTER_N_EVENTS)
\r
1261 #if (TRACE_RECORDER_STORE_MODE == TRACE_STORE_MODE_RING_BUFFER)
\r
1262 /* Make sure the next entry is cleared correctly */
\r
1263 prvCheckDataToBeOverwrittenForMultiEntryEvents(1);
\r
1268 trcCRITICAL_SECTION_END();
\r
1270 #elif (USE_SEPARATE_USER_EVENT_BUFFER == 1)
\r
1271 /* Use the separate user event buffer */
\r
1272 traceLabel formatLabel;
\r
1273 UserEventChannel channel;
\r
1275 if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)
\r
1277 formatLabel = xTraceOpenLabel(formatStr);
\r
1279 channel = xTraceRegisterChannelFormat(eventLabel, formatLabel);
\r
1281 prvTraceUserEventHelper1(channel, eventLabel, formatLabel, vl);
\r
1286 /******************************************************************************
\r
1289 * Basic user event (Standard and Professional Edition only)
\r
1291 * Generates a User Event with a text label. The label is created/looked up
\r
1292 * in the symbol table using xTraceOpenLabel.
\r
1293 ******************************************************************************/
\r
1294 void vTraceUserEvent(traceLabel eventLabel)
\r
1296 #if (USE_SEPARATE_USER_EVENT_BUFFER == 0)
\r
1299 TRACE_SR_ALLOC_CRITICAL_SECTION();
\r
1301 TRACE_ASSERT(eventLabel > 0, "vTraceUserEvent: Invalid value for eventLabel", );
\r
1303 trcCRITICAL_SECTION_BEGIN();
\r
1304 if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)
\r
1306 dts1 = (uint8_t)prvTraceGetDTS(0xFF);
\r
1308 if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */
\r
1310 ue = (UserEvent*) xTraceNextFreeEventBufferSlot();
\r
1314 ue->type = USER_EVENT;
\r
1315 ue->payload = eventLabel;
\r
1316 prvTraceUpdateCounters();
\r
1320 trcCRITICAL_SECTION_END();
\r
1322 #elif (USE_SEPARATE_USER_EVENT_BUFFER == 1)
\r
1323 UserEventChannel channel;
\r
1324 uint32_t noOfSlots = 1;
\r
1325 uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];
\r
1326 if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)
\r
1328 channel = xTraceRegisterChannelFormat(0, eventLabel);
\r
1332 /* We are dealing with an unknown channel format pair */
\r
1333 noOfSlots++; /* Also need room for channel and format */
\r
1334 ((uint16_t*)tempDataBuffer)[2] = 0;
\r
1335 ((uint16_t*)tempDataBuffer)[3] = eventLabel;
\r
1338 prvTraceUserEventHelper2(channel, tempDataBuffer, noOfSlots);
\r
1343 /*******************************************************************************
\r
1346 * Creates user event labels for user event channels or for individual events.
\r
1347 * User events can be used to log application events and data for display in
\r
1348 * the visualization tool. A user event is identified by a label, i.e., a string,
\r
1349 * which is stored in the recorder's symbol table.
\r
1350 * When logging a user event, a numeric handle (reference) to this string is
\r
1351 * used to identify the event. This is obtained by calling
\r
1353 * xTraceOpenLabel()
\r
1355 * which adds the string to the symbol table (if not already present)
\r
1356 * and returns the corresponding handle.
\r
1358 * This can be used in two ways:
\r
1360 * 1. The handle is looked up every time, when storing the user event.
\r
1363 * vTraceUserEvent(xTraceOpenLabel("MyUserEvent"));
\r
1365 * 2. The label is registered just once, with the handle stored in an
\r
1366 * application variable - much like using a file handle.
\r
1369 * myEventHandle = xTraceOpenLabel("MyUserEvent");
\r
1371 * vTraceUserEvent(myEventHandle);
\r
1373 * The second option is faster since no lookup is required on each event, and
\r
1374 * therefore recommended for user events that are frequently
\r
1375 * executed and/or located in time-critical code. The lookup operation is
\r
1376 * however fairly fast due to the design of the symbol table.
\r
1377 ******************************************************************************/
\r
1378 traceLabel xTraceOpenLabel(const char* label)
\r
1380 TRACE_ASSERT(label != NULL, "xTraceOpenLabel: label == NULL", (traceLabel)0);
\r
1382 return prvTraceOpenSymbol(label, 0);
\r