]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_FreedomStudio/freedom-metal/src/time.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 / src / time.c
1 /* Copyright 2019 SiFive, Inc */
2 /* SPDX-License-Identifier: Apache-2.0 */
3
4 #include <metal/time.h>
5 #include <metal/timer.h>
6
7 int metal_gettimeofday(struct timeval *tp, void *tzp)
8 {
9     int rv;
10     unsigned long long mcc, timebase;
11     if ((rv = metal_timer_get_cyclecount(0, &mcc))) {
12         return -1;
13     }
14     if ((rv = metal_timer_get_timebase_frequency(0, &timebase))) {
15         return -1;
16     }
17     tp->tv_sec = mcc / timebase;
18     tp->tv_usec = mcc % timebase * 1000000 / timebase;
19     return 0;
20 }
21
22 time_t metal_time (void)
23 {
24     struct timeval now;
25
26     if (metal_gettimeofday(&now, NULL) < 0)
27       now.tv_sec = (time_t) -1;
28
29   return now.tv_sec;
30 }