[PATCH 2/6] score: Add and use _TOD_Get_with_nanoseconds()

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


Delete _TOD_Get_as_timestamp().
---
 cpukit/score/Makefile.am                |    2 +-
 cpukit/score/include/rtems/score/tod.h  |   29 +++++++++++-----
 cpukit/score/inline/rtems/score/tod.inl |   17 +++-------
 cpukit/score/src/coretodget.c           |   22 +++++-------
 cpukit/score/src/coretodgetuptime.c     |   54 -------------------------------
 5 files changed, 35 insertions(+), 89 deletions(-)
 delete mode 100644 cpukit/score/src/coretodgetuptime.c

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index b1e1365..99fbecd 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -308,7 +308,7 @@ libscore_a_SOURCES += src/ts64addto.c src/ts64dividebyinteger.c \
 
 ## TOD_C_FILES
 libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
-    src/coretodgetuptime.c src/coretodgetuptimetimespec.c src/coretodtickle.c \
+    src/coretodgetuptimetimespec.c src/coretodtickle.c \
     src/coretodmsecstoticks.c src/coretodtickspersec.c src/coretodusectoticks.c
 
 ## WATCHDOG_C_FILES
diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h
index 797f4bb..1f21fdb 100644
--- a/cpukit/score/include/rtems/score/tod.h
+++ b/cpukit/score/include/rtems/score/tod.h
@@ -197,22 +197,30 @@ static inline void _TOD_Set(
 }
 
 /**
- *  @brief Returns the time of day in @a tod_as_timestamp.
+ *  @brief Returns a snapshot of a clock.
  *
- *  The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
+ *  This function invokes the nanoseconds extension.
+ *
+ *  @param[out] snapshot The snapshot.
+ *  @param[in] source The clock.
+ *
+ *  @return The snapshot.
  */
-void _TOD_Get_as_timestamp(
-  Timestamp_Control *tod_as_timestamp
+Timestamp_Control *_TOD_Get_with_nanoseconds(
+  Timestamp_Control *snapshot,
+  const Timestamp_Control *clock
 );
 
 static inline void _TOD_Get(
   struct timespec *tod_as_timespec
 )
 {
-  Timestamp_Control tod_as_timestamp;
+  Timestamp_Control  tod_as_timestamp;
+  Timestamp_Control *tod_as_timestamp_ptr;
 
-  _TOD_Get_as_timestamp( &tod_as_timestamp );
-  _Timestamp_To_timespec( &tod_as_timestamp, tod_as_timespec );
+  tod_as_timestamp_ptr =
+    _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now );
+  _Timestamp_To_timespec( tod_as_timestamp_ptr, tod_as_timespec );
 }
 
 /**
@@ -223,9 +231,12 @@ static inline void _TOD_Get(
  *
  *  @param[in] time is a pointer to the uptime to be returned
  */
-void _TOD_Get_uptime(
+static inline void _TOD_Get_uptime(
   Timestamp_Control *time
-);
+)
+{
+  _TOD_Get_with_nanoseconds( time, &_TOD.uptime );
+}
 
 /**
  *  @brief _TOD_Get_uptime_as_timespec
diff --git a/cpukit/score/inline/rtems/score/tod.inl b/cpukit/score/inline/rtems/score/tod.inl
index 14c7b6f..d8a8bb7 100644
--- a/cpukit/score/inline/rtems/score/tod.inl
+++ b/cpukit/score/inline/rtems/score/tod.inl
@@ -56,19 +56,12 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
   struct timeval *time
 )
 {
-  ISR_Level       level;
-  struct timespec now;
-  suseconds_t     useconds;
+  Timestamp_Control  snapshot_as_timestamp;
+  Timestamp_Control *snapshot_as_timestamp_ptr;
 
-  _ISR_Disable(level);
-    _TOD_Get( &now );
-  _ISR_Enable(level);
-
-  useconds = (suseconds_t)now.tv_nsec;
-  useconds /= (suseconds_t)TOD_NANOSECONDS_PER_MICROSECOND;
-
-  time->tv_sec  = now.tv_sec;
-  time->tv_usec = useconds;
+  snapshot_as_timestamp_ptr =
+    _TOD_Get_with_nanoseconds( &snapshot_as_timestamp, &_TOD.now );
+  _Timestamp_To_timeval( snapshot_as_timestamp_ptr, time );
 }
 
 /**@}*/
diff --git a/cpukit/score/src/coretodget.c b/cpukit/score/src/coretodget.c
index 94517e5..448bc7b 100644
--- a/cpukit/score/src/coretodget.c
+++ b/cpukit/score/src/coretodget.c
@@ -10,35 +10,31 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+  #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/timespec.h>
-#include <rtems/score/timestamp.h>
 #include <rtems/score/tod.h>
 #include <rtems/score/watchdog.h>
 
-void _TOD_Get_as_timestamp(
-  Timestamp_Control *tod
+Timestamp_Control *_TOD_Get_with_nanoseconds(
+  Timestamp_Control *snapshot,
+  const Timestamp_Control *clock
 )
 {
   ISR_Level         level;
   Timestamp_Control offset;
   Timestamp_Control now;
-  long              nanoseconds;
+  uint32_t          nanoseconds;
 
-  /* assume time checked for NULL by caller */
-
-  /* _TOD.now is the native current time */
   _ISR_Disable( level );
-    now = _TOD.now;
     nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
+    now = *clock;
   _ISR_Enable( level );
 
   _Timestamp_Set( &offset, 0, nanoseconds );
   _Timestamp_Add_to( &now, &offset );
 
-  *tod = now;
+  *snapshot = now;
+
+  return snapshot;
 }
diff --git a/cpukit/score/src/coretodgetuptime.c b/cpukit/score/src/coretodgetuptime.c
deleted file mode 100644
index c3c05ae..0000000
--- a/cpukit/score/src/coretodgetuptime.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- *  Time of Day (TOD) Handler - get uptime
- */
-
-/*  COPYRIGHT (c) 1989-2008.
- *  On-Line Applications Research Corporation (OAR).
- *
- *  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/system.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/timestamp.h>
-#include <rtems/score/tod.h>
-#include <rtems/score/watchdog.h>
-
-/*
- *  _TOD_Get_uptime
- *
- *  This routine is used to obtain the system uptime
- *
- *  Input parameters:
- *    time  - pointer to the timestamp structure
- *
- *  Output parameters: NONE
- */
-
-void _TOD_Get_uptime(
-  Timestamp_Control *uptime
-)
-{
-  ISR_Level         level;
-  Timestamp_Control offset;
-  Timestamp_Control up;
-  long              nanoseconds;
-
-  /* assume time checked for NULL by caller */
-
-  /* _TOD.uptime is in native timestamp format */
-  _ISR_Disable( level );
-    up = _TOD.uptime;
-    nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
-  _ISR_Enable( level );
-
-  _Timestamp_Set( &offset, 0, nanoseconds );
-  _Timestamp_Add_to( &up, &offset );
-  *uptime = up;
-}
-- 
1.7.7




More information about the devel mailing list