diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-04-02 21:51:52 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2007-04-02 21:51:52 +0000 |
commit | f6e09342eea83a34edeb71a140c988a818053a32 (patch) | |
tree | e95c73dd531486201f9285b7deac1d4627cbf5d6 | |
parent | 2007-04-02 Jennifer Averett <jennifer.averrett@oarcorp.com> (diff) | |
download | rtems-f6e09342eea83a34edeb71a140c988a818053a32.tar.bz2 |
2007-04-02 Joel Sherrill <joel@OARcorp.com>
* 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.
-rw-r--r-- | cpukit/ChangeLog | 9 | ||||
-rw-r--r-- | cpukit/posix/include/rtems/posix/timer.h | 45 | ||||
-rw-r--r-- | cpukit/posix/src/alarm.c | 9 | ||||
-rw-r--r-- | cpukit/posix/src/posixtimespectointerval.c | 4 | ||||
-rw-r--r-- | cpukit/posix/src/ptimer1.c | 79 | ||||
-rw-r--r-- | cpukit/posix/src/sysconf.c | 2 | ||||
-rw-r--r-- | cpukit/posix/src/ualarm.c | 10 | ||||
-rw-r--r-- | cpukit/rtems/src/clockget.c | 22 | ||||
-rw-r--r-- | cpukit/rtems/src/clocktodvalidate.c | 3 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/tod.h | 11 | ||||
-rw-r--r-- | cpukit/score/inline/rtems/score/tod.inl | 4 | ||||
-rw-r--r-- | cpukit/score/src/coretod.c | 9 |
12 files changed, 81 insertions, 126 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 1bc35e81fa..5b95fd4ab5 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,5 +1,14 @@ 2007-04-02 Joel Sherrill <joel@OARcorp.com> + * 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. + +2007-04-02 Joel Sherrill <joel@OARcorp.com> + * itron/src/itrontime.c, libcsupport/src/__gettod.c, posix/include/rtems/posix/time.h, posix/include/rtems/posix/timer.h, posix/src/clockgettime.c, posix/src/clocksettime.c, diff --git a/cpukit/posix/include/rtems/posix/timer.h b/cpukit/posix/include/rtems/posix/timer.h index 7a1bd32c4b..1ecc560249 100644 --- a/cpukit/posix/include/rtems/posix/timer.h +++ b/cpukit/posix/include/rtems/posix/timer.h @@ -10,34 +10,35 @@ #define _RTEMS_POSIX_TIMER_H #include <rtems/posix/config.h> -/* - * Constants - */ -#define STATE_FREE_C 0x01 /* Free position of the table of timers */ -#define STATE_CREATE_NEW_C 0x02 /* Created timer but not running */ -#define STATE_CREATE_RUN_C 0x03 /* Created timer and running */ -#define STATE_CREATE_STOP_C 0x04 /* Created, ran and stopped timer */ -/* Maximum number of nsec allowed */ -#define MAX_NSEC_C (uint32_t )1000000000 -#define MIN_NSEC_C 0 /* Minimum number of nsec allowew */ -#define TIMER_RELATIVE_C 0 /* Indicates that the fire time is - * relative to the current one */ -#define SEC_TO_TICKS_C _TOD_Ticks_per_second /* Number of ticks in a second*/ -/* Nanoseconds in a second */ -#define NSEC_PER_SEC_C (uint32_t )1000000000 +/* Timer is free */ +#define POSIX_TIMER_STATE_FREE 0x01 + +/* Created timer but not running */ +#define POSIX_TIMER_STATE_CREATE_NEW 0x02 + +/* Created timer and running */ +#define POSIX_TIMER_STATE_CREATE_RUN 0x03 -#define SECONDS_PER_YEAR_C (uint32_t )(360 * 24) * (uint32_t )(60 * 60) -#define SECONDS_PER_MONTH_C (uint32_t )( 30 * 24) * (uint32_t )(60 * 60) -#define SECONDS_PER_DAY_C (uint32_t )( 24 * 60) * (uint32_t )(60) -#define SECONDS_PER_HOUR_C (uint32_t )( 60 * 60 ) -#define SECONDS_PER_MINUTE_C (uint32_t )( 60 ) +/* Created, ran and stopped timer */ +#define POSIX_TIMER_STATE_CREATE_STOP 0x04 +/* Indicates that the fire time is relative to the current one */ +#define POSIX_TIMER_RELATIVE 0 /* - * Data for a timer + * POSIX defines TIMER_ABSTIME but no constant for relative. So + * we have one internally but we need to be careful it has a different + * value. */ +#if (POSIX_TIMER_RELATIVE == TIMER_ABSTIME) +#error "POSIX_TIMER_RELATIVE == TIMER_ABSTIME" +#endif + +/* + * Data for a timer + */ typedef struct { Objects_Control Object; Watchdog_Control Timer; /* Internal Timer */ @@ -57,14 +58,12 @@ typedef struct { * * This routine performs the initialization necessary for this manager. */ - void _POSIX_Timer_Manager_initialization ( int max_timers ); /* * The following defines the information control block used to manage * this class of objects. */ - POSIX_EXTERN Objects_Information _POSIX_Timer_Information; #ifndef __RTEMS_APPLICATION__ diff --git a/cpukit/posix/src/alarm.c b/cpukit/posix/src/alarm.c index c061b97e48..71097554c7 100644 --- a/cpukit/posix/src/alarm.c +++ b/cpukit/posix/src/alarm.c @@ -69,9 +69,12 @@ unsigned int alarm( * this. */ - remaining = the_timer->initial - - ((the_timer->stop_time - the_timer->start_time) / - _TOD_Ticks_per_second); + remaining = the_timer->initial; + remaining -= (the_timer->stop_time - the_timer->start_time); + + /* remaining is now in ticks */ + remaining *= _TOD_Microseconds_per_tick; + remaining /= TOD_MICROSECONDS_PER_SECOND; break; } } diff --git a/cpukit/posix/src/posixtimespectointerval.c b/cpukit/posix/src/posixtimespectointerval.c index 024dfe679c..92be3e508f 100644 --- a/cpukit/posix/src/posixtimespectointerval.c +++ b/cpukit/posix/src/posixtimespectointerval.c @@ -28,7 +28,9 @@ Watchdog_Interval _POSIX_Timespec_to_interval( { Watchdog_Interval ticks; - ticks = (time->tv_sec * _TOD_Ticks_per_second); + ticks = time->tv_sec * + (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick); + ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) / _TOD_Microseconds_per_tick; diff --git a/cpukit/posix/src/ptimer1.c b/cpukit/posix/src/ptimer1.c index c8a97b3644..9a63441f52 100644 --- a/cpukit/posix/src/ptimer1.c +++ b/cpukit/posix/src/ptimer1.c @@ -67,48 +67,6 @@ boolean _Watchdog_Insert_ticks_helper( /* #define DEBUG_MESSAGES */ -/* - * ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S - * - * Description: This function converts the data of a structure itimerspec - * into structure rtems_time_of_day - */ - -void ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S( - const struct itimerspec *itimer, - rtems_time_of_day *rtems_time -) -{ - unsigned long int seconds; - - /* The leap years and the months with 28, 29 or 31 days have not been - * considered. It will be made in the future */ - - seconds = itimer->it_value.tv_sec; - - rtems_time->year = seconds / SECONDS_PER_YEAR_C; - seconds = seconds % SECONDS_PER_YEAR_C; - - rtems_time->month = seconds / SECONDS_PER_MONTH_C; - seconds = seconds % SECONDS_PER_MONTH_C; - - rtems_time->day = seconds / SECONDS_PER_DAY_C; - seconds = seconds % SECONDS_PER_DAY_C; - - rtems_time->hour = seconds / SECONDS_PER_HOUR_C; - seconds = seconds % SECONDS_PER_HOUR_C; - - rtems_time->minute = seconds / SECONDS_PER_MINUTE_C; - seconds = seconds % SECONDS_PER_MINUTE_C; - - rtems_time->second = seconds; - - rtems_time->ticks = itimer->it_value.tv_nsec/ - (NSEC_PER_SEC_C / SEC_TO_TICKS_C); - -} - - /* *************************************************************************** * _POSIX_Timer_TSR * @@ -146,10 +104,10 @@ void _POSIX_Timer_TSR(Objects_Id timer, void *data) _TOD_Get( &ptimer->time ); /* The state really did not change but just to be safe */ - ptimer->state = STATE_CREATE_RUN_C; + ptimer->state = POSIX_TIMER_STATE_CREATE_RUN; } else { /* Indicates that the timer is stopped */ - ptimer->state = STATE_CREATE_STOP_C; + ptimer->state = POSIX_TIMER_STATE_CREATE_STOP; } /* @@ -219,7 +177,7 @@ int timer_create( /* The data of the created timer are stored to use them later */ - ptimer->state = STATE_CREATE_NEW_C; + ptimer->state = POSIX_TIMER_STATE_CREATE_NEW; ptimer->thread_id = _Thread_Executing->Object.id; if ( evp != NULL ) { @@ -274,7 +232,7 @@ int timer_delete( case OBJECTS_LOCAL: _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object ); - ptimer->state = STATE_FREE_C; + ptimer->state = POSIX_TIMER_STATE_FREE; (void) _Watchdog_Remove( &ptimer->Timer ); _POSIX_Timer_Free( ptimer ); _Thread_Enable_dispatch(); @@ -308,15 +266,15 @@ int timer_settime( } /* First, it verifies if the structure "value" is correct */ - if ( ( value->it_value.tv_nsec > MAX_NSEC_C ) || - ( value->it_value.tv_nsec < MIN_NSEC_C ) ) { + if ( ( value->it_value.tv_nsec > TOD_NANOSECONDS_PER_SECOND ) || + ( value->it_value.tv_nsec < 0 ) ) { /* The number of nanoseconds is not correct */ rtems_set_errno_and_return_minus_one( EINVAL ); } /* XXX check for seconds in the past */ - if ( flags != TIMER_ABSTIME && flags != TIMER_RELATIVE_C ) { + if ( flags != TIMER_ABSTIME && flags != POSIX_TIMER_RELATIVE ) { rtems_set_errno_and_return_minus_one( EINVAL ); } @@ -348,7 +306,7 @@ int timer_settime( /* The new data are set */ ptimer->timer_data = *value; /* Indicates that the timer is created and stopped */ - ptimer->state = STATE_CREATE_STOP_C; + ptimer->state = POSIX_TIMER_STATE_CREATE_STOP; /* Returns with success */ _Thread_Enable_dispatch(); return 0; @@ -361,11 +319,6 @@ int timer_settime( /* The fire time is absolute: use "rtems_time_fire_when" */ /* First, it converts from struct itimerspec to rtems_time_of_day */ -#if 0 - ITIMERSPEC_TO_RTEMS_TIME_OF_DAY_S( value, &tod ); - status = rtems_timer_fire_when( - ptimer->timer_id, &tod, _POSIX_Timer_TSR, ptimer); -#endif _Watchdog_Initialize( &ptimer->Timer, _POSIX_Timer_TSR, ptimer->Object.id, ptimer ); @@ -380,7 +333,7 @@ int timer_settime( ptimer->timer_data = *value; /* Indicate that the time is running */ - ptimer->state = STATE_CREATE_RUN_C; + ptimer->state = POSIX_TIMER_STATE_CREATE_RUN; /* Stores the time in which the timer was started again */ _TOD_Get( &ptimer->time ); @@ -389,15 +342,10 @@ int timer_settime( break; /* The fire time is relative: use "rtems_time_fire_after" */ - case TIMER_RELATIVE_C: + case POSIX_TIMER_RELATIVE: /* First, convert from seconds and nanoseconds to ticks */ - ptimer->ticks = ( SEC_TO_TICKS_C * value->it_value.tv_sec ) + - ( value->it_value.tv_nsec / (NSEC_PER_SEC_C / SEC_TO_TICKS_C)); + ptimer->ticks = _POSIX_Timespec_to_interval( &value->it_value ); -#if 0 - status = rtems_timer_fire_after( - ptimer->timer_id, ptimer->ticks, _POSIX_Timer_TSR, ptimer ); -#endif activated = _Watchdog_Insert_ticks_helper( &ptimer->Timer, ptimer->ticks, @@ -415,7 +363,7 @@ int timer_settime( ptimer->timer_data = *value; /* Indicate that the time is running */ - ptimer->state = STATE_CREATE_RUN_C; + ptimer->state = POSIX_TIMER_STATE_CREATE_RUN; _TOD_Get( &ptimer->time ); _Thread_Enable_dispatch(); return 0; @@ -474,7 +422,8 @@ int timer_gettime( /* Calculates the time left before the timer finishes */ - _POSIX_Timespec_subtract(&ptimer->timer_data.it_value, ¤t_time, &value->it_value); + _POSIX_Timespec_subtract( + &ptimer->timer_data.it_value, ¤t_time, &value->it_value); value->it_interval.tv_sec = ptimer->timer_data.it_interval.tv_sec; value->it_interval.tv_nsec = ptimer->timer_data.it_interval.tv_nsec; diff --git a/cpukit/posix/src/sysconf.c b/cpukit/posix/src/sysconf.c index 60a890d896..788688ef22 100644 --- a/cpukit/posix/src/sysconf.c +++ b/cpukit/posix/src/sysconf.c @@ -27,7 +27,7 @@ long sysconf( switch (name) { case _SC_CLK_TCK: - return _TOD_Ticks_per_second; + return (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick); case _SC_OPEN_MAX: { extern uint32_t rtems_libio_number_iops; diff --git a/cpukit/posix/src/ualarm.c b/cpukit/posix/src/ualarm.c index ab268d105c..d2b524ef5b 100644 --- a/cpukit/posix/src/ualarm.c +++ b/cpukit/posix/src/ualarm.c @@ -73,10 +73,12 @@ useconds_t ualarm( * this. */ - - ticks = the_timer->initial - - ((the_timer->stop_time - the_timer->start_time) / - _TOD_Ticks_per_second); + ticks = the_timer->initial; + ticks -= (the_timer->stop_time - the_timer->start_time); + + /* remaining is now in ticks */ + ticks *= _TOD_Microseconds_per_tick; + ticks /= TOD_MICROSECONDS_PER_SECOND; _POSIX_Interval_to_timespec( ticks, &tp ); remaining = tp.tv_sec * TOD_MICROSECONDS_PER_SECOND; diff --git a/cpukit/rtems/src/clockget.c b/cpukit/rtems/src/clockget.c index f5948bcffd..1c62256614 100644 --- a/cpukit/rtems/src/clockget.c +++ b/cpukit/rtems/src/clockget.c @@ -75,23 +75,33 @@ rtems_status_code rtems_clock_get( return RTEMS_SUCCESSFUL; } - case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH: + case RTEMS_CLOCK_GET_SECONDS_SINCE_EPOCH: { + rtems_interval *interval = (rtems_interval *)time_buffer; + if ( !_TOD_Is_set ) return RTEMS_NOT_DEFINED; - *(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch; + *interval = _TOD_Seconds_since_epoch; return RTEMS_SUCCESSFUL; + } - case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT: - *(rtems_interval *)time_buffer = _Watchdog_Ticks_since_boot; + case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT: { + rtems_interval *interval = (rtems_interval *)time_buffer; + + *interval = _Watchdog_Ticks_since_boot; return RTEMS_SUCCESSFUL; + } - case RTEMS_CLOCK_GET_TICKS_PER_SECOND: - *(rtems_interval *)time_buffer = _TOD_Ticks_per_second; + case RTEMS_CLOCK_GET_TICKS_PER_SECOND: { + rtems_interval *interval = (rtems_interval *)time_buffer; + + *interval = TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick; return RTEMS_SUCCESSFUL; + } case RTEMS_CLOCK_GET_TIME_VALUE: { struct timeval *time = (struct timeval *)time_buffer; + if ( !_TOD_Is_set ) return RTEMS_NOT_DEFINED; diff --git a/cpukit/rtems/src/clocktodvalidate.c b/cpukit/rtems/src/clocktodvalidate.c index 09cb5b4092..c9bdf4fd12 100644 --- a/cpukit/rtems/src/clocktodvalidate.c +++ b/cpukit/rtems/src/clocktodvalidate.c @@ -53,7 +53,8 @@ boolean _TOD_Validate( uint32_t days_in_month; if ((!the_tod) || - (the_tod->ticks >= _TOD_Ticks_per_second) || + (the_tod->ticks >= + (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick)) || (the_tod->second >= TOD_SECONDS_PER_MINUTE) || (the_tod->minute >= TOD_MINUTES_PER_HOUR) || (the_tod->hour >= TOD_HOURS_PER_DAY) || diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h index 8de4bb9304..8adbebd99e 100644 --- a/cpukit/score/include/rtems/score/tod.h +++ b/cpukit/score/include/rtems/score/tod.h @@ -145,17 +145,6 @@ SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch; */ SCORE_EXTERN uint32_t _TOD_Microseconds_per_tick; -/** @brief Clock Ticks per Second - * - * The following contains the number of clock ticks per second. - * - * @note If one second is NOT evenly divisible by the number of microseconds - * per clock tick, this value will contain only the integer portion - * of the division. This means that the interval between clock ticks - * can be a source of error in the current time of day. - */ -SCORE_EXTERN uint32_t _TOD_Ticks_per_second; - /** @brief _TOD_Handler_initialization * * This routine performs the initialization necessary for this handler. diff --git a/cpukit/score/inline/rtems/score/tod.inl b/cpukit/score/inline/rtems/score/tod.inl index 733c4e1ede..f132a0723d 100644 --- a/cpukit/score/inline/rtems/score/tod.inl +++ b/cpukit/score/inline/rtems/score/tod.inl @@ -96,9 +96,7 @@ RTEMS_INLINE_ROUTINE void _TOD_Deactivate( void ) * This routine activates updating of the current time of day. */ -RTEMS_INLINE_ROUTINE void _TOD_Activate( - Watchdog_Interval ticks -) +RTEMS_INLINE_ROUTINE void _TOD_Activate() { /* XXX do we need something now that we are using timespec for TOD */ } diff --git a/cpukit/score/src/coretod.c b/cpukit/score/src/coretod.c index 142d8782bc..5c9c935483 100644 --- a/cpukit/score/src/coretod.c +++ b/cpukit/score/src/coretod.c @@ -51,14 +51,7 @@ void _TOD_Handler_initialization( /* Seconds since RTEMS Epoch (1988) */ _TOD_Seconds_since_epoch = 0; - /* Protect ourselves from a divide by zero fault */ - if ( microseconds_per_tick == 0 ) - _TOD_Ticks_per_second = 0; - else - _TOD_Ticks_per_second = - TOD_MICROSECONDS_PER_SECOND / microseconds_per_tick; - /* TOD has not been set */ _TOD_Is_set = FALSE; - _TOD_Activate( _TOD_Ticks_per_second ); + _TOD_Activate(); } |