summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/or1k/generic_or1k/timer/timer.c
diff options
context:
space:
mode:
authorHesham ALMatary <heshamelmatary@gmail.com>2015-04-18 17:25:51 +0100
committerGedare Bloom <gedare@rtems.org>2015-04-19 06:26:36 -0400
commit3d597c04ed42d61fcd22a42f1d68c4b1621334fe (patch)
treeff0951ca63f0ff5c8cd432fa63aafffd677ca078 /c/src/lib/libbsp/or1k/generic_or1k/timer/timer.c
parentsp13: Document message buffer usage and adjust configuration (diff)
downloadrtems-3d597c04ed42d61fcd22a42f1d68c4b1621334fe.tar.bz2
Rename or1ksim BSP to generic_or1k
or1ksim BSP was initially named after or1ksim simulator, and it was intented to only run there. But now it can also run on QEMU, jor1k and real FPGA boards without modifications. It makes more sense to give it a new generic name like generic_or1k.
Diffstat (limited to 'c/src/lib/libbsp/or1k/generic_or1k/timer/timer.c')
-rw-r--r--c/src/lib/libbsp/or1k/generic_or1k/timer/timer.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/or1k/generic_or1k/timer/timer.c b/c/src/lib/libbsp/or1k/generic_or1k/timer/timer.c
new file mode 100644
index 0000000000..872f1af7be
--- /dev/null
+++ b/c/src/lib/libbsp/or1k/generic_or1k/timer/timer.c
@@ -0,0 +1,64 @@
+/**
+ * @file
+ *
+ * @ingroup generic_or1k
+ *
+ * @brief Benchmark timer support.
+ */
+
+/*
+ * Copyright (c) 2014-2015 by Hesham ALMatary
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE
+ */
+
+#include <rtems.h>
+#include <rtems/btimer.h>
+#include <bsp/generic_or1k.h>
+#include <rtems/score/or1k-utility.h>
+
+#define OR1K_NANOSECONDS_PER_CLK_CYCLE 10
+
+static bool benchmark_timer_find_average_overhead = false;
+static uint64_t benchmark_timer_base;
+
+void benchmark_timer_initialize(void)
+{
+ benchmark_timer_base = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
+}
+
+#define AVG_OVERHEAD 0
+#define LEAST_VALID 1
+
+benchmark_timer_t benchmark_timer_read( void )
+{
+ uint64_t clicks;
+ uint64_t total;
+ uint64_t delta;
+ /*
+ * Read the timer and see how many clicks (clock cycles)
+ * has passed since timer initialization.
+ */
+ clicks = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);
+
+ delta = clicks - benchmark_timer_base;
+
+ /* total in nanoseconds */
+ total = OR1K_NANOSECONDS_PER_CLK_CYCLE * (delta);
+
+ if ( benchmark_timer_find_average_overhead == true )
+ return total; /* in nanoseconds microsecond units */
+ else {
+ if ( total < LEAST_VALID )
+ return 0; /* below timer resolution */
+
+ return (total - AVG_OVERHEAD);
+ }
+}
+
+void benchmark_timer_disable_subtracting_average_overhead(bool find_flag)
+{
+ benchmark_timer_find_average_overhead = find_flag;
+}