MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / clock_gettime

Function clock_gettime

components/libc/compilers/common/ctime.c:628–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626RTM_EXPORT(clock_getres);
627
628int clock_gettime(clockid_t clockid, struct timespec *tp)
629{
630 if (tp == RT_NULL)
631 {
632 rt_set_errno(EFAULT);
633 return -1;
634 }
635
636 switch (clockid)
637 {
638 case CLOCK_REALTIME: // use RTC
639 case CLOCK_REALTIME_COARSE:
640#ifdef RT_USING_RTC
641 return _control_rtc(RT_DEVICE_CTRL_RTC_GET_TIMESPEC, tp);
642#endif /* RT_USING_RTC */
643
644 case CLOCK_MONOTONIC: // use boottime
645 case CLOCK_MONOTONIC_COARSE:
646 case CLOCK_MONOTONIC_RAW:
647 case CLOCK_BOOTTIME:
648 return rt_ktime_boottime_get_ns(tp);
649
650 case CLOCK_PROCESS_CPUTIME_ID:
651 case CLOCK_THREAD_CPUTIME_ID:
652 return rt_ktime_boottime_get_ns(tp); // TODO not yet implemented
653
654 default:
655 tp->tv_sec = 0;
656 tp->tv_nsec = 0;
657 rt_set_errno(EINVAL);
658 return -1;
659 }
660}
661RTM_EXPORT(clock_gettime);
662
663int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp)

Callers 5

sys_clock_gettimeFunction · 0.85
get_current_timeFunction · 0.85
nowMethod · 0.85
rt_timespec_to_tickFunction · 0.85
gettimeFunction · 0.85

Calls 3

rt_set_errnoFunction · 0.85
_control_rtcFunction · 0.85
rt_ktime_boottime_get_nsFunction · 0.85

Tested by 1

gettimeFunction · 0.68