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.
This commit is contained in:
Joel Sherrill
2007-04-02 21:51:52 +00:00
parent a6ec372127
commit f6e09342ee
12 changed files with 83 additions and 128 deletions

View File

@@ -1,3 +1,12 @@
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> 2007-04-02 Joel Sherrill <joel@OARcorp.com>
* itron/src/itrontime.c, libcsupport/src/__gettod.c, * itron/src/itrontime.c, libcsupport/src/__gettod.c,

View File

@@ -10,34 +10,35 @@
#define _RTEMS_POSIX_TIMER_H #define _RTEMS_POSIX_TIMER_H
#include <rtems/posix/config.h> #include <rtems/posix/config.h>
/* 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
/* 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
/* /*
* Constants * 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.
#define STATE_FREE_C 0x01 /* Free position of the table of timers */ */
#define STATE_CREATE_NEW_C 0x02 /* Created timer but not running */ #if (POSIX_TIMER_RELATIVE == TIMER_ABSTIME)
#define STATE_CREATE_RUN_C 0x03 /* Created timer and running */ #error "POSIX_TIMER_RELATIVE == TIMER_ABSTIME"
#define STATE_CREATE_STOP_C 0x04 /* Created, ran and stopped timer */ #endif
/* 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
#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 )
/* /*
* Data for a timer * Data for a timer
*/ */
typedef struct { typedef struct {
Objects_Control Object; Objects_Control Object;
Watchdog_Control Timer; /* Internal Timer */ Watchdog_Control Timer; /* Internal Timer */
@@ -57,14 +58,12 @@ typedef struct {
* *
* This routine performs the initialization necessary for this manager. * This routine performs the initialization necessary for this manager.
*/ */
void _POSIX_Timer_Manager_initialization ( int max_timers ); void _POSIX_Timer_Manager_initialization ( int max_timers );
/* /*
* The following defines the information control block used to manage * The following defines the information control block used to manage
* this class of objects. * this class of objects.
*/ */
POSIX_EXTERN Objects_Information _POSIX_Timer_Information; POSIX_EXTERN Objects_Information _POSIX_Timer_Information;
#ifndef __RTEMS_APPLICATION__ #ifndef __RTEMS_APPLICATION__

View File

@@ -69,9 +69,12 @@ unsigned int alarm(
* this. * this.
*/ */
remaining = the_timer->initial - remaining = the_timer->initial;
((the_timer->stop_time - the_timer->start_time) / remaining -= (the_timer->stop_time - the_timer->start_time);
_TOD_Ticks_per_second);
/* remaining is now in ticks */
remaining *= _TOD_Microseconds_per_tick;
remaining /= TOD_MICROSECONDS_PER_SECOND;
break; break;
} }
} }

View File

