aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-07-16 17:13:32 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-07-16 17:13:32 +0000
commit3739568d8918ee183f432c55ff753867737f1f07 (patch)
tree90589431669fb5c20a477c4e3a73afd14d34a417 /os
parent43a7a0820fa1873dba8e77d7890b614fb5dd93dd (diff)
downloadChibiOS-3739568d8918ee183f432c55ff753867737f1f07.tar.gz
ChibiOS-3739568d8918ee183f432c55ff753867737f1f07.tar.bz2
ChibiOS-3739568d8918ee183f432c55ff753867737f1f07.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5978 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/kernel/include/chvt.h70
-rw-r--r--os/kernel/src/chvt.c11
2 files changed, 59 insertions, 22 deletions
diff --git a/os/kernel/include/chvt.h b/os/kernel/include/chvt.h
index 8aa8c5840..0afc7f385 100644
--- a/os/kernel/include/chvt.h
+++ b/os/kernel/include/chvt.h
@@ -56,6 +56,18 @@ typedef void (*vtfunc_t)(void *);
typedef struct VirtualTimer VirtualTimer;
/**
+ * @brief Virtual timers list header.
+ * @note The timers list is implemented as a double link bidirectional list
+ * in order to make the unlink time constant, the reset of a virtual
+ * timer is often used in the code.
+ */
+typedef struct {
+ VirtualTimer *vt_next; /**< @brief Next timer in the list. */
+ VirtualTimer *vt_prev; /**< @brief Last timer in the list. */
+ volatile systime_t vt_time; /**< @brief Current system time. */
+} VTList;
+
+/**
* @extends VTList
*
* @brief Virtual Timer descriptor structure.
@@ -70,18 +82,6 @@ struct VirtualTimer {
parameter. */
};
-/**
- * @brief Virtual timers list header.
- * @note The timers list is implemented as a double link bidirectional list
- * in order to make the unlink time constant, the reset of a virtual
- * timer is often used in the code.
- */
-typedef struct {
- VirtualTimer *vt_next; /**< @brief Next timer in the list. */
- VirtualTimer *vt_prev; /**< @brief Last timer in the list. */
- volatile systime_t vt_time; /**< @brief Current system time. */
-} VTList;
-
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
@@ -143,7 +143,7 @@ extern VTList vtlist;
extern "C" {
#endif
void _vt_init(void);
- bool_t chVTIsSystemTimeWithin(systime_t start, systime_t end);
+ bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end);
void chVTSetAbsoluteI(VirtualTimer *vtp, systime_t time,
vtfunc_t vtfunc, void *par);
void chVTResetI(VirtualTimer *vtp);
@@ -185,13 +185,49 @@ static inline systime_t chVTGetSystemTimeI(void) {
static inline systime_t chVTGetSystemTime(void) {
systime_t systime;
- chSysLock()
+ chSysLock();
systime = chVTGetSystemTimeI();
chSysUnlock();
return systime;
}
/**
+ * @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
+ * whole time range is specified.
+ *
+ * @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.
+ *
+ * @api
+ */
+static inline bool chVTIsSystemTimeWithinI(systime_t start, systime_t end) {
+
+ return chVTIsTimeWithin(chVTGetSystemTimeI(), start, end);
+}
+
+/**
+ * @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
+ * whole time range is specified.
+ *
+ * @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.
+ *
+ * @api
+ */
+static inline bool chVTIsSystemTimeWithin(systime_t start, systime_t end) {
+
+ return chVTIsTimeWithin(chVTGetSystemTime(), start, end);
+}
+
+/**
* @brief Initializes a @p VirtualTimer object.
* @note Initializing a timer object is not strictly required because
* the function @p chVTSetI() initializes the object too. This
@@ -208,7 +244,7 @@ static inline void chVTObjectInit(VirtualTimer *vtp) {
}
/**
- * @brief Returns @p TRUE if the specified timer is armed.
+ * @brief Returns @p true if the specified timer is armed.
* @pre The timer must have been initialized using @p chVTObjectInit()
* or @p chVTSetI() (or @p chVTSetI() variants).
*
@@ -217,11 +253,11 @@ static inline void chVTObjectInit(VirtualTimer *vtp) {
*
* @iclass
*/
-static inline bool_t chVTIsArmedI(VirtualTimer *vtp) {
+static inline bool chVTIsArmedI(VirtualTimer *vtp) {
chDbgCheckClassI();
- return (bool_t)(vtp->vt_func != NULL);
+ return (bool)(vtp->vt_func != NULL);
}
/**
diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c
index d27f3170c..8864bce0c 100644
--- a/os/kernel/src/chvt.c
+++ b/os/kernel/src/chvt.c
@@ -75,17 +75,18 @@ void _vt_init(void) {
* 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.
+ * @retval true current time within the specified time window.
+ * @retval false current time not within the specified time window.
*
- * @api
+ * @special
*/
-bool_t chVTIsSystemTimeWithin(systime_t start, systime_t end) {
+bool chVTIsTimeWithin(systime_t time, systime_t start, systime_t end) {
- systime_t time = chVTGetSystemTime();
return end > start ? (time >= start) && (time < end) :
(time >= start) || (time < end);
}