summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
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/src
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/src')
-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
11 files changed, 282 insertions, 24 deletions
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;
+}