Changeset f6e0934 in rtems


Ignore:
Timestamp:
Apr 2, 2007, 9:51:52 PM (13 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
dfa1f0bc
Parents:
a6ec372
Message:

2007-04-02 Joel Sherrill <joel@…>

  • posix/include/rtems/posix/timer.h, posix/src/alarm.c, posix/src/posixtimespectointerval.c, posix/src/ptimer1.c, posix/src/sysconf.c, posix/src/ualarm.c, rtems/src/clockget.c, rtems/src/clocktodvalidate.c, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c: Eliminate TOD_Ticks_per_second variable.
Location:
cpukit
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    ra6ec372 rf6e0934  
     12007-04-02      Joel Sherrill <joel@OARcorp.com>
     2
     3        * posix/include/rtems/posix/timer.h, posix/src/alarm.c,
     4        posix/src/posixtimespectointerval.c, posix/src/ptimer1.c,
     5        posix/src/sysconf.c, posix/src/ualarm.c, rtems/src/clockget.c,
     6        rtems/src/clocktodvalidate.c, score/include/rtems/score/tod.h,
     7        score/inline/rtems/score/tod.inl, score/src/coretod.c: Eliminate
     8        TOD_Ticks_per_second variable.
     9
    1102007-04-02      Joel Sherrill <joel@OARcorp.com>
    211
  • cpukit/posix/include/rtems/posix/timer.h

    ra6ec372 rf6e0934  
    1111
    1212#include <rtems/posix/config.h>
     13
     14/* Timer is free */
     15#define POSIX_TIMER_STATE_FREE        0x01
     16                                                               
     17/* Created timer but not running          */
     18#define POSIX_TIMER_STATE_CREATE_NEW  0x02
     19
     20/* Created timer and running              */
     21#define POSIX_TIMER_STATE_CREATE_RUN  0x03
     22
     23/* Created, ran and stopped timer         */
     24#define POSIX_TIMER_STATE_CREATE_STOP 0x04
     25
     26/* Indicates that the fire time is relative to the current one */
     27#define POSIX_TIMER_RELATIVE       0
     28
    1329/*
    14  * Constants
    15  */
    16 
    17 #define STATE_FREE_C        0x01 /* Free position of the table of timers   */
    18 #define STATE_CREATE_NEW_C  0x02 /* Created timer but not running          */
    19 #define STATE_CREATE_RUN_C  0x03 /* Created timer and running              */
    20 #define STATE_CREATE_STOP_C 0x04 /* Created, ran and stopped timer         */
    21 /* Maximum number of nsec allowed         */
    22 #define MAX_NSEC_C    (uint32_t  )1000000000
    23 #define MIN_NSEC_C             0 /* Minimum number of nsec allowew         */
    24 #define TIMER_RELATIVE_C       0 /* Indicates that the fire time is
    25                                   * relative to the current one            */
    26 #define SEC_TO_TICKS_C _TOD_Ticks_per_second /* Number of ticks in a second*/
    27 /* Nanoseconds in a second               */
    28 #define NSEC_PER_SEC_C (uint32_t  )1000000000
    29 
    30 #define SECONDS_PER_YEAR_C    (uint32_t  )(360 * 24) * (uint32_t  )(60 * 60)
    31 #define SECONDS_PER_MONTH_C   (uint32_t  )( 30 * 24) * (uint32_t  )(60 * 60)
    32 #define SECONDS_PER_DAY_C     (uint32_t  )( 24 * 60) * (uint32_t  )(60)
    33 #define SECONDS_PER_HOUR_C               (uint32_t  )( 60 * 60 )
    34 #define SECONDS_PER_MINUTE_C                  (uint32_t  )( 60 )
     30 * POSIX defines TIMER_ABSTIME but no constant for relative.  So
     31 * we have one internally but we need to be careful it has a different
     32 * value.
     33 */
     34#if (POSIX_TIMER_RELATIVE == TIMER_ABSTIME)
     35#error "POSIX_TIMER_RELATIVE == TIMER_ABSTIME"
     36#endif
    3537
    3638
     
    3840 * Data for a timer
    3941 */
    40 
    4142typedef struct {
    4243  Objects_Control   Object;
     
    5859 *  This routine performs the initialization necessary for this manager.
    5960 */
    60 
    6161void _POSIX_Timer_Manager_initialization ( int max_timers );
    6262
     
    6565 *  this class of objects.
    6666 */
    67 
    6867POSIX_EXTERN Objects_Information  _POSIX_Timer_Information;
    6968
  • cpukit/posix/src/alarm.c

    ra6ec372 rf6e0934  
    7070         */
    7171
    72         remaining = the_timer->initial -
    73          ((the_timer->stop_time - the_timer->start_time) /
    74            _TOD_Ticks_per_second);
     72        remaining = the_timer->initial;
     73        remaining -= (the_timer->stop_time - the_timer->start_time);
     74       
     75        /* remaining is now in ticks */
     76        remaining *= _TOD_Microseconds_per_tick;
     77        remaining /= TOD_MICROSECONDS_PER_SECOND;
    7578        break;
    7679    }
  • cpukit/posix/src/posixtimespectointerval.c

    ra6ec372 rf6e0934  
    2929  Watchdog_Interval  ticks;
    3030
    31   ticks  = (time->tv_sec * _TOD_Ticks_per_second);
     31  ticks  = time->tv_sec *
     32           (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick);
     33
    3234  ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
    3335             _TOD_Microseconds_per_tick;
  • cpukit/posix/src/ptimer1.c

    ra6ec372 rf6e0934  
    6868/* #define DEBUG_MESSAGES */
    6969
    70 /*
    71  * ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S
    72  *
    73  *  Description: This function converts the data of a structure itimerspec
    74  *               into structure rtems_time_of_day
    75   */
    76 
    77 void ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S(
    78   const struct itimerspec *itimer,
    79   rtems_time_of_day *rtems_time
    80 )
    81 {
    82    unsigned long int seconds;
    83 
    84    /* The leap years and the months with 28, 29 or 31 days have not been
    85     * considered. It will be made in the future */
    86 
    87    seconds            = itimer->it_value.tv_sec;
    88 
    89    rtems_time->year   = seconds / SECONDS_PER_YEAR_C;
    90    seconds            = seconds % SECONDS_PER_YEAR_C;
    91 
    92    rtems_time->month  = seconds / SECONDS_PER_MONTH_C;
    93    seconds            = seconds % SECONDS_PER_MONTH_C;
    94 
    95    rtems_time->day    = seconds / SECONDS_PER_DAY_C;
    96    seconds            = seconds % SECONDS_PER_DAY_C;
    97 
    98    rtems_time->hour   = seconds / SECONDS_PER_HOUR_C;
    99    seconds            = seconds % SECONDS_PER_HOUR_C;
    100 
    101    rtems_time->minute = seconds / SECONDS_PER_MINUTE_C;
    102    seconds            = seconds % SECONDS_PER_MINUTE_C;
    103 
    104    rtems_time->second = seconds;
    105 
    106    rtems_time->ticks  = itimer->it_value.tv_nsec/
    107                         (NSEC_PER_SEC_C / SEC_TO_TICKS_C);
    108 
    109 }
    110 
    111 
    11270/* ***************************************************************************
    11371 * _POSIX_Timer_TSR
     
    147105
    148106    /* The state really did not change but just to be safe */
    149     ptimer->state = STATE_CREATE_RUN_C;
     107    ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
    150108  } else {
    151109   /* Indicates that the timer is stopped */
    152    ptimer->state = STATE_CREATE_STOP_C;
     110   ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
    153111  }
    154112
     
    220178  /* The data of the created timer are stored to use them later */
    221179
    222   ptimer->state     = STATE_CREATE_NEW_C;
     180  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;
    223181  ptimer->thread_id = _Thread_Executing->Object.id;
    224182
     
    275233    case OBJECTS_LOCAL:
    276234      _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object );
    277       ptimer->state = STATE_FREE_C;
     235      ptimer->state = POSIX_TIMER_STATE_FREE;
    278236      (void) _Watchdog_Remove( &ptimer->Timer );
    279237      _POSIX_Timer_Free( ptimer );
     
    309267
    310268  /* First, it verifies if the structure "value" is correct */
    311   if ( ( value->it_value.tv_nsec > MAX_NSEC_C ) ||
    312        ( value->it_value.tv_nsec < MIN_NSEC_C ) ) {
     269  if ( ( value->it_value.tv_nsec > TOD_NANOSECONDS_PER_SECOND ) ||
     270       ( value->it_value.tv_nsec < 0 ) ) {
    313271    /* The number of nanoseconds is not correct */
    314272    rtems_set_errno_and_return_minus_one( EINVAL );
     
    317275  /* XXX check for seconds in the past */
    318276
    319   if ( flags != TIMER_ABSTIME && flags != TIMER_RELATIVE_C ) {
     277  if ( flags != TIMER_ABSTIME && flags != POSIX_TIMER_RELATIVE ) {
    320278    rtems_set_errno_and_return_minus_one( EINVAL );
    321279  }
     
    349307         ptimer->timer_data = *value;
    350308         /* Indicates that the timer is created and stopped */
    351          ptimer->state = STATE_CREATE_STOP_C;
     309         ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
    352310         /* Returns with success */
    353311        _Thread_Enable_dispatch();
     
    362320           /* First, it converts from struct itimerspec to rtems_time_of_day */
    363321
    364 #if 0
    365            ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S( value, &tod );
    366            status = rtems_timer_fire_when(
    367              ptimer->timer_id, &tod, _POSIX_Timer_TSR, ptimer);
    368 #endif
    369322           _Watchdog_Initialize(
    370323             &ptimer->Timer, _POSIX_Timer_TSR, ptimer->Object.id, ptimer );
     
    381334
    382335           /* Indicate that the time is running */
    383            ptimer->state = STATE_CREATE_RUN_C;
     336           ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
    384337
    385338           /* Stores the time in which the timer was started again */
     
    390343
    391344         /* The fire time is relative: use "rtems_time_fire_after" */
    392          case TIMER_RELATIVE_C:
     345         case POSIX_TIMER_RELATIVE:
    393346           /* First, convert from seconds and nanoseconds to ticks */
    394            ptimer->ticks = ( SEC_TO_TICKS_C * value->it_value.tv_sec ) +
    395                 ( value->it_value.tv_nsec / (NSEC_PER_SEC_C / SEC_TO_TICKS_C));
    396 
    397 #if 0
    398            status = rtems_timer_fire_after(
    399              ptimer->timer_id, ptimer->ticks, _POSIX_Timer_TSR, ptimer );
    400 #endif
     347           ptimer->ticks = _POSIX_Timespec_to_interval( &value->it_value );
     348
    401349           activated = _Watchdog_Insert_ticks_helper(
    402350             &ptimer->Timer,
     
    416364
    417365           /* Indicate that the time is running */
    418            ptimer->state = STATE_CREATE_RUN_C;
     366           ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
    419367           _TOD_Get( &ptimer->time );
    420368            _Thread_Enable_dispatch();
     
    475423      /* Calculates the time left before the timer finishes */
    476424
    477       _POSIX_Timespec_subtract(&ptimer->timer_data.it_value, &current_time, &value->it_value);
     425      _POSIX_Timespec_subtract(
     426        &ptimer->timer_data.it_value, &current_time, &value->it_value);
    478427
    479428      value->it_interval.tv_sec  = ptimer->timer_data.it_interval.tv_sec;
  • cpukit/posix/src/sysconf.c

    ra6ec372 rf6e0934  
    2828  switch (name) {
    2929    case _SC_CLK_TCK:
    30       return _TOD_Ticks_per_second;
     30      return (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick);
    3131
    3232    case _SC_OPEN_MAX: {
  • cpukit/posix/src/ualarm.c

    ra6ec372 rf6e0934  
    7474         */
    7575
    76 
    77         ticks = the_timer->initial -
    78          ((the_timer->stop_time - the_timer->start_time) /
    79            _TOD_Ticks_per_second);
     76        ticks = the_timer->initial;
     77        ticks -= (the_timer->stop_time - the_timer->start_time);
     78       
     79        /* remaining is now in ticks */
     80        ticks *= _TOD_Microseconds_per_tick;
     81        ticks /= TOD_MICROSECONDS_PER_SECOND;
    8082
    8183        _POSIX_Interval_to_timespec( ticks, &tp );
  • cpukit/rtems/src/clockget.c

    ra6ec372 rf6e0934  
    7676      return RTEMS_SUCCESSFUL;
    7777    }
    78     case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH:
     78    case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH: {
     79      rtems_interval *interval = (rtems_interval *)time_buffer;
     80
    7981      if ( !_TOD_Is_set )
    8082        return RTEMS_NOT_DEFINED;
    8183
    82       *(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch;
     84      *interval = _TOD_Seconds_since_epoch;
    8385      return RTEMS_SUCCESSFUL;
     86    }
    8487
    85     case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT:
    86       *(rtems_interval *)time_buffer = _Watchdog_Ticks_since_boot;
     88    case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT: {
     89      rtems_interval *interval = (rtems_interval *)time_buffer;
     90
     91      *interval = _Watchdog_Ticks_since_boot;
    8792      return RTEMS_SUCCESSFUL;
     93    }
    8894
    89     case RTEMS_CLOCK_GET_TICKS_PER_SECOND:
    90       *(rtems_interval *)time_buffer = _TOD_Ticks_per_second;
     95    case RTEMS_CLOCK_GET_TICKS_PER_SECOND: {
     96      rtems_interval *interval = (rtems_interval *)time_buffer;
     97
     98      *interval = TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick;
    9199      return RTEMS_SUCCESSFUL;
     100    }
    92101
    93102    case RTEMS_CLOCK_GET_TIME_VALUE: {
    94103      struct timeval *time = (struct timeval *)time_buffer;
     104
    95105      if ( !_TOD_Is_set )
    96106        return RTEMS_NOT_DEFINED;
  • cpukit/rtems/src/clocktodvalidate.c

    ra6ec372 rf6e0934  
    5454
    5555  if ((!the_tod)                                  ||
    56       (the_tod->ticks  >= _TOD_Ticks_per_second)  ||
     56      (the_tod->ticks  >=
     57          (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick))  ||
    5758      (the_tod->second >= TOD_SECONDS_PER_MINUTE) ||
    5859      (the_tod->minute >= TOD_MINUTES_PER_HOUR)   ||
  • cpukit/score/include/rtems/score/tod.h

    ra6ec372 rf6e0934  
    146146SCORE_EXTERN uint32_t   _TOD_Microseconds_per_tick;
    147147
    148 /** @brief Clock Ticks per Second
    149  *
    150  *  The following contains the number of clock ticks per second.
    151  *
    152  *  @note If one second is NOT evenly divisible by the number of microseconds
    153  *  per clock tick, this value will contain only the integer portion
    154  *  of the division.  This means that the interval between clock ticks
    155  *  can be a source of error in the current time of day.
    156  */
    157 SCORE_EXTERN uint32_t   _TOD_Ticks_per_second;
    158 
    159148/** @brief _TOD_Handler_initialization
    160149 *
  • cpukit/score/inline/rtems/score/tod.inl

    ra6ec372 rf6e0934  
    9797 */
    9898
    99 RTEMS_INLINE_ROUTINE void _TOD_Activate(
    100   Watchdog_Interval ticks
    101 )
     99RTEMS_INLINE_ROUTINE void _TOD_Activate()
    102100{
    103101  /* XXX do we need something now that we are using timespec for TOD */
  • cpukit/score/src/coretod.c

    ra6ec372 rf6e0934  
    5252  _TOD_Seconds_since_epoch = 0;
    5353
    54   /* Protect ourselves from a divide by zero fault */
    55   if ( microseconds_per_tick == 0 )
    56     _TOD_Ticks_per_second = 0;
    57   else
    58     _TOD_Ticks_per_second =
    59        TOD_MICROSECONDS_PER_SECOND / microseconds_per_tick;
    60 
    6154  /* TOD has not been set */
    6255  _TOD_Is_set = FALSE;
    63   _TOD_Activate( _TOD_Ticks_per_second );
     56  _TOD_Activate();
    6457}
Note: See TracChangeset for help on using the changeset viewer.