[PATCH 1/6] score: Add _Timestamp_To_timeval()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Nov 16 15:31:06 UTC 2012


---
 cpukit/score/Makefile.am                       |    2 +-
 cpukit/score/include/rtems/score/timestamp.h   |   19 +++++++++++++++
 cpukit/score/include/rtems/score/timestamp64.h |   27 ++++++++++++++++++++++
 cpukit/score/src/ts64totimeval.c               |   29 ++++++++++++++++++++++++
 4 files changed, 76 insertions(+), 1 deletions(-)
 create mode 100644 cpukit/score/src/ts64totimeval.c

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index ce1251a..b1e1365 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -304,7 +304,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 83948b4..385a9be 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 1c1ea2c..41735fa 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 0000000..29bbb78
--- /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 at 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
-- 
1.7.7




More information about the devel mailing list