[PATCH 4/5] score: Move nanoseconds since last tick support
Sebastian Huber
sebastian.huber at embedded-brains.de
Wed Jul 31 13:15:13 UTC 2013
Move the nanoseconds since last tick support from the Watchdog to the
TOD handler. Now the TOD managment is encapsulated in the TOD_Control
structure.
---
cpukit/rtems/include/rtems/rtems/clock.h | 3 +-
cpukit/rtems/src/clocksetnsecshandler.c | 22 ++----------
cpukit/score/Makefile.am | 4 +-
cpukit/score/include/rtems/score/tod.h | 41 +++++++++++++++++++++++
cpukit/score/include/rtems/score/todimpl.h | 16 ++++++++-
cpukit/score/include/rtems/score/watchdog.h | 9 -----
cpukit/score/include/rtems/score/watchdogimpl.h | 16 ---------
cpukit/score/preinstall.am | 4 ++
cpukit/score/src/coretod.c | 18 +++++++---
cpukit/score/src/coretodget.c | 4 +-
cpukit/score/src/watchdognanoseconds.c | 36 --------------------
11 files changed, 82 insertions(+), 91 deletions(-)
create mode 100644 cpukit/score/include/rtems/score/tod.h
delete mode 100644 cpukit/score/src/watchdognanoseconds.c
diff --git a/cpukit/rtems/include/rtems/rtems/clock.h b/cpukit/rtems/include/rtems/rtems/clock.h
index 3c32ccd..ec8d8f8 100644
--- a/cpukit/rtems/include/rtems/rtems/clock.h
+++ b/cpukit/rtems/include/rtems/rtems/clock.h
@@ -31,6 +31,7 @@
#define _RTEMS_RTEMS_CLOCK_H
#include <rtems/score/watchdog.h>
+#include <rtems/score/tod.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/types.h>
@@ -68,7 +69,7 @@ typedef enum {
/**
* Type for the nanoseconds since last tick BSP extension.
*/
-typedef Watchdog_Nanoseconds_since_last_tick_routine
+typedef TOD_Nanoseconds_since_last_tick_routine
rtems_nanoseconds_extension_routine;
/**
diff --git a/cpukit/rtems/src/clocksetnsecshandler.c b/cpukit/rtems/src/clocksetnsecshandler.c
index 25c0ad7..5c50af1 100644
--- a/cpukit/rtems/src/clocksetnsecshandler.c
+++ b/cpukit/rtems/src/clocksetnsecshandler.c
@@ -18,26 +18,9 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/rtems/status.h>
#include <rtems/rtems/clock.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/watchdogimpl.h>
+#include <rtems/score/todimpl.h>
-/*
- * rtems_clock_set_nanoseconds_extension
- *
- * This directive sets the BSP provided nanoseconds since last tick
- * extension.
- *
- * Input parameters:
- * routine - pointer to the extension routine
- *
- * Output parameters:
- * RTEMS_SUCCESSFUL - if successful
- * error code - if unsuccessful
- */
rtems_status_code rtems_clock_set_nanoseconds_extension(
rtems_nanoseconds_extension_routine routine
)
@@ -45,6 +28,7 @@ rtems_status_code rtems_clock_set_nanoseconds_extension(
if ( !routine )
return RTEMS_INVALID_ADDRESS;
- _Watchdog_Nanoseconds_since_tick_handler = routine;
+ _TOD_Set_nanoseconds_since_last_tick_handler( routine );
+
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 015b230..e300c3e 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -70,6 +70,7 @@ include_rtems_score_HEADERS += include/rtems/score/threadsync.h
include_rtems_score_HEADERS += include/rtems/score/timespec.h
include_rtems_score_HEADERS += include/rtems/score/timestamp.h
include_rtems_score_HEADERS += include/rtems/score/timestamp64.h
+include_rtems_score_HEADERS += include/rtems/score/tod.h
include_rtems_score_HEADERS += include/rtems/score/todimpl.h
include_rtems_score_HEADERS += include/rtems/score/userext.h
include_rtems_score_HEADERS += include/rtems/score/userextimpl.h
@@ -305,8 +306,7 @@ libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
## WATCHDOG_C_FILES
libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \
src/watchdogadjusttochain.c src/watchdoginsert.c src/watchdogremove.c \
- src/watchdogtickle.c src/watchdogreport.c src/watchdogreportchain.c \
- src/watchdognanoseconds.c
+ src/watchdogtickle.c src/watchdogreport.c src/watchdogreportchain.c
## USEREXT_C_FILES
libscore_a_SOURCES += src/userextaddset.c \
diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h
new file mode 100644
index 0000000..57609b9
--- /dev/null
+++ b/cpukit/score/include/rtems/score/tod.h
@@ -0,0 +1,41 @@
+/**
+ * @file
+ *
+ * @ingroup ScoreTOD
+ *
+ * @brief Time of Day Handler API
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2009.
+ * 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.
+ */
+
+#ifndef _RTEMS_SCORE_TOD_H
+#define _RTEMS_SCORE_TOD_H
+
+#include <rtems/score/basedefs.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Returns the nanoseconds since the last clock tick.
+ *
+ * @ingroup ScoreTOD
+ *
+ * @return The nanoseconds since the last clock tick.
+ */
+typedef uint32_t ( *TOD_Nanoseconds_since_last_tick_routine )( void );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h
index 0e2da2f..a7c3e5d 100644
--- a/cpukit/score/include/rtems/score/todimpl.h
+++ b/cpukit/score/include/rtems/score/todimpl.h
@@ -18,7 +18,7 @@
#ifndef _RTEMS_SCORE_TODIMPL_H
#define _RTEMS_SCORE_TODIMPL_H
-#include <rtems/score/basedefs.h>
+#include <rtems/score/tod.h>
#include <rtems/score/timestamp.h>
#include <sys/time.h>
@@ -149,6 +149,13 @@ typedef struct {
uint32_t seconds_trigger;
/**
+ * @brief The current nanoseconds since last tick handler.
+ *
+ * This field must not be NULL after initialization.
+ */
+ TOD_Nanoseconds_since_last_tick_routine nanoseconds_since_last_tick;
+
+ /**
* @brief Indicates if the time of day is set.
*
* This is true if the application has set the current
@@ -300,6 +307,13 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
_Timestamp_To_timeval( snapshot_as_timestamp_ptr, time );
}
+RTEMS_INLINE_ROUTINE void _TOD_Set_nanoseconds_since_last_tick_handler(
+ TOD_Nanoseconds_since_last_tick_routine routine
+)
+{
+ _TOD.nanoseconds_since_last_tick = routine;
+}
+
RTEMS_INLINE_ROUTINE bool _TOD_Is_set( void )
{
return _TOD.is_set;
diff --git a/cpukit/score/include/rtems/score/watchdog.h b/cpukit/score/include/rtems/score/watchdog.h
index b67e5ca..bd218fd 100644
--- a/cpukit/score/include/rtems/score/watchdog.h
+++ b/cpukit/score/include/rtems/score/watchdog.h
@@ -64,15 +64,6 @@ typedef Watchdog_Service_routine ( *Watchdog_Service_routine_entry )(
);
/**
- * @brief Pointer to the BSP plugin to obtain the number
- * of nanoseconds since the last clock tick.
- *
- * This type defines a pointer to the BSP plugin to obtain the number
- * of nanoseconds since the last clock tick.
- */
-typedef uint32_t (*Watchdog_Nanoseconds_since_last_tick_routine)(void);
-
-/**
* @brief The constant for indefinite wait.
*
* This is the constant for indefinite wait. It is actually an
diff --git a/cpukit/score/include/rtems/score/watchdogimpl.h b/cpukit/score/include/rtems/score/watchdogimpl.h
index 3085a44..faf68fa 100644
--- a/cpukit/score/include/rtems/score/watchdogimpl.h
+++ b/cpukit/score/include/rtems/score/watchdogimpl.h
@@ -93,15 +93,6 @@ SCORE_EXTERN volatile uint32_t _Watchdog_Sync_count;
SCORE_EXTERN volatile Watchdog_Interval _Watchdog_Ticks_since_boot;
/**
- * @brief The number of nanoseconds since the last clock tick.
- *
- * This is a pointer to the optional BSP plugin to obtain the number
- * of nanoseconds since the last clock tick.
- */
-extern Watchdog_Nanoseconds_since_last_tick_routine
- _Watchdog_Nanoseconds_since_tick_handler;
-
-/**
* @brief Watchdog chain which is managed at ticks.
*
* This is the watchdog chain which is managed at ticks.
@@ -245,13 +236,6 @@ void _Watchdog_Report_chain(
);
/**
- * @brief Handler for default nanoseconds since last tick.
- *
- * @retval 0 Always.
- */
-uint32_t _Watchdog_Nanoseconds_since_tick_default_handler( void );
-
-/**
* This routine initializes the specified watchdog. The watchdog is
* made inactive, the watchdog id and handler routine are set to the
* specified values.
diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am
index 6d0cb81..80fad5b 100644
--- a/cpukit/score/preinstall.am
+++ b/cpukit/score/preinstall.am
@@ -263,6 +263,10 @@ $(PROJECT_INCLUDE)/rtems/score/timestamp64.h: include/rtems/score/timestamp64.h
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timestamp64.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timestamp64.h
+$(PROJECT_INCLUDE)/rtems/score/tod.h: include/rtems/score/tod.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tod.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tod.h
+
$(PROJECT_INCLUDE)/rtems/score/todimpl.h: include/rtems/score/todimpl.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/todimpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/todimpl.h
diff --git a/cpukit/score/src/coretod.c b/cpukit/score/src/coretod.c
index bcdfa39..3359d4e 100644
--- a/cpukit/score/src/coretod.c
+++ b/cpukit/score/src/coretod.c
@@ -20,14 +20,22 @@
#include <rtems/score/todimpl.h>
+static uint32_t _TOD_Nanoseconds_since_tick_default_handler( void )
+{
+ return 0;
+}
+
void _TOD_Handler_initialization(void)
{
- /* POSIX format TOD (timespec) */
- _Timestamp_Set( &_TOD.now, TOD_SECONDS_1970_THROUGH_1988, 0 );
+ TOD_Control *tod = &_TOD;
+
+ _Timestamp_Set( &tod->now, TOD_SECONDS_1970_THROUGH_1988, 0 );
+
+ _Timestamp_Set_to_zero( &tod->uptime );
- /* Uptime (timespec) */
- _Timestamp_Set_to_zero( &_TOD.uptime );
+ tod->nanoseconds_since_last_tick =
+ _TOD_Nanoseconds_since_tick_default_handler;
/* TOD has not been set */
- _TOD.is_set = false;
+ tod->is_set = false;
}
diff --git a/cpukit/score/src/coretodget.c b/cpukit/score/src/coretodget.c
index b45930a..50262fd 100644
--- a/cpukit/score/src/coretodget.c
+++ b/cpukit/score/src/coretodget.c
@@ -20,20 +20,20 @@
#include <rtems/score/todimpl.h>
#include <rtems/score/isrlevel.h>
-#include <rtems/score/watchdogimpl.h>
Timestamp_Control *_TOD_Get_with_nanoseconds(
Timestamp_Control *snapshot,
const Timestamp_Control *clock
)
{
+ TOD_Control *tod = &_TOD;
ISR_Level level;
Timestamp_Control offset;
Timestamp_Control now;
uint32_t nanoseconds;
_ISR_Disable( level );
- nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
+ nanoseconds = ( *tod->nanoseconds_since_last_tick )();
now = *clock;
_ISR_Enable( level );
diff --git a/cpukit/score/src/watchdognanoseconds.c b/cpukit/score/src/watchdognanoseconds.c
deleted file mode 100644
index 9c25239..0000000
--- a/cpukit/score/src/watchdognanoseconds.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * @file
- *
- * @brief Default Nanoseconds Since Last Tick Handler
- * @ingroup ScoreWatchdog
- */
-
-/*
- * Copyright (c) 2010 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/system.h>
-#include <rtems/score/watchdogimpl.h>
-
-Watchdog_Nanoseconds_since_last_tick_routine
- _Watchdog_Nanoseconds_since_tick_handler =
- _Watchdog_Nanoseconds_since_tick_default_handler;
-
-uint32_t _Watchdog_Nanoseconds_since_tick_default_handler( void )
-{
- return 0;
-}
--
1.7.7
More information about the devel
mailing list