diff options
-rw-r--r-- | os/nil/include/nil.h | 18 | ||||
-rw-r--r-- | os/nil/src/nil.c | 20 | ||||
-rw-r--r-- | os/rt/include/chvt.h | 35 | ||||
-rw-r--r-- | os/rt/src/chvt.c | 20 |
4 files changed, 51 insertions, 42 deletions
diff --git a/os/nil/include/nil.h b/os/nil/include/nil.h index 480baa0e6..b6ef8436d 100644 --- a/os/nil/include/nil.h +++ b/os/nil/include/nil.h @@ -720,6 +720,23 @@ typedef struct { #endif
/**
+ * @brief Checks if the specified time is within the specified time window.
+ * @note When start==end then the function returns always true because the
+ * whole time range is specified.
+ * @note This function can be called from any context.
+ *
+ * @param[in] time the time to be verified
+ * @param[in] start the start of the time window (inclusive)
+ * @param[in] end the end of the time window (non inclusive)
+ * @retval true current time within the specified time window.
+ * @retval false current time not within the specified time window.
+ *
+ * @xclass
+ */
+#define chVTIsTimeWithinX(time, start, end) \
+ ((bool)((time) - (start) < (end) - (start)))
+
+/**
* @brief Condition assertion.
* @details If the condition check fails then the kernel panics with a
* message and halts.
@@ -765,7 +782,6 @@ extern "C" { void chThdResumeI(thread_reference_t *trp, msg_t msg);
void chThdSleep(systime_t time);
void chThdSleepUntil(systime_t time);
- bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end);
msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time);
msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time);
void chSemSignal(semaphore_t *sp);
diff --git a/os/nil/src/nil.c b/os/nil/src/nil.c index 5d9a660f7..9141129cb 100644 --- a/os/nil/src/nil.c +++ b/os/nil/src/nil.c @@ -467,26 +467,6 @@ void chThdSleepUntil(systime_t time) { }
/**
- * @brief Checks if the specified time is within the specified time window.
- * @note When start==end then the function returns always true because the
- * whole time range is specified.
- * @note This function can be called from any context.
- *
- * @param[in] time the time to be verified
- * @param[in] start the start of the time window (inclusive)
- * @param[in] end the end of the time window (non inclusive)
- * @retval true current time within the specified time window.
- * @retval false current time not within the specified time window.
- *
- * @xclass
- */
-bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end) {
-
- return end > start ? (time >= start) && (time < end) :
- (time >= start) || (time < end);
-}
-
-/**
* @brief Performs a wait operation on a semaphore with timeout specification.
*
* @param[in] sp pointer to a @p semaphore_t structure
diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index fa859e8fe..66eda87f3 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -152,7 +152,6 @@ struct virtual_timer { extern "C" {
#endif
void _vt_init(void);
- bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end);
void chVTDoSetI(virtual_timer_t *vtp, systime_t delay,
vtfunc_t vtfunc, void *par);
void chVTDoResetI(virtual_timer_t *vtp);
@@ -222,6 +221,40 @@ static inline systime_t chVTGetSystemTime(void) { }
/**
+ * @brief Returns the elapsed time since the specified start time.
+ *
+ * @param[in] start start time
+ * @return The elapsed time.
+ *
+ * @xclass
+ */
+static inline systime_t chVTTimeElapsedSinceX(systime_t start) {
+
+ return chVTGetSystemTimeX() - start;
+}
+
+/**
+ * @brief Checks if the specified time is within the specified time window.
+ * @note When start==end then the function returns always true because the
+ * whole time range is specified.
+ * @note This function can be called from any context.
+ *
+ * @param[in] time the time to be verified
+ * @param[in] start the start of the time window (inclusive)
+ * @param[in] end the end of the time window (non inclusive)
+ * @retval true current time within the specified time window.
+ * @retval false current time not within the specified time window.
+ *
+ * @xclass
+ */
+static inline bool chVTIsTimeWithinX(systime_t time,
+ systime_t start,
+ systime_t end) {
+
+ return (bool)(time - start < end - start);
+}
+
+/**
* @brief Checks if the current system time is within the specified time
* window.
* @note When start==end then the function returns always true because the
diff --git a/os/rt/src/chvt.c b/os/rt/src/chvt.c index 6139abd53..e87c2d12c 100644 --- a/os/rt/src/chvt.c +++ b/os/rt/src/chvt.c @@ -71,26 +71,6 @@ void _vt_init(void) { }
/**
- * @brief Checks if the specified time is within the specified time window.
- * @note When start==end then the function returns always true because the
- * whole time range is specified.
- * @note This function can be called from any context.
- *
- * @param[in] time the time to be verified
- * @param[in] start the start of the time window (inclusive)
- * @param[in] end the end of the time window (non inclusive)
- * @retval true current time within the specified time window.
- * @retval false current time not within the specified time window.
- *
- * @xclass
- */
-bool chVTIsTimeWithinX(systime_t time, systime_t start, systime_t end) {
-
- return end > start ? (time >= start) && (time < end) :
- (time >= start) || (time < end);
-}
-
-/**
* @brief Enables a virtual timer.
* @details The timer is enabled and programmed to trigger after the delay
* specified as parameter.
|