From 80284bf64ae30d7c28adc1ff550c7423db53d418 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 10 Aug 2014 16:45:47 +0000 Subject: Added systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next) API. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7165 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/src/chthreads.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'os/rt/src') diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index f7694f593..d7e9bc13d 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -311,6 +311,11 @@ void chThdSleep(systime_t time) { /** * @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 * @@ -324,6 +329,31 @@ void chThdSleepUntil(systime_t 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 Yields the time slot. * @details Yields the CPU control to the next thread in the ready list with -- cgit v1.2.3