| 593 | #if defined(RT_USING_POSIX_CLOCK) && defined(RT_USING_KTIME) |
| 594 | |
| 595 | int clock_getres(clockid_t clockid, struct timespec *res) |
| 596 | { |
| 597 | if (res == RT_NULL) |
| 598 | { |
| 599 | rt_set_errno(EFAULT); |
| 600 | return -1; |
| 601 | } |
| 602 | |
| 603 | switch (clockid) |
| 604 | { |
| 605 | case CLOCK_REALTIME: // use RTC |
| 606 | case CLOCK_REALTIME_COARSE: |
| 607 | #ifdef RT_USING_RTC |
| 608 | return _control_rtc(RT_DEVICE_CTRL_RTC_GET_TIMERES, res); |
| 609 | #endif /* RT_USING_RTC */ |
| 610 | |
| 611 | case CLOCK_MONOTONIC: // use cputimer |
| 612 | case CLOCK_MONOTONIC_COARSE: |
| 613 | case CLOCK_MONOTONIC_RAW: |
| 614 | case CLOCK_BOOTTIME: |
| 615 | case CLOCK_PROCESS_CPUTIME_ID: |
| 616 | case CLOCK_THREAD_CPUTIME_ID: |
| 617 | res->tv_sec = 0; |
| 618 | res->tv_nsec = (rt_ktime_cputimer_getres() / RT_KTIME_RESMUL); |
| 619 | return 0; |
| 620 | |
| 621 | default: |
| 622 | rt_set_errno(EINVAL); |
| 623 | return -1; |
| 624 | } |
| 625 | } |
| 626 | RTM_EXPORT(clock_getres); |
| 627 | |
| 628 | int clock_gettime(clockid_t clockid, struct timespec *tp) |
no test coverage detected