[bsp/simulator] Add RTC device RT_DEVICE_CTRL_RTC_GET_TIME_US command implement.
This commit is contained in:
parent
b027ad8b2e
commit
2a66024bdc
|
@ -48,7 +48,7 @@ static void soft_rtc_alarm_update(struct rt_rtc_wkalarm *palarm)
|
||||||
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;
|
||||||
struct tm *newtime;
|
struct tm newtime;
|
||||||
|
|
||||||
RT_ASSERT(dev != RT_NULL);
|
RT_ASSERT(dev != RT_NULL);
|
||||||
|
|
||||||
|
@ -57,10 +57,16 @@ 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;
|
t = (__time32_t *)args;
|
||||||
_time32(t);
|
SYSTEMTIME sys_time;
|
||||||
/* TODO The libc time module not support timezone now. So get the time from locatime. */
|
|
||||||
newtime = _localtime32(t);
|
GetSystemTime(&sys_time);
|
||||||
*t = _mkgmtime32(newtime);
|
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;
|
||||||
|
*t = timegm(&newtime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
case RT_DEVICE_CTRL_RTC_SET_TIME:
|
||||||
|
@ -79,6 +85,16 @@ 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:
|
||||||
|
return -RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
|
|
Loading…
Reference in New Issue