aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-11-04 13:35:10 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-11-04 13:35:10 +0000
commit202661e81e18dad821a1855caf39add96440f6cf (patch)
tree2dab0a7863bdc1d504b730db2c936a6d57872763 /os
parent3d2ebf13f5b01f802fae0afec8651cde4c121be8 (diff)
downloadChibiOS-202661e81e18dad821a1855caf39add96440f6cf.tar.gz
ChibiOS-202661e81e18dad821a1855caf39add96440f6cf.tar.bz2
ChibiOS-202661e81e18dad821a1855caf39add96440f6cf.zip
Improved time range functions. Reduced size for NIL when tickless mode is used.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6416 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/nil/include/nil.h18
-rw-r--r--os/nil/src/nil.c20
-rw-r--r--os/rt/include/chvt.h35
-rw-r--r--os/rt/src/chvt.c20
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.