summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 21:51:52 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-02 21:51:52 +0000
commitf6e09342eea83a34edeb71a140c988a818053a32 (patch)
treee95c73dd531486201f9285b7deac1d4627cbf5d6 /cpukit/posix
parent2007-04-02 Jennifer Averett <jennifer.averrett@oarcorp.com> (diff)
downloadrtems-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.
Diffstat (limited to 'cpukit/posix')
-rw-r--r--cpukit/posix/include/rtems/posix/timer.h45
-rw-r--r--cpukit/posix/src/alarm.c9
-rw-r--r--cpukit/posix/src/posixtimespectointerval.c4
-rw-r--r--cpukit/posix/src/ptimer1.c79
-rw-r--r--cpukit/posix/src/sysconf.c2
-rw-r--r--cpukit/posix/src/ualarm.c10
6 files changed, 52 insertions, 97 deletions
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, &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_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;