git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5978 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
43a7a0820f
commit
3739568d89
|
@ -55,6 +55,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
|
||||
*
|
||||
|
@ -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,12 +185,48 @@ 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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue