]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcHardwarePort.c
Update to latest FreeRTOS+Trace recorder code.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-Trace / trcHardwarePort.c
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcHardwarePort.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcHardwarePort.c
new file mode 100644 (file)
index 0000000..754b321
--- /dev/null
@@ -0,0 +1,119 @@
+/******************************************************************************* \r
+ * Tracealyzer v2.4.1 Recorder Library\r
+ * Percepio AB, www.percepio.com\r
+ *\r
+ * trcHardwarePort.c\r
+ *\r
+ * Contains together with trcHardwarePort.h all hardware portability issues of \r
+ * the trace recorder library.\r
+ *\r
+ * Terms of Use\r
+ * This software is copyright Percepio AB. The recorder library is free for\r
+ * use together with Percepio products. You may distribute the recorder library\r
+ * in its original form, including modifications in trcPort.c and trcPort.h\r
+ * given that these modification are clearly marked as your own modifications\r
+ * and documented in the initial comment section of these source files. \r
+ * This software is the intellectual property of Percepio AB and may not be \r
+ * sold or in other ways commercially redistributed without explicit written \r
+ * permission by Percepio AB.\r
+ *\r
+ * Disclaimer \r
+ * The trace tool and recorder library is being delivered to you AS IS and \r
+ * Percepio AB makes no warranty as to its use or performance. Percepio AB does \r
+ * not and cannot warrant the performance or results you may obtain by using the \r
+ * software or documentation. Percepio AB make no warranties, express or \r
+ * implied, as to noninfringement of third party rights, merchantability, or \r
+ * fitness for any particular purpose. In no event will Percepio AB, its \r
+ * technology partners, or distributors be liable to you for any consequential, \r
+ * incidental or special damages, including any lost profits or lost savings, \r
+ * even if a representative of Percepio AB has been advised of the possibility \r
+ * of such damages, or for any claim by any third party. Some jurisdictions do \r
+ * not allow the exclusion or limitation of incidental, consequential or special \r
+ * damages, or the exclusion of implied warranties or limitations on how long an \r
+ * implied warranty may last, so the above limitations may not apply to you.\r
+ *\r
+ * Copyright Percepio AB, 2013.\r
+ * www.percepio.com\r
+ ******************************************************************************/\r
+\r
+#include "trcHardwarePort.h"\r
+\r
+#if (USE_TRACEALYZER_RECORDER == 1)\r
+\r
+#include <stdint.h>\r
+\r
+\r
+/*******************************************************************************\r
+ * uiTraceTickCount\r
+ *\r
+ * This variable is should be updated by the Kernel tick interrupt. This does \r
+ * not need to be modified when developing a new timer port. It is preferred to \r
+ * keep any timer port changes in the HWTC macro definitions, which typically \r
+ * give sufficient flexibility.\r
+ ******************************************************************************/\r
+uint32_t uiTraceTickCount = 0;\r
+\r
+/******************************************************************************\r
+ * vTracePortGetTimeStamp\r
+ *\r
+ * Returns the current time based on the HWTC macros which provide a hardware\r
+ * isolation layer towards the hardware timer/counter.\r
+ *\r
+ * The HWTC macros and vTracePortGetTimeStamp is the main porting issue\r
+ * or the trace recorder library. Typically you should not need to change\r
+ * the code of vTracePortGetTimeStamp if using the HWTC macros.\r
+ *\r
+ ******************************************************************************/\r
+void vTracePortGetTimeStamp(uint32_t *pTimestamp)\r
+{\r
+       static uint32_t last_traceTickCount = 0;\r
+    static uint32_t last_hwtc_count = 0;\r
+    uint32_t traceTickCount = 0;\r
+    uint32_t hwtc_count = 0;\r
+    \r
+    /* Retrieve HWTC_COUNT only once since the same value should be used all throughout this function. */\r
+#if (HWTC_COUNT_DIRECTION == DIRECTION_INCREMENTING)\r
+    hwtc_count = HWTC_COUNT;\r
+#elif (HWTC_COUNT_DIRECTION == DIRECTION_DECREMENTING)\r
+    hwtc_count = HWTC_PERIOD - HWTC_COUNT;\r
+#else\r
+    Junk text to cause compiler error - HWTC_COUNT_DIRECTION is not set correctly!\r
+    Should be DIRECTION_INCREMENTING or DIRECTION_DECREMENTING\r
+#endif\r
+    \r
+    if (last_traceTickCount - uiTraceTickCount - 1 < 0x80000000)\r
+    {\r
+        /* This means last_traceTickCount is higher than uiTraceTickCount,\r
+        so we have previously compensated for a missed tick.\r
+        Therefore we use the last stored value because that is more accurate. */\r
+        traceTickCount = last_traceTickCount;\r
+    }\r
+    else\r
+    {\r
+        /* Business as usual */\r
+        traceTickCount = uiTraceTickCount;\r
+    }\r
+\r
+    /* Check for overflow. May occur if the update of uiTraceTickCount has been \r
+    delayed due to disabled interrupts. */\r
+    if (traceTickCount == last_traceTickCount && hwtc_count < last_hwtc_count)\r
+    {\r
+        /* A trace tick has occurred but not been executed by the kernel, so we compensate manually. */\r
+        traceTickCount++;\r
+    }\r
+    \r
+    /* Check if the return address is OK, then we perform the calculation. */\r
+    if (pTimestamp)\r
+    {\r
+        /* Get timestamp from trace ticks. Scale down the period to avoid unwanted overflows. */\r
+        *pTimestamp = traceTickCount * (HWTC_PERIOD / HWTC_DIVISOR);\r
+        /* Increase timestamp by (hwtc_count + "lost hardware ticks from scaling down period") / HWTC_DIVISOR. */\r
+        *pTimestamp += (hwtc_count + traceTickCount * (HWTC_PERIOD % HWTC_DIVISOR)) / HWTC_DIVISOR;\r
+    }\r
+    \r
+    /* Store the previous values. */\r
+    last_traceTickCount = traceTickCount;\r
+    last_hwtc_count = hwtc_count;\r
+}\r
+\r
+#endif
\ No newline at end of file