summaryrefslogtreecommitdiff
path: root/bsp/env/freedom-e300-arty
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2017-01-03 17:45:33 -0800
committerAndrew Waterman <andrew@sifive.com>2017-01-03 18:53:28 -0800
commit005b1a8f84ff743710ebd693b70d208da583098d (patch)
treeebc479178e5e74a3a7ecd5e6e99e3b1cc2a06fb9 /bsp/env/freedom-e300-arty
parent2398dfda399f445cf114e29b61d9331fddb09b4e (diff)
Regularize timing code
Provide get_timer_value() and get_timer_freq() and use them. On Arty, they use mcycle and the known-fixed core frequency, whereas on HiFive1 they use mtime and the known-fixed mtime frequency.
Diffstat (limited to 'bsp/env/freedom-e300-arty')
-rw-r--r--bsp/env/freedom-e300-arty/init.c21
-rw-r--r--bsp/env/freedom-e300-arty/platform.h3
2 files changed, 23 insertions, 1 deletions
diff --git a/bsp/env/freedom-e300-arty/init.c b/bsp/env/freedom-e300-arty/init.c
index 0a80cbb..35b1104 100644
--- a/bsp/env/freedom-e300-arty/init.c
+++ b/bsp/env/freedom-e300-arty/init.c
@@ -9,11 +9,30 @@
extern int main(int argc, char** argv);
extern void trap_entry();
-uint32_t get_cpu_freq()
+static unsigned long get_cpu_freq()
{
return 65000000;
}
+unsigned long get_timer_freq()
+{
+ return get_cpu_freq();
+}
+
+uint64_t get_timer_value()
+{
+#if __riscv_xlen == 32
+ while (1) {
+ uint32_t hi = read_csr(mcycleh);
+ uint32_t lo = read_csr(mcycle);
+ if (hi == read_csr(mcycleh))
+ return ((uint64_t)hi << 32) | lo;
+ }
+#else
+ return read_csr(mcycle);
+#endif
+}
+
static void uart_init(size_t baud_rate)
{
GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_UART0_MASK;
diff --git a/bsp/env/freedom-e300-arty/platform.h b/bsp/env/freedom-e300-arty/platform.h
index 1f62956..d5d6dda 100644
--- a/bsp/env/freedom-e300-arty/platform.h
+++ b/bsp/env/freedom-e300-arty/platform.h
@@ -119,4 +119,7 @@
#define HAS_BOARD_BUTTONS
#include "hifive1.h"
+unsigned long get_timer_freq(void);
+uint64_t get_timer_value(void);
+
#endif /* _SIFIVE_PLATFORM_H */