Time conversion macros fixes.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7851 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2015-04-04 08:19:04 +00:00
parent b3c635dc4b
commit 5047ce62e8
3 changed files with 17 additions and 15 deletions

View File

@ -425,8 +425,8 @@ typedef struct {
* @api * @api
*/ */
#define OSAL_MS2ST(msec) \ #define OSAL_MS2ST(msec) \
((systime_t)((((((uint32_t)(msec)) * \ ((systime_t)((((uint32_t)(msec)) * \
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL)) ((uint32_t)OSAL_ST_FREQUENCY) + 999UL) / 1000UL))
/** /**
* @brief Microseconds to system ticks. * @brief Microseconds to system ticks.
@ -439,8 +439,8 @@ typedef struct {
* @api * @api
*/ */
#define OSAL_US2ST(usec) \ #define OSAL_US2ST(usec) \
((systime_t)((((((uint32_t)(usec)) * \ ((systime_t)((((uint32_t)(usec)) * \
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL)) ((uint32_t)OSAL_ST_FREQUENCY) + 999999UL) / 1000000UL))
/** @} */ /** @} */
/** /**

View File

@ -596,8 +596,8 @@ struct nil_system {
* @api * @api
*/ */
#define MS2ST(msec) \ #define MS2ST(msec) \
((systime_t)((((((uint32_t)(msec)) * \ ((systime_t)((((uint32_t)(msec)) * \
((uint32_t)NIL_CFG_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL)) ((uint32_t)NIL_CFG_ST_FREQUENCY) + 999UL) / 1000UL))
/** /**
* @brief Microseconds to system ticks. * @brief Microseconds to system ticks.
@ -610,8 +610,8 @@ struct nil_system {
* @api * @api
*/ */
#define US2ST(usec) \ #define US2ST(usec) \
((systime_t)((((((uint32_t)(usec)) * \ ((systime_t)((((uint32_t)(usec)) * \
((uint32_t)NIL_CFG_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL)) ((uint32_t)NIL_CFG_ST_FREQUENCY) + 999999UL) / 1000000UL))
/** @} */ /** @} */
/** /**

View File

@ -118,8 +118,8 @@
* @api * @api
*/ */
#define MS2ST(msec) \ #define MS2ST(msec) \
((systime_t)((((((uint32_t)(msec)) * \ ((systime_t)((((uint32_t)(msec)) * \
((uint32_t)CH_CFG_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL)) ((uint32_t)CH_CFG_ST_FREQUENCY) + 999UL) / 1000UL))
/** /**
* @brief Microseconds to system ticks. * @brief Microseconds to system ticks.
@ -132,8 +132,8 @@
* @api * @api
*/ */
#define US2ST(usec) \ #define US2ST(usec) \
((systime_t)((((((uint32_t)(usec)) * \ ((systime_t)((((uint32_t)(usec)) * \
((uint32_t)CH_CFG_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL)) ((uint32_t)CH_CFG_ST_FREQUENCY) + 999999UL) / 1000000UL))
/** /**
* @brief System ticks to seconds. * @brief System ticks to seconds.
@ -145,7 +145,7 @@
* *
* @api * @api
*/ */
#define ST2S(n) (((((n) - 1UL) * 1UL) / CH_CFG_ST_FREQUENCY) + 1UL) #define ST2S(n) (((n) + CH_CFG_ST_FREQUENCY - 1UL) / CH_CFG_ST_FREQUENCY)
/** /**
* @brief System ticks to milliseconds. * @brief System ticks to milliseconds.
@ -157,7 +157,8 @@
* *
* @api * @api
*/ */
#define ST2MS(n) (((((n) - 1UL) * 1000UL) / CH_CFG_ST_FREQUENCY) + 1UL) #define ST2MS(n) (((n) * 1000UL + CH_CFG_ST_FREQUENCY - 1UL) / \
CH_CFG_ST_FREQUENCY)
/** /**
* @brief System ticks to microseconds. * @brief System ticks to microseconds.
@ -169,7 +170,8 @@
* *
* @api * @api
*/ */
#define ST2US(n) (((((n) - 1UL) * 1000000UL) / CH_CFG_ST_FREQUENCY) + 1UL) #define ST2US(n) (((n) * 1000000UL + CH_CFG_ST_FREQUENCY - 1UL) / \
CH_CFG_ST_FREQUENCY)
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/