[PATCH 4/6] rtems: Add rtems_clock_get_uptime_seconds()

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


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

diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index 10a5cfa..6295990 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -155,6 +155,7 @@ 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/clockgetuptimeseconds.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 9805f58..c7b9a4a 100644
--- a/cpukit/rtems/include/rtems/rtems/clock.h
+++ b/cpukit/rtems/include/rtems/rtems/clock.h
@@ -235,6 +235,13 @@ rtems_status_code rtems_clock_get_uptime(
 void rtems_clock_get_uptime_timeval( struct timeval *uptime );
 
 /**
+ *  @brief Returns the system uptime in seconds.
+ *
+ *  @return The system uptime in seconds.
+ */
+time_t rtems_clock_get_uptime_seconds( void );
+
+/**
  *  @brief _TOD_Validate
  *
  *  This support function returns true if @a the_tod contains
diff --git a/cpukit/rtems/src/clockgetuptimeseconds.c b/cpukit/rtems/src/clockgetuptimeseconds.c
new file mode 100644
index 0000000..dc98d1d
--- /dev/null
+++ b/cpukit/rtems/src/clockgetuptimeseconds.c
@@ -0,0 +1,34 @@
+/*
+ * 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>
+
+time_t rtems_clock_get_uptime_seconds( void )
+{
+  Timestamp_Control snapshot_as_timestamp;
+  struct timespec   snapshot_as_timespec;
+  ISR_Level         level;
+
+  _ISR_Disable( level );
+  snapshot_as_timestamp = _TOD.uptime;
+  _ISR_Enable( level );
+
+  _Timestamp_To_timespec( &snapshot_as_timestamp, &snapshot_as_timespec );
+
+  return snapshot_as_timespec.tv_sec;
+}
diff --git a/doc/user/clock.t b/doc/user/clock.t
index 9bc37c5..864d9d3 100644
--- a/doc/user/clock.t
+++ b/doc/user/clock.t
@@ -23,6 +23,7 @@ the clock manager are:
 @item @code{@value{DIRPREFIX}clock_get_ticks_since_boot} - Get ticks since boot
 @item @code{@value{DIRPREFIX}clock_get_uptime} - Get time since boot
 @item @code{@value{DIRPREFIX}clock_get_uptime_timeval} - Get time since boot in timeval format
+ at item @code{@value{DIRPREFIX}clock_get_uptime_seconds} - Get seconds since boot
 @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
@@ -705,6 +706,36 @@ This directive may be called from an ISR.
 @c
 @c
 @page
+ at subsection CLOCK_GET_UPTIME_SECONDS - Get the seconds since boot
+
+ at cindex clock get uptime
+ at cindex uptime
+
+ at subheading CALLING SEQUENCE:
+
+ at ifset is-C
+ at findex rtems_clock_get_uptime_seconds
+ at example
+time_t rtems_clock_get_uptime_seconds(void);
+ at end example
+ at end ifset
+
+ at subheading DIRECTIVE STATUS CODES:
+
+The system uptime in seconds.
+
+ at subheading DESCRIPTION:
+
+This directive returns the seconds since the system was booted.
+
+ at subheading NOTES:
+
+This directive may be called from an ISR.
+
+ at c
+ at c
+ at c
+ at page
 @subsection CLOCK_SET_NANOSECONDS_EXTENSION - Install the nanoseconds since last tick handler
 
 @cindex clock set nanoseconds extension
diff --git a/testsuites/sptests/sp09/screen02.c b/testsuites/sptests/sp09/screen02.c
index d4fe370..fb735da 100644
--- a/testsuites/sptests/sp09/screen02.c
+++ b/testsuites/sptests/sp09/screen02.c
@@ -86,6 +86,9 @@ void Screen2()
   puts( "TA1 - rtems_clock_get_uptime_timeval" );
   rtems_clock_get_uptime_timeval( &tv );
 
+  puts( "TA1 - rtems_clock_get_uptime_seconds" );
+  rtems_clock_get_uptime_seconds();
+
   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 938091e..d1a616d 100644
--- a/testsuites/sptests/sp09/sp09.scn
+++ b/testsuites/sptests/sp09/sp09.scn
@@ -32,6 +32,7 @@ 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_uptime_seconds
 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