summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/gloss/sys_gettimeofday.c
blob: 3f867e4eb73119ee7f2ecca9907199afc3682b8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#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;
    if (rv = metal_timer_get_cyclecount(0, &mcc)) {
        return -1;
    }
    if (rv = metal_timer_get_timebase_frequency(0, &timebase)) {
        return -1;
    }
    tp->tv_sec = mcc / timebase;
    tp->tv_usec = mcc % timebase * 1000000 / timebase;
    return 0;
}