Improved time range check in the kernel.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@6401 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2013-10-30 13:14:36 +00:00
parent c96e390f3a
commit 6e9303ee9c
3 changed files with 28 additions and 21 deletions

View File

@ -207,6 +207,32 @@ typedef struct {
* @api * @api
*/ */
#define chTimeNow() (vtlist.vt_systime) #define chTimeNow() (vtlist.vt_systime)
/**
* @brief Returns the elapsed time since the specified start time.
*
* @param[in] start start time
* @return The elapsed time.
*
* @api
*/
#define chTimeElapsedSince(start) (chTimeNow() - (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
* 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
*/
#define chTimeIsWithin(start, end) \
(chTimeElapsedSince(start) < ((end) - (start)))
/** @} */ /** @} */
extern VTList vtlist; extern VTList vtlist;
@ -220,7 +246,6 @@ extern "C" {
void _vt_init(void); void _vt_init(void);
void chVTSetI(VirtualTimer *vtp, systime_t time, vtfunc_t vtfunc, void *par); void chVTSetI(VirtualTimer *vtp, systime_t time, vtfunc_t vtfunc, void *par);
void chVTResetI(VirtualTimer *vtp); void chVTResetI(VirtualTimer *vtp);
bool_t chTimeIsWithin(systime_t start, systime_t end);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -111,24 +111,4 @@ void chVTResetI(VirtualTimer *vtp) {
vtp->vt_func = (vtfunc_t)NULL; vtp->vt_func = (vtfunc_t)NULL;
} }
/**
* @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
*/
bool_t chTimeIsWithin(systime_t start, systime_t end) {
systime_t time = chTimeNow();
return end > start ? (time >= start) && (time < end) :
(time >= start) || (time < end);
}
/** @} */ /** @} */

View File

@ -116,6 +116,8 @@
(backported to 2.6.0). (backported to 2.6.0).
- FIX: Fixed MS2ST() and US2ST() macros error (bug #415)(backported to 2.6.0, - FIX: Fixed MS2ST() and US2ST() macros error (bug #415)(backported to 2.6.0,
2.4.4, 2.2.10, NilRTOS). 2.4.4, 2.2.10, NilRTOS).
- NEW: Improved time range check in the kernel, new API chTimeElapsedSince()
introduced. The API chTimeIsWithin() is now a macro.
- NEW: Added a new function shellExit() to the shell. It allows to exit the - NEW: Added a new function shellExit() to the shell. It allows to exit the
shell from any command handler. shell from any command handler.
- NEW: Added support for STM32F401/STM32F42x/STM32F43x devices. - NEW: Added support for STM32F401/STM32F42x/STM32F43x devices.