Changeset 96ec8ee8 in rtems


Ignore:
Timestamp:
Aug 22, 2014, 3:09:36 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
9907dde
Parents:
8f1bdcb9
git-author:
Sebastian Huber <sebastian.huber@…> (08/22/14 15:09:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/26/14 08:21:27)
Message:

rtems: Add more clock tick functions

Add rtems_clock_tick_later(), rtems_clock_tick_later_usec() and
rtems_clock_tick_before().

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/rtems/include/rtems/rtems/clock.h

    r8f1bdcb9 r96ec8ee8  
    3535#include <rtems/rtems/status.h>
    3636#include <rtems/rtems/types.h>
     37#include <rtems/config.h>
    3738
    3839#include <sys/time.h> /* struct timeval */
     
    161162
    162163/**
     164 * @brief Returns the ticks counter value delta ticks in the future.
     165 *
     166 * @param[in] delta The ticks delta value.
     167 *
     168 * @return The tick counter value delta ticks in the future.
     169 */
     170RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_tick_later(
     171  rtems_interval delta
     172)
     173{
     174  return _Watchdog_Ticks_since_boot + delta;
     175}
     176
     177/**
     178 * @brief Returns the ticks counter value at least delta microseconds in the
     179 * future.
     180 *
     181 * @param[in] delta_in_usec The delta value in microseconds.
     182 *
     183 * @return The tick counter value at least delta microseconds in the future.
     184 */
     185RTEMS_INLINE_ROUTINE rtems_interval rtems_clock_tick_later_usec(
     186  rtems_interval delta_in_usec
     187)
     188{
     189  rtems_interval us_per_tick = rtems_configuration_get_microseconds_per_tick();
     190
     191  /*
     192   * Add one additional tick, since we don't know the time to the clock next
     193   * tick.
     194   */
     195  return _Watchdog_Ticks_since_boot
     196    + (delta_in_usec + us_per_tick - 1) / us_per_tick + 1;
     197}
     198
     199/**
     200 * @brief Returns true if the current ticks counter value indicates a time
     201 * before the time specified by the tick value and false otherwise.
     202 *
     203 * @param[in] tick The tick value.
     204 *
     205 * This can be used to write busy loops with a timeout.
     206 *
     207 * @code
     208 * status busy( void )
     209 * {
     210 *   rtems_interval timeout = rtems_clock_tick_later_usec( 10000 );
     211 *
     212 *   do {
     213 *     if ( ok() ) {
     214 *       return success;
     215 *     }
     216 *   } while ( rtems_clock_tick_before( timeout ) );
     217 *
     218 *   return timeout;
     219 * }
     220 * @endcode
     221 *
     222 * @retval true The current ticks counter value indicates a time before the
     223 * time specified by the tick value.
     224 * @retval false Otherwise.
     225 */
     226RTEMS_INLINE_ROUTINE bool rtems_clock_tick_before(
     227  rtems_interval tick
     228)
     229{
     230  return (int32_t) ( tick - _Watchdog_Ticks_since_boot ) > 0;
     231}
     232
     233/**
    163234 * @brief Obtain Ticks Per Seconds
    164235 *
  • doc/user/clock.t

    r8f1bdcb9 r96ec8ee8  
    2222@item @code{@value{DIRPREFIX}clock_get_ticks_per_second} - Get ticks per second
    2323@item @code{@value{DIRPREFIX}clock_get_ticks_since_boot} - Get current ticks counter value
     24@item @code{@value{DIRPREFIX}clock_tick_later} - Get tick value in the future
     25@item @code{@value{DIRPREFIX}clock_tick_later_usec} - Get tick value in the future in microseconds
     26@item @code{@value{DIRPREFIX}clock_tick_before} - Is tick value is before a point in time
    2427@item @code{@value{DIRPREFIX}clock_get_uptime} - Get time since boot
    2528@item @code{@value{DIRPREFIX}clock_get_uptime_timeval} - Get time since boot in timeval format
     
    618621@c
    619622@page
     623@subsection CLOCK_TICK_LATER - Get tick value in the future
     624
     625@subheading CALLING SEQUENCE:
     626
     627@ifset is-C
     628@findex rtems_clock_tick_later
     629@example
     630rtems_interval rtems_clock_tick_later(
     631  rtems_interval delta
     632);
     633@end example
     634@end ifset
     635
     636@subheading DESCRIPTION:
     637
     638Returns the ticks counter value delta ticks in the future.
     639
     640@subheading NOTES:
     641
     642This directive is callable from an ISR.
     643
     644This directive will not cause the running task to be preempted.
     645
     646@c
     647@c
     648@c
     649@page
     650@subsection CLOCK_TICK_LATER_USEC - Get tick value in the future in microseconds
     651
     652@subheading CALLING SEQUENCE:
     653
     654@ifset is-C
     655@findex rtems_clock_tick_later_usec
     656@example
     657rtems_interval rtems_clock_tick_later_usec(
     658  rtems_interval delta_in_usec
     659);
     660@end example
     661@end ifset
     662
     663@subheading DESCRIPTION:
     664
     665Returns the ticks counter value at least delta microseconds in the future.
     666
     667@subheading NOTES:
     668
     669This directive is callable from an ISR.
     670
     671This directive will not cause the running task to be preempted.
     672
     673@c
     674@c
     675@c
     676@page
     677@subsection CLOCK_TICK_BEFORE - Is tick value is before a point in time
     678
     679@subheading CALLING SEQUENCE:
     680
     681@ifset is-C
     682@findex rtems_clock_tick_before
     683@example
     684rtems_interval rtems_clock_tick_before(
     685  rtems_interval tick
     686);
     687@end example
     688@end ifset
     689
     690@subheading DESCRIPTION:
     691
     692Returns true if the current ticks counter value indicates a time before the
     693time specified by the tick value and false otherwise.
     694
     695@subheading NOTES:
     696
     697This directive is callable from an ISR.
     698
     699This directive will not cause the running task to be preempted.
     700
     701@subheading EXAMPLE:
     702
     703@example
     704@group
     705status busy( void )
     706@{
     707  rtems_interval timeout = rtems_clock_tick_later_usec( 10000 );
     708
     709  do @{
     710    if ( ok() ) @{
     711      return success;
     712    @}
     713  @} while ( rtems_clock_tick_before( timeout ) );
     714
     715  return timeout;
     716@}
     717@end group
     718@end example
     719
     720@c
     721@c
     722@c
     723@page
    620724@subsection CLOCK_GET_UPTIME - Get the time since boot
    621725
  • testsuites/sptests/sp37/init.c

    r8f1bdcb9 r96ec8ee8  
    231231}
    232232
     233static void test_clock_tick_functions( void )
     234{
     235  rtems_interrupt_level level;
     236  Watchdog_Interval saved_ticks;
     237
     238  _Thread_Disable_dispatch();
     239  rtems_interrupt_disable( level );
     240
     241  saved_ticks = _Watchdog_Ticks_since_boot;
     242
     243  _Watchdog_Ticks_since_boot = 0xdeadbeef;
     244  rtems_test_assert( rtems_clock_get_ticks_since_boot() == 0xdeadbeef );
     245
     246  rtems_test_assert( rtems_clock_tick_later( 0 ) == 0xdeadbeef );
     247  rtems_test_assert( rtems_clock_tick_later( 0x8160311e ) == 0x600df00d );
     248
     249  _Watchdog_Ticks_since_boot = 0;
     250  rtems_test_assert( rtems_clock_tick_later_usec( 0 ) == 1 );
     251  rtems_test_assert( rtems_clock_tick_later_usec( 1 ) == 2 );
     252  rtems_test_assert( rtems_clock_tick_later_usec( US_PER_TICK ) == 2 );
     253  rtems_test_assert( rtems_clock_tick_later_usec( US_PER_TICK + 1 ) == 3 );
     254
     255  _Watchdog_Ticks_since_boot = 0;
     256  rtems_test_assert( !rtems_clock_tick_before( 0xffffffff ) );
     257  rtems_test_assert( !rtems_clock_tick_before( 0 ) );
     258  rtems_test_assert( rtems_clock_tick_before( 1 ) );
     259
     260  _Watchdog_Ticks_since_boot = 1;
     261  rtems_test_assert( !rtems_clock_tick_before( 0 ) );
     262  rtems_test_assert( !rtems_clock_tick_before( 1 ) );
     263  rtems_test_assert( rtems_clock_tick_before( 2 ) );
     264
     265  _Watchdog_Ticks_since_boot = 0x7fffffff;
     266  rtems_test_assert( !rtems_clock_tick_before( 0x7ffffffe ) );
     267  rtems_test_assert( !rtems_clock_tick_before( 0x7fffffff ) );
     268  rtems_test_assert( rtems_clock_tick_before( 0x80000000 ) );
     269
     270  _Watchdog_Ticks_since_boot = 0x80000000;
     271  rtems_test_assert( !rtems_clock_tick_before( 0x7fffffff ) );
     272  rtems_test_assert( !rtems_clock_tick_before( 0x80000000 ) );
     273  rtems_test_assert( rtems_clock_tick_before( 0x80000001 ) );
     274
     275  _Watchdog_Ticks_since_boot = 0xffffffff;
     276  rtems_test_assert( !rtems_clock_tick_before( 0xfffffffe ) );
     277  rtems_test_assert( !rtems_clock_tick_before( 0xffffffff ) );
     278  rtems_test_assert( rtems_clock_tick_before( 0 ) );
     279
     280  _Watchdog_Ticks_since_boot = saved_ticks;
     281
     282  rtems_interrupt_enable( level );
     283  _Thread_Enable_dispatch();
     284}
     285
    233286void test_interrupt_inline(void)
    234287{
     
    413466  directive_failed( status, "rtems_clock_tick" );
    414467  puts( "clock_tick from task level" );
     468
     469  test_clock_tick_functions();
    415470
    416471  /*
  • testsuites/sptests/sp37/system.h

    r8f1bdcb9 r96ec8ee8  
    1616#include <tmacros.h>
    1717
     18#define US_PER_TICK 10000
     19
    1820/* functions */
    1921
     
    2931#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    3032
     33#define CONFIGURE_MICROSECONDS_PER_TICK US_PER_TICK
     34
    3135#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    3236#define CONFIGURE_INIT_TASK_PRIORITY        2
Note: See TracChangeset for help on using the changeset viewer.