]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c
Update RISCC-V-RV32-SiFive_HiFive1_FreedomStudio project to latest tools and metal...
[freertos] / FreeRTOS / Demo / RISC-V_RV32_SiFive_HiFive1_FreedomStudio / freedom-metal / gloss / sys_gettimeofday.c
1 #include <errno.h>
2 #include <metal/timer.h>
3 #include <sys/time.h>
4
5 int
6 _gettimeofday(struct timeval *tp, void *tzp)
7 {
8     int rv;
9     unsigned long long mcc, timebase;
10     rv = metal_timer_get_cyclecount(0, &mcc);
11     if (rv != 0) {
12         return -1;
13     }
14     rv = metal_timer_get_timebase_frequency(0, &timebase);
15     if (rv != 0) {
16         return -1;
17     }
18     tp->tv_sec = mcc / timebase;
19     tp->tv_usec = mcc % timebase * 1000000 / timebase;
20     return 0;
21 }