summaryrefslogtreecommitdiffstats
path: root/cpukit/score
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/score
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 'cpukit/score')
-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.c34
-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
16 files changed, 435 insertions, 58 deletions
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/score/src/timespecfromticks.c b/cpukit/score/src/timespecfromticks.c
new file mode 100644
index 0000000000..73dda79db9
--- /dev/null
+++ b/cpukit/score/src/timespecfromticks.c
@@ -0,0 +1,34 @@
+/*
+ * 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 <time.h>
+
+#include <rtems/system.h>
+#include <rtems/score/timespec.h>
+#include <rtems/score/tod.h>
+
+void _Timespec_From_ticks(
+ uint32_t ticks,
+ struct timespec *time
+)
+{
+ uint32_t usecs;
+
+ usecs = ticks * _TOD_Microseconds_per_tick;
+
+ time->tv_sec = usecs / TOD_MICROSECONDS_PER_SECOND;
+ time->tv_nsec = (usecs % TOD_MICROSECONDS_PER_SECOND) *
+ TOD_NANOSECONDS_PER_MICROSECOND;
+}
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;
+}