1 /* Copyright 2019 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
4 #include <metal/time.h>
5 #include <metal/timer.h>
7 int metal_gettimeofday(struct timeval *tp, void *tzp)
10 unsigned long long mcc, timebase;
11 if ((rv = metal_timer_get_cyclecount(0, &mcc))) {
14 if ((rv = metal_timer_get_timebase_frequency(0, &timebase))) {
17 tp->tv_sec = mcc / timebase;
18 tp->tv_usec = mcc % timebase * 1000000 / timebase;
22 time_t metal_time (void)
26 if (metal_gettimeofday(&now, NULL) < 0)
27 now.tv_sec = (time_t) -1;