修复不使能 RT_USING_DEVICE 时编译报错 (#9145)
* 修复不使能 RT_USING_DEVICE 时编译报错 * 删除 ctime.c 中多余引用
This commit is contained in:
parent
c9d4fd5059
commit
47cd52d162
|
@ -30,8 +30,10 @@
|
||||||
|
|
||||||
#include "sys/time.h"
|
#include "sys/time.h"
|
||||||
#include <rthw.h>
|
#include <rthw.h>
|
||||||
|
#include <rtthread.h>
|
||||||
|
#ifdef RT_USING_RTC
|
||||||
#include <rtdevice.h>
|
#include <rtdevice.h>
|
||||||
#include <drivers/rtc.h>
|
#endif /* RT_USING_RTC */
|
||||||
#include <sys/errno.h>
|
#include <sys/errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef RT_USING_SMART
|
#ifdef RT_USING_SMART
|
||||||
|
@ -87,9 +89,9 @@ static void num2str(char *c, int i)
|
||||||
c[1] = i % 10 + '0';
|
c[1] = i % 10 + '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RT_USING_RTC
|
||||||
static rt_err_t _control_rtc(int cmd, void *arg)
|
static rt_err_t _control_rtc(int cmd, void *arg)
|
||||||
{
|
{
|
||||||
#ifdef RT_USING_RTC
|
|
||||||
static rt_device_t device = RT_NULL;
|
static rt_device_t device = RT_NULL;
|
||||||
rt_err_t rst = -RT_ERROR;
|
rt_err_t rst = -RT_ERROR;
|
||||||
|
|
||||||
|
@ -113,11 +115,8 @@ static rt_err_t _control_rtc(int cmd, void *arg)
|
||||||
return -RT_ENOSYS;
|
return -RT_ENOSYS;
|
||||||
}
|
}
|
||||||
return rst;
|
return rst;
|
||||||
#else
|
|
||||||
LOG_W(_WARNING_NO_RTC);
|
|
||||||
return -RT_ENOSYS;
|
|
||||||
#endif /* RT_USING_RTC */
|
|
||||||
}
|
}
|
||||||
|
#endif /* RT_USING_RTC */
|
||||||
|
|
||||||
/* lightweight timezone and daylight saving time */
|
/* lightweight timezone and daylight saving time */
|
||||||
#ifdef RT_LIBC_USING_LIGHT_TZ_DST
|
#ifdef RT_LIBC_USING_LIGHT_TZ_DST
|
||||||
|
@ -340,6 +339,7 @@ RTM_EXPORT(strftime); /* inherent in the toolchain */
|
||||||
*/
|
*/
|
||||||
rt_weak time_t time(time_t *t)
|
rt_weak time_t time(time_t *t)
|
||||||
{
|
{
|
||||||
|
#ifdef RT_USING_RTC
|
||||||
time_t _t;
|
time_t _t;
|
||||||
|
|
||||||
if (_control_rtc(RT_DEVICE_CTRL_RTC_GET_TIME, &_t) != RT_EOK)
|
if (_control_rtc(RT_DEVICE_CTRL_RTC_GET_TIME, &_t) != RT_EOK)
|
||||||
|
@ -352,6 +352,10 @@ rt_weak time_t time(time_t *t)
|
||||||
*t = _t;
|
*t = _t;
|
||||||
|
|
||||||
return _t;
|
return _t;
|
||||||
|
#else
|
||||||
|
rt_set_errno(EFAULT);
|
||||||
|
return (time_t)-1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
RTM_EXPORT(time);
|
RTM_EXPORT(time);
|
||||||
|
|
||||||
|
@ -363,10 +367,12 @@ RTM_EXPORT(clock);
|
||||||
|
|
||||||
int stime(const time_t *t)
|
int stime(const time_t *t)
|
||||||
{
|
{
|
||||||
|
#ifdef RT_USING_RTC
|
||||||
if ((t != RT_NULL) && (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIME, (void *)t) == RT_EOK))
|
if ((t != RT_NULL) && (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIME, (void *)t) == RT_EOK))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* RT_USING_RTC */
|
||||||
|
|
||||||
rt_set_errno(EFAULT);
|
rt_set_errno(EFAULT);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -475,6 +481,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
#endif /* RT_LIBC_USING_LIGHT_TZ_DST */
|
#endif /* RT_LIBC_USING_LIGHT_TZ_DST */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RT_USING_RTC
|
||||||
if (tv != RT_NULL)
|
if (tv != RT_NULL)
|
||||||
{
|
{
|
||||||
tv->tv_sec = 0;
|
tv->tv_sec = 0;
|
||||||
|
@ -492,6 +499,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* RT_USING_RTC */
|
||||||
|
|
||||||
rt_set_errno(EINVAL);
|
rt_set_errno(EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -505,6 +513,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
|
||||||
* The tz_dsttime field has never been used under Linux.
|
* The tz_dsttime field has never been used under Linux.
|
||||||
* Thus, the following is purely of historic interest.
|
* Thus, the following is purely of historic interest.
|
||||||
*/
|
*/
|
||||||
|
#ifdef RT_USING_RTC
|
||||||
if (tv != RT_NULL && (long)tv->tv_usec >= 0 && (long)tv->tv_sec >= 0)
|
if (tv != RT_NULL && (long)tv->tv_usec >= 0 && (long)tv->tv_sec >= 0)
|
||||||
{
|
{
|
||||||
if (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIMEVAL, (void *)tv) == RT_EOK)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* RT_USING_RTC */
|
||||||
|
|
||||||
rt_set_errno(EINVAL);
|
rt_set_errno(EINVAL);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue