Percepio Trace Recorder  v4.6.6
trcRecorder.h
Go to the documentation of this file.
1 /*
2  * Trace Recorder for Tracealyzer v4.6.6
3  * Copyright 2021 Percepio AB
4  * www.percepio.com
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #ifndef TRC_RECORDER_H
10 #define TRC_RECORDER_H
11 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
29 #define TRC_ACKNOWLEDGED (0xABC99123)
30 
31 #include <trcDefines.h>
32 #include <trcConfig.h>
33 #include <trcKernelPortConfig.h>
34 #include <trcTypes.h>
35 
36 #ifndef TRC_CFG_TEST_MODE
37 #define TRC_CFG_TEST_MODE 0
38 #endif
39 
40 /* Unless defined by the kernel port, we assume there is no support for
41  * the classic snapshot mode and default to streaming mode where
42  * the new RingBuffer snapshot mode provides snapshot functionality.
43  */
44 #ifndef TRC_CFG_RECORDER_MODE
45 #define TRC_CFG_RECORDER_MODE TRC_RECORDER_MODE_STREAMING
46 #endif
47 
48 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
49 #include <trcSnapshotConfig.h>
50 #include <trcKernelPortSnapshotConfig.h>
51 
52 /* Calls xTraceError if the _assert condition is false. For void functions,
53 where no return value is to be provided. */
54 #define TRC_ASSERT_VOID(_assert, _err) if (! (_assert)){ prvTraceError(_err); return; }
55 
56 /* Calls xTraceError if the _assert condition is false. For non-void functions,
57 where a return value is to be provided. */
58 #define TRC_ASSERT_RET(_assert, _err, _return) if (! (_assert)){ prvTraceError(_err); return _return; }
59 
60 typedef uint8_t traceUBChannel;
61 typedef uint8_t traceObjectClass;
62 
63 #undef traceHandle
64 #if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)
65 typedef uint16_t traceHandle;
66 #else /* (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1) */
67 typedef uint8_t traceHandle;
68 #endif /* (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1) */
69 
70 #undef TraceISRHandle_t
71 #define TraceISRHandle_t traceHandle
72 
73 #include <trcHardwarePort.h>
74 #include <trcKernelPort.h>
75 
76 /* Not yet available in snapshot mode */
77 #define vTraceConsoleChannelPrintF(fmt, ...) (void)
78 #define xTraceConsoleChannelPrintF(fmt, ...) (void)
79 #define prvTraceStoreEvent_None(...)
80 #define prvTraceStoreEvent_Handle(...)
81 #define prvTraceStoreEvent_Param(...)
82 #define prvTraceStoreEvent_HandleParam(...)
83 #define prvTraceStoreEvent_ParamParam(...)
84 #define prvTraceStoreEvent_HandleParamParam(...)
85 #define prvTraceStoreEvent_ParamParamParam(...)
86 
87 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT) */
88 
89 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
90 #include <trcStreamingConfig.h>
91 #include <trcKernelPortStreamingConfig.h>
92 
93 /* Unless specified in trcConfig.h we assume this is a single core target */
94 #ifndef TRC_CFG_CORE_COUNT
95 #define TRC_CFG_CORE_COUNT 1
96 #endif
97 
98 /* Unless specified in trcConfig.h we assume this is a single core target */
99 #ifndef TRC_CFG_GET_CURRENT_CORE
100 #define TRC_CFG_GET_CURRENT_CORE() 0
101 #endif
102 
103 /* Unless specified in trcConfig.h or trcKernelPortConfig.h we assume
104  * GCC statement expressions aren't supported. */
105 #ifndef TRC_CFG_USE_GCC_STATEMENT_EXPR
106 #define TRC_CFG_USE_GCC_STATEMENT_EXPR 0
107 #endif
108 
109 /* Backwards compatibility */
110 #undef traceHandle
111 #define traceHandle TraceISRHandle_t
112 
113 /* Maximum event size */
114 #define TRC_MAX_BLOB_SIZE (16 * sizeof(uint32_t))
115 
116 /* Platform name length */
117 #define TRC_PLATFORM_CFG_LENGTH 8
118 
119 /* Header size */
120 #define TRC_HEADER_BUFFER_SIZE (sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + (sizeof(char) * (TRC_PLATFORM_CFG_LENGTH)) + sizeof(uint16_t) + sizeof(uint8_t) + sizeof(uint8_t))
121 
122 typedef struct TraceHeaderBuffer
123 {
124  uint8_t buffer[TRC_HEADER_BUFFER_SIZE];
125 } TraceHeaderBuffer_t;
126 
127 #include <trcHardwarePort.h>
128 #include <trcKernelPort.h>
129 #include <trcString.h>
130 #include <trcStaticBuffer.h>
131 #include <trcError.h>
132 #include <trcEvent.h>
133 #include <trcEventBuffer.h>
134 #include <trcMultiCoreEventBuffer.h>
135 #include <trcTimestamp.h>
136 #include <trcEntryTable.h>
137 #include <trcStreamPort.h>
138 #include <trcISR.h>
139 #include <trcTask.h>
140 #include <trcObject.h>
141 #include <trcPrint.h>
142 #include <trcHeap.h>
143 #include <trcExtension.h>
144 #include <trcUtility.h>
145 #include <trcStackMonitor.h>
146 #include <trcInternalEventBuffer.h>
147 #include <trcDiagnostics.h>
148 #include <trcAssert.h>
149 
150 #endif /* (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) */
151 
152 /* These includes offer functionality for Streaming mode only, but they are included here in order to avoid compilation errors */
153 #include <trcInterval.h>
154 #include <trcStateMachine.h>
155 #include <trcCounter.h>
156 
157 #if (TRC_USE_TRACEALYZER_RECORDER == 1)
158 
159 /******************************************************************************/
160 /*** Common API - both Snapshot and Streaming mode ****************************/
161 /******************************************************************************/
162 
173 traceResult xTraceInitialize(void);
174 
241 traceResult xTraceEnable(uint32_t uiStartOption);
242 
249 traceResult xTraceDisable(void);
250 
300 void vTraceSetFilterGroup(uint16_t filterGroup);
301 
322 void vTraceSetFilterMask(uint16_t filterMask);
323 
324 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)
325 
326 #include <stdarg.h>
327 
333 #define TRACE_GET_LOW16(value) ((uint16_t)((value) & 0x0000FFFF))
334 
340 #define TRACE_GET_HIGH16(value) ((uint16_t)(((value) >> 16) & 0x0000FFFF))
341 
348 #define TRACE_SET_LOW16(current, value) (((current) & 0xFFFF0000) | (value))
349 
356 #define TRACE_SET_HIGH16(current, value) (((current) & 0x0000FFFF) | (((uint32_t)(value)) << 16))
357 
358 #if defined (TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)
359 
364 void prvAddTaskToStackMonitor(void* task);
365 
371 void prvRemoveTaskFromStackMonitor(void* task);
372 
376 void prvReportStackUsage(void);
377 
378 #else /* defined (TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0) */
379 
380 #define prvAddTaskToStackMonitor(task)
381 #define prvRemoveTaskFromStackMonitor(task)
382 #define prvReportStackUsage()
383 
384 #endif /* defined (TRC_CFG_ENABLE_STACK_MONITOR) && (TRC_CFG_ENABLE_STACK_MONITOR == 1) && (TRC_CFG_SCHEDULING_ONLY == 0) */
385 
389 traceHandle xTraceSetISRProperties(const char* szName, uint8_t uiPriority);
390 
409 traceResult xTraceISRRegister(const char* szName, uint32_t uiPriority, TraceISRHandle_t* pxISRHandle);
410 
435 traceResult xTraceISRBegin(TraceISRHandle_t xHandle);
436 
437 #define vTraceStoreISRBegin(__handle) (void)xTraceISRBegin((TraceISRHandle_t)(__handle))
438 
466 traceResult xTraceISREnd(int pendingISR);
467 
468 #define vTraceStoreISREnd(__pendingISR) (void)xTraceISREnd(__pendingISR)
469 
476 uint32_t xTraceIsRecorderEnabled(void);
477 
484 uint32_t xTraceIsRecorderInitialized(void);
485 
496 traceResult xTraceTaskInstanceFinishedNow(void);
497 
512 traceResult xTraceTaskInstanceFinishedNext(void);
513 
523 traceResult xTraceStringRegister(const char* label, TraceStringHandle_t* pxString);
524 
534 TraceStringHandle_t xTraceRegisterString(const char* name);
535 
536 #if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)
537 
615 traceResult xTracePrintF(TraceStringHandle_t chn, const char* fmt, ...);
616 #else
617 #define xTracePrintF(chn, fmt, ...) ((void)(chn), (void)(fmt), TRC_SUCCESS) /* Comma operator is used to avoid "unused variable" compiler warnings in a single statement */
618 #endif
619 
620 #if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)
621 
634 traceResult xTraceVPrintF(TraceStringHandle_t eventLabel, const char* formatStr, va_list vl);
635 #else
636 #define xTraceVPrintF(chn, formatStr, vl) ((void)(chn), (void)(formatStr), (void)(vl), TRC_SUCCESS) /* Comma operator is used to avoid "unused variable" compiler warnings in a single statement */
637 #endif
638 
639 #if (TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1)
640 
656 traceResult xTracePrint(TraceStringHandle_t chn, const char* str);
657 #else
658 #define xTracePrint(chn, str) ((void)(chn), (void)(str), TRC_SUCCESS)
659 #endif
660 
661 /******************************************************************************/
662 /*** Extended API for Snapshot mode *******************************************/
663 /******************************************************************************/
664 
668 typedef void(*TRACE_STOP_HOOK)(void);
669 
677 void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction);
678 
689 void vTraceClear(void);
690 
691 /*****************************************************************************/
692 /*** INTERNAL SNAPSHOT FUNCTIONS *********************************************/
693 /*****************************************************************************/
694 
695 #define TRC_UNUSED
696 
697 #ifndef TRC_CFG_INCLUDE_OBJECT_DELETE
698 #define TRC_CFG_INCLUDE_OBJECT_DELETE 0
699 #endif
700 
701 #ifndef TRC_CFG_INCLUDE_READY_EVENTS
702 #define TRC_CFG_INCLUDE_READY_EVENTS 1
703 #endif
704 
705 #ifndef TRC_CFG_INCLUDE_OSTICK_EVENTS
706 #define TRC_CFG_INCLUDE_OSTICK_EVENTS 0
707 #endif
708 
709 /* This macro will create a task in the object table */
710 #undef trcKERNEL_HOOKS_TASK_CREATE
711 #define trcKERNEL_HOOKS_TASK_CREATE(SERVICE, CLASS, pxTCB) \
712  if ((pxTCB) != 0) \
713  { \
714  TRACE_SET_OBJECT_NUMBER(TASK, pxTCB); \
715  TRACE_SET_OBJECT_FILTER(TASK, pxTCB, CurrentFilterGroup); \
716  prvTraceSetObjectName(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_NAME(pxTCB)); \
717  prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \
718  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
719  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
720  prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \
721  } \
722  else \
723  { \
724  /* pxTCB is null */ \
725  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
726  { \
727  prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, 0); \
728  } \
729  }
730 
731 /* This macro will remove the task and store it in the event buffer */
732 #undef trcKERNEL_HOOKS_TASK_DELETE
733 #define trcKERNEL_HOOKS_TASK_DELETE(SERVICE, SERVICE_NAME, SERVICE_PROP, pxTCB) \
734  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
735  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
736  prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \
737  prvTraceStoreObjectNameOnCloseEvent(SERVICE_NAME, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \
738  prvTraceStoreObjectPropertiesOnCloseEvent(SERVICE_PROP, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_CLASS_TASK); \
739  prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TRACE_GET_TASK_PRIORITY(pxTCB)); \
740  prvTraceSetObjectState(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), TASK_STATE_INSTANCE_NOT_ACTIVE); \
741  prvTraceFreeObjectHandle(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
742 
743 
744 /* This macro will setup a task in the object table */
745 #undef trcKERNEL_HOOKS_OBJECT_CREATE
746 #define trcKERNEL_HOOKS_OBJECT_CREATE(SERVICE, CLASS, pxObject) \
747  TRACE_SET_OBJECT_NUMBER(CLASS, pxObject); \
748  TRACE_SET_OBJECT_FILTER(CLASS, pxObject, CurrentFilterGroup); \
749  prvMarkObjectAsUsed(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));\
750  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
751  if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
752  prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \
753  prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), 0);
754 
755 /* This macro will setup a task in the object table */
756 #undef trcKERNEL_HOOKS_OBJECT_CREATE_FAILED
757 #define trcKERNEL_HOOKS_OBJECT_CREATE_FAILED(SERVICE, TRACE_CLASS)\
758  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
759  { \
760  prvTraceStoreKernelCall(SERVICE, TRACE_CLASS, 0); \
761  }
762 
763 /* This macro will remove the object and store it in the event buffer */
764 #undef trcKERNEL_HOOKS_OBJECT_DELETE
765 #define trcKERNEL_HOOKS_OBJECT_DELETE(SERVICE, SERVICE_NAME, SERVICE_PROP, CLASS, pxObject) \
766  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
767  if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
768  prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject)); \
769  prvTraceStoreObjectNameOnCloseEvent(SERVICE_NAME, TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \
770  prvTraceStoreObjectPropertiesOnCloseEvent(SERVICE_PROP, TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject)); \
771  prvTraceFreeObjectHandle(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
772 
773 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */
774 #undef trcKERNEL_HOOKS_KERNEL_SERVICE
775 #define trcKERNEL_HOOKS_KERNEL_SERVICE(SERVICE, CLASS, pxObject) \
776  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
777  if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
778  prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
779 
780 /* This macro will create a call to a kernel service with a certain result, with a null object as parameter */
781 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT
782 #define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT(SERVICE, TRACECLASS) \
783  if (TRACE_GET_TASK_FILTER(TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
784  prvTraceStoreKernelCall(SERVICE, TRACECLASS, 0);
785 
786 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */
787 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM
788 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM(SERVICE, CLASS, pxObject, param) \
789  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
790  if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
791  prvTraceStoreKernelCallWithParam(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint32_t)param);
792 
793 /* This macro will create a call to a kernel service with a certain result, with a null object and other value as parameter */
794 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM
795 #define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM(SERVICE, TRACECLASS, param) \
796  if (TRACE_GET_TASK_FILTER(TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
797  prvTraceStoreKernelCallWithParam(SERVICE, TRACECLASS, 0, param);
798 
799 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */
800 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY
801 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY(SERVICE, param) \
802  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
803  prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, (uint32_t)param);
804 
805 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */
806 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR
807 #define trcKERNEL_HOOKS_KERNEL_SERVICE_FROM_ISR(SERVICE, CLASS, pxObject) \
808  if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
809  prvTraceStoreKernelCall(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject));
810 
811 /* This macro will create a call to a kernel service with a certain result, with a null object as parameter */
812 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_FROM_ISR
813 #define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_FROM_ISR(SERVICE, TRACECLASS) \
814  prvTraceStoreKernelCall(SERVICE, TRACECLASS, 0);
815 
816 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */
817 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR
818 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_PARAM_FROM_ISR(SERVICE, CLASS, pxObject, param) \
819  if (TRACE_GET_OBJECT_FILTER(CLASS, pxObject) & CurrentFilterMask) \
820  prvTraceStoreKernelCallWithParam(SERVICE, TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint32_t)param);
821 
822 /* This macro will create a call to a kernel service with a certain result, with a null object and other value as parameter */
823 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM_FROM_ISR
824 #define trcKERNEL_HOOKS_KERNEL_SERVICE_NULL_OBJECT_WITH_PARAM_FROM_ISR(SERVICE, TRACECLASS, param) \
825  prvTraceStoreKernelCallWithParam(SERVICE, TRACECLASS, 0, param);
826 
827 /* This macro will create a call to a kernel service with a certain result, with an object as parameter */
828 #undef trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY_FROM_ISR
829 #define trcKERNEL_HOOKS_KERNEL_SERVICE_WITH_NUMERIC_PARAM_ONLY_FROM_ISR(SERVICE, param) \
830  prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, (uint32_t)param);
831 
832 /* This macro will set the state for an object */
833 #undef trcKERNEL_HOOKS_SET_OBJECT_STATE
834 #define trcKERNEL_HOOKS_SET_OBJECT_STATE(CLASS, pxObject, STATE) \
835  prvTraceSetObjectState(TRACE_GET_OBJECT_TRACE_CLASS(CLASS, pxObject), TRACE_GET_OBJECT_NUMBER(CLASS, pxObject), (uint8_t)STATE);
836 
837 /* This macro will flag a certain task as a finished instance */
838 #undef trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED
839 #define trcKERNEL_HOOKS_SET_TASK_INSTANCE_FINISHED() \
840  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
841  prvTraceSetTaskInstanceFinished(TRACE_GET_TASK_NUMBER(TRACE_GET_CURRENT_TASK()));
842 
843 #if (TRC_CFG_INCLUDE_READY_EVENTS == 1)
844 /* This macro will create an event to indicate that a task became Ready */
845 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE
846 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB) \
847  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
848  prvTraceStoreTaskReady(TRACE_GET_TASK_NUMBER(pxTCB));
849 #else /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/
850 #undef trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE
851 #define trcKERNEL_HOOKS_MOVED_TASK_TO_READY_STATE(pxTCB)
852 #endif /*(TRC_CFG_INCLUDE_READY_EVENTS == 1)*/
853 
854 /* This macro will update the internal tick counter and call prvTracePortGetTimeStamp(0) to update the internal counters */
855 #undef trcKERNEL_HOOKS_INCREMENT_TICK
856 #define trcKERNEL_HOOKS_INCREMENT_TICK() \
857  { \
858  extern uint32_t uiTraceTickCount; \
859  uiTraceTickCount++; \
860  prvTracePortGetTimeStamp(0); \
861  }
862 
863 #if (TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)
864 /* This macro will create an event indicating that the OS tick count has increased */
865 #undef trcKERNEL_HOOKS_NEW_TIME
866 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue) \
867  prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue);
868 #else /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/
869 #undef trcKERNEL_HOOKS_NEW_TIME
870 #define trcKERNEL_HOOKS_NEW_TIME(SERVICE, xValue)
871 #endif /*(TRC_CFG_INCLUDE_OSTICK_EVENTS == 1)*/
872 
873 /* This macro will create a task switch event to the currently executing task */
874 #undef trcKERNEL_HOOKS_TASK_SWITCH
875 #define trcKERNEL_HOOKS_TASK_SWITCH( pxTCB ) \
876  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
877  prvTraceStoreTaskswitch(TRACE_GET_TASK_NUMBER(pxTCB));
878 
879 /* This macro will create an event to indicate that the task has been suspended */
880 #undef trcKERNEL_HOOKS_TASK_SUSPEND
881 #define trcKERNEL_HOOKS_TASK_SUSPEND(SERVICE, pxTCB) \
882  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
883  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
884  prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)); \
885  prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB));
886 
887 /* This macro will create an event to indicate that a task has called a wait/delay function */
888 #undef trcKERNEL_HOOKS_TASK_DELAY
889 #define trcKERNEL_HOOKS_TASK_DELAY(SERVICE, pxTCB, xValue) \
890  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
891  { \
892  prvTraceStoreKernelCallWithNumericParamOnly(SERVICE, xValue); \
893  prvTraceSetTaskInstanceFinished((uint8_t)TRACE_GET_TASK_NUMBER(pxTCB)); \
894  }
895 
896 /* This macro will create an event to indicate that a task has gotten its priority changed */
897 #undef trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE
898 #define trcKERNEL_HOOKS_TASK_PRIORITY_CHANGE(SERVICE, pxTCB, uxNewPriority) \
899  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
900  { \
901  prvTraceStoreKernelCallWithParam(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), prvTraceGetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB)));\
902  prvTraceSetPriorityProperty(TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB), (uint8_t)uxNewPriority); \
903  }
904 
905 /* This macro will create an event to indicate that the task has been resumed */
906 #undef trcKERNEL_HOOKS_TASK_RESUME
907 #define trcKERNEL_HOOKS_TASK_RESUME(SERVICE, pxTCB) \
908  if (TRACE_GET_OBJECT_FILTER(TASK, TRACE_GET_CURRENT_TASK()) & CurrentFilterMask) \
909  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
910  prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
911 
912 /* This macro will create an event to indicate that the task has been resumed from ISR */
913 #undef trcKERNEL_HOOKS_TASK_RESUME_FROM_ISR
914 #define trcKERNEL_HOOKS_TASK_RESUME_FROM_ISR(SERVICE, pxTCB) \
915  if (TRACE_GET_OBJECT_FILTER(TASK, pxTCB) & CurrentFilterMask) \
916  prvTraceStoreKernelCall(SERVICE, TRACE_CLASS_TASK, TRACE_GET_TASK_NUMBER(pxTCB));
917 
918 #if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1
919 
924 void prvTraceSetReadyEventsEnabled(uint32_t flag);
925 
931 void prvTraceStoreTaskReady(traceHandle handle);
932 #else
933 #define prvTraceSetReadyEventsEnabled(status) (void)status;
934 #endif
935 
941 void prvTraceStoreLowPower(uint32_t flag);
942 
948 void prvTraceStoreTaskswitch(traceHandle task_handle);
949 
950 #if (TRC_CFG_SCHEDULING_ONLY == 0)
951 
959 void prvTraceStoreKernelCall(uint32_t eventcode, traceObjectClass objectClass, uint32_t objectNumber);
960 
967 void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t param);
968 
977 void prvTraceStoreKernelCallWithParam(uint32_t evtcode, traceObjectClass objectClass,
978  uint32_t objectNumber, uint32_t param);
979 #else
980 
981 #define prvTraceStoreKernelCall(eventcode, objectClass, byteParam) {}
982 #define prvTraceStoreKernelCallWithNumericParamOnly(evtcode, param) {}
983 #define prvTraceStoreKernelCallWithParam(evtcode, objectClass, objectNumber, param) {}
984 
985 #endif
986 
992 void prvTraceSetTaskInstanceFinished(traceHandle handle);
993 
1001 void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value);
1002 
1011 uint8_t prvTraceGetPriorityProperty(uint8_t objectclass, traceHandle id);
1012 
1020 void prvTraceSetObjectState(uint8_t objectclass, traceHandle id, uint8_t value);
1021 
1028 void prvMarkObjectAsUsed(traceObjectClass objectclass, traceHandle handle);
1029 
1037 void prvTraceStoreObjectNameOnCloseEvent(uint8_t evtcode, traceHandle handle,
1038  traceObjectClass objectclass);
1039 
1047 void prvTraceStoreObjectPropertiesOnCloseEvent(uint8_t evtcode, traceHandle handle,
1048  traceObjectClass objectclass);
1049 
1050 /* Internal constants for task state */
1051 #define TASK_STATE_INSTANCE_NOT_ACTIVE 0
1052 #define TASK_STATE_INSTANCE_ACTIVE 1
1053 
1054 
1055 #if (TRC_CFG_INCLUDE_ISR_TRACING == 0)
1056 
1057 #undef vTraceSetISRProperties
1058 #define vTraceSetISRProperties(handle, name, priority) (void)(handle), (void)(name), (void)(priority) /* Comma operator is used to avoid "unused variable" compiler warnings in a single statement */
1059 
1060 #undef vTraceStoreISRBegin
1061 #define vTraceStoreISRBegin(x) (void)(x)
1062 
1063 #undef vTraceStoreISREnd
1064 #define vTraceStoreISREnd(x) (void)(x)
1065 
1066 #undef xTraceSetISRProperties
1067 #define xTraceSetISRProperties(name, priority) ((void)(name), (void)(priority), (traceHandle)0) /* Comma operator in parenthesis is used to avoid "unused variable" compiler warnings and return 0 in a single statement */
1068 
1069 #endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/
1070 
1081 void* xTraceGetTraceBuffer(void);
1082 
1092 uint32_t uiTraceGetTraceBufferSize(void);
1093 
1094 #if (TRC_CFG_SCHEDULING_ONLY == 1)
1095 #undef TRC_CFG_INCLUDE_USER_EVENTS
1096 #define TRC_CFG_INCLUDE_USER_EVENTS 0
1097 #endif /*(TRC_CFG_SCHEDULING_ONLY == 1)*/
1098 
1099 #if ((TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
1100 
1109 traceUBChannel xTraceRegisterUBChannel(TraceStringHandle_t channel, TraceStringHandle_t formatStr);
1110 
1117 void vTraceUBData(traceUBChannel channel, ...);
1118 
1124 void vTraceUBEvent(traceUBChannel channel);
1125 #else
1126 #define xTraceRegisterChannelFormat(eventLabel, formatStr) ((void)(eventLabel), (void)(formatStr), 0)
1127 #define vTraceUBData(label, ...) (void)(label)
1128 #endif /*(TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)*/
1129 
1130 #define NEventCodes 0x100
1131 
1132 /* Our local critical sections for the recorder */
1133 #define trcCRITICAL_SECTION_BEGIN() {TRACE_ENTER_CRITICAL_SECTION(); recorder_busy++;}
1134 #define trcCRITICAL_SECTION_END() {recorder_busy--; TRACE_EXIT_CRITICAL_SECTION();}
1135 
1136 #if (TRC_CFG_HARDWARE_PORT == TRC_HARDWARE_PORT_ARM_Cortex_M)
1137  #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY TRACE_ALLOC_CRITICAL_SECTION
1138  #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_BEGIN
1139  #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY trcCRITICAL_SECTION_END
1140 #else
1141  #define trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY() {}
1142  #define trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY() recorder_busy++;
1143  #define trcCRITICAL_SECTION_END_ON_CORTEX_M_ONLY() recorder_busy--;
1144 #endif
1145 
1170 typedef struct
1171 {
1172  uint16_t indexOfNextAvailableHandle[ TRACE_NCLASSES ];
1173  uint16_t lowestIndexOfClass[ TRACE_NCLASSES ];
1174  uint16_t highestIndexOfClass[ TRACE_NCLASSES ];
1175  uint16_t handleCountWaterMarksOfClass[ TRACE_NCLASSES ];
1176  traceHandle objectHandles[ TRACE_KERNEL_OBJECT_COUNT ];
1177 } objectHandleStackType;
1178 
1179 extern objectHandleStackType objectHandleStacks;
1180 
1198 typedef struct
1199 {
1200  /* = NCLASSES */
1201  uint32_t NumberOfObjectClasses;
1202  uint32_t ObjectPropertyTableSizeInBytes;
1204  /* This is used to calculate the index in the dynamic object table
1205  (handle - 1 - nofStaticObjects = index)*/
1206 #if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)
1207  traceHandle NumberOfObjectsPerClass[2*((TRACE_NCLASSES+1)/2)];
1208 #else
1209  traceHandle NumberOfObjectsPerClass[4*((TRACE_NCLASSES+3)/4)];
1210 #endif
1211  /* Allocation size rounded up to the closest multiple of 4 */
1212  uint8_t NameLengthPerClass[ 4*((TRACE_NCLASSES+3)/4) ];
1214  /* Allocation size rounded up to the closest multiple of 2 */
1215  uint8_t TotalPropertyBytesPerClass[ 4*((TRACE_NCLASSES+3)/4) ];
1217  /* */
1218  uint16_t StartIndexOfClass[ 2*((TRACE_NCLASSES+1)/2) ];
1220  /* The actual handles issued, should be Initiated to all zeros */
1221  uint8_t objbytes[ 4*((TRACE_OBJECT_TABLE_SIZE+3)/4) ];
1222 } ObjectPropertyTableType;
1223 
1227 typedef struct
1228 {
1229  /* = SYMBOL_HISTORY_TABLE_SIZE_IN_BYTES */
1230  uint32_t symTableSize;
1232  /* Entry 0 is reserved. Any reference to entry 0 implies NULL*/
1233  uint32_t nextFreeSymbolIndex;
1235  /* Size rounded up to closest multiple of 4, to avoid alignment issues*/
1236  uint8_t symbytes[4*(((TRC_CFG_SYMBOL_TABLE_SIZE)+3)/4)];
1238  /* Used for lookups - Up to 64 linked lists within the symbol table
1239  connecting all entries with the same 6 bit checksum.
1240  This field holds the current list heads. Should be initiated to zeros */
1241  uint16_t latestEntryOfChecksum[64];
1242 } symbolTableType;
1243 
1244 
1245 /*******************************************************************************
1246  * The data structures of the different events, all 4 bytes long
1247  ******************************************************************************/
1248 
1249 typedef struct
1250 {
1251  uint8_t type;
1252  uint8_t objHandle;
1253  uint16_t dts; /* differential timestamp - time since last event */
1254 } TSEvent, TREvent;
1255 
1256 typedef struct
1257 {
1258  uint8_t type;
1259  uint8_t dummy;
1260  uint16_t dts; /* differential timestamp - time since last event */
1261 } LPEvent;
1262 
1263 typedef struct
1264 {
1265  uint8_t type;
1266  uint8_t objHandle;
1267  uint16_t dts; /* differential timestamp - time since last event */
1268 } KernelCall;
1269 
1270 typedef struct
1271 {
1272  uint8_t type;
1273  uint8_t objHandle;
1274  uint8_t param;
1275  uint8_t dts; /* differential timestamp - time since last event */
1276 } KernelCallWithParamAndHandle;
1277 
1278 typedef struct
1279 {
1280  uint8_t type;
1281  uint8_t dts; /* differential timestamp - time since last event */
1282  uint16_t param;
1283 } KernelCallWithParam16;
1284 
1285 typedef struct
1286 {
1287  uint8_t type;
1288  uint8_t objHandle; /* the handle of the closed object */
1289  uint16_t symbolIndex; /* the name of the closed object */
1290 } ObjCloseNameEvent;
1291 
1292 typedef struct
1293 {
1294  uint8_t type;
1295  uint8_t arg1;
1296  uint8_t arg2;
1297  uint8_t arg3;
1298 } ObjClosePropEvent;
1299 
1300 typedef struct
1301 {
1302  uint8_t type;
1303  uint8_t unused1;
1304  uint8_t unused2;
1305  uint8_t dts;
1306 } TaskInstanceStatusEvent;
1307 
1308 typedef struct
1309 {
1310  uint8_t type;
1311  uint8_t dts;
1312  uint16_t payload; /* the name of the user event */
1313 } UserEvent;
1314 
1315 typedef struct
1316 {
1317  uint8_t type;
1318 
1319  /* 8 bits extra for storing DTS, if it does not fit in ordinary event
1320  (this one is always MSB if used) */
1321  uint8_t xts_8;
1322 
1323  /* 16 bits extra for storing DTS, if it does not fit in ordinary event. */
1324  uint16_t xts_16;
1325 } XTSEvent;
1326 
1327 typedef struct
1328 {
1329  uint8_t type;
1330 
1331  uint8_t xps_8;
1332  uint16_t xps_16;
1333 } XPSEvent;
1334 
1335 typedef struct{
1336  uint8_t type;
1337  uint8_t dts;
1338  uint16_t size;
1339 } MemEventSize;
1340 
1341 typedef struct{
1342  uint8_t type;
1343  uint8_t addr_high;
1344  uint16_t addr_low;
1345 } MemEventAddr;
1346 
1347 /*******************************************************************************
1348  * The separate user event buffer structure. Can be enabled in trcConfig.h.
1349  ******************************************************************************/
1350 
1351 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
1352 typedef struct
1353 {
1354  TraceStringHandle_t name;
1355  TraceStringHandle_t defaultFormat;
1356 } ChannelFormatPair;
1357 
1358 typedef struct
1359 {
1360  uint16_t bufferID;
1361  uint16_t version;
1362  uint32_t wraparoundCounter;
1363  uint32_t numberOfSlots;
1364  uint32_t nextSlotToWrite;
1365  uint8_t numberOfChannels;
1366  uint8_t padding1;
1367  uint8_t padding2;
1368  uint8_t padding3;
1369  ChannelFormatPair channels[(TRC_CFG_UB_CHANNELS)+1];
1370  uint8_t channelBuffer[((TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) + 3) & 0xFFFFFFFC]; /* 1 byte per slot, with padding for 4 byte alignment */
1371  uint8_t dataBuffer[(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) * 4]; /* 4 bytes per slot */
1372 
1373 } UserEventBuffer;
1374 #endif /* (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1) */
1375 
1376 /*******************************************************************************
1377  * The main data structure, read by Tracealyzer from the RAM dump
1378  ******************************************************************************/
1379 
1380 typedef struct
1381 {
1382  volatile uint8_t startmarker0; /* Volatile is important, see init code. */
1383  volatile uint8_t startmarker1;
1384  volatile uint8_t startmarker2;
1385  volatile uint8_t startmarker3;
1386  volatile uint8_t startmarker4;
1387  volatile uint8_t startmarker5;
1388  volatile uint8_t startmarker6;
1389  volatile uint8_t startmarker7;
1390  volatile uint8_t startmarker8;
1391  volatile uint8_t startmarker9;
1392  volatile uint8_t startmarker10;
1393  volatile uint8_t startmarker11;
1394 
1395  /* Used to determine Kernel and Endianess */
1396  uint16_t version;
1397 
1398  /* Currently 7 */
1399  uint8_t minor_version;
1400 
1401  /* This should be 0 if lower IRQ priority values implies higher priority
1402  levels, such as on ARM Cortex M. If the opposite scheme is used, i.e.,
1403  if higher IRQ priority values means higher priority, this should be 1. */
1404  uint8_t irq_priority_order;
1405 
1406  /* sizeof(RecorderDataType) - just for control */
1407  uint32_t filesize;
1408 
1409  /* Current number of events recorded */
1410  uint32_t numEvents;
1411 
1412  /* The buffer size, in number of event records */
1413  uint32_t maxEvents;
1414 
1415  /* The event buffer index, where to write the next event */
1416  uint32_t nextFreeIndex;
1417 
1418  /* 1 if the buffer is full, 0 otherwise */
1419  uint32_t bufferIsFull;
1420 
1421  /* The frequency of the clock/timer/counter used as time base */
1422  uint32_t frequency;
1423 
1424  /* The absolute timestamp of the last stored event, in the native
1425  timebase, modulo frequency! */
1426  uint32_t absTimeLastEvent;
1427 
1428  /* The number of seconds in total - lasts for 136 years */
1429  uint32_t absTimeLastEventSecond;
1430 
1431  /* 1 if the recorder has been started, 0 if not yet started or stopped.
1432  This is a 32 bit variable due to alignment issues. */
1433  uint32_t recorderActive;
1434 
1435  /* If > 0, tells the maximum time between two traced ISRs that execute
1436  back-to-back. If the time between vTraceStoreISREnd and a directly
1437  following vTraceISRBegin is above isrTailchainingThreshold, we assume a
1438  return to the previous context in between the ISRs, otherwise we assume
1439  the have executed back-to-back and don't show any fragment of the previous
1440  context in between. */
1441  uint32_t isrTailchainingThreshold;
1442 
1443  /* The maximum amount of heap memory that was allocated */
1444  uint32_t heapMemMaxUsage;
1445 
1446  /* The amount of heap memory used */
1447  uint32_t heapMemUsage;
1448 
1449  /* 0xF0F0F0F0 - for control only */
1450  int32_t debugMarker0;
1451 
1452  /* Set to value of TRC_CFG_USE_16BIT_OBJECT_HANDLES */
1453  uint32_t isUsing16bitHandles;
1454 
1455  /* The Object Property Table holds information about currently active
1456  tasks, queues, and other recorded objects. This is updated on each
1457  create call and includes object name and other properties. */
1458  ObjectPropertyTableType ObjectPropertyTable;
1459 
1460  /* 0xF1F1F1F1 - for control only */
1461  int32_t debugMarker1;
1462 
1463  /* The Symbol Table stores strings for User Events and is also used to
1464  store names of deleted objects, which still may be in the trace but no
1465  longer are available. */
1466  symbolTableType SymbolTable;
1467 
1468  /* For inclusion of float support, and for endian detection of floats.
1469  The value should be (float)1 or (uint32_t)0 */
1470 #if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)
1471  float exampleFloatEncoding;
1472 #else
1473  uint32_t exampleFloatEncoding;
1474 #endif
1475  /* This is non-zero if an internal error occurred in the recorder, e.g., if
1476  one of the Nxxx constants was too small. The systemInfo string will then
1477  contain an error message that is displayed when attempting to view the
1478  trace file. */
1479  uint32_t internalErrorOccured;
1480 
1481  /* 0xF2F2F2F2 - for control only */
1482  int32_t debugMarker2;
1483 
1484  /* Error messages from the recorder. */
1485  char systemInfo[80];
1486 
1487  /* 0xF3F3F3F3 - for control only */
1488  int32_t debugMarker3;
1489 
1490  /* The event data, in 4-byte records */
1491  uint8_t eventData[ (TRC_CFG_EVENT_BUFFER_SIZE) * 4 ];
1492 
1493 #if (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1)
1494  UserEventBuffer userEventBuffer;
1495 #endif
1496 
1497  /* This should always be 0 */
1498  uint32_t endOfSecondaryBlocks;
1499 
1500  uint8_t endmarker0;
1501  uint8_t endmarker1;
1502  uint8_t endmarker2;
1503  uint8_t endmarker3;
1504  uint8_t endmarker4;
1505  uint8_t endmarker5;
1506  uint8_t endmarker6;
1507  uint8_t endmarker7;
1508  uint8_t endmarker8;
1509  uint8_t endmarker9;
1510  uint8_t endmarker10;
1511  uint8_t endmarker11;
1512 } RecorderDataType;
1513 
1514 extern RecorderDataType* RecorderDataPtr;
1515 
1516 /* Internal functions */
1517 
1523 void prvTraceError(const char* msg);
1524 
1537 void prvTracePortGetTimeStamp(uint32_t *puiTimestamp);
1538 
1546 traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass);
1547 
1554 void prvTraceFreeObjectHandle(traceObjectClass objectclass,
1555  traceHandle handle);
1556 
1557 /* Private function. Use the public functions in trcKernelPort.h */
1558 
1566 void prvTraceSetObjectName(traceObjectClass objectclass,
1567  traceHandle handle,
1568  const char* name);
1569 
1570 /* Internal macros */
1571 
1572 #define TRACE_PROPERTY_NAME_GET(objectclass, objecthandle) \
1573  (const char*)(& RecorderDataPtr->ObjectPropertyTable.objbytes \
1574  [uiIndexOfObject(objecthandle, objectclass)])
1575 
1576 #define TRACE_PROPERTY_OBJECT_STATE(objectclass, handle) \
1577  RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \
1578  + RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass]]
1579 
1580 #define TRACE_PROPERTY_ACTOR_PRIORITY(objectclass, handle) \
1581  RecorderDataPtr->ObjectPropertyTable.objbytes[uiIndexOfObject(handle, objectclass) \
1582  + RecorderDataPtr->ObjectPropertyTable.NameLengthPerClass[objectclass] + 1]
1583 
1584 /* DEBUG ASSERTS */
1585 #if defined TRC_CFG_USE_TRACE_ASSERT && TRC_CFG_USE_TRACE_ASSERT != 0
1586 #define TRACE_ASSERT(eval, msg, defRetVal) \
1587  if (!(eval)) \
1588  { \
1589  prvTraceError("TRACE_ASSERT: " msg); \
1590  return defRetVal; \
1591  }
1592 #else
1593 #define TRACE_ASSERT(eval, msg, defRetVal)
1594 #endif
1595 
1596 typedef RecorderDataType TraceRecorderDataBuffer_t;
1597 
1598 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_SNAPSHOT)*/
1599 
1600 #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)
1601 
1602 #ifndef TRC_EXTERNAL_BUFFERS
1603 #define TRC_EXTERNAL_BUFFERS 0
1604 #endif
1605 
1606 typedef struct TraceRecorderData
1607 {
1608  uint32_t uiSessionCounter;
1609  uint32_t uiRecorderEnabled;
1610  uint32_t uiTraceSystemState;
1611 
1612  TraceAssertBuffer_t xAssertBuffer;
1613 #if (TRC_EXTERNAL_BUFFERS == 0)
1614  TraceHeaderBuffer_t xHeaderBuffer;
1615  TraceEntryTableBuffer_t xEntryTableBuffer;
1616  TraceTimestampBuffer_t xTimestampBuffer;
1617 #endif
1618  TraceStreamPortBuffer_t xStreamPortBuffer;
1619  TraceStaticBufferBuffer_t xStaticBufferBuffer;
1620  TraceEventDataBuffer_t xEventDataBuffer;
1621  TracePrintBuffer_t xPrintBuffer;
1622  TraceErrorBuffer_t xErrorBuffer;
1623  TraceISRInfoBuffer_t xISRInfoBuffer;
1624  TraceKernelPortDataBuffer_t xKernelPortBuffer;
1625  TraceTaskInfoBuffer_t xTaskInfoBuffer;
1626  TraceStackMonitorBuffer_t xStackMonitorBuffer;
1627  TraceDiagnosticsBuffer_t xDiagnosticsBuffer;
1628 } TraceRecorderData_t;
1629 
1630 extern TraceRecorderData_t* pxTraceRecorderData;
1631 extern uint32_t RecorderInitialized;
1632 
1633 #define TRC_RECORDER_DATA_BUFFER_SIZE (sizeof(TraceRecorderData_t))
1634 
1635 typedef struct TraceRecorderDataBuffer
1636 {
1637  uint8_t buffer[(TRC_RECORDER_DATA_BUFFER_SIZE)];
1638 } TraceRecorderDataBuffer_t;
1639 
1648 traceResult xTraceHeaderInitialize(TraceHeaderBuffer_t* pxBuffer);
1649 
1656 #define xTraceIsRecorderEnabled() (xTraceIsRecorderInitialized() & pxTraceRecorderData->uiRecorderEnabled)
1664 #define xTraceIsRecorderInitialized() xTraceIsComponentInitialized(TRC_RECORDER_COMPONENT_CORE)
1674 #define xTraceSetComponentInitialized(uiComponentBit) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(RecorderInitialized |= (uiComponentBit), TRC_SUCCESS)
1684 #define xTraceIsComponentInitialized(uiComponentBit) ((RecorderInitialized & (uiComponentBit)) ? 1 : 0)
1694 #define xTraceStateSet(uiState) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(pxTraceRecorderData->uiTraceSystemState = (uiState), TRC_SUCCESS)
1704 #define xTraceStateGet(puiState) TRC_COMMA_EXPR_TO_STATEMENT_EXPR_2(*(puiState) = pxTraceRecorderData->uiTraceSystemState, TRC_SUCCESS)
1712 traceResult xTraceTzCtrl(void);
1713 
1714 /******************************************************************************/
1715 /*** INTERNAL STREAMING FUNCTIONS *********************************************/
1716 /******************************************************************************/
1717 
1723 #define prvTraceStoreEvent_None(_eventID) \
1724  { \
1725  TraceEventHandle_t _xEventHandle = 0; \
1726  if (xTraceEventBegin(_eventID, 0, &_xEventHandle) == TRC_SUCCESS) \
1727  { \
1728  xTraceEventEnd(_xEventHandle); \
1729  } \
1730  }
1731 
1738 #define prvTraceStoreEvent_Handle(_eventID, _handle) \
1739  { \
1740  TraceEventHandle_t _xEventHandle = 0; \
1741  if (xTraceEventBegin(_eventID, sizeof(void*), &_xEventHandle) == TRC_SUCCESS) \
1742  { \
1743  xTraceEventAddPointer(_xEventHandle, (void*)(_handle)); \
1744  xTraceEventEnd(_xEventHandle); \
1745  } \
1746  }
1747 
1754 #define prvTraceStoreEvent_Param(_eventID, _param1) \
1755  { \
1756  TraceEventHandle_t _xEventHandle = 0; \
1757  if (xTraceEventBegin(_eventID, sizeof(uint32_t), &_xEventHandle) == TRC_SUCCESS) \
1758  { \
1759  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param1)); \
1760  xTraceEventEnd(_xEventHandle); \
1761  } \
1762  }
1763 
1771 #define prvTraceStoreEvent_HandleParam(_eventID, _handle, _param1) \
1772  { \
1773  TraceEventHandle_t _xEventHandle = 0; \
1774  if (xTraceEventBegin(_eventID, sizeof(void*) + sizeof(uint32_t), &_xEventHandle) == TRC_SUCCESS) \
1775  { \
1776  xTraceEventAddPointer(_xEventHandle, (void*)(_handle)); \
1777  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param1)); \
1778  xTraceEventEnd(_xEventHandle); \
1779  } \
1780  }
1781 
1789 #define prvTraceStoreEvent_ParamParam(_eventID, _param1, _param2) \
1790  { \
1791  TraceEventHandle_t _xEventHandle = 0; \
1792  if (xTraceEventBegin(_eventID, sizeof(uint32_t) + sizeof(uint32_t), &_xEventHandle) == TRC_SUCCESS) \
1793  { \
1794  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param1)); \
1795  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param2)); \
1796  xTraceEventEnd(_xEventHandle); \
1797  } \
1798  }
1799 
1808 #define prvTraceStoreEvent_HandleParamParam(_eventID, _handle, _param1, _param2) \
1809  { \
1810  TraceEventHandle_t _xEventHandle = 0; \
1811  if (xTraceEventBegin(_eventID, sizeof(void*) + sizeof(uint32_t) + sizeof(uint32_t), &_xEventHandle) == TRC_SUCCESS) \
1812  { \
1813  xTraceEventAddPointer(_xEventHandle, (void*)(_handle)); \
1814  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param1)); \
1815  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param2)); \
1816  xTraceEventEnd(_xEventHandle); \
1817  } \
1818  }
1819 
1828 #define prvTraceStoreEvent_ParamParamParam(_eventID, _param1, _param2, _param3) \
1829  { \
1830  TraceEventHandle_t _xEventHandle = 0; \
1831  if (xTraceEventBegin(_eventID, sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t), &_xEventHandle) == TRC_SUCCESS) \
1832  { \
1833  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param1)); \
1834  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param2)); \
1835  xTraceEventAdd32(_xEventHandle, (uint32_t)(_param3)); \
1836  xTraceEventEnd(_xEventHandle); \
1837  } \
1838  }
1839 
1845 #define vTraceSetStopHook(x) (void)(x)
1850 #define vTraceInitTimestamps()
1852 #endif /*(TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING)*/
1853 
1854 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_CUSTOM)
1855 
1863 traceResult xTraceSetBuffer(TraceRecorderDataBuffer_t *pxBuffer);
1864 #else
1865 #define xTraceSetBuffer(p) (TRC_SUCCESS)
1866 #endif
1867 
1877 traceResult xTraceGetEventBuffer(void** ppvBuffer, TraceUnsignedBaseType_t * puiSize);
1878 
1879 #else /* when TRC_USE_TRACEALYZER_RECORDER == 0 */
1880 
1881 #define xTraceInitialize() (TRC_SUCCESS)
1882 #define xTraceEnable(x) ((void)(x), TRC_SUCCESS)
1883 #define xTraceDisable() (TRC_SUCCESS)
1884 #define xTraceStringRegister(x, y) ((void)(x), (void)y, TRC_SUCCESS) /* Comma operator in parenthesis is used to avoid "unused variable" compiler warnings and return 0 in a single statement */
1885 #define xTracePrint(chn, ...) ((void)(chn), TRC_SUCCESS)
1886 #define xTracePrintF(chn, fmt, ...) ((void)(chn), (void)(fmt), TRC_SUCCESS) /* Comma operator is used to avoid "unused variable" compiler warnings in a single statement */
1887 #define xTraceVPrintF(chn, formatStr, vl) ((void)(chn), (void)(formatStr), (void)(vl), TRC_SUCCESS) /* Comma operator is used to avoid "unused variable" compiler warnings in a single statement */
1888 #define xTraceTaskInstanceFinishedNow()
1889 #define xTraceTaskInstanceFinishedNext()
1890 #define vTraceStoreISRBegin(x) (void)(x)
1891 #define vTraceStoreISREnd(x) (void)(x)
1892 #define xTraceSetISRProperties(a, b) ((void)(a), (void)(b), (traceHandle)0) /* Comma operator in parenthesis is used to avoid "unused variable" compiler warnings and return 0 in a single statement */
1893 #define xTraceRegisterChannelFormat(eventLabel, formatStr) ((void)(eventLabel), (void)(formatStr), 0) /* Comma operator in parenthesis is used to avoid "unused variable" compiler warnings and return 0 in a single statement */
1894 #define vTraceUBData(label, ...) (void)(label)
1895 
1896 #define vTraceSetFilterGroup(x) (void)(x)
1897 #define vTraceSetFilterMask(x) (void)(x)
1898 
1899 #define prvTraceSetReadyEventsEnabled(status) (void)(status)
1900 
1901 #define vTraceExcludeTask(handle) (void)(handle)
1902 
1903 #define vTraceConsoleChannelPrintF(fmt, ...) (void)(fmt)
1904 
1905 #ifndef TRC_ALLOC_CUSTOM_BUFFER
1906 #define TRC_ALLOC_CUSTOM_BUFFER(bufname)
1907 #endif
1908 
1909 #define xTraceIsRecorderEnabled() (0)
1910 #define xTraceIsRecorderInitialized() (0)
1911 
1912 #define xTraceSetBuffer(p) (TRC_SUCCESS)
1913 #define xTraceGetEventBuffer(p) (TRC_FAIL)
1914 
1915 #define vTraceSetStopHook(x) (void)(x)
1916 
1917 #define TraceRecorderDataBuffer_t uint32_t
1918 
1919 #endif /* (TRC_USE_TRACEALYZER_RECORDER == 1) */
1920 
1924 #define vTraceInitialize (void)xTraceInitialize
1929 #define vTraceEnable (void)xTraceEnable
1934 #define vTraceStop (void)xTraceDisable
1939 #define vTraceInstanceFinishedNow (void)xTraceTaskInstanceFinishedNow
1944 #define vTraceInstanceFinishedNext (void)xTraceTaskInstanceFinishedNext
1949 #define vTracePrintF (void)xTracePrintF
1954 #define vTraceVPrintF (void)xTraceVPrintF
1959 #define vTracePrint (void)xTracePrint
1964 #define vTraceSetRecorderDataBuffer(pxBuffer) xTraceSetBuffer((TraceRecorderDataBuffer_t*)(pxBuffer))
1966 #ifdef __cplusplus
1967 }
1968 #endif
1969 
1970 #endif /* TRC_RECORDER_H */
TraceStreamPortBuffer
A structure representing the trace stream port buffer.
Definition: trcStreamPort.h:80
xTracePrintF
traceResult xTracePrintF(TraceStringHandle_t xChannel, const char *szFormat,...)
Generates "User Events" with formatted text and data.
Definition: trcPrint.c:185
trcTask.h
Public trace task APIs.
xTraceISRRegister
traceResult xTraceISRRegister(const char *szName, uint32_t uiPriority, TraceISRHandle_t *pxISRHandle)
Registers trace ISR.
Definition: trcISR.c:50
xTraceRegisterString
TraceStringHandle_t xTraceRegisterString(const char *name)
Registers a trace string.
Definition: trcSnapshotRecorder.c:1621
xTraceHeaderInitialize
traceResult xTraceHeaderInitialize(TraceHeaderBuffer_t *pxBuffer)
Initializes the header data.
Definition: trcStreamingRecorder.c:228
xTraceISRBegin
traceResult xTraceISRBegin(TraceISRHandle_t xISRHandle)
Registers the beginning of an Interrupt Service Routine.
Definition: trcISR.c:109
xTraceTzCtrl
traceResult xTraceTzCtrl(void)
Call this function periodically.
Definition: trcStreamingRecorder.c:368
trcCounter.h
Public trace counter APIs.
trcStackMonitor.h
Public trace stack monitor APIs.
trcISR.h
Public trace ISR APIs.
trcString.h
Public trace string APIs.
trcAssert.h
Public trace assert APIs.
trcDiagnostics.h
Public trace diagnostic APIs.
vTraceSetFilterMask
void vTraceSetFilterMask(uint16_t filterMask)
For snapshot mode only: Sets the "filter mask" that is used to filter the events by object....
Definition: trcSnapshotRecorder.c:2636
trcError.h
Public trace error APIs.
vTraceSetFilterGroup
void vTraceSetFilterGroup(uint16_t filterGroup)
For snapshot mode only: Sets the "filter group" to assign when creating RTOS objects,...
Definition: trcSnapshotRecorder.c:2641
xTraceStringRegister
traceResult xTraceStringRegister(const char *szString, TraceStringHandle_t *pString)
Registers a trace string.
Definition: trcSnapshotRecorder.c:1610
xTracePrint
traceResult xTracePrint(TraceStringHandle_t xChannel, const char *szString)
Generate "User Events" with unformatted text.
Definition: trcPrint.c:72
trcExtension.h
Public trace extension APIs.
xTraceInitialize
traceResult xTraceInitialize(void)
Initializes the recorder data. xTraceInitialize() or xTraceEnable(...) must be called before any atte...
Definition: trcSnapshotRecorder.c:1630
xTraceDisable
traceResult xTraceDisable(void)
Disables tracing.
Definition: trcSnapshotRecorder.c:363
xTraceGetEventBuffer
traceResult xTraceGetEventBuffer(void **ppvBuffer, TraceUnsignedBaseType_t *puiSize)
Retrieve the event buffer and event buffer size.
Definition: trcSnapshotRecorder.c:314
trcObject.h
Public trace object APIs.
xTraceIsRecorderEnabled
#define xTraceIsRecorderEnabled()
Query if recorder is enabled.
Definition: trcRecorder.h:1656
trcEvent.h
Public trace event APIs.
trcStateMachine.h
Public trace state machine APIs.
trcStaticBuffer.h
Public trace static buffer APIs.
xTraceIsRecorderInitialized
#define xTraceIsRecorderInitialized()
Query if recorder initialized.
Definition: trcRecorder.h:1664
vTraceSetStopHook
#define vTraceSetStopHook(x)
Snapshot mode only. Trace stop hook.
Definition: trcRecorder.h:1845
trcTimestamp.h
Public trace timestamp APIs.
trcMultiCoreEventBuffer.h
trcHeap.h
Public trace heap APIs.
trcInterval.h
Public trace interval APIs.
xTraceVPrintF
traceResult xTraceVPrintF(TraceStringHandle_t xChannel, const char *szFormat, va_list xVL)
Generates "User Events" with formatted text and data.
Definition: trcPrint.c:210
trcPrint.h
Public trace print APIs.
xTraceTaskInstanceFinishedNext
traceResult xTraceTaskInstanceFinishedNext(void)
Marks the current trace task instance as finished on the next kernel call.
Definition: trcSnapshotRecorder.c:593
trcEventBuffer.h
Public trace event buffer APIs.
xTraceTaskInstanceFinishedNow
traceResult xTraceTaskInstanceFinishedNow(void)
Registers trace task instance finished event.
Definition: trcSnapshotRecorder.c:624
TraceEntryTableBuffer
Definition: trcEntryTable.h:62
trcEntryTable.h
Public trace entry table APIs.
trcInternalEventBuffer.h
Public internal event buffer APIs.
TraceKernelPortDataBuffer
A structure representing the kernel port buffer.
Definition: trcKernelPort.h:105
xTraceISREnd
traceResult xTraceISREnd(TraceBaseType_t xIsTaskSwitchRequired)
Registers the end of an Interrupt Service Routine.
Definition: trcCTI.c:1952