| * Copyright (c) 2018 Friedt Professional Engineering Services, Inc |
| * SPDX-License-Identifier: Apache-2.0 |
| /* required for struct timespec */ |
| * @brief Suspend execution for nanosecond intervals. |
| int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) |
| const bool update_rmtp = rmtp != NULL; |
| if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 |
| || rqtp->tv_nsec >= NSEC_PER_SEC) { |
| if (rqtp->tv_sec == 0 && rqtp->tv_nsec == 0) { |
| if (unlikely(rqtp->tv_sec >= ULLONG_MAX / NSEC_PER_SEC)) { |
| /* If a user passes this in, we could be here a while, but |
| * at least it's technically correct-ish |
| ns = rqtp->tv_nsec + NSEC_PER_SEC |
| + k_sleep(K_SECONDS(rqtp->tv_sec - 1)) * NSEC_PER_MSEC; |
| ns = rqtp->tv_sec * NSEC_PER_SEC + rqtp->tv_nsec; |
| /* TODO: improve upper bound when hr timers are available */ |
| us = ceiling_fraction(ns, NSEC_PER_USEC); |