Ticket #1894: pr1894.diff

File pr1894.diff, 3.5 KB (added by Joel Sherrill, on 08/21/11 at 18:11:08)

Cover over time conversion helpers.

  • cpukit/score/src/coretodmsecstoticks.c

    RCS file: /usr1/CVS/rtems/cpukit/score/src/coretodmsecstoticks.c,v
    retrieving revision 1.1
    diff -u -r1.1 coretodmsecstoticks.c
     
    1 /*  COPYRIGHT (c) 1989-2008.
     1/*  COPYRIGHT (c) 1989-2011.
    22 *  On-Line Applications Research Corporation (OAR).
    33 *
    44 *  The license and distribution terms for this file may be
     
    2121  uint32_t milliseconds
    2222)
    2323{
    24   return (milliseconds / rtems_configuration_get_milliseconds_per_tick());
     24  uint32_t ticks;
     25  uint32_t milliseconds_per_tick;
     26
     27  /**
     28   *  We should ensure the ticks not be truncated by integer division.  We
     29   *  need to have it be greater than or equal to the requested time.  It
     30   *  should not be shorter.
     31   */
     32  milliseconds_per_tick = rtems_configuration_get_milliseconds_per_tick();
     33  ticks                 = milliseconds / milliseconds_per_tick;
     34  if ( (milliseconds % milliseconds_per_tick) != 0 )
     35    ticks += 1;
     36
     37  return ticks;
    2538}
  • cpukit/score/src/coretodusectoticks.c

    RCS file: /usr1/CVS/rtems/cpukit/score/src/coretodusectoticks.c,v
    retrieving revision 1.1
    diff -u -r1.1 coretodusectoticks.c
     
    1 /*  COPYRIGHT (c) 1989-2008.
     1/*  COPYRIGHT (c) 1989-2011.
    22 *  On-Line Applications Research Corporation (OAR).
    33 *
    44 *  The license and distribution terms for this file may be
     
    2121  uint32_t microseconds
    2222)
    2323{
    24   return (microseconds / rtems_configuration_get_microseconds_per_tick());
     24  uint32_t ticks;
     25  uint32_t microseconds_per_tick;
     26
     27  /**
     28   *  We should ensure the ticks not be truncated by integer division.  We
     29   *  need to have it be greater than or equal to the requested time.  It
     30   *  should not be shorter.
     31   */
     32  microseconds_per_tick = rtems_configuration_get_microseconds_per_tick();
     33  ticks                 = microseconds / microseconds_per_tick;
     34  if ( (microseconds % microseconds_per_tick) != 0 )
     35    ticks += 1;
     36
     37  return ticks;
    2538}
  • cpukit/score/src/timespectoticks.c

    RCS file: /usr1/CVS/rtems/cpukit/score/src/timespectoticks.c,v
    retrieving revision 1.3
    diff -u -r1.3 timespectoticks.c
     
    3535)
    3636{
    3737  uint32_t  ticks;
     38  uint32_t  nanoseconds_per_tick;
    3839
    3940  if ( (time->tv_sec == 0) && (time->tv_nsec == 0) )
    4041    return 0;
    4142
    42   ticks  = time->tv_sec * TOD_TICKS_PER_SECOND;
     43  /**
     44   *  We should ensure the ticks not be truncated by integer division.  We
     45   *  need to have it be greater than or equal to the requested time.  It
     46   *  should not be shorter.
     47   */
     48  ticks                 = time->tv_sec * TOD_TICKS_PER_SECOND;
     49  nanoseconds_per_tick  = rtems_configuration_get_nanoseconds_per_tick();
     50  ticks                += time->tv_nsec / nanoseconds_per_tick;
    4351
    44   ticks += time->tv_nsec / rtems_configuration_get_nanoseconds_per_tick();
     52  if ( (time->tv_nsec % nanoseconds_per_tick) != 0 )
     53    ticks += 1;
    4554
    46   if (ticks)
    47     return ticks;
    48 
    49   return 1;
     55  return ticks;
    5056}