summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c
diff options
context:
space:
mode:
Diffstat (limited to 'FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c')
-rw-r--r--FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c b/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c
new file mode 100644
index 000000000..409b2ce2f
--- /dev/null
+++ b/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1-RevB_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c
@@ -0,0 +1,21 @@
+#include <errno.h>
+#include <metal/timer.h>
+#include <sys/time.h>
+
+int
+_gettimeofday(struct timeval *tp, void *tzp)
+{
+ int rv;
+ unsigned long long mcc, timebase;
+ rv = metal_timer_get_cyclecount(0, &mcc);
+ if (rv != 0) {
+ return -1;
+ }
+ rv = metal_timer_get_timebase_frequency(0, &timebase);
+ if (rv != 0) {
+ return -1;
+ }
+ tp->tv_sec = mcc / timebase;
+ tp->tv_usec = mcc % timebase * 1000000 / timebase;
+ return 0;
+}