Skip to content

修复不使能 RT_USING_DEVICE 时编译报错 #9145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions components/libc/compilers/common/ctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

#include "sys/time.h"
#include <rthw.h>
#include <rtthread.h>
#ifdef RT_USING_RTC
#include <rtdevice.h>
#include <drivers/rtc.h>
#endif /* RT_USING_RTC */
#include <sys/errno.h>
#include <unistd.h>
#ifdef RT_USING_SMART
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -492,6 +499,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
}
}
}
#endif /* RT_USING_RTC */

rt_set_errno(EINVAL);
return -1;
Expand All @@ -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)
Expand All @@ -519,6 +528,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
}
}
}
#endif /* RT_USING_RTC */

rt_set_errno(EINVAL);
return -1;
Expand Down
Loading