diff options
Diffstat (limited to 'os/rt/src/chthreads.c')
-rw-r--r-- | os/rt/src/chthreads.c | 30 |
1 files changed, 30 insertions, 0 deletions
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
*
@@ -325,6 +330,31 @@ void chThdSleepUntil(systime_t time) { }
/**
+ * @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
* equal priority, if any.
|