2018-01-16 17:10:54 +08:00
|
|
|
#include <sys/time.h>
|
2018-05-03 15:45:36 +08:00
|
|
|
#include <rtdevice.h>
|
2018-01-16 17:10:54 +08:00
|
|
|
|
2018-05-03 15:45:36 +08:00
|
|
|
#if defined(RT_USING_DEVICE) && defined(RT_USING_RTC)
|
2018-01-16 17:10:54 +08:00
|
|
|
int gettimeofday(struct timeval *tp, void *ignore)
|
|
|
|
{
|
2018-05-03 15:45:36 +08:00
|
|
|
time_t time;
|
|
|
|
rt_device_t device;
|
2018-01-16 17:10:54 +08:00
|
|
|
|
2018-05-03 15:45:36 +08:00
|
|
|
device = rt_device_find("rtc");
|
|
|
|
if (device != RT_NULL)
|
|
|
|
{
|
|
|
|
rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
|
|
|
|
if (tp != RT_NULL)
|
|
|
|
{
|
|
|
|
tp->tv_sec = time;
|
|
|
|
tp->tv_usec = 0;
|
|
|
|
}
|
2018-01-16 17:10:54 +08:00
|
|
|
|
2018-05-03 15:45:36 +08:00
|
|
|
return time;
|
|
|
|
}
|
2018-01-16 17:10:54 +08:00
|
|
|
|
2018-05-03 15:45:36 +08:00
|
|
|
return 0;
|
2018-01-16 17:10:54 +08:00
|
|
|
}
|
2018-05-03 15:45:36 +08:00
|
|
|
#endif
|