From 47cd52d162248eed0b8a5d6a1d04c870874ddae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E9=BE=99=E4=BC=9F?= <2544047213@qq.com> Date: Sun, 4 Aug 2024 09:56:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8D=E4=BD=BF=E8=83=BD?= =?UTF-8?q?=20RT=5FUSING=5FDEVICE=20=E6=97=B6=E7=BC=96=E8=AF=91=E6=8A=A5?= =?UTF-8?q?=E9=94=99=20(#9145)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复不使能 RT_USING_DEVICE 时编译报错 * 删除 ctime.c 中多余引用 --- components/libc/compilers/common/ctime.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c index ef006c4a1e..b523c827f9 100644 --- a/components/libc/compilers/common/ctime.c +++ b/components/libc/compilers/common/ctime.c @@ -30,8 +30,10 @@ #include "sys/time.h" #include +#include +#ifdef RT_USING_RTC #include -#include +#endif /* RT_USING_RTC */ #include #include #ifdef RT_USING_SMART @@ -87,9 +89,9 @@ static void num2str(char *c, int i) c[1] = i % 10 + '0'; } +#ifdef RT_USING_RTC static rt_err_t _control_rtc(int cmd, void *arg) { -#ifdef RT_USING_RTC static rt_device_t device = RT_NULL; rt_err_t rst = -RT_ERROR; @@ -113,11 +115,8 @@ static rt_err_t _control_rtc(int cmd, void *arg) return -RT_ENOSYS; } 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 */ #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) { +#ifdef RT_USING_RTC time_t _t; 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; return _t; +#else + rt_set_errno(EFAULT); + return (time_t)-1; +#endif } RTM_EXPORT(time); @@ -363,10 +367,12 @@ RTM_EXPORT(clock); 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)) { return 0; } +#endif /* RT_USING_RTC */ rt_set_errno(EFAULT); return -1; @@ -475,6 +481,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) #endif /* RT_LIBC_USING_LIGHT_TZ_DST */ } +#ifdef RT_USING_RTC if (tv != RT_NULL) { tv->tv_sec = 0; @@ -492,6 +499,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) } } } +#endif /* RT_USING_RTC */ rt_set_errno(EINVAL); 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. * 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 (_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); return -1;