summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-11-16 13:39:55 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-11-21 16:24:22 +0100
commit154721c4348084e1b2ae96cd7f2ec824f27c345a (patch)
tree889634e37035a87f75a4b8647a382e4f8e791e91
parentbsp/mpc55xx: Update due to API changes (diff)
downloadrtems-154721c4348084e1b2ae96cd7f2ec824f27c345a.tar.bz2
score: Add _Timestamp_To_timeval()
-rw-r--r--cpukit/score/Makefile.am2
-rw-r--r--cpukit/score/include/rtems/score/timestamp.h19
-rw-r--r--cpukit/score/include/rtems/score/timestamp64.h27
-rw-r--r--cpukit/score/src/ts64totimeval.c29
4 files changed, 76 insertions, 1 deletions
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 7b7757f8f0..a7a77d9d73 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -303,7 +303,7 @@ libscore_a_SOURCES += src/ts64addto.c src/ts64dividebyinteger.c \
src/ts64getnanoseconds.c src/ts64getseconds.c \
src/ts64lessthan.c \
src/ts64set.c src/ts64settozero.c src/ts64subtract.c \
- src/ts64toticks.c src/ts64totimespec.c
+ src/ts64toticks.c src/ts64totimespec.c src/ts64totimeval.c
## TOD_C_FILES
libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
diff --git a/cpukit/score/include/rtems/score/timestamp.h b/cpukit/score/include/rtems/score/timestamp.h
index 83948b46e1..fb16886947 100644
--- a/cpukit/score/include/rtems/score/timestamp.h
+++ b/cpukit/score/include/rtems/score/timestamp.h
@@ -38,6 +38,8 @@
*/
/**@{*/
+#include <sys/time.h>
+
#include <rtems/score/cpu.h>
#include <rtems/score/timespec.h>
@@ -342,6 +344,23 @@ extern "C" {
_Timestamp64_To_timespec( _timestamp, _timespec )
#endif
+/**
+ * @brief Convert Timestamp to struct timeval
+ *
+ * @param[in] _timestamp points to the timestamp
+ * @param[in] _timeval points to the timeval
+ */
+#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
+ #define _Timestamp_To_timeval( _timestamp, _timeval ) \
+ do { \
+ (_timeval)->tv_sec = (_timestamp)->tv_sec; \
+ (_timeval)->tv_usec = (_timestamp)->tv_nsec / 1000; \
+ } while (0)
+#else
+ #define _Timestamp_To_timeval( _timestamp, _timeval ) \
+ _Timestamp64_To_timeval( _timestamp, _timeval )
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/include/rtems/score/timestamp64.h b/cpukit/score/include/rtems/score/timestamp64.h
index 1c1ea2c90c..41735fa144 100644
--- a/cpukit/score/include/rtems/score/timestamp64.h
+++ b/cpukit/score/include/rtems/score/timestamp64.h
@@ -393,6 +393,33 @@ static inline void _Timestamp64_implementation_To_timespec(
);
#endif
+static inline void _Timestamp64_implementation_To_timeval(
+ const Timestamp64_Control *_timestamp,
+ struct timeval *_timeval
+)
+{
+ _timeval->tv_sec = (time_t) (*_timestamp / 1000000000U);
+ _timeval->tv_usec = (suseconds_t) ((*_timestamp % 1000000000U) / 1000U);
+}
+
+/**
+ * @brief Convert Timestamp to struct timeval
+ *
+ * This method returns the seconds portion of the specified timestamp
+ *
+ * @param[in] _timestamp points to the timestamp
+ * @param[out] _timeval points to the timeval
+ */
+#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
+ #define _Timestamp64_To_timeval( _timestamp, _timeval ) \
+ _Timestamp64_implementation_To_timeval( _timestamp, _timeval )
+#else
+ void _Timestamp64_To_timeval(
+ const Timestamp64_Control *_timestamp,
+ struct timeval *_timeval
+ );
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/score/src/ts64totimeval.c b/cpukit/score/src/ts64totimeval.c
new file mode 100644
index 0000000000..29bbb7895c
--- /dev/null
+++ b/cpukit/score/src/ts64totimeval.c
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2012 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * 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.
+ */
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/score/timestamp.h>
+
+#if CPU_TIMESTAMP_USE_INT64 == TRUE
+void _Timestamp64_To_timeval(
+ const Timestamp64_Control *_timestamp,
+ struct timeval *_timeval
+)
+{
+ _Timestamp64_implementation_To_timeval( _timestamp, _timeval );
+}
+#endif