score: Add _Timestamp_To_timeval()

This commit is contained in:
Sebastian Huber
2012-11-21 16:24:22 +01:00
parent 7ca64d69fa
commit 154721c434
4 changed files with 76 additions and 1 deletions
+1 -1
View File
@@ -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 \
@@ -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
@@ -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
+29
View File
@@ -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