提交 3fafe6e8 编写于 作者: armink_ztl's avatar armink_ztl

[bsp][simulator] Add RT_DEVICE_CTRL_RTC_GET_TIMEVAL support for RTC driver

上级 75e0ec12
...@@ -45,6 +45,23 @@ static void soft_rtc_alarm_update(struct rt_rtc_wkalarm *palarm) ...@@ -45,6 +45,23 @@ static void soft_rtc_alarm_update(struct rt_rtc_wkalarm *palarm)
#endif #endif
static void get_rtc_timeval(struct timeval *tv)
{
struct tm newtime = { 0 };
SYSTEMTIME sys_time;
GetSystemTime(&sys_time);
newtime.tm_year = sys_time.wYear - 1900;
newtime.tm_mon = sys_time.wMonth - 1;
newtime.tm_mday = sys_time.wDay;
newtime.tm_hour = sys_time.wHour;
newtime.tm_min = sys_time.wMinute;
newtime.tm_sec = sys_time.wSecond;
tv->tv_sec = timegm(&newtime);
tv->tv_usec = sys_time.wMilliseconds * 1000UL;
}
static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args) static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
{ {
__time32_t *t; __time32_t *t;
...@@ -56,17 +73,14 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -56,17 +73,14 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
{ {
case RT_DEVICE_CTRL_RTC_GET_TIME: case RT_DEVICE_CTRL_RTC_GET_TIME:
{ {
t = (__time32_t *)args; struct timeval tv;
SYSTEMTIME sys_time; get_rtc_timeval(&tv);
*(rt_uint32_t *) args = tv.tv_sec;
GetSystemTime(&sys_time); break;
newtime.tm_year = sys_time.wYear - 1900; }
newtime.tm_mon = sys_time.wMonth - 1; case RT_DEVICE_CTRL_RTC_GET_TIMEVAL:
newtime.tm_mday = sys_time.wDay; {
newtime.tm_hour = sys_time.wHour; get_rtc_timeval((struct timeval *) args);
newtime.tm_min = sys_time.wMinute;
newtime.tm_sec = sys_time.wSecond;
*t = timegm(&newtime);
break; break;
} }
case RT_DEVICE_CTRL_RTC_SET_TIME: case RT_DEVICE_CTRL_RTC_SET_TIME:
...@@ -85,14 +99,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args) ...@@ -85,14 +99,6 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
soft_rtc_alarm_update(&wkalarm); soft_rtc_alarm_update(&wkalarm);
break; break;
#endif #endif
case RT_DEVICE_CTRL_RTC_GET_TIME_US:
{
long *tv_usec = (long *)args;
SYSTEMTIME sys_time;
GetSystemTime(&sys_time);
*tv_usec = sys_time.wMilliseconds * 1000UL;
break;
}
default: default:
return -RT_ERROR; return -RT_ERROR;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册