| 626 | RTM_EXPORT(clock_getres); |
| 627 | |
| 628 | int 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 | } |
| 661 | RTM_EXPORT(clock_gettime); |
| 662 | |
| 663 | int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, struct timespec *rmtp) |