From 5dd0539293ef38a56a49abec8003bc70b6db7dfb Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 3 May 2018 15:39:43 +0800 Subject: [PATCH] [Components/libc] Add gettimeofday to newlib libc. --- components/libc/compilers/newlib/time.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 components/libc/compilers/newlib/time.c diff --git a/components/libc/compilers/newlib/time.c b/components/libc/compilers/newlib/time.c new file mode 100644 index 000000000..acd69f57c --- /dev/null +++ b/components/libc/compilers/newlib/time.c @@ -0,0 +1,25 @@ +#include +#include + +#if defined(RT_USING_DEVICE) && defined(RT_USING_RTC) +int gettimeofday(struct timeval *tp, void *ignore) +{ + time_t time; + rt_device_t device; + + device = rt_device_find("rtc"); + if (device != RT_NULL) + { + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); + if (tp != RT_NULL) + { + tp->tv_sec = time; + tp->tv_usec = 0; + } + + return time; + } + + return 0; +} +#endif