/** * @brief Suspends the invoking thread until the system time arrives to the * specified value. * @note The function has no concept of "past", all specifiable times * are in the future, this means that if you call this function * exceeding your calculated intervals then the function will * return in a far future time, not immediately. * @see chThdSleepUntilWindowed() * * @param[in] time absolute system time * * @api */ void chThdSleepUntil(systime_t time) { chSysLock(); if ((time -= chVTGetSystemTimeX()) > 0) chThdSleepS(time); chSysUnlock(); }
/** * @brief Suspends the invoking thread until the system time arrives to the * specified value. * * @param[in] time absolute system time * * @api */ void chThdSleepUntil(systime_t time) { chSysLock(); if ((time -= chTimeNowS()) > 0) chThdSleepS(time); chSysUnlock(); }
/** * @brief Suspends the invoking thread for the specified time. * * @param[in] time the delay in system ticks, the special values are * handled as follow: * - @a TIME_INFINITE the thread enters an infinite sleep * state. * - @a TIME_IMMEDIATE this value is not allowed. * . * * @api */ void chThdSleep(systime_t time) { chDbgCheck(time != TIME_IMMEDIATE, "chThdSleep"); chSysLock(); chThdSleepS(time); chSysUnlock(); }
/** * @brief Suspends the invoking thread until the system time arrives to the * specified value. * @note The function has no concept of "past", all specifiable times * are in the future, this means that if you call this function * exceeding your calculated intervals then the function will * return in a far future time, not immediately. * @see chThdSleepUntilWindowed() * * @param[in] time absolute system time * * @api */ void chThdSleepUntil(systime_t time) { chSysLock(); time -= chVTGetSystemTimeX(); if (time > (systime_t)0) { chThdSleepS(time); } chSysUnlock(); }
/** * @brief Suspends the invoking thread until the system time arrives to the * specified value. * @note The system time is assumed to be between @p prev and @p time * else the call is assumed to have been called outside the * allowed time interval, in this case no sleep is performed. * @see chThdSleepUntilWindowed() * * @param[in] prev absolute system time of the previous deadline * @param[in] next absolute system time of the next deadline * @return the @p next parameter * * @api */ systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next) { systime_t time; chSysLock(); time = chVTGetSystemTimeX(); if (chVTIsTimeWithinX(time, prev, next)) chThdSleepS(next - time); chSysUnlock(); return next; }
/** * * @brief Suspends execution of current thread for a regular interval. * * @param[in] previous_ms pointer to system time of last execution, * must have been initialized with PIOS_Thread_Systime() on first invocation * @param[in] increment_ms time of regular interval in milliseconds * */ void PIOS_Thread_Sleep_Until(uint32_t *previous_ms, uint32_t increment_ms) { systime_t future = MS2ST(*previous_ms) + MS2ST(increment_ms); chSysLock(); systime_t now = chTimeNow(); int mustDelay = now < MS2ST(*previous_ms) ? (now < future && future < MS2ST(*previous_ms)) : (now < future || future < MS2ST(*previous_ms)); if (mustDelay) chThdSleepS(future - now); chSysUnlock(); *previous_ms = ST2MS(future); }
/** Sleep thread until a period has elapsed. * Keeps track of the previous wake-up time to ensure that a periodic task is * woken up on time even if there is jitter in the time the task takes to * execute (e.g. due to preemption by higher priority tasks). * * References: * -# https://www.rfc1149.net/blog/2013/04/03/sleeping-just-the-right-amount-of-time/ * * \param previous Time that the thread was previously woken up * \param period Period in system time ticks */ void sleep_until(systime_t *previous, systime_t period) { systime_t future = *previous + period; chSysLock(); systime_t now = chVTGetSystemTimeX(); int must_delay = now < *previous ? (now < future && future < *previous) : (now < future || future < *previous); if (must_delay) { chThdSleepS(future - now); } chSysUnlock(); *previous = future; }
/** * @brief Configures and activates the CAN peripheral. * @note Activating the CAN bus can be a slow operation this this function * is not atomic, it waits internally for the initialization to * complete. * * @param[in] canp pointer to the @p CANDriver object * @param[in] config pointer to the @p CANConfig object. Depending on * the implementation the value can be @p NULL. * * @api */ void canStart(CANDriver *canp, const CANConfig *config) { chDbgCheck(canp != NULL, "canStart"); chSysLock(); chDbgAssert((canp->state == CAN_STOP) || (canp->state == CAN_STARTING) || (canp->state == CAN_READY), "canStart(), #1", "invalid state"); while (canp->state == CAN_STARTING) chThdSleepS(1); if (canp->state == CAN_STOP) { canp->config = config; can_lld_start(canp); canp->state = CAN_READY; } chSysUnlock(); }
/** * @brief Suspends the invoking thread for the specified time. * * @param[in] time the delay in system ticks, the special values are * handled as follow: * - @a TIME_INFINITE the thread enters an infinite sleep * state. * - @a TIME_IMMEDIATE this value is not allowed. * . * * @api */ void chThdSleep(systime_t time) { chSysLock(); chThdSleepS(time); chSysUnlock(); }