]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c
Update trace recorder code to the latest.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace / trcSnapshotRecorder.c
index 6da36201054478814ed4c3555a81db4e8d9942c5..9eec9d2edd61f86211c72cc5a67149f56a43c389 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Trace Recorder Library for Tracealyzer v3.1.2\r
+ * Trace Recorder Library for Tracealyzer v4.1.5\r
  * Percepio AB, www.percepio.com\r
  *\r
  * trcSnapshotRecorder.c\r
@@ -7,7 +7,7 @@
  * The generic core of the trace recorder's snapshot mode.\r
  *\r
  * Terms of Use\r
- * This file is part of the trace recorder library (RECORDER), which is the \r
+ * This file is part of the trace recorder library (RECORDER), which is the\r
  * intellectual property of Percepio AB (PERCEPIO) and provided under a\r
  * license as follows.\r
  * The RECORDER may be used free of charge for the purpose of recording data\r
  * You may distribute the RECORDER in its original source code form, assuming\r
  * this text (terms of use, disclaimer, copyright notice) is unchanged. You are\r
  * allowed to distribute the RECORDER with minor modifications intended for\r
- * configuration or porting of the RECORDER, e.g., to allow using it on a \r
+ * configuration or porting of the RECORDER, e.g., to allow using it on a\r
  * specific processor, processor family or with a specific communication\r
  * interface. Any such modifications should be documented directly below\r
- * this comment block.  \r
+ * this comment block.\r
  *\r
  * Disclaimer\r
  * The RECORDER is being delivered to you AS IS and PERCEPIO makes no warranty\r
- * as to its use or performance. PERCEPIO does not and cannot warrant the \r
+ * as to its use or performance. PERCEPIO does not and cannot warrant the\r
  * performance or results you may obtain by using the RECORDER or documentation.\r
  * PERCEPIO make no warranties, express or implied, as to noninfringement of\r
  * third party rights, merchantability, or fitness for any particular purpose.\r
@@ -38,7 +38,7 @@
  *\r
  * Tabs are used for indent in this file (1 tab = 4 spaces)\r
  *\r
- * Copyright Percepio AB, 2017.\r
+ * Copyright Percepio AB, 2018.\r
  * www.percepio.com\r
  ******************************************************************************/\r
 \r
@@ -66,6 +66,7 @@ int32_t isPendingContextSwitch = 0;
 #if !defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1\r
 static int readyEventsEnabled = 1;\r
 #endif /*!defined TRC_CFG_INCLUDE_READY_EVENTS || TRC_CFG_INCLUDE_READY_EVENTS == 1*/\r
+\r
 /*******************************************************************************\r
  * uiTraceTickCount\r
  *\r
@@ -77,7 +78,9 @@ static int readyEventsEnabled = 1;
 uint32_t uiTraceTickCount = 0;\r
 \r
 uint32_t trace_disable_timestamp = 0;\r
+\r
 static uint32_t last_timestamp = 0;\r
+\r
 /* Flag that shows if inside a critical section of the recorder */\r
 volatile int recorder_busy = 0;\r
 \r
@@ -87,27 +90,32 @@ uint32_t timestampFrequency = 0;
 /* The last error message of the recorder. NULL if no error message. */\r
 const char* traceErrorMessage = NULL;\r
 \r
-\r
 int8_t nISRactive = 0;\r
-traceHandle handle_of_last_logged_task = 0;\r
-uint8_t inExcludedTask = 0;\r
 \r
-extern uint8_t inExcludedTask;\r
-extern int8_t nISRactive;\r
-extern traceHandle handle_of_last_logged_task;\r
+traceHandle handle_of_last_logged_task = 0;\r
 \r
 /* Called when the recorder is stopped, set by vTraceSetStopHook. */\r
 TRACE_STOP_HOOK vTraceStopHookPtr = (TRACE_STOP_HOOK)0;\r
 \r
+uint16_t CurrentFilterMask = 0xFFFF;\r
+\r
+uint16_t CurrentFilterGroup = FilterGroup0;\r
+\r
+extern int8_t nISRactive;\r
+\r
+extern traceHandle handle_of_last_logged_task;\r
+\r
 /*************** Private Functions *******************************************/\r
 static void prvStrncpy(char* dst, const char* src, uint32_t maxLength);\r
-static uint8_t prvTraceGetObjectState(uint8_t objectclass, traceHandle id); \r
-static void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength); \r
-static void* prvTraceNextFreeEventBufferSlot(void); \r
+static uint8_t prvTraceGetObjectState(uint8_t objectclass, traceHandle id);\r
+static void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength);\r
+static void* prvTraceNextFreeEventBufferSlot(void);\r
 static uint16_t prvTraceGetDTS(uint16_t param_maxDTS);\r
 static traceString prvTraceOpenSymbol(const char* name, traceString userEventChannel);\r
 static void prvTraceUpdateCounters(void);\r
 \r
+void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t signed_size);\r
+\r
 #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
 static void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nEntries);\r
 #endif\r
