summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2018-05-04 16:45:24 +0800
committerGitHub <[email protected]>2018-05-04 16:45:24 +0800
commitfeb275db4252222ce827728162d0ba5245af8b5c (patch)
tree9632d7851cfd851f2a77e5bc05952e82f07ae05a /components
parent76c30dc399eee178081493ef532f16fcd09f7b74 (diff)
parentf09e39ebd31dff5522e51b385f171084b199a012 (diff)
Merge pull request #1397 from armink/fix_newlib
[Components/libc] Add gettimeofday to newlib libc.
Diffstat (limited to 'components')
-rw-r--r--components/libc/compilers/armlibc/time.c32
-rw-r--r--components/libc/compilers/dlib/time.c32
-rw-r--r--components/libc/compilers/newlib/time.c25
3 files changed, 59 insertions, 30 deletions
diff --git a/components/libc/compilers/armlibc/time.c b/components/libc/compilers/armlibc/time.c
index 701b57fb27..7b9c2f185b 100644
--- a/components/libc/compilers/armlibc/time.c
+++ b/components/libc/compilers/armlibc/time.c
@@ -1,23 +1,25 @@
#include <sys/time.h>
+#include <rtthread.h>
+#if defined(RT_USING_DEVICE) && defined(RT_USING_RTC)
int gettimeofday(struct timeval *tp, void *ignore)
{
- time_t time;
- rt_device_t device;
+ 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;
- }
+ 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 time;
+ }
- return 0;
+ return 0;
}
-
+#endif
diff --git a/components/libc/compilers/dlib/time.c b/components/libc/compilers/dlib/time.c
index 701b57fb27..7b9c2f185b 100644
--- a/components/libc/compilers/dlib/time.c
+++ b/components/libc/compilers/dlib/time.c
@@ -1,23 +1,25 @@
#include <sys/time.h>
+#include <rtthread.h>
+#if defined(RT_USING_DEVICE) && defined(RT_USING_RTC)
int gettimeofday(struct timeval *tp, void *ignore)
{
- time_t time;
- rt_device_t device;
+ 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;
- }
+ 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 time;
+ }
- return 0;
+ return 0;
}
-
+#endif
diff --git a/components/libc/compilers/newlib/time.c b/components/libc/compilers/newlib/time.c
new file mode 100644
index 0000000000..7b9c2f185b
--- /dev/null
+++ b/components/libc/compilers/newlib/time.c
@@ -0,0 +1,25 @@
+#include <sys/time.h>
+#include <rtthread.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