@@ -28,7 +28,9 @@ Watchdog_Interval _POSIX_Timespec_to_interval(
{ {
Watchdog_Interval ticks; 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) / ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
_TOD_Microseconds_per_tick; _TOD_Microseconds_per_tick;

View File

@@ -67,48 +67,6 @@ boolean _Watchdog_Insert_ticks_helper(
/* #define DEBUG_MESSAGES */ /* #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 * _POSIX_Timer_TSR
* *
@@ -146,10 +104,10 @@ void _POSIX_Timer_TSR(Objects_Id timer, void *data)
_TOD_Get( &ptimer->time ); _TOD_Get( &ptimer->time );
/* The state really did not change but just to be safe */ /* 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 { } else {
/* Indicates that the timer is stopped */ /* 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 */ /* 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; ptimer->thread_id = _Thread_Executing->Object.id;
if ( evp != NULL ) { if ( evp != NULL ) {
@@ -274,7 +232,7 @@ int timer_delete(
case OBJECTS_LOCAL: case OBJECTS_LOCAL:
_Objects_Close( &_POSIX_Timer_Information, &ptimer->Object ); _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object );
ptimer->state = STATE_FREE_C; ptimer->state = POSIX_TIMER_STATE_FREE;
(void) _Watchdog_Remove( &ptimer->Timer ); (void) _Watchdog_Remove( &ptimer->Timer );
_POSIX_Timer_Free( ptimer ); _POSIX_Timer_Free( ptimer );
_Thread_Enable_dispatch(); _Thread_Enable_dispatch();
@@ -308,15 +266,15 @@ int timer_settime(
} }
/* First, it verifies if the structure "value" is correct */ /* First, it verifies if the structure "value" is correct */
if ( ( value->it_value.tv_nsec > MAX_NSEC_C ) || if ( ( value->it_value.tv_nsec > TOD_NANOSECONDS_PER_SECOND ) ||
( value->it_value.tv_nsec < MIN_NSEC_C ) ) { ( value->it_value.tv_nsec < 0 ) ) {
/* The number of nanoseconds is not correct */ /* The number of nanoseconds is not correct */
rtems_set_errno_and_return_minus_one( EINVAL ); rtems_set_errno_and_return_minus_one( EINVAL );
} }
/* XXX check for seconds in the past */ /* 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 ); rtems_set_errno_and_return_minus_one( EINVAL );
} }
@@ -348,7 +306,7 @@ int timer_settime(
/* The new data are set */ /* The new data are set */
ptimer->timer_data = *value; ptimer->timer_data = *value;
/* Indicates that the timer is created and stopped */ /* Indicates that the timer is created and stopped */
ptimer->state = STATE_CREATE_STOP_C; ptimer->state = POSIX_TIMER_STATE_CREATE_STOP;
/* Returns with success */ /* Returns with success */
_Thread_Enable_dispatch(); _Thread_Enable_dispatch();
return 0; return 0;
@@ -361,11 +319,6 @@ int timer_settime(
/* The fire time is absolute: use "rtems_time_fire_when" */ /* The fire time is absolute: use "rtems_time_fire_when" */
/* First, it converts from struct itimerspec to rtems_time_of_day */ /* 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( _Watchdog_Initialize(
&ptimer->Timer, _POSIX_Timer_TSR, ptimer->Object.id, ptimer ); &ptimer->Timer, _POSIX_Timer_TSR, ptimer->Object.id, ptimer );
@@ -380,7 +333,7 @@ int timer_settime(
ptimer->timer_data = *value; ptimer->timer_data = *value;
/* Indicate that the time is running */ /* 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 */ /* Stores the time in which the timer was started again */
_TOD_Get( &ptimer->time ); _TOD_Get( &ptimer->time );
@@ -389,15 +342,10 @@ int timer_settime(
break; break;
/* The fire time is relative: use "rtems_time_fire_after" */ /* 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 */ /* First, convert from seconds and nanoseconds to ticks */
ptimer->ticks = ( SEC_TO_TICKS_C * value->it_value.tv_sec ) + ptimer->ticks = _POSIX_Timespec_to_interval( &value->it_value );
( value->it_value.tv_nsec / (NSEC_PER_SEC_C / SEC_TO_TICKS_C));
#if 0
status = rtems_timer_fire_after(
ptimer->timer_id, ptimer->ticks, _POSIX_Timer_TSR, ptimer );
#endif
activated = _Watchdog_Insert_ticks_helper( activated = _Watchdog_Insert_ticks_helper(
&ptimer->Timer, &ptimer->Timer,
ptimer->ticks, ptimer->ticks,
@@ -415,7 +363,7 @@ int timer_settime(
ptimer->timer_data = *value; ptimer->timer_data = *value;
/* Indicate that the time is running */ /* Indicate that the time is running */
ptimer->state = STATE_CREATE_RUN_C; ptimer->state = POSIX_TIMER_STATE_CREATE_RUN;
_TOD_Get( &ptimer->time ); _TOD_Get( &ptimer->time );
_Thread_Enable_dispatch(); _Thread_Enable_dispatch();
return 0; return 0;
@@ -474,7 +422,8 @@ int timer_gettime(
/* Calculates the time left before the timer finishes */ /* Calculates the time left before the timer finishes */
_POSIX_Timespec_subtract(&ptimer->timer_data.it_value, &current_time, &value->it_value); _POSIX_Timespec_subtract(
&ptimer->timer_data.it_value, &current_time, &value->it_value);
value->it_interval.tv_sec = ptimer->timer_data.it_interval.tv_sec; value->it_interval.tv_sec = ptimer->timer_data.it_interval.tv_sec;
value->it_interval.tv_nsec = ptimer->timer_data.it_interval.tv_nsec; value->it_interval.tv_nsec = ptimer->timer_data.it_interval.tv_nsec;

View File

@@ -27,7 +27,7 @@ long sysconf(
switch (name) { switch (name) {
case _SC_CLK_TCK: case _SC_CLK_TCK:
return _TOD_Ticks_per_second; return (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick);
case _SC_OPEN_MAX: { case _SC_OPEN_MAX: {
extern uint32_t rtems_libio_number_iops; extern uint32_t rtems_libio_number_iops;

View File

@@ -73,10 +73,12 @@ useconds_t ualarm(
* this. * this.
*/ */
ticks = the_timer->initial;
ticks = the_timer->initial - ticks -= (the_timer->stop_time - the_timer->start_time);
((the_timer->stop_time - the_timer->start_time) /
_TOD_Ticks_per_second); /* remaining is now in ticks */
ticks *= _TOD_Microseconds_per_tick;
ticks /= TOD_MICROSECONDS_PER_SECOND;
_POSIX_Interval_to_timespec( ticks, &tp ); _POSIX_Interval_to_timespec( ticks, &tp );
remaining = tp.tv_sec * TOD_MICROSECONDS_PER_SECOND; remaining = tp.tv_sec * TOD_MICROSECONDS_PER_SECOND;

View File

@@ -75,23 +75,33 @@ rtems_status_code rtems_clock_get(
return RTEMS_SUCCESSFUL; 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 ) if ( !_TOD_Is_set )
return RTEMS_NOT_DEFINED; return RTEMS_NOT_DEFINED;
*(rtems_interval *)time_buffer = _TOD_Seconds_since_epoch; *interval = _TOD_Seconds_since_epoch;
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;
}
case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT: case RTEMS_CLOCK_GET_TICKS_SINCE_BOOT: {
*(rtems_interval *)time_buffer = _Watchdog_Ticks_since_boot; rtems_interval *interval = (rtems_interval *)time_buffer;
return RTEMS_SUCCESSFUL;
case RTEMS_CLOCK_GET_TICKS_PER_SECOND: *interval = _Watchdog_Ticks_since_boot;
*(rtems_interval *)time_buffer = _TOD_Ticks_per_second;
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;
}
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: { case RTEMS_CLOCK_GET_TIME_VALUE: {
struct timeval *time = (struct timeval *)time_buffer; struct timeval *time = (struct timeval *)time_buffer;
if ( !_TOD_Is_set ) if ( !_TOD_Is_set )
return RTEMS_NOT_DEFINED; return RTEMS_NOT_DEFINED;

View File

@@ -53,7 +53,8 @@ boolean _TOD_Validate(
uint32_t days_in_month; uint32_t days_in_month;
if ((!the_tod) || 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->second >= TOD_SECONDS_PER_MINUTE) ||
(the_tod->minute >= TOD_MINUTES_PER_HOUR) || (the_tod->minute >= TOD_MINUTES_PER_HOUR) ||
(the_tod->hour >= TOD_HOURS_PER_DAY) || (the_tod->hour >= TOD_HOURS_PER_DAY) ||

View File

@@ -145,17 +145,6 @@ SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch;
*/ */
SCORE_EXTERN uint32_t _TOD_Microseconds_per_tick; 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 /** @brief _TOD_Handler_initialization
* *
* This routine performs the initialization necessary for this handler. * This routine performs the initialization necessary for this handler.

View File

@@ -96,9 +96,7 @@ RTEMS_INLINE_ROUTINE void _TOD_Deactivate( void )
* This routine activates updating of the current time of day. * This routine activates updating of the current time of day.
*/ */
RTEMS_INLINE_ROUTINE void _TOD_Activate( RTEMS_INLINE_ROUTINE void _TOD_Activate()
Watchdog_Interval ticks
)
{ {
/* XXX do we need something now that we are using timespec for TOD */ /* XXX do we need something now that we are using timespec for TOD */
} }

View File

@@ -51,14 +51,7 @@ void _TOD_Handler_initialization(
/* Seconds since RTEMS Epoch (1988) */ /* Seconds since RTEMS Epoch (1988) */
_TOD_Seconds_since_epoch = 0; _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 has not been set */
_TOD_Is_set = FALSE; _TOD_Is_set = FALSE;
_TOD_Activate( _TOD_Ticks_per_second ); _TOD_Activate();
} }