time.c 493 B

12345678910111213141516171819202122232425
  1. #include <sys/time.h>
  2. #include <rtdevice.h>
  3. #if defined(RT_USING_DEVICE) && defined(RT_USING_RTC)
  4. int gettimeofday(struct timeval *tp, void *ignore)
  5. {
  6. time_t time;
  7. rt_device_t device;
  8. device = rt_device_find("rtc");
  9. if (device != RT_NULL)
  10. {
  11. rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
  12. if (tp != RT_NULL)
  13. {
  14. tp->tv_sec = time;
  15. tp->tv_usec = 0;
  16. }
  17. return time;
  18. }
  19. return 0;
  20. }
  21. #endif