summaryrefslogtreecommitdiff
path: root/components/libc/compilers/common
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-02-08 10:33:12 +0800
committerMeco Man <[email protected]>2021-02-08 10:33:12 +0800
commitd0c2631b1215af38eb07b24cd25a751640e9c07c (patch)
tree90225f23976d608644e9400c3ccbb54bbb3ddbae /components/libc/compilers/common
parent6c7dd305329602611aba93772357aa5a394a3a6e (diff)
revert time()
Diffstat (limited to 'components/libc/compilers/common')
-rw-r--r--components/libc/compilers/common/time.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index 155a04f92f..a67c0497af 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -8,7 +8,7 @@
* 2019-08-21 zhangjun copy from minilibc
* 2020-09-07 Meco Man combine gcc armcc iccarm
* 2021-02-05 Meco Man add timegm()
- * 2021-02-07 Meco Man fixed gettimeofday() time()
+ * 2021-02-07 Meco Man fixed gettimeofday()
* 2021-02-08 Meco Man add settimeofday() stime()
*/
@@ -177,15 +177,24 @@ time_t time(time_t *t)
#endif
{
time_t time_now = 0;
+
#ifdef RT_USING_RTC
- rt_device_t device;
+ static rt_device_t device = RT_NULL;
+
+ /* optimization: find rtc device only first. */
+ if (device == RT_NULL)
+ {
+ device = rt_device_find("rtc");
+ }
/* read timestamp from RTC device. */
- device = rt_device_find("rtc");
- if (rt_device_open(device, 0) == RT_EOK)
+ if (device != RT_NULL)
{
- rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
- rt_device_close(device);
+ if (rt_device_open(device, 0) == RT_EOK)
+ {
+ rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
+ rt_device_close(device);
+ }
}
#endif /* RT_USING_RTC */