aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/rt/include/chthreads.h1
-rw-r--r--os/rt/src/chthreads.c30
2 files changed, 31 insertions, 0 deletions
diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h
index 28bd41a06..e7eeeee1d 100644
--- a/os/rt/include/chthreads.h
+++ b/os/rt/include/chthreads.h
@@ -252,6 +252,7 @@ extern "C" {
void chThdTerminate(thread_t *tp);
void chThdSleep(systime_t time);
void chThdSleepUntil(systime_t time);
+ systime_t chThdSleepUntilWindowed(systime_t prev, systime_t next);
void chThdYield(void);
void chThdExit(msg_t msg);
void chThdExitS(msg_t msg);
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.