summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-05 21:17:27 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-04-05 21:17:27 +0000
commit412dbff629308745d967718fbd91e272c91b055c (patch)
tree7fb92204e9ab59173a92e8950d633cc4b39e16ac /cpukit
parent2007-04-05 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-412dbff629308745d967718fbd91e272c91b055c.tar.bz2
2007-04-05 Joel Sherrill <joel@OARcorp.com>
* posix/Makefile.am, posix/include/rtems/posix/time.h, posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c, posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/pthread.c, posix/src/pthreadcreate.c, posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c, posix/src/sched.c, posix/src/semtimedwait.c, posix/src/sigtimedwait.c, posix/src/ualarm.c, rtems/src/clocktodtoseconds.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c, score/src/coretodget.c, score/src/coretodgetuptime.c, score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec manipulation routines in the SuperCore. Use them everywhere possible. This lead to significant cleanup in the API routines and eliminated some of the same code from the POSIX API. At this point, the SuperCore keeps time in POSIX timespec format properly from 1970. You just cannot set it before 1988 in keeping with RTEMS traditional behavior. * score/include/rtems/score/timespec.h, score/src/timespecaddto.c, score/src/timespecfromticks.c, score/src/timespecisvalid.c, score/src/timespeclessthan.c, score/src/timespecsubtract.c, score/src/timespectoticks.c: New files. * posix/src/posixintervaltotimespec.c, posix/src/posixtimespecsubtract.c, posix/src/posixtimespectointerval.c: Removed.
Diffstat (limited to '')
-rw-r--r--cpukit/ChangeLog30
-rw-r--r--cpukit/posix/Makefile.am3
-rw-r--r--cpukit/posix/include/rtems/posix/time.h43
-rw-r--r--cpukit/posix/src/adjtime.c26
-rw-r--r--cpukit/posix/src/alarm.c15
-rw-r--r--cpukit/posix/src/clockgetres.c13
-rw-r--r--cpukit/posix/src/condtimedwait.c34
-rw-r--r--cpukit/posix/src/mqueuetimedreceive.c11
-rw-r--r--cpukit/posix/src/mqueuetimedsend.c11
-rw-r--r--cpukit/posix/src/mutextimedlock.c14
-rw-r--r--cpukit/posix/src/nanosleep.c37
-rw-r--r--cpukit/posix/src/posixtimespecabsolutetimeout.c39
-rw-r--r--cpukit/posix/src/posixtimespecsubtract.c58
-rw-r--r--cpukit/posix/src/posixtimespectointerval.c41
-rw-r--r--cpukit/posix/src/pthread.c11
-rw-r--r--cpukit/posix/src/pthreadcreate.c11
-rw-r--r--cpukit/posix/src/pthreadsetschedparam.c9
-rw-r--r--cpukit/posix/src/ptimer1.c21
-rw-r--r--cpukit/posix/src/sched.c11
-rw-r--r--cpukit/posix/src/semtimedwait.c27
-rw-r--r--cpukit/posix/src/sigtimedwait.c15
-rw-r--r--cpukit/posix/src/ualarm.c12
-rw-r--r--cpukit/rtems/src/clocktodtoseconds.c3
-rw-r--r--cpukit/score/Makefile.am12
-rw-r--r--cpukit/score/include/rtems/score/timespec.h130
-rw-r--r--cpukit/score/include/rtems/score/tod.h13
-rw-r--r--cpukit/score/inline/rtems/score/tod.inl28
-rw-r--r--cpukit/score/preinstall.am4
-rw-r--r--cpukit/score/src/coretod.c9
-rw-r--r--cpukit/score/src/coretodget.c3
-rw-r--r--cpukit/score/src/coretodgetuptime.c8
-rw-r--r--cpukit/score/src/coretodset.c15
-rw-r--r--cpukit/score/src/coretodtickle.c11
-rw-r--r--cpukit/score/src/timespecaddto.c51
-rw-r--r--cpukit/score/src/timespecfromticks.c (renamed from cpukit/posix/src/posixintervaltotimespec.c)25
-rw-r--r--cpukit/score/src/timespecisvalid.c43
-rw-r--r--cpukit/score/src/timespeclessthan.c42
-rw-r--r--cpukit/score/src/timespecsubtract.c41
-rw-r--r--cpukit/score/src/timespectoticks.c49
39 files changed, 645 insertions, 334 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index f158538554..8102018513 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,3 +1,33 @@
+2007-04-05 Joel Sherrill <joel@OARcorp.com>
+
+ * posix/Makefile.am, posix/include/rtems/posix/time.h,
+ posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c,
+ posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c,
+ posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c,
+ posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c,
+ posix/src/pthread.c, posix/src/pthreadcreate.c,
+ posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c,
+ posix/src/sched.c, posix/src/semtimedwait.c,
+ posix/src/sigtimedwait.c, posix/src/ualarm.c,
+ rtems/src/clocktodtoseconds.c, score/Makefile.am,
+ score/preinstall.am, score/include/rtems/score/tod.h,
+ score/inline/rtems/score/tod.inl, score/src/coretod.c,
+ score/src/coretodget.c, score/src/coretodgetuptime.c,
+ score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec
+ manipulation routines in the SuperCore. Use them everywhere possible.
+ This lead to significant cleanup in the API routines and eliminated
+ some of the same code from the POSIX API. At this point, the
+ SuperCore keeps time in POSIX timespec format properly from 1970. You
+ just cannot set it before 1988 in keeping with RTEMS traditional
+ behavior.
+ * score/include/rtems/score/timespec.h, score/src/timespecaddto.c,
+ score/src/timespecfromticks.c, score/src/timespecisvalid.c,
+ score/src/timespeclessthan.c, score/src/timespecsubtract.c,
+ score/src/timespectoticks.c: New files.
+ * posix/src/posixintervaltotimespec.c,
+ posix/src/posixtimespecsubtract.c,
+ posix/src/posixtimespectointerval.c: Removed.
+
2007-04-04 Joel Sherrill <joel@OARcorp.com>
* score/Makefile.am, score/include/rtems/score/tod.h,
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index 271925d97a..df21ab3fd4 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -144,8 +144,7 @@ libposix_a_SOURCES += src/pspin.c src/pspindestroy.c src/pspininit.c \
src/pspinunlock.c
## TIME_C_FILES
-libposix_a_SOURCES += src/adjtime.c src/posixtimespecsubtract.c \
- src/posixtimespectointerval.c src/posixintervaltotimespec.c \
+libposix_a_SOURCES += src/adjtime.c \
src/posixtimespecabsolutetimeout.c src/clockgetcpuclockid.c \
src/clockgetenableattr.c src/clockgetres.c src/clockgettime.c \
src/clocksetenableattr.c src/clocksettime.c src/nanosleep.c src/sleep.c \
diff --git a/cpukit/posix/include/rtems/posix/time.h b/cpukit/posix/include/rtems/posix/time.h
index 09a60aa428..8f4d4b6257 100644
--- a/cpukit/posix/include/rtems/posix/time.h
+++ b/cpukit/posix/include/rtems/posix/time.h
@@ -3,7 +3,12 @@
*/
/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
@@ -11,43 +16,7 @@
#ifndef _RTEMS_POSIX_TIME_H
#define _RTEMS_POSIX_TIME_H
-#include <rtems/score/tod.h>
-
-/*
- * Seconds from January 1, 1970 to January 1, 1988. Used to account for
- * differences between POSIX API and RTEMS core.
- *
- * XXX probably able to be removed once core switches completely to timespec
- * XXX for current TOD.
- */
-#define POSIX_TIME_SECONDS_1970_THROUGH_1988 TOD_SECONDS_1970_THROUGH_1988
-
-/*
- * _POSIX_Timespec_subtract
- */
-
-void _POSIX_Timespec_subtract(
- const struct timespec *the_start,
- const struct timespec *end,
- struct timespec *result
-);
-
-/*
- * _POSIX_Timespec_to_interval
- */
-
-Watchdog_Interval _POSIX_Timespec_to_interval(
- const struct timespec *time
-);
-
-/*
- * _POSIX_Interval_to_timespec
- */
-
-void _POSIX_Interval_to_timespec(
- Watchdog_Interval ticks,
- struct timespec *time
-);
+#include <rtems/score/timespec.h>
/*
* _POSIX_Absolute_timeout_to_ticks
diff --git a/cpukit/posix/src/adjtime.c b/cpukit/posix/src/adjtime.c
index 1e06dab608..e8743181aa 100644
--- a/cpukit/posix/src/adjtime.c
+++ b/cpukit/posix/src/adjtime.c
@@ -1,8 +1,17 @@
/*
- * adjustime() function - required by NTP
+ * adjime() function - required by NTP
*
* I am unaware of the history behind the definition of this service
* and don't know if its behavior is covered by any standard. --joel
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
@@ -32,16 +41,19 @@ int adjtime ( struct timeval *delta, struct timeval *olddelta )
if ( !delta )
return -1;
- __adjustment = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND) + delta->tv_usec;
+ /* convert delta to microseconds */
+ __adjustment = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND);
+ __adjustment += delta->tv_usec;
+
/* too small to account for */
if ( __adjustment < _TOD_Microseconds_per_tick )
return 0;
- clock_gettime( CLOCK_REALTIME, &ts );
+ /* Grab the current TOD */
+ _TOD_Get( &ts );
- ts.tv_sec += (__adjustment / TOD_MICROSECONDS_PER_SECOND);
- ts.tv_nsec += (__adjustment % TOD_MICROSECONDS_PER_SECOND) *
- TOD_NANOSECONDS_PER_MICROSECOND;
+ ts.tv_sec += delta->tv_sec;
+ ts.tv_nsec += delta->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;
/* if adjustment is too much positive */
while ( ts.tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
@@ -55,6 +67,6 @@ int adjtime ( struct timeval *delta, struct timeval *olddelta )
ts.tv_sec--;
}
- clock_settime( CLOCK_REALTIME, &ts );
+ _TOD_Set( &ts );
return 0;
}
diff --git a/cpukit/posix/src/alarm.c b/cpukit/posix/src/alarm.c
index 71097554c7..1f3151b919 100644
--- a/cpukit/posix/src/alarm.c
+++ b/cpukit/posix/src/alarm.c
@@ -1,7 +1,8 @@
/*
* 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
- *
- * COPYRIGHT (c) 1989-1999.
+ */
+
+/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -16,7 +17,6 @@
#endif
#include <pthread.h>
-/* #include <errno.h> */
#include <rtems/system.h>
#include <rtems/posix/pthread.h>
@@ -69,12 +69,9 @@ unsigned int alarm(
* this.
*/
- 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;
+ remaining = the_timer->initial -
+ ((the_timer->stop_time - the_timer->start_time) /
+ TOD_TICKS_PER_SECOND);
break;
}
}
diff --git a/cpukit/posix/src/clockgetres.c b/cpukit/posix/src/clockgetres.c
index 936e35ab74..9c5f1be925 100644
--- a/cpukit/posix/src/clockgetres.c
+++ b/cpukit/posix/src/clockgetres.c
@@ -2,6 +2,17 @@
* $Id$
*/
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
#if HAVE_CONFIG_H
#include "config.h"
#endif
@@ -42,7 +53,7 @@ int clock_getres(
if ( res ) {
res->tv_sec = _TOD_Microseconds_per_tick / 1000000;
res->tv_nsec = _TOD_Microseconds_per_tick * 1000;
- /* _POSIX_Interval_to_timespec( _TOD_Microseconds_per_tick, res ); */
+ /* _TOD_From_ticks( _TOD_Microseconds_per_tick, res ); */
}
break;
diff --git a/cpukit/posix/src/condtimedwait.c b/cpukit/posix/src/condtimedwait.c
index 32ce1d4a05..717851a8c8 100644
--- a/cpukit/posix/src/condtimedwait.c
+++ b/cpukit/posix/src/condtimedwait.c
@@ -2,6 +2,17 @@
* $Id$
*/
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
#if HAVE_CONFIG_H
#include "config.h"
#endif
@@ -33,24 +44,27 @@ int pthread_cond_timedwait(
struct timespec difference;
boolean already_timedout = FALSE;
- if ( !abstime )
+ if ( !_Timespec_Is_valid(abstime) )
return EINVAL;
/*
* The abstime is a walltime. We turn it into an interval.
*/
- (void) clock_gettime( CLOCK_REALTIME, &current_time );
+ _TOD_Get( &current_time );
- /* XXX probably some error checking should go here */
-
- _POSIX_Timespec_subtract( &current_time, abstime, &difference );
-
- if ( ( difference.tv_sec < 0 ) || ( ( difference.tv_sec == 0 ) &&
- ( difference.tv_nsec < 0 ) ) )
+ /*
+ * Make sure the timeout is in the future
+ */
+ if ( _Timespec_Less_than( abstime, &current_time ) ) {
already_timedout = TRUE;
-
- timeout = _POSIX_Timespec_to_interval( &difference );
+ difference.tv_sec = 0;
+ difference.tv_nsec = 0;
+ timeout = 0;
+ } else {
+ _Timespec_Subtract( &current_time, abstime, &difference );
+ timeout = _Timespec_To_ticks( &difference );
+ }
return _POSIX_Condition_variables_Wait_support(
cond,
diff --git a/cpukit/posix/src/mqueuetimedreceive.c b/cpukit/posix/src/mqueuetimedreceive.c
index 2ad5f4c6d6..493ac7aa66 100644
--- a/cpukit/posix/src/mqueuetimedreceive.c
+++ b/cpukit/posix/src/mqueuetimedreceive.c
@@ -10,6 +10,15 @@
*
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
* time.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
@@ -52,6 +61,6 @@ ssize_t mq_timedreceive(
msg_ptr,
msg_len,
msg_prio,
- _POSIX_Timespec_to_interval( timeout )
+ _Timespec_To_ticks( timeout )
);
}
diff --git a/cpukit/posix/src/mqueuetimedsend.c b/cpukit/posix/src/mqueuetimedsend.c
index 89569368be..262bf8baa9 100644
--- a/cpukit/posix/src/mqueuetimedsend.c
+++ b/cpukit/posix/src/mqueuetimedsend.c
@@ -10,6 +10,15 @@
*
* This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
* time.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
@@ -52,6 +61,6 @@ int mq_timedsend(
msg_ptr,
msg_len,
msg_prio,
- _POSIX_Timespec_to_interval( timeout )
+ _Timespec_To_ticks( timeout )
);
}
diff --git a/cpukit/posix/src/mutextimedlock.c b/cpukit/posix/src/mutextimedlock.c
index e86c3040dd..85a1782114 100644
--- a/cpukit/posix/src/mutextimedlock.c
+++ b/cpukit/posix/src/mutextimedlock.c
@@ -1,4 +1,15 @@
/*
+ * Mutex Timed Lock
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
* $Id$
*/
@@ -31,9 +42,10 @@ int pthread_mutex_timedlock(
const struct timespec *timeout
)
{
+ /* XXX does timeout need to be based on CLOCK_REALTIME and be TOD? */
return _POSIX_Mutex_Lock_support(
mutex,
TRUE,
- _POSIX_Timespec_to_interval( timeout )
+ _Timespec_To_ticks( timeout )
);
}
diff --git a/cpukit/posix/src/nanosleep.c b/cpukit/posix/src/nanosleep.c
index 47f7cbad0e..bca61ad709 100644
--- a/cpukit/posix/src/nanosleep.c
+++ b/cpukit/posix/src/nanosleep.c
@@ -1,4 +1,11 @@
/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
* $Id$
*/
@@ -28,41 +35,25 @@ int nanosleep(
)
{
Watchdog_Interval ticks;
- struct timespec *the_rqtp;
- if ( !rqtp )
+ if ( !_Timespec_Is_valid( rqtp ) )
rtems_set_errno_and_return_minus_one( EINVAL );
- the_rqtp = (struct timespec *)rqtp;
-
/*
- * Return EAGAIN if the delay interval is negative.
+ * Return EINVAL if the delay interval is negative.
*
* NOTE: This behavior is beyond the POSIX specification.
- * FSU pthreads shares this behavior.
+ * FSU and GNU/Linux pthreads shares this behavior.
*/
-
- if ( the_rqtp->tv_sec < 0 )
- the_rqtp->tv_sec = 0;
-
- if ( /* the_rqtp->tv_sec < 0 || */ the_rqtp->tv_nsec < 0 )
- rtems_set_errno_and_return_minus_one( EAGAIN );
-
- if ( the_rqtp->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
+ if ( rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 )
rtems_set_errno_and_return_minus_one( EINVAL );
- ticks = _POSIX_Timespec_to_interval( the_rqtp );
-
- /*
- * Bump the ticks by one so the delay is at least the number of
- * ticks requested
- */
- ticks++;
+ ticks = _Timespec_To_ticks( rqtp );
/*
* A nanosleep for zero time is implemented as a yield.
* This behavior is also beyond the POSIX specification but is
- * consistent with the RTEMS api and yields desirable behavior.
+ * consistent with the RTEMS API and yields desirable behavior.
*/
if ( !ticks ) {
@@ -99,7 +90,7 @@ int nanosleep(
ticks -=
_Thread_Executing->Timer.stop_time - _Thread_Executing->Timer.start_time;
- _POSIX_Interval_to_timespec( ticks, rmtp );
+ _Timespec_From_ticks( ticks, rmtp );
/*
* If there is time remaining, then we were interrupted by a signal.
diff --git a/cpukit/posix/src/posixtimespecabsolutetimeout.c b/cpukit/posix/src/posixtimespecabsolutetimeout.c
index df70c90533..52208e380b 100644
--- a/cpukit/posix/src/posixtimespecabsolutetimeout.c
+++ b/cpukit/posix/src/posixtimespecabsolutetimeout.c
@@ -1,5 +1,14 @@
/*
* Convert abstime timeout to ticks
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
@@ -30,39 +39,23 @@ int _POSIX_Absolute_timeout_to_ticks(
Watchdog_Interval *ticks_out
)
{
- struct timespec current_time;
- struct timespec difference;
-
- if ( !abstime )
- return EINVAL;
+ struct timespec current_time;
+ struct timespec difference;
- /*
- * Error check the absolute time to timeout
- */
-#if 0
- /* they are unsigned so this is impossible */
- if ( abstime->tv_sec < 0 || abstime->tv_nsec < 0 )
+ if ( !_Timespec_Is_valid(abstime) )
return EINVAL;
-#endif
- if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
- return EINVAL;
-
- (void) clock_gettime( CLOCK_REALTIME, &current_time );
+ _TOD_Get( &current_time );
/*
* Make sure the abstime is in the future
*/
- if ( abstime->tv_sec < current_time.tv_sec )
- return EINVAL;
-
- if ( (abstime->tv_sec == current_time.tv_sec) &&
- (abstime->tv_nsec <= current_time.tv_nsec) )
+ if ( _Timespec_Less_than( abstime, &current_time ) )
return EINVAL;
- _POSIX_Timespec_subtract( &current_time, abstime, &difference );
+ _Timespec_Subtract( &current_time, abstime, &difference );
- *ticks_out = _POSIX_Timespec_to_interval( &difference );
+ *ticks_out = _Timespec_To_ticks( &difference );
return 0;
}
diff --git a/cpukit/posix/src/posixtimespecsubtract.c b/cpukit/posix/src/posixtimespecsubtract.c
deleted file mode 100644
index a2cce2a332..0000000000
--- a/cpukit/posix/src/posixtimespecsubtract.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * $Id$
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <time.h>
-#include <errno.h>
-
-#include <rtems/system.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/tod.h>
-
-#include <rtems/seterr.h>
-#include <rtems/posix/time.h>
-
-/*PAGE
- *
- * _POSIX_Timespec_subtract
- */
-
-void _POSIX_Timespec_subtract(
- const struct timespec *start,
- const struct timespec *end,
- struct timespec *result
-)
-{
-#if 0
- struct timespec start_struct = *the_start;
- struct timespec *start = &start_struct;
- uint32_t nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND;
-
- if (end->tv_nsec < start->tv_nsec) {
- int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1;
- start->tv_nsec -= nsecs_per_sec * seconds;
- start->tv_sec += seconds;
- }
-
- if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) {
- int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec;
- start->tv_nsec += nsecs_per_sec * seconds;
- start->tv_sec -= seconds;
- }
-#else
-
-#endif
-
- if (end->tv_nsec < start->tv_nsec) {
- result->tv_sec = end->tv_sec - start->tv_sec - 1;
- result->tv_nsec = (TOD_NANOSECONDS_PER_SECOND - start->tv_nsec) + end->tv_nsec;
- } else {
- result->tv_sec = end->tv_sec - start->tv_sec;
- result->tv_nsec = end->tv_nsec - start->tv_nsec;
- }
-}
diff --git a/cpukit/posix/src/posixtimespectointerval.c b/cpukit/posix/src/posixtimespectointerval.c
deleted file mode 100644
index 92be3e508f..0000000000
--- a/cpukit/posix/src/posixtimespectointerval.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * $Id$
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <time.h>
-#include <errno.h>
-
-#include <rtems/system.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/tod.h>
-
-#include <rtems/seterr.h>
-#include <rtems/posix/time.h>
-
-/*PAGE
- *
- * _POSIX_Timespec_to_interval
- */
-
-Watchdog_Interval _POSIX_Timespec_to_interval(
- const struct timespec *time
-)
-{
- Watchdog_Interval ticks;
-
- ticks = time->tv_sec *
- (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick);
-
- ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
- _TOD_Microseconds_per_tick;
-
- if (ticks)
- return ticks;
-
- return 1;
-}
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index bbd7a73a9e..9b04b5bfdf 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -1,4 +1,11 @@
/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
* $Id$
*/
@@ -70,7 +77,7 @@ void _POSIX_Threads_Sporadic_budget_TSR(
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- ticks = _POSIX_Timespec_to_interval( &api->schedparam.ss_initial_budget );
+ ticks = _Timespec_To_ticks( &api->schedparam.ss_initial_budget );
if ( !ticks )
ticks = 1;
@@ -84,7 +91,7 @@ void _POSIX_Threads_Sporadic_budget_TSR(
the_thread->current_priority > new_priority )
_Thread_Change_priority( the_thread, new_priority, TRUE );
- ticks = _POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period );
+ ticks = _Timespec_To_ticks( &api->schedparam.ss_replenish_period );
if ( !ticks )
ticks = 1;
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 61a59c01f8..b2b1ed128b 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -1,7 +1,8 @@
/*
* 16.1.2 Thread Creation, P1003.1c/Draft 10, p. 144
- *
- * COPYRIGHT (c) 1989-1999.
+ */
+
+/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -126,8 +127,8 @@ int pthread_create(
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
budget_callout = _POSIX_Threads_Sporadic_budget_callout;
- if ( _POSIX_Timespec_to_interval( &schedparam.ss_replenish_period ) <
- _POSIX_Timespec_to_interval( &schedparam.ss_initial_budget ) )
+ if ( _Timespec_To_ticks( &schedparam.ss_replenish_period ) <
+ _Timespec_To_ticks( &schedparam.ss_initial_budget ) )
return EINVAL;
if ( !_POSIX_Priority_Is_valid( schedparam.ss_low_priority ) )
@@ -230,7 +231,7 @@ int pthread_create(
if ( schedpolicy == SCHED_SPORADIC ) {
_Watchdog_Insert_ticks(
&api->Sporadic_timer,
- _POSIX_Timespec_to_interval( &api->schedparam.ss_replenish_period )
+ _Timespec_To_ticks( &api->schedparam.ss_replenish_period )
);
}
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 3413dbfc74..63b45f8669 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -1,8 +1,9 @@
/*
* 13.5.2 Dynamic Thread Scheduling Parameters Access,
* P1003.1c/Draft 10, p. 124
- *
- * COPYRIGHT (c) 1989-1999.
+ */
+
+/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -66,8 +67,8 @@ int pthread_setschedparam(
budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_CALLOUT;
budget_callout = _POSIX_Threads_Sporadic_budget_callout;
- if ( _POSIX_Timespec_to_interval( &param->ss_replenish_period ) <
- _POSIX_Timespec_to_interval( &param->ss_initial_budget ) )
+ if ( _Timespec_To_ticks( &param->ss_replenish_period ) <
+ _Timespec_To_ticks( &param->ss_initial_budget ) )
return EINVAL;
if ( !_POSIX_Priority_Is_valid( param->ss_low_priority ) )
diff --git a/cpukit/posix/src/ptimer1.c b/cpukit/posix/src/ptimer1.c
index 9a63441f52..2ee201ddda 100644
--- a/cpukit/posix/src/ptimer1.c
+++ b/cpukit/posix/src/ptimer1.c
@@ -1,5 +1,12 @@
/*
- * ptimer.c,v 1.1 1996/06/03 16:29:58 joel Exp
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
*/
#if HAVE_CONFIG_H
@@ -344,7 +351,7 @@ int timer_settime(
/* The fire time is relative: use "rtems_time_fire_after" */
case POSIX_TIMER_RELATIVE:
/* First, convert from seconds and nanoseconds to ticks */
- ptimer->ticks = _POSIX_Timespec_to_interval( &value->it_value );
+ ptimer->ticks = _Timespec_To_ticks( &value->it_value );
activated = _Watchdog_Insert_ticks_helper(
&ptimer->Timer,
@@ -422,11 +429,13 @@ int timer_gettime(
/* Calculates the time left before the timer finishes */
- _POSIX_Timespec_subtract(
- &ptimer->timer_data.it_value, &current_time, &value->it_value);
+ _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;
+ value->it_interval = ptimer->timer_data.it_interval;
_Thread_Enable_dispatch();
return 0;
diff --git a/cpukit/posix/src/sched.c b/cpukit/posix/src/sched.c
index 825294e056..c298655dc7 100644
--- a/cpukit/posix/src/sched.c
+++ b/cpukit/posix/src/sched.c
@@ -1,4 +1,11 @@
/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
* $Id$
*/
@@ -126,8 +133,6 @@ int sched_rr_get_interval(
struct timespec *interval
)
{
- /* XXX do we need to support different time quantums per thread */
-
/*
* Only supported for the "calling process" (i.e. this node).
*/
@@ -138,7 +143,7 @@ int sched_rr_get_interval(
if ( !interval )
rtems_set_errno_and_return_minus_one( EINVAL );
- _POSIX_Interval_to_timespec( _Thread_Ticks_per_timeslice, interval );
+ _Timespec_From_ticks( _Thread_Ticks_per_timeslice, interval );
return 0;
}
diff --git a/cpukit/posix/src/semtimedwait.c b/cpukit/posix/src/semtimedwait.c
index 662845ecd9..6b93b9232b 100644
--- a/cpukit/posix/src/semtimedwait.c
+++ b/cpukit/posix/src/semtimedwait.c
@@ -1,4 +1,11 @@
/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
* $Id$
*/
@@ -43,26 +50,18 @@ int sem_timedwait(
/*
* Error check the absolute time to timeout
*/
-#if 0
- if ( /* abstime->tv_sec < 0 || */ abstime->tv_nsec ) /* tv_sec is unsigned */
+ if ( !_Timespec_Is_valid( abstime ) ) {
blocking = CORE_SEMAPHORE_BAD_TIMEOUT_VALUE;
- else
-#endif
- if ( abstime->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
- blocking = CORE_SEMAPHORE_BAD_TIMEOUT;
} else {
- clock_gettime( CLOCK_REALTIME, &current_time );
+ _TOD_Get( &current_time );
/*
* Make sure the abstime is in the future
*/
- if ( abstime->tv_sec < current_time.tv_sec )
- blocking = CORE_SEMAPHORE_BAD_TIMEOUT;
- else if ( (abstime->tv_sec == current_time.tv_sec) &&
- (abstime->tv_nsec <= current_time.tv_nsec) )
+ if ( _Timespec_Less_than( abstime, &current_time ) ) {
blocking = CORE_SEMAPHORE_BAD_TIMEOUT;
- else {
- _POSIX_Timespec_subtract( &current_time, abstime, &difference );
- ticks = _POSIX_Timespec_to_interval( &difference );
+ } else {
+ _Timespec_Subtract( &current_time, abstime, &difference );
+ ticks = _Timespec_To_ticks( &difference );
blocking = CORE_SEMAPHORE_BLOCK_WITH_TIMEOUT;
}
}
diff --git a/cpukit/posix/src/sigtimedwait.c b/cpukit/posix/src/sigtimedwait.c
index 1486be3054..311e6cc90a 100644
--- a/cpukit/posix/src/sigtimedwait.c
+++ b/cpukit/posix/src/sigtimedwait.c
@@ -1,7 +1,7 @@
/*
* 3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -68,12 +68,11 @@ int sigtimedwait(
interval = 0;
if ( timeout ) {
- if ( timeout->tv_nsec < 0 ||
- timeout->tv_nsec >= TOD_NANOSECONDS_PER_SECOND) {
+ if ( !_Timespec_Is_valid( timeout ) ) {
rtems_set_errno_and_return_minus_one( EINVAL );
}
- interval = _POSIX_Timespec_to_interval( timeout );
+ interval = _Timespec_To_ticks( timeout );
}
/*
@@ -96,7 +95,13 @@ int sigtimedwait(
if ( *set & api->signals_pending ) {
/* XXX real info later */
the_info->si_signo = _POSIX_signals_Get_highest( api->signals_pending );
- _POSIX_signals_Clear_signals( api, the_info->si_signo, the_info, FALSE, FALSE );
+ _POSIX_signals_Clear_signals(
+ api,
+ the_info->si_signo,
+ the_info,
+ FALSE,
+ FALSE
+ );
_ISR_Enable( level );
the_info->si_code = SI_USER;
diff --git a/cpukit/posix/src/ualarm.c b/cpukit/posix/src/ualarm.c
index d2b524ef5b..a5a8ee926b 100644
--- a/cpukit/posix/src/ualarm.c
+++ b/cpukit/posix/src/ualarm.c
@@ -1,7 +1,7 @@
/*
- * XXX 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
+ * 3.4.1 Schedule Alarm, P1003.1b-1993, p. 79
*
- * COPYRIGHT (c) 1989-2003.
+ * COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -75,12 +75,9 @@ useconds_t ualarm(
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 );
+ _Timespec_From_ticks( ticks, &tp );
remaining = tp.tv_sec * TOD_MICROSECONDS_PER_SECOND;
remaining += tp.tv_nsec / 1000;
break;
@@ -89,8 +86,7 @@ useconds_t ualarm(
tp.tv_sec = useconds / TOD_MICROSECONDS_PER_SECOND;
tp.tv_nsec = (useconds % TOD_MICROSECONDS_PER_SECOND) * 1000;
- ticks = _POSIX_Timespec_to_interval( &tp );
- _Watchdog_Insert_ticks( the_timer, ticks );
+ _Watchdog_Insert_ticks( the_timer, _Timespec_To_ticks( &tp ) );
return remaining;
}
diff --git a/cpukit/rtems/src/clocktodtoseconds.c b/cpukit/rtems/src/clocktodtoseconds.c
index 0caac50214..f9ec18b4c3 100644
--- a/cpukit/rtems/src/clocktodtoseconds.c
+++ b/cpukit/rtems/src/clocktodtoseconds.c
@@ -1,7 +1,6 @@
/*
* Time of Day (TOD) Handler - Classic TOD to Seconds
*
- *
* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
@@ -80,5 +79,7 @@ uint32_t _TOD_To_seconds(
time += the_tod->second;
+ time += TOD_SECONDS_1970_THROUGH_1988;
+
return( time );
}
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index a4b217fda1..53aa6c4243 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -28,10 +28,10 @@ include_rtems_score_HEADERS = include/rtems/score/address.h \
include/rtems/score/object.h include/rtems/score/priority.h \
include/rtems/score/stack.h include/rtems/score/states.h \
include/rtems/score/sysstate.h include/rtems/score/thread.h \
- include/rtems/score/threadq.h include/rtems/score/tod.h \
- include/rtems/score/tqdata.h include/rtems/score/userext.h \
- include/rtems/score/watchdog.h include/rtems/score/wkspace.h \
- include/rtems/score/cpuopts.h
+ include/rtems/score/threadq.h include/rtems/score/timespec.h \
+ include/rtems/score/tod.h include/rtems/score/tqdata.h \
+ include/rtems/score/userext.h include/rtems/score/watchdog.h \
+ include/rtems/score/wkspace.h include/rtems/score/cpuopts.h
if HAS_MP
# We only build multiprocessing related files if HAS_MP was defined
@@ -140,7 +140,9 @@ libscore_a_SOURCES += src/threadq.c src/threadqdequeue.c \
src/threadqtimeout.c
## TIMESPEC_C_FILES
-## libscore_a_SOURCES +=
+libscore_a_SOURCES += src/timespecaddto.c src/timespecfromticks.c \
+ src/timespecisvalid.c src/timespeclessthan.c src/timespecsubtract.c \
+ src/timespectoticks.c
## TOD_C_FILES
libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
diff --git a/cpukit/score/include/rtems/score/timespec.h b/cpukit/score/include/rtems/score/timespec.h
new file mode 100644
index 0000000000..b8c4d16f24
--- /dev/null
+++ b/cpukit/score/include/rtems/score/timespec.h
@@ -0,0 +1,130 @@
+/**
+ * @file rtems/score/timespec.h
+ *
+ * This include file contains helpers for manipulating timespecs.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef _RTEMS_SCORE_TIMESPEC_H
+#define _RTEMS_SCORE_TIMESPEC_H
+
+/**
+ * @defgroup Timespec Helpers
+ *
+ * This handler encapsulates functionality related to manipulating
+ * POSIX struct timespecs.
+ */
+/**@{*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/** @brief Is Timespec Valid
+ *
+ * This method determines the validatity of a timespec.
+ *
+ * @param[in] time is the timespec instance to validate.
+ *
+ * @return This method returns true if @a time is valid and
+ * false otherwise.
+ */
+boolean _Timespec_Is_valid(
+ const struct timespec *time
+);
+
+/** @brief Timespec Less Than Operator
+ *
+ * This method is the less than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the left hand side timespec
+ *
+ * @return This method returns true if @a lhs is less than the @a rhs and
+ * false otherwise.
+ */
+boolean _Timespec_Less_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+);
+
+/** @brief Add to a Timespec
+ *
+ * This routine adds two timespecs. The second argument is added
+ * to the first.
+ *
+ * @param[in] time is the base time to be added to
+ * @param[in] add is the timespec to add to the first argument
+ *
+ * @return This method returns the number of seconds @a time increased by.
+ */
+uint32_t _Timespec_Add_to(
+ struct timespec *time,
+ const struct timespec *add
+);
+
+/** @brief Convert Timespec to Number of Ticks
+ *
+ * This routine convert the @a time timespec to the corresponding number
+ * of clock ticks.
+ *
+ * @param[in] time is the time to be converted
+ *
+ * @return This method returns the number of ticks computed.
+ */
+uint32_t _Timespec_To_ticks(
+ const struct timespec *time
+);
+
+/** @brief Convert Ticks to Timespec
+ *
+ * This routine converts the @a ticks value to the corresponding
+ * timespec format @a time.
+ *
+ * @param[in] time is the timespec format time result
+ * @param[in] ticks is the number of ticks to convert
+ */
+void _Timespec_From_ticks(
+ uint32_t ticks,
+ struct timespec *time
+);
+
+/** @brief Subtract Two Timespec
+ *
+ * This routine subtracts two timespecs. @a result is set to
+ * @a end - @a start.
+ *
+ * @param[in] start is the starting time
+ * @param[in] end is the ending time
+ * @param[in] result is the difference between starting and ending time.
+ *
+ * @return This method fills in @a result.
+ */
+void _Timespec_Subtract(
+ const struct timespec *start,
+ const struct timespec *end,
+ struct timespec *result
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h
index c07a48a3e5..a0c252e376 100644
--- a/cpukit/score/include/rtems/score/tod.h
+++ b/cpukit/score/include/rtems/score/tod.h
@@ -137,7 +137,7 @@ SCORE_EXTERN struct timespec _TOD_Uptime;
* The following contains the number of seconds from 00:00:00
* January 1, TOD_BASE_YEAR until the current time of day.
*/
-SCORE_EXTERN Watchdog_Interval _TOD_Seconds_since_epoch;
+#define _TOD_Seconds_since_epoch (_TOD_Now.tv_sec)
/** @brief Microseconds per Clock Tick
*
@@ -217,6 +217,17 @@ void _TOD_Tickle_ticks( void );
#define TOD_MILLISECONDS_TO_TICKS(_ms) \
(TOD_MILLISECONDS_TO_MICROSECONDS(_ms) / _TOD_Microseconds_per_tick)
+
+/** @brief How many ticks in a second?
+ *
+ * This macro returns the number of ticks in a second.
+ *
+ * @note If the clock tick value does not multiply evenly into a second
+ * then this number of ticks will be slightly shorter than a second.
+ */
+#define TOD_TICKS_PER_SECOND \
+ (TOD_MICROSECONDS_PER_SECOND / _TOD_Microseconds_per_tick)
+
#ifndef __RTEMS_APPLICATION__
#include <rtems/score/tod.inl>
#endif
diff --git a/cpukit/score/inline/rtems/score/tod.inl b/cpukit/score/inline/rtems/score/tod.inl
index 10a370f7f2..fbfd7037de 100644
--- a/cpukit/score/inline/rtems/score/tod.inl
+++ b/cpukit/score/inline/rtems/score/tod.inl
@@ -27,34 +27,6 @@
*/
/**
- *
- * This routines adds two timespecs. The second argument is added
- * to the first.
- */
-
-RTEMS_INLINE_ROUTINE uint32_t _TOD_Add_timespec(
- struct timespec *time,
- struct timespec *add
-)
-{
- uint32_t seconds = 0;
-
-
- /* Add the basics */
- time->tv_sec += add->tv_sec;
- time->tv_nsec += add->tv_nsec;
-
- /* Now adjust it so nanoseconds is in range */
- while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
- time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
- time->tv_sec++;
- seconds++;
- }
-
- return seconds;
-}
-
-/**
* This routine deactivates updating of the current time of day.
*/
diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am
index b2d277b788..c82a22b21b 100644
--- a/cpukit/score/preinstall.am
+++ b/cpukit/score/preinstall.am
@@ -127,6 +127,10 @@ $(PROJECT_INCLUDE)/rtems/score/threadq.h: include/rtems/score/threadq.h $(PROJEC
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/threadq.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/threadq.h
+$(PROJECT_INCLUDE)/rtems/score/timespec.h: include/rtems/score/timespec.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timespec.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timespec.h
+
$(PROJECT_INCLUDE)/rtems/score/tod.h: include/rtems/score/tod.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tod.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tod.h
diff --git a/cpukit/score/src/coretod.c b/cpukit/score/src/coretod.c
index 5c9c935483..fbadaf673d 100644
--- a/cpukit/score/src/coretod.c
+++ b/cpukit/score/src/coretod.c
@@ -1,8 +1,8 @@
/*
* Time of Day (TOD) Handler
- *
- *
- * COPYRIGHT (c) 1989-1999.
+ */
+
+/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -48,9 +48,6 @@ void _TOD_Handler_initialization(
_TOD_Uptime.tv_sec = 0;
_TOD_Uptime.tv_nsec = 0;
- /* Seconds since RTEMS Epoch (1988) */
- _TOD_Seconds_since_epoch = 0;
-
/* TOD has not been set */
_TOD_Is_set = FALSE;
_TOD_Activate();
diff --git a/cpukit/score/src/coretodget.c b/cpukit/score/src/coretodget.c
index 96ae194f30..3a5e2db16c 100644
--- a/cpukit/score/src/coretodget.c
+++ b/cpukit/score/src/coretodget.c
@@ -17,6 +17,7 @@
#include <rtems/system.h>
#include <rtems/score/isr.h>
+#include <rtems/score/timespec.h>
#include <rtems/score/tod.h>
/*
@@ -49,5 +50,5 @@ void _TOD_Get(
offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)();
_ISR_Enable( level );
- _TOD_Add_timespec( time, &offset );
+ _Timespec_Add_to( time, &offset );
}
diff --git a/cpukit/score/src/coretodgetuptime.c b/cpukit/score/src/coretodgetuptime.c
index e420c0863d..e0047070b5 100644
--- a/cpukit/score/src/coretodgetuptime.c
+++ b/cpukit/score/src/coretodgetuptime.c
@@ -1,7 +1,8 @@
/*
* Time of Day (TOD) Handler - get uptime
- *
- * COPYRIGHT (c) 1989-2007.
+ */
+
+/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -17,6 +18,7 @@
#include <rtems/system.h>
#include <rtems/score/isr.h>
+#include <rtems/score/timespec.h>
#include <rtems/score/tod.h>
/*
@@ -48,5 +50,5 @@ void _TOD_Get_uptime(
offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)();
_ISR_Enable( level );
- _TOD_Add_timespec( uptime, &offset );
+ _Timespec_Add_to( uptime, &offset );
}
diff --git a/cpukit/score/src/coretodset.c b/cpukit/score/src/coretodset.c
index 21f77d8001..d689a62e89 100644
--- a/cpukit/score/src/coretodset.c
+++ b/cpukit/score/src/coretodset.c
@@ -1,8 +1,8 @@
/*
- * Time of Day (TOD) Handler
- *
- *
- * COPYRIGHT (c) 1989-1999.
+ * Time of Day (TOD) Handler -- Set Time
+ */
+
+/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -49,12 +49,9 @@ void _TOD_Set(
_Watchdog_Adjust_seconds( WATCHDOG_FORWARD,
time->tv_sec - _TOD_Seconds_since_epoch );
- _TOD_Seconds_since_epoch = time->tv_sec;
- _TOD_Is_set = TRUE;
-
/* POSIX format TOD (timespec) */
- _TOD_Now = *time;
- _TOD_Now.tv_sec += TOD_SECONDS_1970_THROUGH_1988;
+ _TOD_Now = *time;
+ _TOD_Is_set = TRUE;
_TOD_Activate( 0 );
diff --git a/cpukit/score/src/coretodtickle.c b/cpukit/score/src/coretodtickle.c
index a9b12646f4..1afef420a2 100644
--- a/cpukit/score/src/coretodtickle.c
+++ b/cpukit/score/src/coretodtickle.c
@@ -1,8 +1,8 @@
-
/*
* Time of Day (TOD) Handler -- Tickle Ticks
- *
- * COPYRIGHT (c) 1989-2007.
+ */
+
+/* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -19,6 +19,7 @@
#include <rtems/system.h>
#include <rtems/score/object.h>
#include <rtems/score/thread.h>
+#include <rtems/score/timespec.h>
#include <rtems/score/tod.h>
#include <rtems/score/watchdog.h>
@@ -46,11 +47,11 @@ void _TOD_Tickle_ticks( void )
_Watchdog_Ticks_since_boot += 1;
/* Update the timespec format uptime */
- (void) _TOD_Add_timespec( &_TOD_Uptime, &tick );
+ (void) _Timespec_Add_to( &_TOD_Uptime, &tick );
/* we do not care how much the uptime changed */
/* Update the timespec format TOD */
- seconds = _TOD_Add_timespec( &_TOD_Now, &tick );
+ seconds = _Timespec_Add_to( &_TOD_Now, &tick );
while ( seconds ) {
_Watchdog_Tickle_seconds();
seconds--;
diff --git a/cpukit/score/src/timespecaddto.c b/cpukit/score/src/timespecaddto.c
new file mode 100644
index 0000000000..400b675405
--- /dev/null
+++ b/cpukit/score/src/timespecaddto.c
@@ -0,0 +1,51 @@
+/**
+ * @file score/src//timespecaddto.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ *
+ * This routines adds two timespecs. The second argument is added
+ * to the first.
+ */
+
+uint32_t _Timespec_Add_to(
+ struct timespec *time,
+ const struct timespec *add
+)
+{
+ uint32_t seconds = add->tv_sec;
+
+ /* Add the basics */
+ time->tv_sec += add->tv_sec;
+ time->tv_nsec += add->tv_nsec;
+
+ /* Now adjust it so nanoseconds is in range */
+ while ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) {
+ time->tv_nsec -= TOD_NANOSECONDS_PER_SECOND;
+ time->tv_sec++;
+ seconds++;
+ }
+
+ return seconds;
+}
diff --git a/cpukit/posix/src/posixintervaltotimespec.c b/cpukit/score/src/timespecfromticks.c
index b507c56935..73dda79db9 100644
--- a/cpukit/posix/src/posixintervaltotimespec.c
+++ b/cpukit/score/src/timespecfromticks.c
@@ -1,4 +1,11 @@
/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
* $Id$
*/
@@ -7,24 +14,14 @@
#endif
#include <time.h>
-#include <errno.h>
#include <rtems/system.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/thread.h>
+#include <rtems/score/timespec.h>
#include <rtems/score/tod.h>
-#include <rtems/seterr.h>
-#include <rtems/posix/time.h>
-
-/*PAGE
- *
- * _POSIX_Interval_to_timespec
- */
-
-void _POSIX_Interval_to_timespec(
- Watchdog_Interval ticks,
- struct timespec *time
+void _Timespec_From_ticks(
+ uint32_t ticks,
+ struct timespec *time
)
{
uint32_t usecs;
diff --git a/cpukit/score/src/timespecisvalid.c b/cpukit/score/src/timespecisvalid.c
new file mode 100644
index 0000000000..5ae50f3c4c
--- /dev/null
+++ b/cpukit/score/src/timespecisvalid.c
@@ -0,0 +1,43 @@
+/**
+ * @file score/src/timespecisvalid.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+boolean _Timespec_Is_valid(
+ const struct timespec *time
+)
+{
+ if ( !time )
+ return FALSE;
+
+ if ( time->tv_sec < 0 )
+ return FALSE;
+
+ if ( time->tv_nsec < 0 )
+ return FALSE;
+
+ if ( time->tv_nsec >= TOD_NANOSECONDS_PER_SECOND )
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/cpukit/score/src/timespeclessthan.c b/cpukit/score/src/timespeclessthan.c
new file mode 100644
index 0000000000..df824b2d27
--- /dev/null
+++ b/cpukit/score/src/timespeclessthan.c
@@ -0,0 +1,42 @@
+/**
+ * @file score/src/timespeclessthan.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+boolean _Timespec_Less_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+)
+{
+ if ( lhs->tv_sec < rhs->tv_sec )
+ return TRUE;
+
+ if ( lhs->tv_sec > rhs->tv_sec )
+ return FALSE;
+
+ /* ASSERT: lhs->tv_sec == rhs->tv_sec */
+ if ( lhs->tv_nsec < rhs->tv_nsec )
+ return TRUE;
+
+ return FALSE;
+}
diff --git a/cpukit/score/src/timespecsubtract.c b/cpukit/score/src/timespecsubtract.c
new file mode 100644
index 0000000000..d17107fcc0
--- /dev/null
+++ b/cpukit/score/src/timespecsubtract.c
@@ -0,0 +1,41 @@
+/**
+ * @file score/src/timespecsubtract.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <sys/types.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+void _Timespec_Subtract(
+ const struct timespec *start,
+ const struct timespec *end,
+ struct timespec *result
+)
+{
+
+ if (end->tv_nsec < start->tv_nsec) {
+ result->tv_sec = end->tv_sec - start->tv_sec - 1;
+ result->tv_nsec =
+ (TOD_NANOSECONDS_PER_SECOND - start->tv_nsec) + end->tv_nsec;
+ } else {
+ result->tv_sec = end->tv_sec - start->tv_sec;
+ result->tv_nsec = end->tv_nsec - start->tv_nsec;
+ }
+}
diff --git a/cpukit/score/src/timespectoticks.c b/cpukit/score/src/timespectoticks.c
new file mode 100644
index 0000000000..550ce617b3
--- /dev/null
+++ b/cpukit/score/src/timespectoticks.c
@@ -0,0 +1,49 @@
+/**
+ * @file score/src/timespectoticks.c
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <sys/types.h>
+#include <rtems/score/tod.h>
+#include <rtems/score/watchdog.h>
+
+/**
+ *
+ * This routines converts a timespec to the corresponding number of ticks.
+ */
+
+uint32_t _Timespec_To_ticks(
+ const struct timespec *time
+)
+{
+ uint32_t ticks;
+
+ if ( (time->tv_sec == 0) && (time->tv_nsec == 0) )
+ return 0;
+
+ ticks = time->tv_sec * TOD_TICKS_PER_SECOND;
+
+ ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) /
+ _TOD_Microseconds_per_tick;
+
+ if (ticks)
+ return ticks;
+
+ return 1;
+}