@@ -128,7 +136,7 @@ static traceString prvTraceLookupSymbolTableEntry(const char* name,
 void prvTraceIncreaseISRActive(void);\r
 void prvTraceDecreaseISRActive(void);\r
 #endif /*(TRC_CFG_INCLUDE_ISR_TRACING == 0)*/\r
-                                                                                \r
+\r
 #if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
 static uint8_t prvTraceGet8BitHandle(traceHandle handle);\r
 #else\r
@@ -137,8 +145,7 @@ static uint8_t prvTraceGet8BitHandle(traceHandle handle);
 \r
 \r
 #if (TRC_CFG_INCLUDE_MEMMANG_EVENTS == 1) && (TRC_CFG_SCHEDULING_ONLY == 0)\r
- /* Current heap usage. Always updated. */\r
- static uint32_t heapMemUsage = 0;\r
+static uint32_t heapMemUsage = 0;\r
 #endif\r
 \r
 #if (TRC_CFG_SCHEDULING_ONLY == 0)\r
@@ -197,19 +204,19 @@ void prvTraceError(const char* msg);
 * Initializes and optionally starts the trace, depending on the start option.\r
 * To use the trace recorder, the startup must call vTraceEnable before any RTOS\r
 * calls are made (including "create" calls). Three start options are provided:\r
-* \r
-* TRC_START: Starts the tracing directly. In snapshot mode this allows for \r
+*\r
+* TRC_START: Starts the tracing directly. In snapshot mode this allows for\r
 * starting the trace at any point in your code, assuming vTraceEnable(TRC_INIT)\r
 * has been called in the startup.\r
 * Can also be used for streaming without Tracealyzer control, e.g. to a local\r
 * flash file system (assuming such a "stream port", see trcStreamingPort.h).\r
-* \r
+*\r
 * TRC_INIT: Initializes the trace recorder, but does not start the tracing.\r
 * In snapshot mode, this must be followed by a vTraceEnable(TRC_START) sometime\r
 * later.\r
 *\r
 * Usage examples, in snapshot mode:\r
-* \r
+*\r
 * Snapshot trace, from startup:\r
 *      <board init>\r
 *      vTraceEnable(TRC_START);\r
@@ -221,14 +228,14 @@ void prvTraceError(const char* msg);
 *      <RTOS init>\r
 *      ...\r
 *      vTraceEnable(TRC_START); // e.g., in task context, at some relevant event\r
-* \r
+*\r
 *\r
 * Note: See other implementation of vTraceEnable in trcStreamingRecorder.c\r
 ******************************************************************************/\r
 void vTraceEnable(int startOption)\r
 {\r
        prvTraceInitTraceData();\r
-       \r
+\r
        if (startOption == TRC_START)\r
        {\r
                vTraceStart();\r
@@ -240,7 +247,7 @@ void vTraceEnable(int startOption)
        else if (startOption != TRC_INIT)\r
        {\r
                prvTraceError("Unexpected argument to vTraceEnable (snapshot mode)");\r
-       }       \r
+       }\r
 }\r
 \r
 /*******************************************************************************\r
@@ -261,7 +268,8 @@ void vTraceSetRecorderDataBuffer(void* pRecorderData)
  * vTraceSetStopHook\r
  *\r
  * Sets a function to be called when the recorder is stopped. This can be used\r
- * to save the trace to a file system, if available. \r
+ * to save the trace to a file system, if available. This is only implemented\r
+ * for snapshot mode.\r
  ******************************************************************************/\r
 void vTraceSetStopHook(TRACE_STOP_HOOK stopHookFunction)\r
 {\r
@@ -314,10 +322,10 @@ uint32_t uiTraceStart(void)
 \r
        if (RecorderDataPtr == NULL)\r
        {\r
-               prvTraceError("RecorderDataPtr is NULL. Call vTraceInitTraceData() before starting trace.");\r
+               TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized. Use vTraceEnable() instead!", 0);\r
                return 0;\r
        }\r
-       \r
+\r
        if (RecorderDataPtr->recorderActive == 1)\r
                return 1; /* Already running */\r
 \r
@@ -368,7 +376,10 @@ void vTraceStart(void)
  ******************************************************************************/\r
 void vTraceStop(void)\r
 {\r
-       RecorderDataPtr->recorderActive = 0;\r
+       if (RecorderDataPtr != NULL)\r
+       {\r
+               RecorderDataPtr->recorderActive = 0;\r
+       }\r
 \r
        if (vTraceStopHookPtr != (TRACE_STOP_HOOK)0)\r
        {\r
@@ -376,6 +387,22 @@ void vTraceStop(void)
        }\r
 }\r
 \r
+/*******************************************************************************\r
+* xTraceIsRecordingEnabled\r
+* Returns true (1) if the recorder is enabled (i.e. is recording), otherwise 0.\r
+******************************************************************************/\r
+int xTraceIsRecordingEnabled(void)\r
+{\r
+       if (RecorderDataPtr != NULL)\r
+       {\r
+               return (int)RecorderDataPtr->recorderActive;\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
+}\r
+\r
 /*******************************************************************************\r
  * xTraceGetLastError\r
  *\r
@@ -433,7 +460,6 @@ uint32_t uiTraceGetTraceBufferSize(void)
  * prvTraceTaskInstanceFinish\r
  *\r
  * Private common function for the vTraceTaskInstanceFinishXXX functions.\r
- * \r
  *****************************************************************************/\r
 static void prvTraceTaskInstanceFinish(int8_t direct)\r
 {\r
@@ -443,7 +469,7 @@ static void prvTraceTaskInstanceFinish(int8_t direct)
        TRACE_ALLOC_CRITICAL_SECTION();\r
 \r
        trcCRITICAL_SECTION_BEGIN();\r
-       if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
                dts45 = (uint8_t)prvTraceGetDTS(0xFF);\r
                tis = (TaskInstanceStatusEvent*) prvTraceNextFreeEventBufferSlot();\r
@@ -482,9 +508,6 @@ static void prvTraceTaskInstanceFinish(int8_t direct)
  *                     processCommand(command);\r
  *          vTraceInstanceFinishedNext();\r
  *             }\r
- *\r
- * Note: This is only supported in Tracealyzer tools v2.7 or later\r
- *\r
  *****************************************************************************/\r
 void vTraceInstanceFinishedNext(void)\r
 {\r
@@ -514,9 +537,6 @@ void vTraceInstanceFinishedNext(void)
  *                     DoSometingElse();\r
  *          vTraceInstanceFinishedNext();\r
  *      }\r
- *\r
- * Note: This is only supported in Tracealyzer tools v2.7 or later\r
- *\r
  *****************************************************************************/\r
 void vTraceInstanceFinishedNow(void)\r
 {\r
@@ -533,7 +553,7 @@ void vTraceInstanceFinishedNow(void)
  * xTraceSetISRProperties\r
  *\r
  * Stores a name and priority level for an Interrupt Service Routine, to allow\r
- * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin. \r
+ * for better visualization. Returns a traceHandle used by vTraceStoreISRBegin.\r
  *\r
  * Example:\r
  *      #define PRIO_ISR_TIMER1 3 // the hardware priority of the interrupt\r
@@ -546,18 +566,19 @@ void vTraceInstanceFinishedNow(void)
  *              ...\r
  *              vTraceStoreISREnd(0);\r
  *      }\r
- *\r
  ******************************************************************************/\r
  traceHandle xTraceSetISRProperties(const char* name, uint8_t priority)\r
 {\r
        static traceHandle handle = 0;\r
-       handle++;\r
+       TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized, call vTraceEnable() first!", (traceHandle)0);\r
        TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "xTraceSetISRProperties: Invalid value for handle", 0);\r
        TRACE_ASSERT(name != NULL, "xTraceSetISRProperties: name == NULL", 0);\r
 \r
+       handle++;\r
+\r
        prvTraceSetObjectName(TRACE_CLASS_ISR, handle, name);\r
        prvTraceSetPriorityProperty(TRACE_CLASS_ISR, handle, priority);\r
-       \r
+\r
        return handle;\r
 }\r
 \r
@@ -578,7 +599,6 @@ void vTraceInstanceFinishedNow(void)
  *              ...\r
  *              vTraceStoreISREnd(0);\r
  *      }\r
- *\r
  ******************************************************************************/\r
 void vTraceStoreISRBegin(traceHandle handle)\r
 {\r
@@ -588,7 +608,7 @@ void vTraceStoreISRBegin(traceHandle handle)
        {\r
                /*************************************************************************\r
                * This occurs if an ISR calls a trace function, preempting a previous\r
-               * trace call that is being processed in a different ISR or task. \r
+               * trace call that is being processed in a different ISR or task.\r
                * If this occurs, there is probably a problem in the definition of the\r
                * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
                * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
@@ -600,13 +620,14 @@ void vTraceStoreISRBegin(traceHandle handle)
                return;\r
        }\r
        trcCRITICAL_SECTION_BEGIN();\r
-       \r
+\r
        if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
                uint16_t dts4;\r
-               \r
-               TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceStoreISRBegin: Invalid value for handle", TRC_UNUSED);\r
-               \r
+\r
+               TRACE_ASSERT(handle != 0, "vTraceStoreISRBegin: Invalid ISR handle (NULL)", TRC_UNUSED);\r
+               TRACE_ASSERT(handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[TRACE_CLASS_ISR], "vTraceStoreISRBegin: Invalid ISR handle (> NISR)", TRC_UNUSED);\r
+\r
                dts4 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
 \r
                if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */\r
@@ -642,7 +663,7 @@ void vTraceStoreISRBegin(traceHandle handle)
  * Registers the end of an Interrupt Service Routine.\r
  *\r
  * The parameter pendingISR indicates if the interrupt has requested a\r
- * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the \r
+ * task-switch (= 1), e.g., by signaling a semaphore. Otherwise (= 0) the\r
  * interrupt is assumed to return to the previous context.\r
  *\r
  * Example:\r
@@ -657,14 +678,13 @@ void vTraceStoreISRBegin(traceHandle handle)
  *              ...\r
  *              vTraceStoreISREnd(0);\r
  *      }\r
- *\r
  ******************************************************************************/\r
 void vTraceStoreISREnd(int pendingISR)\r
 {\r
        TSEvent* ts;\r
        uint16_t dts5;\r
        uint8_t hnd8 = 0, type = 0;\r
-       \r
+\r
        TRACE_ALLOC_CRITICAL_SECTION();\r
 \r
        if (! RecorderDataPtr->recorderActive ||  ! handle_of_last_logged_task)\r
@@ -676,7 +696,7 @@ void vTraceStoreISREnd(int pendingISR)
        {\r
                /*************************************************************************\r
                * This occurs if an ISR calls a trace function, preempting a previous\r
-               * trace call that is being processed in a different ISR or task. \r
+               * trace call that is being processed in a different ISR or task.\r
                * If this occurs, there is probably a problem in the definition of the\r
                * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
                * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
@@ -687,7 +707,7 @@ void vTraceStoreISREnd(int pendingISR)
                prvTraceError("vTraceStoreISREnd - recorder busy! See code comment.");\r
                return;\r
        }\r
-       \r
+\r
        if (nISRactive == 0)\r
        {\r
                prvTraceError("Unmatched call to vTraceStoreISREnd (nISRactive == 0, expected > 0)");\r
@@ -703,7 +723,7 @@ void vTraceStoreISREnd(int pendingISR)
                type = TS_ISR_RESUME;\r
                hnd8 = prvTraceGet8BitHandle(isrstack[nISRactive - 1]); /* isrstack[nISRactive] is the handle of the ISR we're currently exiting. isrstack[nISRactive - 1] is the handle of the ISR that was executing previously. */\r
        }\r
-       else if ((isPendingContextSwitch == 0) || (prvTraceIsSchedulerSuspended()))     \r
+       else if ((isPendingContextSwitch == 0) || (prvTraceIsSchedulerSuspended()))\r
        {\r
                /* Return to interrupted task, if no context switch will occur in between. */\r
                type = TS_TASK_RESUME;\r
@@ -742,6 +762,7 @@ void prvTraceDecreaseISRActive(void)
 }\r
 #endif /* (TRC_CFG_INCLUDE_ISR_TRACING == 1)*/\r
 \r
+\r
 /********************************************************************************/\r
 /* User Event functions                                                                                                                        */\r
 /********************************************************************************/\r
@@ -1036,13 +1057,13 @@ static void prvTraceClearChannelBuffer(uint32_t count)
 {\r
        uint32_t slots;\r
 \r
-       TRACE_ASSERT(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE >= count,\r
+       TRACE_ASSERT((TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) >= count,\r
                "prvTraceClearChannelBuffer: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);\r
 \r
        /* Check if we're close to the end of the buffer */\r
-       if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE)\r
+       if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE))\r
        {\r
-               slots = TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
+               slots = (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
                (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite], 0, slots);\r
                (void)memset(&RecorderDataPtr->userEventBuffer.channelBuffer[0], 0, (count - slots));\r
        }\r
@@ -1060,15 +1081,15 @@ static void prvTraceClearChannelBuffer(uint32_t count)
 static void prvTraceCopyToDataBuffer(uint32_t* data, uint32_t count)\r
 {\r
        uint32_t slots;\r
-       \r
+\r
        TRACE_ASSERT(data != NULL,\r
                "prvTraceCopyToDataBuffer: data == NULL.", TRC_UNUSED);\r
-       TRACE_ASSERT(count <= TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE,\r
+       TRACE_ASSERT(count <= (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE),\r
                "prvTraceCopyToDataBuffer: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);\r
        /* Check if we're close to the end of the buffer */\r
-       if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE)\r
+       if (RecorderDataPtr->userEventBuffer.nextSlotToWrite + count > (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE))\r
        {\r
-               slots = TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
+               slots = (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) - RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Number of slots before end of buffer */\r
                (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[RecorderDataPtr->userEventBuffer.nextSlotToWrite * 4], data, slots * 4);\r
                (void)memcpy(&RecorderDataPtr->userEventBuffer.dataBuffer[0], data + slots, (count - slots) * 4);\r
        }\r
@@ -1116,10 +1137,10 @@ static void prvTraceUBHelper2(traceUBChannel channel, uint32_t* data, uint32_t n
 {\r
        static uint32_t old_timestamp = 0;\r
        uint32_t old_nextSlotToWrite = 0;\r
-       \r
+\r
        TRACE_ALLOC_CRITICAL_SECTION();\r
 \r
-       TRACE_ASSERT(TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE >= noOfSlots, "prvTraceUBHelper2: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);\r
+       TRACE_ASSERT((TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE) >= noOfSlots, "prvTraceUBHelper2: TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE is too small to handle this event.", TRC_UNUSED);\r
 \r
        trcCRITICAL_SECTION_BEGIN();\r
        /* Store the timestamp */\r
@@ -1138,7 +1159,7 @@ static void prvTraceUBHelper2(traceUBChannel channel, uint32_t* data, uint32_t n
        prvTraceCopyToDataBuffer(data, noOfSlots); /* Will wrap around the data if necessary */\r
 \r
        old_nextSlotToWrite = RecorderDataPtr->userEventBuffer.nextSlotToWrite; /* Save the index that we want to write the channel data at when we're done */\r
-       RecorderDataPtr->userEventBuffer.nextSlotToWrite = (RecorderDataPtr->userEventBuffer.nextSlotToWrite + noOfSlots) % TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE; /* Make sure we never end up outside the buffer */\r
+       RecorderDataPtr->userEventBuffer.nextSlotToWrite = (RecorderDataPtr->userEventBuffer.nextSlotToWrite + noOfSlots) % (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE); /* Make sure we never end up outside the buffer */\r
 \r
        /* Write to the channel buffer to indicate that this user event is ready to be used */\r
        if (channel != 0)\r
@@ -1168,13 +1189,13 @@ traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatSt
 {\r
        uint8_t i;\r
        traceUBChannel retVal = 0;\r
-       \r
+\r
        TRACE_ALLOC_CRITICAL_SECTION();\r
 \r
        TRACE_ASSERT(formatStr != 0, "xTraceRegisterChannelFormat: formatStr == 0", (traceUBChannel)0);\r
 \r
        trcCRITICAL_SECTION_BEGIN();\r
-       for (i = 1; i <= TRC_CFG_UB_CHANNELS; i++) /* Size of the channels buffer is TRC_CFG_UB_CHANNELS + 1. Index 0 is unused. */\r
+       for (i = 1; i <= (TRC_CFG_UB_CHANNELS); i++) /* Size of the channels buffer is TRC_CFG_UB_CHANNELS + 1. Index 0 is unused. */\r
        {\r
                if(RecorderDataPtr->userEventBuffer.channels[i].name == 0 && RecorderDataPtr->userEventBuffer.channels[i].defaultFormat == 0)\r
                {\r
@@ -1203,15 +1224,14 @@ traceUBChannel xTraceRegisterUBChannel(traceString channel, traceString formatSt
  *\r
  * Slightly faster version of vTracePrintF() due to no lookups.\r
  *\r
- * Note: This is only available if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is enabled in\r
- * trcConfig.h\r
- *\r
+ * Note: This is only available if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER is\r
+ * enabled in trcSnapshotConfig.h\r
  ******************************************************************************/\r
 #if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1) && (TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER == 1))\r
 void vTraceUBData(traceUBChannel channelPair, ...)\r
 {\r
        va_list vl;\r
-       \r
+\r
        TRACE_ASSERT(channelPair != 0, "vTraceUBData: Not a valid traceUBChannel!", TRC_UNUSED);\r
 \r
        va_start(vl, channelPair);\r
@@ -1228,7 +1248,7 @@ void vTraceUBData_Helper(traceUBChannel channelPair, va_list vl)
        traceString formatStr;\r
 \r
        TRACE_ASSERT(channelPair != 0, "vTraceUBData_Helper: channelPair == 0", TRC_UNUSED);\r
-       TRACE_ASSERT(channelPair <= TRC_CFG_UB_CHANNELS, "vTraceUBData_Helper: ", TRC_UNUSED);\r
+       TRACE_ASSERT(channelPair <= (TRC_CFG_UB_CHANNELS), "vTraceUBData_Helper: ", TRC_UNUSED);\r
 \r
        channel = RecorderDataPtr->userEventBuffer.channels[channelPair].name;\r
        formatStr = RecorderDataPtr->userEventBuffer.channels[channelPair].defaultFormat;\r
@@ -1248,7 +1268,7 @@ void vTraceUBEvent(traceUBChannel channelPair)
        uint32_t data[(3 + MAX_ARG_SIZE) / 4];\r
 \r
        TRACE_ASSERT(channelPair != 0, "vTraceUBEvent: channelPair == 0", TRC_UNUSED);\r
-       TRACE_ASSERT(channelPair <= TRC_CFG_UB_CHANNELS, "vTraceUBEvent: ", TRC_UNUSED);\r
+       TRACE_ASSERT(channelPair <= (TRC_CFG_UB_CHANNELS), "vTraceUBEvent: ", TRC_UNUSED);\r
 \r
        prvTraceUBHelper2(channelPair, data, 1); /* Only need one slot for timestamp */\r
 }\r
@@ -1331,7 +1351,7 @@ void vTracePrintF_Helper(traceString eventLabel, const char* formatStr, va_list
 \r
        trcCRITICAL_SECTION_BEGIN();\r
 \r
-       if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
                /* First, write the "primary" user event entry in the local buffer, but\r
                let the event type be "EVENT_BEING_WRITTEN" for now...*/\r
@@ -1396,7 +1416,7 @@ void vTracePrintF_Helper(traceString eventLabel, const char* formatStr, va_list
                                RecorderDataPtr->nextFreeIndex += noOfSlots;\r
                                RecorderDataPtr->numEvents += noOfSlots;\r
 \r
-                               if (RecorderDataPtr->nextFreeIndex >= TRC_CFG_EVENT_BUFFER_SIZE)\r
+                               if (RecorderDataPtr->nextFreeIndex >= (TRC_CFG_EVENT_BUFFER_SIZE))\r
                                {\r
                                        #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
                                        /* We have reached the end, but this is a ring buffer. Start from the beginning again. */\r
@@ -1423,7 +1443,7 @@ void vTracePrintF_Helper(traceString eventLabel, const char* formatStr, va_list
        traceString formatLabel;\r
        traceUBChannel channel;\r
 \r
-       if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
                formatLabel = xTraceRegisterString(formatStr);\r
 \r
@@ -1452,7 +1472,7 @@ void vTracePrint(traceString chn, const char* str)
        TRACE_ALLOC_CRITICAL_SECTION();\r
 \r
        trcCRITICAL_SECTION_BEGIN();\r
-       if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
                dts1 = (uint8_t)prvTraceGetDTS(0xFF);\r
                ue = (UserEvent*) prvTraceNextFreeEventBufferSlot();\r
@@ -1470,7 +1490,7 @@ void vTracePrint(traceString chn, const char* str)
        traceUBChannel channel;\r
        uint32_t noOfSlots = 1;\r
        uint32_t tempDataBuffer[(3 + MAX_ARG_SIZE) / 4];\r
-       if (RecorderDataPtr->recorderActive && (! inExcludedTask || nISRactive) && handle_of_last_logged_task)\r
+       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
                traceString trcStr = prvTraceOpenSymbol(str, chn);\r
                channel = xTraceRegisterUBChannel(chn, trcStr);\r
@@ -1498,13 +1518,12 @@ void vTracePrint(traceString chn, const char* str)
  *      myEventHandle = xTraceRegisterString("MyUserEvent");\r
  *      ...\r
  *      vTracePrintF(myEventHandle, "My value is: %d", myValue);\r
- *\r
  ******************************************************************************/\r
 #if ((TRC_CFG_SCHEDULING_ONLY == 0) && (TRC_CFG_INCLUDE_USER_EVENTS == 1))\r
 traceString xTraceRegisterString(const char* label)\r
 {\r
        TRACE_ASSERT(label != NULL, "xTraceRegisterString: label == NULL", (traceString)0);\r
-\r
+       TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized, call vTraceEnable() first!", (traceHandle)0);\r
        return prvTraceOpenSymbol(label, 0);\r
 }\r
 #endif\r
@@ -1512,7 +1531,7 @@ traceString xTraceRegisterString(const char* label)
 \r
 #if ((!defined TRC_CFG_INCLUDE_READY_EVENTS) || (TRC_CFG_INCLUDE_READY_EVENTS == 1))\r
 \r
-void prvTraceSetReadyEventsEnabled(int status) \r
+void prvTraceSetReadyEventsEnabled(int status)\r
 {\r
        readyEventsEnabled = status;\r
 }\r
@@ -1522,7 +1541,7 @@ void prvTraceSetReadyEventsEnabled(int status)
  *\r
  * This function stores a ready state for the task handle sent in as parameter.\r
  ******************************************************************************/\r
-void prvTraceStoreTaskReady(traceHandle handle) \r
+void prvTraceStoreTaskReady(traceHandle handle)\r
 {\r
        uint16_t dts3;\r
        TREvent* tr;\r
@@ -1536,22 +1555,22 @@ void prvTraceStoreTaskReady(traceHandle handle)
                placement of the trace macro. In that case, the events are ignored. */\r
                return;\r
        }\r
-       \r
+\r
        if (! readyEventsEnabled)\r
        {\r
-               /* When creating tasks, ready events are also created. If creating \r
-               a "hidden" (not traced) task, we must therefore disable recording \r
+               /* When creating tasks, ready events are also created. If creating\r
+               a "hidden" (not traced) task, we must therefore disable recording\r
                of ready events to avoid an undesired ready event... */\r
                return;\r
        }\r
 \r
-       TRACE_ASSERT(handle <= TRC_CFG_NTASK, "prvTraceStoreTaskReady: Invalid value for handle", TRC_UNUSED);\r
+       TRACE_ASSERT(handle <= (TRC_CFG_NTASK), "prvTraceStoreTaskReady: Invalid value for handle", TRC_UNUSED);\r
 \r
        if (recorder_busy)\r
        {\r
                /*************************************************************************\r
                * This occurs if an ISR calls a trace function, preempting a previous\r
-               * trace call that is being processed in a different ISR or task. \r
+               * trace call that is being processed in a different ISR or task.\r
                * If this occurs, there is probably a problem in the definition of the\r
                * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
                * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
@@ -1566,18 +1585,15 @@ void prvTraceStoreTaskReady(traceHandle handle)
        trcCRITICAL_SECTION_BEGIN();\r
        if (RecorderDataPtr->recorderActive) /* Need to repeat this check! */\r
        {\r
-               if (!TRACE_GET_TASK_FLAG_ISEXCLUDED(handle))\r
+               dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+               hnd8 = prvTraceGet8BitHandle(handle);\r
+               tr = (TREvent*)prvTraceNextFreeEventBufferSlot();\r
+               if (tr != NULL)\r
                {\r
-                       dts3 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
-                       hnd8 = prvTraceGet8BitHandle(handle);\r
-                       tr = (TREvent*)prvTraceNextFreeEventBufferSlot();\r
-                       if (tr != NULL)\r
-                       {\r
-                               tr->type = DIV_TASK_READY;\r
-                               tr->dts = dts3;\r
-                               tr->objHandle = hnd8;\r
-                               prvTraceUpdateCounters();\r
-                       }\r
+                       tr->type = DIV_TASK_READY;\r
+                       tr->dts = dts3;\r
+                       tr->objHandle = hnd8;\r
+                       prvTraceUpdateCounters();\r
                }\r
        }\r
        trcCRITICAL_SECTION_END();\r
@@ -1589,7 +1605,7 @@ void prvTraceStoreTaskReady(traceHandle handle)
  *\r
  * This function stores a low power state.\r
  ******************************************************************************/\r
-void prvTraceStoreLowPower(uint32_t flag) \r
+void prvTraceStoreLowPower(uint32_t flag)\r
 {\r
        uint16_t dts;\r
        LPEvent* lp;\r
@@ -1601,7 +1617,7 @@ void prvTraceStoreLowPower(uint32_t flag)
        {\r
                /*************************************************************************\r
                * This occurs if an ISR calls a trace function, preempting a previous\r
-               * trace call that is being processed in a different ISR or task. \r
+               * trace call that is being processed in a different ISR or task.\r
                * If this occurs, there is probably a problem in the definition of the\r
                * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
                * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
@@ -1655,56 +1671,52 @@ void vTraceStoreMemMangEvent(uint32_t ecode, uint32_t address, int32_t signed_si
                /* Occurs in vTraceInitTraceData, if using dynamic allocation. */\r
                return;\r
        }\r
-       \r
+\r
        if (signed_size < 0)\r
                size = (uint32_t)(- signed_size);\r
        else\r
                size = (uint32_t)(signed_size);\r
 \r
        trcCRITICAL_SECTION_BEGIN();\r
-       \r
+\r
        heapMemUsage = heapMemUsage + (uint32_t)signed_size;\r
-       \r
+\r
        if (RecorderDataPtr->recorderActive)\r
        {\r
-               /* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */\r
-               if (nISRactive || !inExcludedTask)\r
+               dts1 = (uint8_t)prvTraceGetDTS(0xFF);\r
+               size_low = (uint16_t)prvTraceGetParam(0xFFFF, size);\r
+               ms = (MemEventSize *)prvTraceNextFreeEventBufferSlot();\r
+\r
+               if (ms != NULL)\r
                {\r
-                       dts1 = (uint8_t)prvTraceGetDTS(0xFF);\r
-                       size_low = (uint16_t)prvTraceGetParam(0xFFFF, size);\r
-                       ms = (MemEventSize *)prvTraceNextFreeEventBufferSlot();\r
+                       ms->dts = dts1;\r
+                       ms->type = NULL_EVENT; /* Updated when all events are written */\r
+                       ms->size = size_low;\r
+                       prvTraceUpdateCounters();\r
+\r
+                       /* Storing a second record with address (signals "failed" if null) */\r
+                       #if (TRC_CFG_HEAP_SIZE_BELOW_16M)\r
+                               /* If the heap address range is within 16 MB, i.e., the upper 8 bits\r
+                               of addresses are constant, this optimization avoids storing an extra\r
+                               event record by ignoring the upper 8 bit of the address */\r
+                               addr_low = address & 0xFFFF;\r
+                               addr_high = (address >> 16) & 0xFF;\r
+                       #else\r
+                               /* The whole 32 bit address is stored using a second event record\r
+                               for the upper 16 bit */\r
+                               addr_low = (uint16_t)prvTraceGetParam(0xFFFF, address);\r
+                               addr_high = 0;\r
+                       #endif\r
 \r
-                       if (ms != NULL)\r
+                       ma = (MemEventAddr *) prvTraceNextFreeEventBufferSlot();\r
+                       if (ma != NULL)\r
                        {\r
-                               ms->dts = dts1;\r
-                               ms->type = NULL_EVENT; /* Updated when all events are written */\r
-                               ms->size = size_low;\r
+                               ma->addr_low = addr_low;\r
+                               ma->addr_high = addr_high;\r
+                               ma->type = (uint8_t) (ecode  + 1); /* Note this! */\r
+                               ms->type = (uint8_t) ecode;\r
                                prvTraceUpdateCounters();\r
-\r
-                               /* Storing a second record with address (signals "failed" if null) */\r
-                               #if (TRC_CFG_HEAP_SIZE_BELOW_16M)\r
-                                   /* If the heap address range is within 16 MB, i.e., the upper 8 bits\r
-                                       of addresses are constant, this optimization avoids storing an extra\r
-                                       event record by ignoring the upper 8 bit of the address */\r
-                                       addr_low = address & 0xFFFF;          \r
-                                       addr_high = (address >> 16) & 0xFF;\r
-                               #else\r
-                                   /* The whole 32 bit address is stored using a second event record\r
-                                       for the upper 16 bit */\r
-                                       addr_low = (uint16_t)prvTraceGetParam(0xFFFF, address);\r
-                                       addr_high = 0;\r
-                               #endif\r
-\r
-                               ma = (MemEventAddr *) prvTraceNextFreeEventBufferSlot();\r
-                               if (ma != NULL)\r
-                               {\r
-                                       ma->addr_low = addr_low;\r
-                                       ma->addr_high = addr_high;\r
-                                       ma->type = (uint8_t) (ecode  + 1); /* Note this! */\r
-                                       ms->type = (uint8_t) ecode;\r
-                                       prvTraceUpdateCounters();                                       \r
-                                       RecorderDataPtr->heapMemUsage = heapMemUsage;\r
-                               }\r
+                               RecorderDataPtr->heapMemUsage = heapMemUsage;\r
                        }\r
                }\r
        }\r
@@ -1735,7 +1747,7 @@ void prvTraceStoreKernelCall(uint32_t ecode, traceObjectClass objectClass, uint3
        {\r
                /*************************************************************************\r
                * This occurs if an ISR calls a trace function, preempting a previous\r
-               * trace call that is being processed in a different ISR or task. \r
+               * trace call that is being processed in a different ISR or task.\r
                * If this occurs, there is probably a problem in the definition of the\r
                * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
                * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
@@ -1755,23 +1767,15 @@ void prvTraceStoreKernelCall(uint32_t ecode, traceObjectClass objectClass, uint3
        trcCRITICAL_SECTION_BEGIN();\r
        if (RecorderDataPtr->recorderActive)\r
        {\r
-               /* If it is an ISR or NOT an excluded task, this kernel call will be stored in the trace */\r
-               if (nISRactive || !inExcludedTask)\r
+               dts1 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
+               hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);\r
+               kse = (KernelCall*) prvTraceNextFreeEventBufferSlot();\r
+               if (kse != NULL)\r
                {\r
-                       /* Check if the referenced object or the event code is excluded */\r
-                       if (!uiTraceIsObjectExcluded(objectClass, (traceHandle)objectNumber) && !TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(ecode))\r
-                       {\r
-                               dts1 = (uint16_t)prvTraceGetDTS(0xFFFF);\r
-                               hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);\r
-                               kse = (KernelCall*) prvTraceNextFreeEventBufferSlot();\r
-                               if (kse != NULL)\r
-                               {\r
-                                       kse->dts = dts1;\r
-                                       kse->type = (uint8_t)ecode;\r
-                                       kse->objHandle = hnd8;\r
-                                       prvTraceUpdateCounters();\r
-                               }\r
-                       }\r
+                       kse->dts = dts1;\r
+                       kse->type = (uint8_t)ecode;\r
+                       kse->objHandle = hnd8;\r
+                       prvTraceUpdateCounters();\r
                }\r
        }\r
        trcCRITICAL_SECTION_END();\r
@@ -1805,7 +1809,7 @@ void prvTraceStoreKernelCallWithParam(uint32_t evtcode,
        {\r
                /*************************************************************************\r
                * This occurs if an ISR calls a trace function, preempting a previous\r
-               * trace call that is being processed in a different ISR or task. \r
+               * trace call that is being processed in a different ISR or task.\r
                * If this occurs, there is probably a problem in the definition of the\r
                * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
                * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
@@ -1818,24 +1822,19 @@ void prvTraceStoreKernelCallWithParam(uint32_t evtcode,
        }\r
 \r
        trcCRITICAL_SECTION_BEGIN();\r
-       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task && (! inExcludedTask || nISRactive))\r
+       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
-               /* Check if the referenced object or the event code is excluded */\r
-               if (!uiTraceIsObjectExcluded(objectClass, (traceHandle)objectNumber) &&\r
-                       !TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))\r
+               dts2 = (uint8_t)prvTraceGetDTS(0xFF);\r
+               p8 = (uint8_t) prvTraceGetParam(0xFF, param);\r
+               hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);\r
+               kse = (KernelCallWithParamAndHandle*) prvTraceNextFreeEventBufferSlot();\r
+               if (kse != NULL)\r
                {\r
-                       dts2 = (uint8_t)prvTraceGetDTS(0xFF);\r
-                       p8 = (uint8_t) prvTraceGetParam(0xFF, param);\r
-                       hnd8 = prvTraceGet8BitHandle((traceHandle)objectNumber);\r
-                       kse = (KernelCallWithParamAndHandle*) prvTraceNextFreeEventBufferSlot();\r
-                       if (kse != NULL)\r
-                       {\r
-                               kse->dts = dts2;\r
-                               kse->type = (uint8_t)evtcode;\r
-                               kse->objHandle = hnd8;\r
-                               kse->param = p8;\r
-                               prvTraceUpdateCounters();\r
-                       }\r
+                       kse->dts = dts2;\r
+                       kse->type = (uint8_t)evtcode;\r
+                       kse->objHandle = hnd8;\r
+                       kse->param = p8;\r
+                       prvTraceUpdateCounters();\r
                }\r
        }\r
        trcCRITICAL_SECTION_END();\r
@@ -1900,7 +1899,7 @@ void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t para
        {\r
                /*************************************************************************\r
                * This occurs if an ISR calls a trace function, preempting a previous\r
-               * trace call that is being processed in a different ISR or task. \r
+               * trace call that is being processed in a different ISR or task.\r
                * If this occurs, there is probably a problem in the definition of the\r
                * recorder's internal critical sections (TRACE_ENTER_CRITICAL_SECTION and\r
                * TRACE_EXIT_CRITICAL_SECTION). They must disable the RTOS tick interrupt\r
@@ -1913,22 +1912,17 @@ void prvTraceStoreKernelCallWithNumericParamOnly(uint32_t evtcode, uint32_t para
        }\r
 \r
        trcCRITICAL_SECTION_BEGIN();\r
-       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task\r
-               && (! inExcludedTask || nISRactive))\r
+       if (RecorderDataPtr->recorderActive && handle_of_last_logged_task)\r
        {\r
-               /* Check if the event code is excluded */\r
-               if (!TRACE_GET_EVENT_CODE_FLAG_ISEXCLUDED(evtcode))\r
+               dts6 = (uint8_t)prvTraceGetDTS(0xFF);\r
+               restParam = (uint16_t)prvTraceGetParam(0xFFFF, param);\r
+               kse = (KernelCallWithParam16*) prvTraceNextFreeEventBufferSlot();\r
+               if (kse != NULL)\r
                {\r
-                       dts6 = (uint8_t)prvTraceGetDTS(0xFF);\r
-                       restParam = (uint16_t)prvTraceGetParam(0xFFFF, param);\r
-                       kse = (KernelCallWithParam16*) prvTraceNextFreeEventBufferSlot();\r
-                       if (kse != NULL)\r
-                       {\r
-                               kse->dts = dts6;\r
-                               kse->type = (uint8_t)evtcode;\r
-                               kse->param = restParam;\r
-                               prvTraceUpdateCounters();\r
-                       }\r
+                       kse->dts = dts6;\r
+                       kse->type = (uint8_t)evtcode;\r
+                       kse->param = restParam;\r
+                       prvTraceUpdateCounters();\r
                }\r
        }\r
        trcCRITICAL_SECTION_END();\r
@@ -1944,44 +1938,18 @@ void prvTraceStoreTaskswitch(traceHandle task_handle)
 {\r
        uint16_t dts3;\r
        TSEvent* ts;\r
-       int8_t skipEvent;\r
        uint8_t hnd8;\r
 #if (TRC_CFG_INCLUDE_ISR_TRACING == 1)\r
        extern int32_t isPendingContextSwitch;\r
 #endif\r
        trcSR_ALLOC_CRITICAL_SECTION_ON_CORTEX_M_ONLY();\r
 \r
-       skipEvent = 0;\r
-\r
-       TRACE_ASSERT(task_handle <= TRC_CFG_NTASK,\r
+       TRACE_ASSERT(task_handle <= (TRC_CFG_NTASK),\r
                "prvTraceStoreTaskswitch: Invalid value for task_handle", TRC_UNUSED);\r
 \r
-       /* Skip the event if the task has been excluded, using vTraceExcludeTask */\r
-       if (TRACE_GET_TASK_FLAG_ISEXCLUDED(task_handle))\r
-       {\r
-               skipEvent = 1;\r
-               inExcludedTask = 1;\r
-       }\r
-       else\r
-       {\r
-               inExcludedTask = 0;\r
-       }\r
-\r
        trcCRITICAL_SECTION_BEGIN_ON_CORTEX_M_ONLY();\r
 \r
-       /* Skip the event if the same task is scheduled */\r
-       if (task_handle == handle_of_last_logged_task)\r
-       {\r
-               skipEvent = 1;\r
-       }\r
-\r
-       if (!RecorderDataPtr->recorderActive)\r
-       {\r
-               skipEvent = 1;\r
-       }\r
-\r
-       /* If this event should be logged, log it! */\r
-       if (skipEvent == 0)\r
+       if ((task_handle != handle_of_last_logged_task) && (RecorderDataPtr->recorderActive))\r
        {\r
 #if (TRC_CFG_INCLUDE_ISR_TRACING == 1)\r
                isPendingContextSwitch = 0;\r
@@ -2026,8 +1994,7 @@ void prvTraceStoreTaskswitch(traceHandle task_handle)
  * and name (a symbol table handle). The stored name-handle mapping is thus the\r
  * "old" one, valid up until this point.\r
  ******************************************************************************/\r
-#if (TRC_CFG_INCLUDE_OBJECT_DELETE == 1)\r
-void prvTraceStoreObjectNameOnCloseEvent(traceHandle handle,\r
+void prvTraceStoreObjectNameOnCloseEvent(uint8_t evtcode, traceHandle handle,\r
                                                                                traceObjectClass objectclass)\r
 {\r
        ObjCloseNameEvent * ce;\r
@@ -2049,7 +2016,7 @@ void prvTraceStoreObjectNameOnCloseEvent(traceHandle handle,
                ce = (ObjCloseNameEvent*) prvTraceNextFreeEventBufferSlot();\r
                if (ce != NULL)\r
                {\r
-                       ce->type = (uint8_t) (EVENTGROUP_OBJCLOSE_NAME + objectclass);\r
+                       ce->type = (uint8_t) evtcode;\r
                        ce->objHandle = hnd8;\r
                        ce->symbolIndex = idx;\r
                        prvTraceUpdateCounters();\r
@@ -2057,7 +2024,7 @@ void prvTraceStoreObjectNameOnCloseEvent(traceHandle handle,
        }\r
 }\r
 \r
-void prvTraceStoreObjectPropertiesOnCloseEvent(traceHandle handle,\r
+void prvTraceStoreObjectPropertiesOnCloseEvent(uint8_t evtcode, traceHandle handle,\r
                                                                                         traceObjectClass objectclass)\r
 {\r
        ObjClosePropEvent * pe;\r
@@ -2081,12 +2048,11 @@ void prvTraceStoreObjectPropertiesOnCloseEvent(traceHandle handle,
                        {\r
                                pe->arg1 = TRACE_PROPERTY_OBJECT_STATE(objectclass, handle);\r
                        }\r
-                       pe->type = (uint8_t) (EVENTGROUP_OBJCLOSE_PROP + objectclass);\r
+                       pe->type = evtcode;\r
                        prvTraceUpdateCounters();\r
                }\r
        }\r
 }\r
-#endif\r
 \r
 void prvTraceSetPriorityProperty(uint8_t objectclass, traceHandle id, uint8_t value)\r
 {\r
@@ -2142,24 +2108,14 @@ void prvTraceSetTaskInstanceFinished(traceHandle handle)
  * Static data initializations\r
  ******************************************************************************/\r
 \r
-/* Tasks and kernel objects can be explicitly excluded from the trace to reduce\r
-buffer usage. This structure handles the exclude flags for all objects and tasks. \r
-Note that slot 0 is not used, since not a valid handle. */\r
-uint8_t trcExcludedObjects[(TRACE_KERNEL_OBJECT_COUNT + TRACE_NCLASSES) / 8 + 1] = { 0 };\r
-\r
-/* Specific events can also be excluded, i.e., by the event code. This can be\r
-used to exclude kernel calls that don't refer to a kernel object, like a delay.\r
-This structure handle the exclude flags for all event codes */\r
-uint8_t trcExcludedEventCodes[NEventCodes / 8 + 1] = { 0 };\r
-\r
 /* A set of stacks that keeps track of available object handles for each class.\r
-The stacks are empty initially, meaning that allocation of new handles will be \r
+The stacks are empty initially, meaning that allocation of new handles will be\r
 based on a counter (for each object class). Any delete operation will\r
 return the handle to the corresponding stack, for reuse on the next allocate.*/\r
 objectHandleStackType objectHandleStacks = { { 0 }, { 0 }, { 0 }, { 0 }, { 0 } };\r
 \r
-/* Initial TRC_HWTC_COUNT value, for detecting if the time-stamping source is \r
-enabled. If using the OS periodic timer for time-stamping, this might not \r
+/* Initial TRC_HWTC_COUNT value, for detecting if the time-stamping source is\r
+enabled. If using the OS periodic timer for time-stamping, this might not\r
 have been configured on the earliest events during the startup. */\r
 uint32_t init_hwtc_count;\r
 \r
@@ -2178,14 +2134,14 @@ RecorderDataType RecorderData;
 /*******************************************************************************\r
  * RecorderDataPtr\r
  *\r
- * Pointer to the main data structure, when in snapshot mode. \r
+ * Pointer to the main data structure, when in snapshot mode.\r
  ******************************************************************************/\r
 RecorderDataType* RecorderDataPtr = NULL;\r
 \r
 /* This version of the function dynamically allocates the trace data */\r
 void prvTraceInitTraceData()\r
-{      \r
-       \r
+{\r
+\r
        if (RecorderDataPtr == NULL)\r
        {\r
 #if (TRC_CFG_RECORDER_BUFFER_ALLOCATION == TRC_RECORDER_BUFFER_ALLOCATION_STATIC)\r
@@ -2213,16 +2169,16 @@ void prvTraceInitTraceData()
                        return;\r
                }\r
        }\r
-       \r
+\r
        init_hwtc_count = TRC_HWTC_COUNT;\r
-               \r
+\r
        (void)memset(RecorderDataPtr, 0, sizeof(RecorderDataType));\r
-       \r
+\r
        RecorderDataPtr->version = TRACE_KERNEL_VERSION;\r
        RecorderDataPtr->minor_version = TRACE_MINOR_VERSION;\r
        RecorderDataPtr->irq_priority_order = TRC_IRQ_PRIORITY_ORDER;\r
        RecorderDataPtr->filesize = sizeof(RecorderDataType);\r
-       RecorderDataPtr->maxEvents = TRC_CFG_EVENT_BUFFER_SIZE;\r
+       RecorderDataPtr->maxEvents = (TRC_CFG_EVENT_BUFFER_SIZE);\r
        RecorderDataPtr->debugMarker0 = (int32_t) 0xF0F0F0F0;\r
        RecorderDataPtr->isUsing16bitHandles = TRC_CFG_USE_16BIT_OBJECT_HANDLES;\r
        RecorderDataPtr->isrTailchainingThreshold = TRC_CFG_ISR_TAILCHAINING_THRESHOLD;\r
@@ -2231,7 +2187,7 @@ void prvTraceInitTraceData()
        vTraceInitObjectPropertyTable();\r
 \r
        RecorderDataPtr->debugMarker1 = (int32_t)0xF1F1F1F1;\r
-       RecorderDataPtr->SymbolTable.symTableSize = TRC_CFG_SYMBOL_TABLE_SIZE;\r
+       RecorderDataPtr->SymbolTable.symTableSize = (TRC_CFG_SYMBOL_TABLE_SIZE);\r
        RecorderDataPtr->SymbolTable.nextFreeSymbolIndex = 1;\r
 #if (TRC_CFG_INCLUDE_FLOAT_SUPPORT == 1)\r
        RecorderDataPtr->exampleFloatEncoding = 1.0f; /* otherwise already zero */\r
@@ -2255,27 +2211,27 @@ void prvTraceInitTraceData()
 #if TRC_CFG_USE_SEPARATE_USER_EVENT_BUFFER\r
        RecorderDataPtr->userEventBuffer.bufferID = 1;\r
        RecorderDataPtr->userEventBuffer.version = 0;\r
-       RecorderDataPtr->userEventBuffer.numberOfSlots = TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE;\r
-       RecorderDataPtr->userEventBuffer.numberOfChannels = TRC_CFG_UB_CHANNELS + 1;\r
+       RecorderDataPtr->userEventBuffer.numberOfSlots = (TRC_CFG_SEPARATE_USER_EVENT_BUFFER_SIZE);\r
+       RecorderDataPtr->userEventBuffer.numberOfChannels = (TRC_CFG_UB_CHANNELS) + 1;\r
 #endif\r
 \r
        /* Kernel specific initialization of the objectHandleStacks variable */\r
        vTraceInitObjectHandleStack();\r
 \r
-       \r
-       /* Finally, the 12-byte "start markers" are initialized, allowing for \r
-       Tracealyzer to find the trace data in a larger RAM dump. \r
-       \r
+\r
+       /* Finally, the 12-byte "start markers" are initialized, allowing for\r
+       Tracealyzer to find the trace data in a larger RAM dump.\r
+\r
        The start and end markers must be unique, but without proper precautions there\r
        might be a risk of accidental duplicates of the start/end markers, e.g., due to\r
        compiler optimizations.\r
-       \r
-       The below initialization of the start marker is therefore made in reverse order \r
-       and the fields are volatile to ensure this assignment order. This to avoid any \r
+\r
+       The below initialization of the start marker is therefore made in reverse order\r
+       and the fields are volatile to ensure this assignment order. This to avoid any\r
        chance of accidental duplicates of this elsewhere in memory.\r
-       \r
+\r
        Moreover, the fields are set byte-by-byte to avoid endian issues.*/\r
-       \r
+\r
        RecorderDataPtr->startmarker11 = 0xF4;\r
        RecorderDataPtr->startmarker10 = 0xF3;\r
        RecorderDataPtr->startmarker9 = 0xF2;\r
@@ -2286,10 +2242,19 @@ void prvTraceInitTraceData()
        RecorderDataPtr->startmarker4 = 0x71;\r
        RecorderDataPtr->startmarker3 = 0x04;\r
        RecorderDataPtr->startmarker2 = 0x03;\r
-       RecorderDataPtr->startmarker1 = 0x02;   \r
-       RecorderDataPtr->startmarker0 = 0x01; \r
+       RecorderDataPtr->startmarker1 = 0x02;\r
+       RecorderDataPtr->startmarker0 = 0x01;\r
+\r
+       if (traceErrorMessage != NULL)\r
+       {\r
+               // An error was detected before vTraceEnable was called, make sure this is stored in the trace data.\r
+               prvStrncpy(RecorderDataPtr->systemInfo, traceErrorMessage, 80);\r
+               RecorderDataPtr->internalErrorOccured = 1;\r
+               vTraceStop();\r
+       }\r
+\r
+\r
 \r
-       \r
 #ifdef TRC_PORT_SPECIFIC_INIT\r
        TRC_PORT_SPECIFIC_INIT();\r
 #endif\r
@@ -2305,7 +2270,7 @@ void* prvTraceNextFreeEventBufferSlot(void)
                return NULL;\r
        }\r
 \r
-       if (RecorderDataPtr->nextFreeIndex >= TRC_CFG_EVENT_BUFFER_SIZE)\r
+       if (RecorderDataPtr->nextFreeIndex >= (TRC_CFG_EVENT_BUFFER_SIZE))\r
        {\r
                prvTraceError("Attempt to index outside event buffer!");\r
                return NULL;\r
@@ -2315,15 +2280,15 @@ void* prvTraceNextFreeEventBufferSlot(void)
 \r
 uint16_t uiIndexOfObject(traceHandle objecthandle, uint8_t objectclass)\r
 {\r
-       TRACE_ASSERT(objectclass < TRACE_NCLASSES, \r
+       TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
                "uiIndexOfObject: Invalid value for objectclass", 0);\r
-       TRACE_ASSERT(objecthandle > 0 && objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], \r
+       TRACE_ASSERT(objecthandle > 0 && objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
                "uiIndexOfObject: Invalid value for objecthandle", 0);\r
 \r
-       if ((objectclass < TRACE_NCLASSES) && (objecthandle > 0) && \r
+       if ((objectclass < TRACE_NCLASSES) && (objecthandle > 0) &&\r
                (objecthandle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass]))\r
        {\r
-               return (uint16_t)(RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[objectclass] + \r
+               return (uint16_t)(RecorderDataPtr->ObjectPropertyTable.StartIndexOfClass[objectclass] +\r
                        (RecorderDataPtr->ObjectPropertyTable.TotalPropertyBytesPerClass[objectclass] * (objecthandle-1)));\r
        }\r
 \r
@@ -2336,9 +2301,14 @@ traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass)
        traceHandle handle;\r
        static int indexOfHandle;\r
 \r
-       TRACE_ASSERT(objectclass < TRACE_NCLASSES, \r
+       TRACE_ALLOC_CRITICAL_SECTION();\r
+\r
+       TRACE_ASSERT(RecorderDataPtr != NULL, "Recorder not initialized, call vTraceEnable() first!", (traceHandle)0);\r
+\r
+       TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
                "prvTraceGetObjectHandle: Invalid value for objectclass", (traceHandle)0);\r
 \r
+       trcCRITICAL_SECTION_BEGIN();\r
        indexOfHandle = objectHandleStacks.indexOfNextAvailableHandle[objectclass];\r
        if (objectHandleStacks.objectHandles[indexOfHandle] == 0)\r
        {\r
@@ -2372,8 +2342,9 @@ traceHandle prvTraceGetObjectHandle(traceObjectClass objectclass)
                        objectHandleStacks.handleCountWaterMarksOfClass[objectclass] =\r
                                (traceHandle)hndCount;\r
                }\r
-               TRACE_CLEAR_OBJECT_FLAG_ISEXCLUDED(objectclass, handle);\r
        }\r
+       trcCRITICAL_SECTION_END();\r
+\r
        return handle;\r
 }\r
 \r
@@ -2381,9 +2352,9 @@ void prvTraceFreeObjectHandle(traceObjectClass objectclass, traceHandle handle)
 {\r
        int indexOfHandle;\r
 \r
-       TRACE_ASSERT(objectclass < TRACE_NCLASSES, \r
+       TRACE_ASSERT(objectclass < TRACE_NCLASSES,\r
                "prvTraceFreeObjectHandle: Invalid value for objectclass", TRC_UNUSED);\r
-       TRACE_ASSERT(handle > 0 && handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass], \r
+       TRACE_ASSERT(handle > 0 && handle <= RecorderDataPtr->ObjectPropertyTable.NumberOfObjectsPerClass[objectclass],\r
                "prvTraceFreeObjectHandle: Invalid value for handle", TRC_UNUSED);\r
 \r
        /* Check that there is room to push the handle on the stack */\r
@@ -2480,10 +2451,10 @@ traceString prvTraceOpenSymbol(const char* name, traceString userEventChannel)
        uint8_t len;\r
        uint8_t crc;\r
        TRACE_ALLOC_CRITICAL_SECTION();\r
-       \r
+\r
        len = 0;\r
        crc = 0;\r
-       \r
+\r
        TRACE_ASSERT(name != NULL, "prvTraceOpenSymbol: name == NULL", (traceString)0);\r
 \r
        prvTraceGetChecksum(name, &crc, &len);\r
@@ -2537,8 +2508,11 @@ void vTraceSetFrequency(uint32_t frequency)
 void prvTraceError(const char* msg)\r
 {\r
        /* Stop the recorder */\r
-       vTraceStop();\r
-       \r
+       if (RecorderDataPtr != NULL)\r
+       {\r
+               vTraceStop();\r
+       }\r
+\r
        /* If first error only... */\r
        if (traceErrorMessage == NULL)\r
        {\r
@@ -2551,6 +2525,16 @@ void prvTraceError(const char* msg)
        }\r
 }\r
 \r
+void vTraceSetFilterMask(uint16_t filterMask)\r
+{\r
+       CurrentFilterMask = filterMask;\r
+}\r
+\r
+void vTraceSetFilterGroup(uint16_t filterGroup)\r
+{\r
+       CurrentFilterGroup = filterGroup;\r
+}\r
+\r
 /******************************************************************************\r
  * prvCheckDataToBeOverwrittenForMultiEntryEvents\r
  *\r
@@ -2573,7 +2557,7 @@ void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nofEntriesToCheck)
        unsigned int i = 0;\r
        unsigned int e = 0;\r
 \r
-       TRACE_ASSERT(nofEntriesToCheck != 0, \r
+       TRACE_ASSERT(nofEntriesToCheck != 0,\r
                "prvCheckDataToBeOverwrittenForMultiEntryEvents: nofEntriesToCheck == 0", TRC_UNUSED);\r
 \r
        while (i < nofEntriesToCheck)\r
@@ -2613,17 +2597,17 @@ void prvCheckDataToBeOverwrittenForMultiEntryEvents(uint8_t nofEntriesToCheck)
  * Updates the index of the event buffer.\r
  ******************************************************************************/\r
 void prvTraceUpdateCounters(void)\r
-{      \r
+{\r
        if (RecorderDataPtr->recorderActive == 0)\r
        {\r
                return;\r
        }\r
-       \r
+\r
        RecorderDataPtr->numEvents++;\r
 \r
        RecorderDataPtr->nextFreeIndex++;\r
 \r
-       if (RecorderDataPtr->nextFreeIndex >= TRC_CFG_EVENT_BUFFER_SIZE)\r
+       if (RecorderDataPtr->nextFreeIndex >= (TRC_CFG_EVENT_BUFFER_SIZE))\r
        {\r
 #if (TRC_CFG_SNAPSHOT_MODE == TRC_SNAPSHOT_MODE_RING_BUFFER)\r
                RecorderDataPtr->bufferIsFull = 1;\r
@@ -2657,34 +2641,34 @@ uint16_t prvTraceGetDTS(uint16_t param_maxDTS)
 \r
        TRACE_ASSERT(param_maxDTS == 0xFF || param_maxDTS == 0xFFFF, "prvTraceGetDTS: Invalid value for param_maxDTS", 0);\r
 \r
-       \r
+\r
        if (RecorderDataPtr->frequency == 0)\r
-       {       \r
+       {\r
                if (timestampFrequency != 0)\r
                {\r
                        /* If to override default TRC_HWTC_FREQ_HZ value with value set by vTraceSetFrequency */\r
-                       RecorderDataPtr->frequency = timestampFrequency / TRC_HWTC_DIVISOR;\r
-               } \r
-               else if (init_hwtc_count != TRC_HWTC_COUNT)\r
+                       RecorderDataPtr->frequency = timestampFrequency / (TRC_HWTC_DIVISOR);\r
+               }\r
+               else if (init_hwtc_count != (TRC_HWTC_COUNT))\r
                {\r
-                       /* If using default value and timer has been started. \r
+                       /* If using default value and timer has been started.\r
                        Note: If the default frequency value set here would be incorrect, e.g.,\r
-                       if the timer has actually not been configured yet, override this \r
+                       if the timer has actually not been configured yet, override this\r
                        with vTraceSetFrequency.\r
                        */\r
-                       RecorderDataPtr->frequency = TRC_HWTC_FREQ_HZ / TRC_HWTC_DIVISOR;               \r
+                       RecorderDataPtr->frequency = (TRC_HWTC_FREQ_HZ) / (TRC_HWTC_DIVISOR);\r
                }\r
                /* If no override (vTraceSetFrequency) and timer inactive -> no action */\r
        }\r
-       \r
+\r
        /**************************************************************************\r
        * The below statements read the timestamp from the timer port module.\r
        * If necessary, whole seconds are extracted using division while the rest\r
        * comes from the modulo operation.\r
        **************************************************************************/\r
-       \r
-       prvTracePortGetTimeStamp(&timestamp);   \r
-       \r
+\r
+       prvTracePortGetTimeStamp(&timestamp);\r
+\r
        /***************************************************************************\r
        * Since dts is unsigned the result will be correct even if timestamp has\r
        * wrapped around.\r
@@ -2819,7 +2803,7 @@ uint16_t prvTraceCreateSymbolTableEntry(const char* name,
        TRACE_ASSERT(name != NULL, "prvTraceCreateSymbolTableEntry: name == NULL", 0);\r
        TRACE_ASSERT(len != 0, "prvTraceCreateSymbolTableEntry: len == 0", 0);\r
 \r
-       if (RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + len + 4 >= TRC_CFG_SYMBOL_TABLE_SIZE)\r
+       if (RecorderDataPtr->SymbolTable.nextFreeSymbolIndex + len + 4 >= (TRC_CFG_SYMBOL_TABLE_SIZE))\r
        {\r
                prvTraceError("Symbol table full. Increase TRC_CFG_SYMBOL_TABLE_SIZE in trcConfig.h");\r
                ret = 0;\r
@@ -2894,14 +2878,14 @@ void prvTraceGetChecksum(const char *pname, uint8_t* pcrc, uint8_t* plength)
 \r
 #if (TRC_CFG_USE_16BIT_OBJECT_HANDLES == 1)\r
 \r
-static void prvTraceStoreXID(traceHandle handle); \r
+static void prvTraceStoreXID(traceHandle handle);\r
 \r
 /******************************************************************************\r
  * prvTraceStoreXID\r
  *\r
  * Stores an XID (eXtended IDentifier) event.\r
  * This is used if an object/task handle is larger than 255.\r
- * The parameter "handle" is the full (16 bit) handle, assumed to be 256 or \r
+ * The parameter "handle" is the full (16 bit) handle, assumed to be 256 or\r
  * larger. Handles below 256 should not use this function.\r
  *\r
  * NOTE: this function MUST be called from within a critical section.\r
@@ -2919,7 +2903,7 @@ static void prvTraceStoreXID(traceHandle handle)
                xid->type = XID;\r
 \r
                /* This function is (only) used when traceHandle is 16 bit... */\r
-               xid->xps_16 = handle; \r
+               xid->xps_16 = handle;\r
 \r
                prvTraceUpdateCounters();\r
        }\r
@@ -2928,11 +2912,11 @@ static void prvTraceStoreXID(traceHandle handle)
 static uint8_t prvTraceGet8BitHandle(traceHandle handle)\r
 {\r
        if (handle > 255)\r
-       {               \r
+       {\r
                prvTraceStoreXID(handle);\r
-               /* The full handle (16 bit) is stored in the XID event. \r
+               /* The full handle (16 bit) is stored in the XID event.\r
                This code (255) is used instead of zero (which is an error code).*/\r
-               return 255; \r
+               return 255;\r
        }\r
        return (uint8_t)(handle & 0xFF);\r
 }\r
@@ -2955,15 +2939,15 @@ void prvTraceInitCortexM()
                if (TRC_REG_DEMCR == 0)\r
                {\r
                        /* This function is called on Cortex-M3, M4 and M7 devices to initialize\r
-                       the DWT unit, assumed present. The DWT cycle counter is used for timestamping. \r
-                       \r
+                       the DWT unit, assumed present. The DWT cycle counter is used for timestamping.\r
+\r
                        If the below error is produced, the DWT unit does not seem to be available.\r
-                       \r
+\r
                        In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build\r
-                       to use SysTick timestamping instead, or define your own timestamping by \r
+                       to use SysTick timestamping instead, or define your own timestamping by\r
                        setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED\r
                        and make the necessary definitions, as explained in trcHardwarePort.h.*/\r
-                       \r
+\r
                        prvTraceError("DWT unit not available, see code comment.");\r
                        break;\r
                }\r
@@ -2972,12 +2956,12 @@ void prvTraceInitCortexM()
                if (TRC_REG_DWT_CTRL & TRC_DWT_CTRL_NOCYCCNT)\r
                {\r
                        /* This function is called on Cortex-M3, M4 and M7 devices to initialize\r
-                       the DWT unit, assumed present. The DWT cycle counter is used for timestamping. \r
-                       \r
+                       the DWT unit, assumed present. The DWT cycle counter is used for timestamping.\r
+\r
                        If the below error is produced, the cycle counter does not seem to be available.\r
-                       \r
+\r
                        In that case, define the macro TRC_CFG_ARM_CM_USE_SYSTICK in your build\r
-                       to use SysTick timestamping instead, or define your own timestamping by \r
+                       to use SysTick timestamping instead, or define your own timestamping by\r
                        setting TRC_CFG_HARDWARE_PORT to TRC_HARDWARE_PORT_APPLICATION_DEFINED\r
                        and make the necessary definitions, as explained in trcHardwarePort.h.*/\r
 \r
@@ -3033,10 +3017,10 @@ void prvTracePortGetTimeStamp(uint32_t *pTimestamp)
        /* Retrieve TRC_HWTC_COUNT only once since the same value should be used all throughout this function. */\r
 #if (TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_INCR)\r
        /* Get the increasing tick count */\r
-       hwtc_count = TRC_HWTC_COUNT;\r
+       hwtc_count = (TRC_HWTC_COUNT);\r
 #elif (TRC_HWTC_TYPE == TRC_OS_TIMER_DECR || TRC_HWTC_TYPE == TRC_FREE_RUNNING_32BIT_DECR)\r
        /* Convert decreasing tick count into increasing tick count */\r
-       hwtc_count = TRC_HWTC_PERIOD - TRC_HWTC_COUNT;\r
+       hwtc_count = (TRC_HWTC_PERIOD) - (TRC_HWTC_COUNT);\r
 #else\r
        #error "TRC_HWTC_TYPE has unexpected value"\r
 #endif\r
@@ -3081,28 +3065,28 @@ void prvTracePortGetTimeStamp(uint32_t *pTimestamp)
        if (pTimestamp)\r
        {\r
                /* Get timestamp from trace ticks. Scale down the period to avoid unwanted overflows. */\r
-               last_timestamp = traceTickCount * (TRC_HWTC_PERIOD / TRC_HWTC_DIVISOR);\r
+               last_timestamp = traceTickCount * ((TRC_HWTC_PERIOD) / (TRC_HWTC_DIVISOR));\r
                /* Increase timestamp by (hwtc_count + "lost hardware ticks from scaling down period") / TRC_HWTC_DIVISOR. */\r
-               last_timestamp += (hwtc_count + traceTickCount * (TRC_HWTC_PERIOD % TRC_HWTC_DIVISOR)) / TRC_HWTC_DIVISOR;\r
+               last_timestamp += (hwtc_count + traceTickCount * ((TRC_HWTC_PERIOD) % (TRC_HWTC_DIVISOR))) / (TRC_HWTC_DIVISOR);\r
        }\r
        /* Store the previous value */\r
        last_traceTickCount = traceTickCount;\r
-       \r
+\r
 #else /*(TRC_HWTC_TYPE == TRC_OS_TIMER_INCR || TRC_HWTC_TYPE == TRC_OS_TIMER_DECR)*/\r
-       \r
+\r
        /* Timestamping is based on a free running timer */\r
        /* This part handles free running clocks that can be scaled down to avoid too large DTS values.\r
        Without this, the scaled timestamp will incorrectly wrap at (2^32 / TRC_HWTC_DIVISOR) ticks.\r
        The scaled timestamp returned from this function is supposed to go from 0 -> 2^32, which in real time would represent (0 -> 2^32 * TRC_HWTC_DIVISOR) ticks. */\r
-       \r
+\r
        /* First we see how long time has passed since the last timestamp call, and we also add the ticks that was lost when we scaled down the last time. */\r
        diff = (hwtc_count - last_hwtc_count) + last_hwtc_rest;\r
-       \r
+\r
        /* Scale down the diff */\r
-       diff_scaled = diff / TRC_HWTC_DIVISOR;\r
-       \r
+       diff_scaled = diff / (TRC_HWTC_DIVISOR);\r
+\r
        /* Find out how many ticks were lost when scaling down, so we can add them the next time */\r
-       last_hwtc_rest = diff % TRC_HWTC_DIVISOR;\r
+       last_hwtc_rest = diff % (TRC_HWTC_DIVISOR);\r
 \r
        /* We increase the scaled timestamp by the scaled amount */\r
        last_timestamp += diff_scaled;\r