[PATCH 2/2] rtems: Add more clock tick functions
Gedare Bloom
gedare at rtems.org
Fri Aug 22 15:19:07 UTC 2014
These also would go into the clockimpl.h
On Fri, Aug 22, 2014 at 11:12 AM, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
> Add rtems_clock_ticks_later(), rtems_clock_ticks_later_us() and
> rtems_clock_ticks_later_us().
>
> FIXME: Patch is incomplete. Documentation and tests are missing. Just
> for API review.
> ---
> cpukit/rtems/include/rtems/rtems/clock.h | 66 ++++++++++++++++++++++++++++++++
> 1 file changed, 66 insertions(+)
>
> diff --git a/cpukit/rtems/include/rtems/rtems/clock.h b/cpukit/rtems/include/rtems/rtems/clock.h
> index ff71665..cee930e 100644
> --- a/cpukit/rtems/include/rtems/rtems/clock.h
> +++ b/cpukit/rtems/include/rtems/rtems/clock.h
> @@ -34,6 +34,7 @@
> #include <rtems/score/tod.h>
> #include <rtems/rtems/status.h>
> #include <rtems/rtems/types.h>
> +#include <rtems/config.h>
>
> #include <sys/time.h> /* struct timeval */
>
> @@ -160,6 +161,71 @@ RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_get_ticks_since_boot(void)
> }
>
> /**
> + * @brief Returns the ticks counter value delta ticks in the future.
> + *
> + * @param[in] delta The ticks delta value.
> + *
> + * @return The tick counter value delta ticks in the future.
> + */
> +RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_ticks_later(
> + rtems_interval delta
> +)
> +{
> + return _Watchdog_Ticks_since_boot + delta;
> +}
> +
> +/**
> + * @brief Returns the ticks counter value at least delta microseconds in the
> + * future.
> + *
> + * @param[in] delta The delta value in microseconds.
> + *
> + * @return The tick counter value at least delta microseconds in the future.
> + */
> +RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_ticks_later_us(
> + rtems_interval delta
> +)
> +{
> + rtems_interval us_per_tick = rtems_configuration_get_microseconds_per_tick();
> +
> + return _Watchdog_Ticks_since_boot + (delta + us_per_tick - 1) / us_per_tick;
> +}
> +
> +/**
> + * @brief Returns true if the current ticks counter value indicates a time
> + * before the time specified by the ticks value and false otherwise.
> + *
> + * @param[in] ticks The ticks value.
> + *
> + * This can be used to write busy loops with a timeout.
> + *
> + * @code
> + * status busy( void )
> + * {
> + * rtems_interval timeout = rtems_clock_ticks_later_us( 10000 );
> + *
> + * do {
> + * if ( ok() ) {
> + * return success;
> + * }
> + * } while ( rtems_clock_ticks_before( timeout ) );
> + *
> + * return timeout;
> + * }
> + * @endcode
> + *
> + * @retval true The current ticks counter value indicates a time before the
> + * time specified by the ticks value.
> + * @retval false Otherwise.
> + */
> +RTEMS_INLINE_ROUTINE bool rtems_clock_ticks_before(
> + rtems_interval ticks
> +)
> +{
> + return ( (int32_t) ticks - (int32_t) _Watchdog_Ticks_since_boot ) > 0;
> +}
> +
> +/**
> * @brief Obtain Ticks Per Seconds
> *
> * This routine implements the rtems_clock_get_ticks_per_second
> --
> 1.8.4.5
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
More information about the devel
mailing list