summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/timespecaddto.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cpukit/score/src/timespecaddto.c51
1 files changed, 51 insertions, 0 deletions
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;
+}