From 154721c4348084e1b2ae96cd7f2ec824f27c345a Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 16 Nov 2012 13:39:55 +0100 Subject: score: Add _Timestamp_To_timeval() --- 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 deletion(-) create mode 100644 cpukit/score/src/ts64totimeval.c 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 + #include #include @@ -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 + * + * + * 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 + +#if CPU_TIMESTAMP_USE_INT64 == TRUE +void _Timestamp64_To_timeval( + const Timestamp64_Control *_timestamp, + struct timeval *_timeval +) +{ + _Timestamp64_implementation_To_timeval( _timestamp, _timeval ); +} +#endif -- cgit v1.2.3