time.c 342 B

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