From 83fa155385e88ac06d6834604ab57c1132c5b0af Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 29 Nov 2013 13:24:08 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6513 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chsys.h | 9 ++++++--- os/rt/include/chvt.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'os/rt/include') diff --git a/os/rt/include/chsys.h b/os/rt/include/chsys.h index 9a74788ae..1b80bba65 100644 --- a/os/rt/include/chsys.h +++ b/os/rt/include/chsys.h @@ -145,35 +145,38 @@ /** * @brief Realtime counter cycles to seconds. * @details Converts from realtime counter cycles number to seconds. + * @note The result is rounded up to the next second boundary. * * @param[in] n number of cycles * @return The number of seconds. * * @api */ -#define RTC2S(n) (rtcnt_t)(CH_CFG_RTC_FREQUENCY / (freq)) +#define RTC2S(n) ((((n) - 1UL) / CH_CFG_RTC_FREQUENCY) + 1UL) /** * @brief Realtime counter cycles to milliseconds. * @details Converts from realtime counter cycles number to milliseconds. + * @note The result is rounded up to the next millisecond boundary. * * @param[in] n number of cycles * @return The number of milliseconds. * * @api */ -#define RTC2MS(n) ((n) / (CH_CFG_RTC_FREQUENCY / 1000UL)) +#define RTC2MS(n) ((((n) - 1UL) / (CH_CFG_RTC_FREQUENCY / 1000UL)) + 1UL) /** * @brief Realtime counter cycles to microseconds. * @details Converts from realtime counter cycles number to microseconds. + * @note The result is rounded up to the next microsecond boundary. * * @param[in] n number of cycles * @return The number of microseconds. * * @api */ -#define RTC2US(n) ((n) / (CH_CFG_RTC_FREQUENCY / 1000000UL)) +#define RTC2US(n) ((((n) - 1UL) / (CH_CFG_RTC_FREQUENCY / 1000000UL)) + 1UL) /** @} */ /** diff --git a/os/rt/include/chvt.h b/os/rt/include/chvt.h index ea84df9fd..35d9986c0 100644 --- a/os/rt/include/chvt.h +++ b/os/rt/include/chvt.h @@ -160,6 +160,42 @@ struct virtual_timer { #define US2ST(usec) \ ((systime_t)(((((uint32_t)(usec)) * \ ((uint32_t)CH_CFG_ST_FREQUENCY) - 1UL) / 1000000UL) + 1UL)) + +/** + * @brief System ticks to seconds. + * @details Converts from system ticks number to seconds. + * @note The result is rounded up to the next second boundary. + * + * @param[in] n number of system ticks + * @return The number of seconds. + * + * @api + */ +#define ST2S(n) ((((n) - 1UL) / CH_CFG_ST_FREQUENCY) + 1UL) + +/** + * @brief System ticks to milliseconds. + * @details Converts from system ticks number to milliseconds. + * @note The result is rounded up to the next millisecond boundary. + * + * @param[in] n number of system ticks + * @return The number of milliseconds. + * + * @api + */ +#define ST2MS(n) ((((n) - 1UL) / (CH_CFG_ST_FREQUENCY / 1000UL)) + 1UL) + +/** + * @brief System ticks to microseconds. + * @details Converts from system ticks number to microseconds. + * @note The result is rounded up to the next microsecond boundary. + * + * @param[in] n number of system ticks + * @return The number of microseconds. + * + * @api + */ +#define ST2US(n) ((((n) - 1UL) / (CH_CFG_ST_FREQUENCY / 1000000UL)) + 1UL) /** @} */ /*===========================================================================*/ -- cgit v1.2.3