[PATCH 3/6] rtems: Add rtems_clock_get_uptime_timeval()

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


---
 cpukit/rtems/Makefile.am                 |    1 +
 cpukit/rtems/include/rtems/rtems/clock.h |    7 ++++++
 cpukit/rtems/src/clockgetuptimetimeval.c |   27 +++++++++++++++++++++++
 doc/user/clock.t                         |   35 ++++++++++++++++++++++++++++++
 testsuites/sptests/sp09/screen02.c       |    3 ++
 testsuites/sptests/sp09/sp09.scn         |    1 +
 6 files changed, 74 insertions(+), 0 deletions(-)
 create mode 100644 cpukit/rtems/src/clockgetuptimetimeval.c

diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index ff3174e..10a5cfa 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -154,6 +154,7 @@ librtems_a_SOURCES += src/clockgettickssinceboot.c
 librtems_a_SOURCES += src/clockgettod.c
 librtems_a_SOURCES += src/clockgettodtimeval.c
 librtems_a_SOURCES += src/clockgetuptime.c
+librtems_a_SOURCES += src/clockgetuptimetimeval.c
 librtems_a_SOURCES += src/clockset.c
 librtems_a_SOURCES += src/clocksetnsecshandler.c
 librtems_a_SOURCES += src/clocktick.c
diff --git a/cpukit/rtems/include/rtems/rtems/clock.h b/cpukit/rtems/include/rtems/rtems/clock.h
index 92f02c3..9805f58 100644
--- a/cpukit/rtems/include/rtems/rtems/clock.h
+++ b/cpukit/rtems/include/rtems/rtems/clock.h
@@ -228,6 +228,13 @@ rtems_status_code rtems_clock_get_uptime(
 );
 
 /**
+ *  @brief Gets the system uptime in the struct timeval format.
+ *
+ *  @param[out] Returns the system uptime.  Pointer must not be NULL.
+ */
+void rtems_clock_get_uptime_timeval( struct timeval *uptime );
+
+/**
  *  @brief _TOD_Validate
  *
  *  This support function returns true if @a the_tod contains
diff --git a/cpukit/rtems/src/clockgetuptimetimeval.c b/cpukit/rtems/src/clockgetuptimetimeval.c
new file mode 100644
index 0000000..8ecd2fb
--- /dev/null
+++ b/cpukit/rtems/src/clockgetuptimetimeval.c
@@ -0,0 +1,27 @@
+/*
+ * 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/rtems/clock.h>
+
+void rtems_clock_get_uptime_timeval( struct timeval *uptime )
+{
+  Timestamp_Control snapshot_as_timestamp;
+
+  _TOD_Get_uptime( &snapshot_as_timestamp );
+  _Timestamp_To_timeval( &snapshot_as_timestamp, uptime );
+}
diff --git a/doc/user/clock.t b/doc/user/clock.t
index 6fde5af..9bc37c5 100644
--- a/doc/user/clock.t
+++ b/doc/user/clock.t
@@ -22,6 +22,7 @@ the clock manager are:
 @item @code{@value{DIRPREFIX}clock_get_ticks_per_second} - Get ticks per second
 @item @code{@value{DIRPREFIX}clock_get_ticks_since_boot} - Get ticks since boot
 @item @code{@value{DIRPREFIX}clock_get_uptime} - Get time since boot
+ at item @code{@value{DIRPREFIX}clock_get_uptime_timeval} - Get time since boot in timeval format
 @item @code{@value{DIRPREFIX}clock_set_nanoseconds_extension} - Install the nanoseconds since last tick handler
 @item @code{@value{DIRPREFIX}clock_tick} - Announce a clock tick
 @end itemize
@@ -665,6 +666,40 @@ call.
 
 This directive may be called from an ISR.
 
+ at c
+ at c
+ at c
+ at page
+ at subsection CLOCK_GET_UPTIME_TIMEVAL - Get the time since boot in timeval format
+
+ at cindex clock get uptime
+ at cindex uptime
+
+ at subheading CALLING SEQUENCE:
+
+ at ifset is-C
+ at findex rtems_clock_get_uptime_timeval
+ at example
+void rtems_clock_get_uptime_timeval(
+  struct timeval *uptime
+);
+ at end example
+ at end ifset
+
+ at subheading DIRECTIVE STATUS CODES:
+
+NONE
+
+ at subheading DESCRIPTION:
+
+This directive returns the seconds and nanoseconds since the
+system was booted.  If the BSP supports nanosecond clock
+accuracy, the time reported will probably be different on every
+call.
+
+ at subheading NOTES:
+
+This directive may be called from an ISR.
 
 @c
 @c
diff --git a/testsuites/sptests/sp09/screen02.c b/testsuites/sptests/sp09/screen02.c
index 26325c4..d4fe370 100644
--- a/testsuites/sptests/sp09/screen02.c
+++ b/testsuites/sptests/sp09/screen02.c
@@ -83,6 +83,9 @@ void Screen2()
     "rtems_clock_get_uptime NULL param"
   );
 
+  puts( "TA1 - rtems_clock_get_uptime_timeval" );
+  rtems_clock_get_uptime_timeval( &tv );
+
   puts( "TA1 - rtems_clock_get_tod_timeval - RTEMS_INVALID_ADDRESS" );
   status = rtems_clock_get_tod_timeval( NULL );
   fatal_directive_status(
diff --git a/testsuites/sptests/sp09/sp09.scn b/testsuites/sptests/sp09/sp09.scn
index 5ebb665..938091e 100644
--- a/testsuites/sptests/sp09/sp09.scn
+++ b/testsuites/sptests/sp09/sp09.scn
@@ -31,6 +31,7 @@ TA1 - rtems_clock_get_tod - RTEMS_NOT_DEFINED
 TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_INVALID_ADDRESS
 TA1 - rtems_clock_get_seconds_since_epoch - RTEMS_NOT_DEFINED
 TA1 - rtems_clock_get_uptime - RTEMS_INVALID_ADDRESS
+TA1 - rtems_clock_get_uptime_timeval
 TA1 - rtems_clock_get_tod_timeval - RTEMS_INVALID_ADDRESS
 TA1 - rtems_clock_get_tod_timeval - RTEMS_NOT_DEFINED
 TA1 - rtems_clock_set_nanoseconds_extension - RTEMS_INVALID_ADDRESS
-- 
1.7.7




More information about the devel mailing list