summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorKrzysztof Mięsowicz <krzysztof.miesowicz@gmail.com>2012-08-29 07:38:54 -0500
committerJoel Sherrill <joel.sherrill@oarcorp.com>2012-08-29 07:38:54 -0500
commita6eaa5489c8da1e38300722715326cbf3ab1b65f (patch)
tree0513a9a7103a37b0faded653487404e436b59b23 /cpukit
parentsp77: new test to cover allocated message size overflowing (diff)
downloadrtems-a6eaa5489c8da1e38300722715326cbf3ab1b65f.tar.bz2
timespec helpers: Add wrappers with new test
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/sapi/Makefile.am2
-rw-r--r--cpukit/sapi/include/rtems/timespec.h53
-rw-r--r--cpukit/sapi/inline/rtems/timespec.inl296
-rw-r--r--cpukit/sapi/preinstall.am8
4 files changed, 359 insertions, 0 deletions
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 805cfa7075..67f11eb859 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -15,6 +15,7 @@ include_rtems_HEADERS += include/rtems/cbs.h
include_rtems_HEADERS += include/rtems/rbheap.h
include_rtems_HEADERS += include/rtems/rbtree.h
include_rtems_HEADERS += include/rtems/sptables.h
+include_rtems_HEADERS += include/rtems/timespec.h
EXTRA_DIST = include/rtems/README
@@ -22,6 +23,7 @@ include_rtems_HEADERS += inline/rtems/chain.inl
include_rtems_HEADERS += inline/rtems/extension.inl
include_rtems_HEADERS += inline/rtems/cbs.inl
include_rtems_HEADERS += inline/rtems/rbtree.inl
+include_rtems_HEADERS += inline/rtems/timespec.inl
## src
AM_CPPFLAGS += -D__RTEMS_INSIDE__
diff --git a/cpukit/sapi/include/rtems/timespec.h b/cpukit/sapi/include/rtems/timespec.h
new file mode 100644
index 0000000000..b661d43fc0
--- /dev/null
+++ b/cpukit/sapi/include/rtems/timespec.h
@@ -0,0 +1,53 @@
+/**
+ * @file rtems/sapi/timespec.h
+ *
+ * @ingroup
+ *
+ * @brief Timespec API
+ *
+ * This include file contains API for manipulating timespecs.
+ */
+
+/*
+ * Copyright (c) 2012-.
+ * Krzysztof Miesowicz krzysztof.miesowicz@gmail.com
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_TIMESPEC_H
+#define _RTEMS_TIMESPEC_H
+
+#include <rtems/score/timespec.h>
+
+/**
+ * @defgroup TimespecAPI Timespec
+ *
+ * @ingroup ClassicRTEMS
+ *
+ * @brief Timespec API
+ *
+ */
+/**@{*/
+
+#include <stdbool.h> /* bool */
+#include <stdint.h> /* uint32_t */
+#include <time.h> /* struct timespec */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rtems/timespec.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
+/* end of include file */
+
diff --git a/cpukit/sapi/inline/rtems/timespec.inl b/cpukit/sapi/inline/rtems/timespec.inl
new file mode 100644
index 0000000000..af78e8d3fb
--- /dev/null
+++ b/cpukit/sapi/inline/rtems/timespec.inl
@@ -0,0 +1,296 @@
+/**
+ * @file rtems/sapi/timespec.inl
+ *
+ * @ingroup
+ *
+ * @brief Timespec API.
+ */
+
+/*
+ * Copyright (c) 2012-.
+ * Krzysztof Miesowicz krzysztof.miesowicz@gmail.com
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_TIMESPEC_H
+# error "Never use <rtems/timespec.inl> directly; include <rtems/timespec.h> instead."
+#endif
+
+#ifndef _RTEMS_TIMESPEC_INL
+#define _RTEMS_TIMESPEC_INL
+
+#include <rtems/score/timespec.h>
+
+/**
+ * @addtogroup TimespecAPI Timespec
+ *
+ * @{
+ */
+
+/**
+ * @brief Is Timespec Valid
+ *
+ * This method determines the validity of a timespec.
+ *
+ * @param[in] time is the timespec instance to validate.
+ *
+ * @return This method returns true if @a time is valid and
+ * false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_timespec_is_valid(
+ const struct timespec *time
+)
+{
+ return _Timespec_Is_valid(time);
+}
+
+/**
+ * @brief Timespec Less Than Operator
+ *
+ * This method is the less than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the right hand side timespec
+ *
+ * @return This method returns true if @a lhs is less than the @a rhs and
+ * false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_timespec_less_than(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+)
+{
+ return _Timespec_Less_than(lhs,rhs);
+}
+
+/**
+ * @brief Add to a Timespec
+ *
+ * This routine adds two timespecs. The second argument is added
+ * to the first.
+ *
+ * @param[in] time is the base time to be added to
+ * @param[in] add is the timespec to add to the first argument
+ *
+ * @return This method returns the number of seconds @a time increased by.
+ */
+RTEMS_INLINE_ROUTINE uint32_t rtems_timespec_add_to(
+ struct timespec *time,
+ const struct timespec *add
+)
+{
+ return _Timespec_Add_to(time,add);
+}
+
+/**
+ * @brief Convert Timespec to Number of Ticks
+ *
+ * This routine convert the @a time timespec to the corresponding number
+ * of clock ticks.
+ *
+ * @param[in] time is the time to be converted
+ *
+ * @return This method returns the number of ticks computed.
+ */
+RTEMS_INLINE_ROUTINE uint32_t rtems_timespec_to_ticks(
+ const struct timespec *time
+)
+{
+ return _Timespec_To_ticks(time);
+}
+
+/**
+ * @brief Convert Ticks to Timespec
+ *
+ * This routine converts the @a ticks value to the corresponding
+ * timespec format @a time.
+ *
+ * @param[in] time is the timespec format time result
+ * @param[in] ticks is the number of ticks to convert
+ */
+
+RTEMS_INLINE_ROUTINE void rtems_timespec_from_ticks(
+ uint32_t ticks,
+ struct timespec *time
+)
+{
+ _Timespec_From_ticks(ticks,time);
+}
+
+/**
+ * @brief Subtract Two Timespec
+ *
+ * This routine subtracts two timespecs. @a result is set to
+ * @a end - @a start.
+ *
+ * @param[in] start is the starting time
+ * @param[in] end is the ending time
+ * @param[in] result is the difference between starting and ending time.
+ *
+ * @return This method fills in @a result.
+ */
+RTEMS_INLINE_ROUTINE void rtems_timespec_subtract(
+ const struct timespec *start,
+ const struct timespec *end,
+ struct timespec *result
+)
+{
+ _Timespec_Subtract(start,end,result);
+}
+
+/**
+ * @brief Divide Timespec By Integer
+ *
+ * This routine divides a timespec by an integer value. The expected
+ * use is to assist in benchmark calculations where you typically
+ * divide a duration by a number of iterations.
+ *
+ * @param[in] time is the total
+ * @param[in] iterations is the number of iterations
+ * @param[in] result is the average time.
+ *
+ * @return This method fills in @a result.
+ */
+RTEMS_INLINE_ROUTINE void rtems_timespec_divide_by_integer(
+ const struct timespec *time,
+ uint32_t iterations,
+ struct timespec *result
+)
+{
+ _Timespec_Divide_by_integer(time,iterations,result);
+}
+
+/**
+ * @brief Divide Timespec
+ *
+ * This routine divides a timespec by another timespec. The
+ * intended use is for calculating percentages to three decimal points.
+ *
+ * @param[in] lhs is the left hand number
+ * @param[in] rhs is the right hand number
+ * @param[in] ival_percentage is the integer portion of the average
+ * @param[in] fval_percentage is the thousandths of percentage
+ *
+ * @return This method fills in @a result.
+ */
+RTEMS_INLINE_ROUTINE void rtems_timespec_divide(
+ const struct timespec *lhs,
+ const struct timespec *rhs,
+ uint32_t *ival_percentage,
+ uint32_t *fval_percentage
+)
+{
+ _Timespec_Divide(lhs,rhs,ival_percentage,fval_percentage);
+}
+
+/**
+ * @brief Set Timespec to Seconds Nanosecond
+ *
+ * This method sets the timespec to the specified seconds and nanoseconds
+ * value.
+ *
+ * @param[in] _time points to the timespec instance to validate.
+ * @param[in] _seconds is the seconds portion of the timespec
+ * @param[in] _nanoseconds is the nanoseconds portion of the timespec
+ */
+RTEMS_INLINE_ROUTINE void rtems_timespec_set(
+ struct timespec *_time,
+ time_t _seconds,
+ uint32_t _nanoseconds
+)
+{
+ _Timespec_Set( _time, _seconds, _nanoseconds );
+}
+
+/**
+ * @brief Zero Timespec
+ *
+ * This method sets the timespec to zero.
+ * value.
+ *
+ * @param[in] _time points to the timespec instance to zero.
+ */
+RTEMS_INLINE_ROUTINE void rtems_timespec_zero(
+ struct timespec *_time
+)
+{
+ _Timespec_Set_to_zero( _time );
+}
+
+/**
+ * @brief Get Seconds Portion of Timespec
+ *
+ * This method returns the seconds portion of the specified timespec
+ *
+ * @param[in] _time points to the timespec
+ *
+ * @return The seconds portion of @a _time.
+ */
+RTEMS_INLINE_ROUTINE time_t rtems_timespec_get_seconds(
+ struct timespec *_time
+)
+{
+ return _Timespec_Get_seconds( _time );
+}
+
+/**
+ * @brief Get Nanoseconds Portion of Timespec
+ *
+ * This method returns the nanoseconds portion of the specified timespec
+ *
+ * @param[in] _time points to the timespec
+ *
+ * @return The nanoseconds portion of @a _time.
+ */
+RTEMS_INLINE_ROUTINE uint32_t rtems_timespec_get_nanoseconds(
+ struct timespec *_time
+)
+{
+ return _Timespec_Get_nanoseconds( _time );
+}
+
+
+/**
+ * @brief Timespec Greater Than Operator
+ *
+ * This method is the greater than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the right hand side timespec
+ *
+ * @return This method returns true if @a lhs is greater than the @a rhs and
+ * false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_timespec_greater_than(
+ const struct timespec *_lhs,
+ const struct timespec *_rhs
+)
+{
+ return _Timespec_Greater_than( _lhs, _rhs );
+}
+/**
+ * @brief Timespec equal to Operator
+ *
+ * This method is the is equal to than operator for timespecs.
+ *
+ * @param[in] lhs is the left hand side timespec
+ * @param[in] rhs is the right hand side timespec
+ *
+ * @return This method returns true if @a lhs is equal to @a rhs and
+ * false otherwise.
+ */
+RTEMS_INLINE_ROUTINE bool rtems_timespec_equal_to(
+ const struct timespec *lhs,
+ const struct timespec *rhs
+)
+{
+ return _Timespec_Equal_to( lhs, rhs);
+}
+
+/** @} */
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
index e7c8e2a25c..ccc1bec4ba 100644
--- a/cpukit/sapi/preinstall.am
+++ b/cpukit/sapi/preinstall.am
@@ -76,6 +76,10 @@ $(PROJECT_INCLUDE)/rtems/sptables.h: include/rtems/sptables.h $(PROJECT_INCLUDE)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/sptables.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/sptables.h
+$(PROJECT_INCLUDE)/rtems/timespec.h: include/rtems/timespec.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/timespec.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/timespec.h
+
$(PROJECT_INCLUDE)/rtems/chain.inl: inline/rtems/chain.inl $(PROJECT_INCLUDE)/rtems/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/chain.inl
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/chain.inl
@@ -92,6 +96,10 @@ $(PROJECT_INCLUDE)/rtems/rbtree.inl: inline/rtems/rbtree.inl $(PROJECT_INCLUDE)/
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rbtree.inl
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rbtree.inl
+$(PROJECT_INCLUDE)/rtems/timespec.inl: inline/rtems/timespec.inl $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/timespec.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/timespec.inl
+
$(PROJECT_LIB)/libsapi.a: libsapi.a $(PROJECT_LIB)/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_LIB)/libsapi.a
TMPINSTALL_FILES += $(PROJECT_LIB)/libsapi.a