summaryrefslogtreecommitdiff
path: root/components/libc
diff options
context:
space:
mode:
authorarmink <[email protected]>2018-05-03 15:39:43 +0800
committerarmink <[email protected]>2018-05-03 15:43:14 +0800
commit5dd0539293ef38a56a49abec8003bc70b6db7dfb (patch)
tree40dfe7d16aa8843568b4746e2e9ab5c80b2d2e03 /components/libc
parent3a0a3f7c695d7b471ff1763f5eefa02032dda1e9 (diff)
[Components/libc] Add gettimeofday to newlib libc.
Diffstat (limited to 'components/libc')
-rw-r--r--components/libc/compilers/newlib/time.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/components/libc/compilers/newlib/time.c b/components/libc/compilers/newlib/time.c
new file mode 100644
index 0000000000..acd69f57c8
--- /dev/null
+++ b/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