[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)
|
||||
{
|
||||
__time32_t *t;
|
||||
struct tm *newtime;
|
||||
struct tm newtime;
|
||||
|
||||
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:
|
||||
{
|
||||
t = (__time32_t *)args;
|
||||
_time32(t);
|
||||
/* TODO The libc time module not support timezone now. So get the time from locatime. */
|
||||
newtime = _localtime32(t);
|
||||
*t = _mkgmtime32(newtime);
|
||||
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;
|
||||
*t = timegm(&newtime);
|
||||
break;
|
||||
}
|
||||
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);
|
||||
break;
|
||||
#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;
|
||||
|
|
Loading…
Reference in New Issue