Browse Source

[Components/libc] Add gettimeofday to newlib libc.

armink 7 years ago
parent
commit
5dd0539293
1 changed files with 25 additions and 0 deletions
  1. 25 0
      components/libc/compilers/newlib/time.c

+ 25 - 0
components/libc/compilers/newlib/time.c

@@ -0,0 +1,25 @@
+#include <sys/time.h>
+#include <rtdevice.h>
+
+#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