30
30
31
31
#include "sys/time.h"
32
32
#include <rthw.h>
33
+ #include <rtthread.h>
34
+ #ifdef RT_USING_RTC
33
35
#include <rtdevice.h>
34
- #include <drivers/rtc.h>
36
+ #endif /* RT_USING_RTC */
35
37
#include <sys/errno.h>
36
38
#include <unistd.h>
37
39
#ifdef RT_USING_SMART
@@ -87,9 +89,9 @@ static void num2str(char *c, int i)
87
89
c [1 ] = i % 10 + '0' ;
88
90
}
89
91
92
+ #ifdef RT_USING_RTC
90
93
static rt_err_t _control_rtc (int cmd , void * arg )
91
94
{
92
- #ifdef RT_USING_RTC
93
95
static rt_device_t device = RT_NULL ;
94
96
rt_err_t rst = - RT_ERROR ;
95
97
@@ -113,11 +115,8 @@ static rt_err_t _control_rtc(int cmd, void *arg)
113
115
return - RT_ENOSYS ;
114
116
}
115
117
return rst ;
116
- #else
117
- LOG_W (_WARNING_NO_RTC );
118
- return - RT_ENOSYS ;
119
- #endif /* RT_USING_RTC */
120
118
}
119
+ #endif /* RT_USING_RTC */
121
120
122
121
/* lightweight timezone and daylight saving time */
123
122
#ifdef RT_LIBC_USING_LIGHT_TZ_DST
@@ -340,6 +339,7 @@ RTM_EXPORT(strftime); /* inherent in the toolchain */
340
339
*/
341
340
rt_weak time_t time (time_t * t )
342
341
{
342
+ #ifdef RT_USING_RTC
343
343
time_t _t ;
344
344
345
345
if (_control_rtc (RT_DEVICE_CTRL_RTC_GET_TIME , & _t ) != RT_EOK )
@@ -352,6 +352,10 @@ rt_weak time_t time(time_t *t)
352
352
* t = _t ;
353
353
354
354
return _t ;
355
+ #else
356
+ rt_set_errno (EFAULT );
357
+ return (time_t )- 1 ;
358
+ #endif
355
359
}
356
360
RTM_EXPORT (time );
357
361
@@ -363,10 +367,12 @@ RTM_EXPORT(clock);
363
367
364
368
int stime (const time_t * t )
365
369
{
370
+ #ifdef RT_USING_RTC
366
371
if ((t != RT_NULL ) && (_control_rtc (RT_DEVICE_CTRL_RTC_SET_TIME , (void * )t ) == RT_EOK ))
367
372
{
368
373
return 0 ;
369
374
}
375
+ #endif /* RT_USING_RTC */
370
376
371
377
rt_set_errno (EFAULT );
372
378
return -1 ;
@@ -475,6 +481,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
475
481
#endif /* RT_LIBC_USING_LIGHT_TZ_DST */
476
482
}
477
483
484
+ #ifdef RT_USING_RTC
478
485
if (tv != RT_NULL )
479
486
{
480
487
tv -> tv_sec = 0 ;
@@ -492,6 +499,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
492
499
}
493
500
}
494
501
}
502
+ #endif /* RT_USING_RTC */
495
503
496
504
rt_set_errno (EINVAL );
497
505
return -1 ;
@@ -505,6 +513,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
505
513
* The tz_dsttime field has never been used under Linux.
506
514
* Thus, the following is purely of historic interest.
507
515
*/
516
+ #ifdef RT_USING_RTC
508
517
if (tv != RT_NULL && (long )tv -> tv_usec >= 0 && (long )tv -> tv_sec >= 0 )
509
518
{
510
519
if (_control_rtc (RT_DEVICE_CTRL_RTC_SET_TIMEVAL , (void * )tv ) == RT_EOK )
@@ -519,6 +528,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
519
528
}
520
529
}
521
530
}
531
+ #endif /* RT_USING_RTC */
522
532
523
533
rt_set_errno (EINVAL );
524
534
return -1 ;
0 commit comments