summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include
diff options
context:
space:
mode:
authorAlexander Krutwig <alexander.krutwig@embedded-brains.de>2015-05-12 14:32:47 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-05-20 08:40:33 +0200
commit7cd2484c4cf9fc759b7205ed6d8adcc6d2c28ff6 (patch)
treedd60b6032354124d97233e7070506f09d1566832 /cpukit/score/include
parenttimecounter: Port to RTEMS (diff)
downloadrtems-7cd2484c4cf9fc759b7205ed6d8adcc6d2c28ff6.tar.bz2
timecounter: Use in RTEMS
Replace timestamp implementation with FreeBSD bintime and timecounters. New test sptests/sptimecounter02. Update #2271.
Diffstat (limited to 'cpukit/score/include')
-rw-r--r--cpukit/score/include/rtems/score/timespec.h6
-rw-r--r--cpukit/score/include/rtems/score/timestamp.h253
-rw-r--r--cpukit/score/include/rtems/score/timestamp64.h379
-rw-r--r--cpukit/score/include/rtems/score/tod.h9
-rw-r--r--cpukit/score/include/rtems/score/todimpl.h135
-rw-r--r--cpukit/score/include/rtems/score/watchdogimpl.h7
6 files changed, 209 insertions, 580 deletions
diff --git a/cpukit/score/include/rtems/score/timespec.h b/cpukit/score/include/rtems/score/timespec.h
index 9200880222..72a000177f 100644
--- a/cpukit/score/include/rtems/score/timespec.h
+++ b/cpukit/score/include/rtems/score/timespec.h
@@ -94,13 +94,11 @@ extern "C" {
* This method returns the timestamp as nanoseconds.
*
* @param[in] time points to the timestamp.
- * @param[in] nanoseconds the nanoseconds since the last tick.
*
* @retval The time in nanoseconds.
*/
-uint64_t _Timespec_Get_As_nanoseconds(
- const struct timespec *time,
- const uint32_t nanoseconds
+uint64_t _Timespec_Get_as_nanoseconds(
+ const struct timespec *time
);
/**
diff --git a/cpukit/score/include/rtems/score/timestamp.h b/cpukit/score/include/rtems/score/timestamp.h
index dbd0425ff8..9d25943a8c 100644
--- a/cpukit/score/include/rtems/score/timestamp.h
+++ b/cpukit/score/include/rtems/score/timestamp.h
@@ -42,37 +42,17 @@
#include <sys/time.h>
-#include <rtems/score/cpu.h>
+#include <rtems/score/basedefs.h>
#include <rtems/score/timespec.h>
#ifdef __cplusplus
extern "C" {
#endif
-#if ! ( ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE \
- && CPU_TIMESTAMP_USE_INT64 == FALSE \
- && CPU_TIMESTAMP_USE_INT64_INLINE == FALSE ) \
- || ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == FALSE \
- && CPU_TIMESTAMP_USE_INT64 == TRUE \
- && CPU_TIMESTAMP_USE_INT64_INLINE == FALSE ) \
- || ( CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == FALSE \
- && CPU_TIMESTAMP_USE_INT64 == FALSE \
- && CPU_TIMESTAMP_USE_INT64_INLINE == TRUE ) )
- #error "Invalid SuperCore Timestamp implementations selection."
-#endif
-
-#if CPU_TIMESTAMP_USE_INT64 == TRUE || CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #include <rtems/score/timestamp64.h>
-#endif
-
/**
* Define the Timestamp control type.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- typedef struct timespec Timestamp_Control;
-#else
- typedef Timestamp64_Control Timestamp_Control;
-#endif
+typedef struct bintime Timestamp_Control;
/**
* @brief Set timestamp to specified seconds and nanoseconds.
@@ -84,13 +64,19 @@ extern "C" {
* @param[in] _seconds is the seconds portion of the timestamp
* @param[in] _nanoseconds is the nanoseconds portion of the timestamp
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
- _Timespec_Set( _time, _seconds, _nanoseconds )
-#else
- #define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
- _Timestamp64_Set( _time, _seconds, _nanoseconds )
-#endif
+RTEMS_INLINE_ROUTINE void _Timestamp_Set(
+ Timestamp_Control *_time,
+ time_t _seconds,
+ long _nanoseconds
+)
+{
+ struct timespec _ts;
+
+ _ts.tv_sec = _seconds;
+ _ts.tv_nsec = _nanoseconds;
+
+ timespec2bintime( &_ts, _time );
+}
/**
* @brief Sets the timestamp to zero.
@@ -100,13 +86,14 @@ extern "C" {
*
* @param[in] _time points to the timestamp instance to zero.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Set_to_zero( _time ) \
- _Timespec_Set_to_zero( _time )
-#else
- #define _Timestamp_Set_to_zero( _time ) \
- _Timestamp64_Set_to_zero( _time )
-#endif
+
+RTEMS_INLINE_ROUTINE void _Timestamp_Set_to_zero(
+ Timestamp_Control *_time
+)
+{
+ _time->sec = 0;
+ _time->frac = 0;
+}
/**
* @brief Less than operator for timestamps.
@@ -119,13 +106,20 @@ extern "C" {
* @retval This method returns true if @a _lhs is less than the @a _rhs and
* false otherwise.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Less_than( _lhs, _rhs ) \
- _Timespec_Less_than( _lhs, _rhs )
-#else
- #define _Timestamp_Less_than( _lhs, _rhs ) \
- _Timestamp64_Less_than( _lhs, _rhs )
-#endif
+
+RTEMS_INLINE_ROUTINE bool _Timestamp_Less_than(
+ const Timestamp_Control *_lhs,
+ const Timestamp_Control *_rhs
+)
+{
+ if ( _lhs->sec < _rhs->sec )
+ return true;
+
+ if ( _lhs->sec > _rhs->sec )
+ return false;
+
+ return _lhs->frac < _rhs->frac;
+}
/**
* @brief Greater than operator for timestamps.
@@ -138,8 +132,20 @@ extern "C" {
* @retval This method returns true if @a _lhs is greater than the @a _rhs and
* false otherwise.
*/
-#define _Timestamp_Greater_than( _lhs, _rhs ) \
- _Timestamp_Less_than( _rhs, _lhs )
+
+RTEMS_INLINE_ROUTINE bool _Timestamp_Greater_than(
+ const Timestamp_Control *_lhs,
+ const Timestamp_Control *_rhs
+)
+{
+ if ( _lhs->sec > _rhs->sec )
+ return true;
+
+ if ( _lhs->sec < _rhs->sec )
+ return false;
+
+ return _lhs->frac > _rhs->frac;
+}
/**
* @brief Equal to than operator for timestamps.
@@ -152,13 +158,14 @@ extern "C" {
* @retval This method returns true if @a _lhs is equal to @a _rhs and
* false otherwise.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Equal_to( _lhs, _rhs ) \
- _Timespec_Equal_to( _lhs, _rhs )
-#else
- #define _Timestamp_Equal_to( _lhs, _rhs ) \
- _Timestamp64_Equal_to( _lhs, _rhs )
-#endif
+
+RTEMS_INLINE_ROUTINE bool _Timestamp_Equal_to(
+ const Timestamp_Control *_lhs,
+ const Timestamp_Control *_rhs
+)
+{
+ return _lhs->sec == _rhs->sec && _lhs->frac == _rhs->frac;
+}
/**
* @brief Adds two timestamps.
@@ -171,13 +178,17 @@ extern "C" {
*
* @retval This method returns the number of seconds @a time increased by.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Add_to( _time, _add ) \
- _Timespec_Add_to( _time, _add )
-#else
- #define _Timestamp_Add_to( _time, _add ) \
- _Timestamp64_Add_to( _time, _add )
-#endif
+RTEMS_INLINE_ROUTINE time_t _Timestamp_Add_to(
+ Timestamp_Control *_time,
+ const Timestamp_Control *_add
+)
+{
+ time_t seconds = _time->sec;
+
+ bintime_add( _time, _add );
+
+ return _time->sec - seconds;
+}
/**
* @brief Subtracts two timestamps.
@@ -192,13 +203,17 @@ extern "C" {
*
* @retval This method fills in @a _result.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Subtract( _start, _end, _result ) \
- _Timespec_Subtract( _start, _end, _result )
-#else
- #define _Timestamp_Subtract( _start, _end, _result ) \
- _Timestamp64_Subtract( _start, _end, _result )
-#endif
+RTEMS_INLINE_ROUTINE void _Timestamp_Subtract(
+ const Timestamp_Control *_start,
+ const Timestamp_Control *_end,
+ Timestamp_Control *_result
+)
+{
+ _result->sec = _end->sec;
+ _result->frac = _end->frac;
+
+ bintime_sub( _result, _start );
+}
/**
* @brief Divides a timestamp by another timestamp.
@@ -213,13 +228,26 @@ extern "C" {
*
* @retval This method fills in @a result.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
- _Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
-#else
- #define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
- _Timestamp64_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
-#endif
+RTEMS_INLINE_ROUTINE void _Timestamp_Divide(
+ const Timestamp_Control *_lhs,
+ const Timestamp_Control *_rhs,
+ uint32_t *_ival_percentage,
+ uint32_t *_fval_percentage
+)
+{
+ struct timespec _ts_left;
+ struct timespec _ts_right;
+
+ bintime2timespec( _lhs, &_ts_left );
+ bintime2timespec( _rhs, &_ts_right );
+
+ _Timespec_Divide(
+ &_ts_left,
+ &_ts_right,
+ _ival_percentage,
+ _fval_percentage
+ );
+}
/**
* @brief Get seconds portion of timestamp.
@@ -230,13 +258,12 @@ extern "C" {
*
* @retval The seconds portion of @a _time.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Get_seconds( _time ) \
- _Timespec_Get_seconds( _time )
-#else
- #define _Timestamp_Get_seconds( _time ) \
- _Timestamp64_Get_seconds( _time )
-#endif
+RTEMS_INLINE_ROUTINE time_t _Timestamp_Get_seconds(
+ const Timestamp_Control *_time
+)
+{
+ return _time->sec;
+}
/**
* @brief Get nanoseconds portion of timestamp.
@@ -247,13 +274,16 @@ extern "C" {
*
* @retval The nanoseconds portion of @a _time.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Get_nanoseconds( _time ) \
- _Timespec_Get_nanoseconds( _time )
-#else
- #define _Timestamp_Get_nanoseconds( _time ) \
- _Timestamp64_Get_nanoseconds( _time )
-#endif
+RTEMS_INLINE_ROUTINE uint32_t _Timestamp_Get_nanoseconds(
+ const Timestamp_Control *_time
+)
+{
+ struct timespec _ts;
+
+ bintime2timespec( _time, &_ts );
+
+ return _ts.tv_nsec;
+}
/**
* @brief Get the timestamp as nanoseconds.
@@ -264,13 +294,16 @@ extern "C" {
*
* @retval The time in nanoseconds.
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_Get_As_nanoseconds( _timestamp, _nanoseconds ) \
- _Timespec_Get_As_nanoseconds( _timestamp, _nanoseconds )
-#else
- #define _Timestamp_Get_As_nanoseconds( _timestamp, _nanoseconds ) \
- _Timestamp64_Get_As_nanoseconds( _timestamp, _nanoseconds )
-#endif
+RTEMS_INLINE_ROUTINE uint64_t _Timestamp_Get_as_nanoseconds(
+ const Timestamp_Control *_time
+)
+{
+ struct timespec _ts;
+
+ bintime2timespec( _time, &_ts );
+
+ return _Timespec_Get_as_nanoseconds( &_ts );
+}
/**
* @brief Convert timestamp to struct timespec.
@@ -280,14 +313,13 @@ extern "C" {
* @param[in] _timestamp points to the timestamp
* @param[in] _timespec points to the timespec
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- /* in this case we know they are the same type so use simple assignment */
- #define _Timestamp_To_timespec( _timestamp, _timespec ) \
- *(_timespec) = *(_timestamp)
-#else
- #define _Timestamp_To_timespec( _timestamp, _timespec ) \
- _Timestamp64_To_timespec( _timestamp, _timespec )
-#endif
+RTEMS_INLINE_ROUTINE void _Timestamp_To_timespec(
+ const Timestamp_Control *_timestamp,
+ struct timespec *_timespec
+)
+{
+ bintime2timespec( _timestamp, _timespec );
+}
/**
* @brief Convert timestamp to struct timeval.
@@ -295,16 +327,13 @@ extern "C" {
* @param[in] _timestamp points to the timestamp
* @param[in] _timeval points to the timeval
*/
-#if CPU_TIMESTAMP_USE_STRUCT_TIMESPEC == TRUE
- #define _Timestamp_To_timeval( _timestamp, _timeval ) \
- do { \
- (_timeval)->tv_sec = (_timestamp)->tv_sec; \
- (_timeval)->tv_usec = (_timestamp)->tv_nsec / 1000; \
- } while (0)
-#else
- #define _Timestamp_To_timeval( _timestamp, _timeval ) \
- _Timestamp64_To_timeval( _timestamp, _timeval )
-#endif
+RTEMS_INLINE_ROUTINE void _Timestamp_To_timeval(
+ const Timestamp_Control *_timestamp,
+ struct timeval *_timeval
+)
+{
+ bintime2timeval( _timestamp, _timeval );
+}
#ifdef __cplusplus
}
diff --git a/cpukit/score/include/rtems/score/timestamp64.h b/cpukit/score/include/rtems/score/timestamp64.h
deleted file mode 100644
index 39b4965a8c..0000000000
--- a/cpukit/score/include/rtems/score/timestamp64.h
+++ /dev/null
@@ -1,379 +0,0 @@
-/**
- * @file rtems/score/timestamp64.h
- *
- * @brief Helpers for Manipulating 64-bit Integer Timestamps
- *
- * This include file contains helpers for manipulating
- * 64-bit integer timestamps.
- */
-
-/*
- * 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.org/license/LICENSE.
- */
-
-#ifndef _RTEMS_SCORE_TIMESTAMP64_H
-#define _RTEMS_SCORE_TIMESTAMP64_H
-
-/**
- * @defgroup SuperCoreTimestamp64 SuperCore Sixty-Four Bit Timestamps
- *
- * @ingroup Score
- *
- * This handler encapsulates functionality related to manipulating
- * the 64 bit integer implementation of SuperCore Timestamps.
- */
-/**@{*/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * This .h file is not for general use. It is an alternative
- * implementation of Timestamps and should only be used that way.
- */
-#ifndef _RTEMS_SCORE_TIMESTAMP_H
- #error "Should only be included by rtems/score/timestamp.h"
-#endif
-
-/*
- * Verify something is defined.
- */
-#if CPU_TIMESTAMP_USE_INT64 != TRUE && CPU_TIMESTAMP_USE_INT64_INLINE != TRUE
- #error "SuperCore Timestamp64 implementation included but not defined."
-#endif
-
-/**
- * Define the Timestamp control type.
- */
-typedef int64_t Timestamp64_Control;
-
-static inline void _Timestamp64_implementation_Set(
- Timestamp64_Control *_time,
- Timestamp64_Control _seconds,
- Timestamp64_Control _nanoseconds
-)
-{
- *_time = _seconds * 1000000000L + _nanoseconds;
-}
-
-/**
- * @brief Set 64-bit timestamp to seconds nanosecond.
- *
- * This method sets the timestamp to the specified seconds and nanoseconds
- * value.
- *
- * @param[in] _time points to the timestamp instance to validate.
- * @param[in] _seconds is the seconds portion of the timestamp
- * @param[in] _nanoseconds is the nanoseconds portion of the timestamp
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Set( _time, _seconds, _nanoseconds ) \
- _Timestamp64_implementation_Set( _time, _seconds, _nanoseconds )
-#else
- void _Timestamp64_Set(
- Timestamp64_Control *_time,
- Timestamp64_Control _seconds,
- Timestamp64_Control _nanoseconds
- );
-#endif
-
-static inline void _Timestamp64_implementation_Set_to_zero(
- Timestamp64_Control *_time
-)
-{
- *_time = 0;
-}
-
-/**
- * @brief Sets the 64-bit timestamp to zero.
- *
- * This method sets the timestamp to zero value.
- *
- * @param[in] _time points to the timestamp instance to zero.
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Set_to_zero( _time ) \
- _Timestamp64_implementation_Set_to_zero( _time )
-#else
- void _Timestamp64_Set_to_zero(
- Timestamp64_Control *_time
- );
-#endif
-
-static inline bool _Timestamp64_implementation_Less_than(
- const Timestamp64_Control *_lhs,
- const Timestamp64_Control *_rhs
-)
-{
- return *_lhs < *_rhs;
-}
-
-/**
- * @brief The "less than" operator for 64-bit timestamps.
- *
- * This method is the less than operator for timestamps.
- *
- * @param[in] _lhs points to the left hand side timestamp
- * @param[in] _rhs points to the right hand side timestamp
- *
- * @retval This method returns true if @a _lhs is less than the @a _rhs and
- * false otherwise.
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Less_than( _lhs, _rhs ) \
- _Timestamp64_implementation_Less_than( _lhs, _rhs )
-#else
- bool _Timestamp64_Less_than(
- const Timestamp64_Control *_lhs,
- const Timestamp64_Control *_rhs
- );
-#endif
-
-static inline bool _Timestamp64_implementation_Equal_to(
- const Timestamp64_Control *_lhs,
- const Timestamp64_Control *_rhs
-)
-{
- return *_lhs == *_rhs;
-}
-
-#define _Timestamp64_Greater_than( _lhs, _rhs ) \
- _Timestamp64_Less_than( _rhs, _lhs )
-
-/**
- * @brief The "equal to" operator for 64-bit timestamps.
- *
- * This method is the is equal to than operator for timestamps.
- *
- * @param[in] _lhs points to the left hand side timestamp
- * @param[in] _rhs points to the right hand side timestamp
- *
- * @retval This method returns true if @a _lhs is equal to @a _rhs and
- * false otherwise.
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Equal_to( _lhs, _rhs ) \
- _Timestamp64_implementation_Equal_to( _lhs, _rhs )
-#else
- bool _Timestamp64_Equal_to(
- const Timestamp64_Control *_lhs,
- const Timestamp64_Control *_rhs
- );
-#endif
-
-static inline void _Timestamp64_implementation_Add_to(
- Timestamp64_Control *_time,
- const Timestamp64_Control *_add
-)
-{
- *_time += *_add;
-}
-
-/**
- * @brief Add two 64-bit timestamps.
- *
- * This routine adds two timestamps. The second argument is added
- * to the first.
- *
- * @param[in] _time points to the base time to be added to
- * @param[in] _add points to the timestamp to add to the first argument
- *
- * @retval This method returns the number of seconds @a time increased by.
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Add_to( _time, _add ) \
- _Timestamp64_implementation_Add_to( _time, _add )
-#else
- void _Timestamp64_Add_to(
- Timestamp64_Control *_time,
- const Timestamp64_Control *_add
- );
-#endif
-
-static inline void _Timestamp64_implementation_Subtract(
- const Timestamp64_Control *_start,
- const Timestamp64_Control *_end,
- Timestamp64_Control *_result
-)
-{
- *_result = *_end - *_start;
-}
-
-/**
- * @brief Subtract two 64-bit timestamps.
- *
- * This routine subtracts two timestamps. @a result is set to
- * @a end - @a start.
- *
- * @param[in] _start points to the starting time
- * @param[in] _end points to the ending time
- * @param[out] _result points to the difference between
- * starting and ending time.
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Subtract( _start, _end, _result ) \
- _Timestamp64_implementation_Subtract( _start, _end, _result )
-#else
- void _Timestamp64_Subtract(
- const Timestamp64_Control *_start,
- const Timestamp64_Control *_end,
- Timestamp64_Control *_result
- );
-#endif
-
-/**
- * @brief Divide 64-bit timestamp by another 64-bit timestamp.
- *
- * This routine divides a timestamp by another timestamp. The
- * intended use is for calculating percentages to three decimal points.
- *
- * @param[in] _lhs points to the left hand number
- * @param[in] _rhs points to the right hand number
- * @param[out] _ival_percentage points to the integer portion of the average
- * @param[out] _fval_percentage points to the thousandths of percentage
- */
-void _Timestamp64_Divide(
- const Timestamp64_Control *_lhs,
- const Timestamp64_Control *_rhs,
- uint32_t *_ival_percentage,
- uint32_t *_fval_percentage
-);
-
-static inline uint32_t _Timestamp64_implementation_Get_seconds(
- const Timestamp64_Control *_time
-)
-{
- return (uint32_t) (*_time / 1000000000L);
-}
-
-/**
- * @brief Get seconds portion of a 64-bit timestamp.
- *
- * This method returns the seconds portion of the specified timestamp
- *
- * @param[in] _time points to the timestamp
- *
- * @retval The seconds portion of @a _time.
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Get_seconds( _time ) \
- _Timestamp64_implementation_Get_seconds( _time )
-#else
- uint32_t _Timestamp64_Get_seconds(
- const Timestamp64_Control *_time
- );
-#endif
-
-static inline uint32_t _Timestamp64_implementation_Get_nanoseconds(
- const Timestamp64_Control *_time
-)
-{
- return (uint32_t) (*_time % 1000000000L);
-}
-
-/**
- * @brief Get nanoseconds portion of a 64-bit timestamp.
- *
- * This method returns the nanoseconds portion of the specified timestamp
- *
- * @param[in] _time points to the timestamp
- *
- * @retval The nanoseconds portion of @a _time.
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_Get_nanoseconds( _time ) \
- _Timestamp64_implementation_Get_nanoseconds( _time )
-#else
- uint32_t _Timestamp64_Get_nanoseconds(
- const Timestamp64_Control *_time
- );
-#endif
-
-static inline uint64_t _Timestamp64_implementation_Get_As_nanoseconds(
- const Timestamp64_Control *_time,
- const uint32_t nanoseconds
-)
-{
- return *_time + (uint64_t) nanoseconds;
-}
-
-/**
- * @brief Get the 64-bit timestamp as nanoseconds.
- *
- * This method returns the 64-bit timestamp as it is already in nanoseconds.
- *
- * @param[in] _time points to the timestamp
- *
- * @retval The nanoseconds portion of @a _time.
- */
-#define _Timestamp64_Get_As_nanoseconds( _time, _nanoseconds ) \
- _Timestamp64_implementation_Get_As_nanoseconds( _time, _nanoseconds )
-
-static inline void _Timestamp64_implementation_To_timespec(
- const Timestamp64_Control *_timestamp,
- struct timespec *_timespec
-)
-{
- _timespec->tv_sec = (time_t) (*_timestamp / 1000000000L);
- _timespec->tv_nsec = (long) (*_timestamp % 1000000000L);
-}
-
-/**
- * @brief Convert 64-bit timestamp to struct timespec.
- *
- * This method returns the seconds portion of the specified timestamp
- *
- * @param[in] _timestamp points to the timestamp
- * @param[out] _timespec points to the timespec
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_To_timespec( _timestamp, _timespec ) \
- _Timestamp64_implementation_To_timespec( _timestamp, _timespec )
-#else
- void _Timestamp64_To_timespec(
- const Timestamp64_Control *_timestamp,
- struct timespec *_timespec
- );
-#endif
-
-static inline void _Timestamp64_implementation_To_timeval(
- const Timestamp64_Control *_timestamp,
- struct timeval *_timeval
-)
-{
- _timeval->tv_sec = (time_t) (*_timestamp / 1000000000U);
- _timeval->tv_usec = (suseconds_t) ((*_timestamp % 1000000000U) / 1000U);
-}
-
-/**
- * @brief Convert 64-bit timestamp to struct timeval.
- *
- * This method returns the seconds portion of the specified timestamp
- *
- * @param[in] _timestamp points to the timestamp
- * @param[out] _timeval points to the timeval
- */
-#if CPU_TIMESTAMP_USE_INT64_INLINE == TRUE
- #define _Timestamp64_To_timeval( _timestamp, _timeval ) \
- _Timestamp64_implementation_To_timeval( _timestamp, _timeval )
-#else
- void _Timestamp64_To_timeval(
- const Timestamp64_Control *_timestamp,
- struct timeval *_timeval
- );
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-/**@}*/
-
-#endif
-/* end of include file */
diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h
index 1972b0fa72..c0ab5e795d 100644
--- a/cpukit/score/include/rtems/score/tod.h
+++ b/cpukit/score/include/rtems/score/tod.h
@@ -24,15 +24,6 @@
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
diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h
index ad5ed39dab..56c176d920 100644
--- a/cpukit/score/include/rtems/score/todimpl.h
+++ b/cpukit/score/include/rtems/score/todimpl.h
@@ -19,8 +19,8 @@
#define _RTEMS_SCORE_TODIMPL_H
#include <rtems/score/tod.h>
-#include <rtems/score/isrlock.h>
#include <rtems/score/timestamp.h>
+#include <rtems/score/timecounterimpl.h>
#include <sys/time.h>
#include <time.h>
@@ -131,25 +131,6 @@ extern "C" {
*/
typedef struct {
/**
- * @brief Current time of day value.
- *
- * This field is protected by the lock.
- */
- Timestamp_Control now;
-
- /**
- * @brief System uptime.
- *
- * This field is protected by the lock.
- */
- Timestamp_Control uptime;
-
- /**
- * @brief Lock to protect the now and uptime fields.
- */
- ISR_lock_Control lock;
-
- /**
* @brief Time of day seconds trigger.
*
* This value specifies the nanoseconds since the last time of day second.
@@ -159,13 +140,6 @@ 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
@@ -176,12 +150,6 @@ typedef struct {
SCORE_EXTERN TOD_Control _TOD;
-#define _TOD_Acquire( _tod, lock_context ) \
- _ISR_lock_ISR_disable_and_acquire( &( _tod )->lock, lock_context )
-
-#define _TOD_Release( _tod, lock_context ) \
- _ISR_lock_Release_and_ISR_enable( &( _tod )->lock, lock_context )
-
/**
* @brief Initializes the time of day handler.
*
@@ -201,6 +169,18 @@ void _TOD_Set_with_timestamp(
const Timestamp_Control *tod_as_timestamp
);
+/**
+ * @brief Sets the time of day from timespec.
+ *
+ * The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
+ * The watchdog seconds chain will be adjusted.
+ *
+ * In the process the input given as timespec will be transformed to FreeBSD
+ * bintime format to guarantee the right format for later setting it with a
+ * timestamp.
+ *
+ * @param[in] tod_as_timespec is the constant of the time of day as a timespec
+ */
static inline void _TOD_Set(
const struct timespec *tod_as_timespec
)
@@ -216,31 +196,27 @@ static inline void _TOD_Set(
}
/**
- * @brief Returns a snapshot of a clock.
- *
- * This function invokes the nanoseconds extension.
+ * @brief Gets the current time in the bintime format.
*
- * @param[out] snapshot points to an area that will contain the current
- * TOD plus the BSP nanoseconds since last tick adjustment
- * @param[in] clock contains the current TOD
- *
- * @retval @a snapshot
+ * @param[out] time is the value gathered by the bintime request
*/
-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 *time
)
{
- Timestamp_Control tod_as_timestamp;
- Timestamp_Control *tod_as_timestamp_ptr;
+ _Timecounter_Bintime(time);
+}
- tod_as_timestamp_ptr =
- _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now );
- _Timestamp_To_timespec( tod_as_timestamp_ptr, tod_as_timespec );
+/**
+ * @brief Gets the current time in the timespec format.
+ *
+ * @param[out] time is the value gathered by the nanotime request
+ */
+static inline void _TOD_Get_as_timespec(
+ struct timespec *time
+)
+{
+ _Timecounter_Nanotime(time);
}
/**
@@ -249,26 +225,47 @@ static inline void _TOD_Get(
* This routine returns the system uptime with potential accuracy
* to the nanosecond.
*
+ * The initial uptime value is undefined.
+ *
* @param[in] time is a pointer to the uptime to be returned
*/
static inline void _TOD_Get_uptime(
Timestamp_Control *time
)
{
- _TOD_Get_with_nanoseconds( time, &_TOD.uptime );
+ _Timecounter_Binuptime( time );
}
/**
* @brief Gets the system uptime with potential accuracy to the nanosecond.
- *
- * This routine returns the system uptime with potential accuracy
* to the nanosecond.
*
+ * The initial uptime value is zero.
+ *
+ * @param[in] time is a pointer to the uptime to be returned
+ */
+static inline void _TOD_Get_zero_based_uptime(
+ Timestamp_Control *time
+)
+{
+ _Timecounter_Binuptime( time );
+ --time->sec;
+}
+
+/**
+ * @brief Gets the system uptime with potential accuracy to the nanosecond.
+ *
+ * The initial uptime value is zero.
+ *
* @param[in] time is a pointer to the uptime to be returned
*/
-void _TOD_Get_uptime_as_timespec(
+static inline void _TOD_Get_zero_based_uptime_as_timespec(
struct timespec *time
-);
+)
+{
+ _Timecounter_Nanouptime( time );
+ --time->tv_sec;
+}
/**
* @brief Number of seconds Since RTEMS epoch.
@@ -276,7 +273,10 @@ void _TOD_Get_uptime_as_timespec(
* The following contains the number of seconds from 00:00:00
* January 1, TOD_BASE_YEAR until the current time of day.
*/
-uint32_t _TOD_Seconds_since_epoch( void );
+static inline uint32_t _TOD_Seconds_since_epoch( void )
+{
+ return (uint32_t) _Timecounter_Time_second;
+}
/**
* @brief Increments time of day at each clock tick.
@@ -314,12 +314,7 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
struct timeval *time
)
{
- Timestamp_Control snapshot_as_timestamp;
- Timestamp_Control *snapshot_as_timestamp_ptr;
-
- snapshot_as_timestamp_ptr =
- _TOD_Get_with_nanoseconds( &snapshot_as_timestamp, &_TOD.now );
- _Timestamp_To_timeval( snapshot_as_timestamp_ptr, time );
+ _Timecounter_Microtime( time );
}
/**
@@ -335,18 +330,6 @@ void _TOD_Adjust(
);
/**
- * @brief Install the BSP's nanoseconds since clock tick handler
- *
- * @param[in] routine is the BSP's nanoseconds since clock tick method
- */
-RTEMS_INLINE_ROUTINE void _TOD_Set_nanoseconds_since_last_tick_handler(
- TOD_Nanoseconds_since_last_tick_routine routine
-)
-{
- _TOD.nanoseconds_since_last_tick = routine;
-}
-
-/**
* @brief Check if the TOD is Set
*
* @return TRUE is the time is set. FALSE otherwise.
diff --git a/cpukit/score/include/rtems/score/watchdogimpl.h b/cpukit/score/include/rtems/score/watchdogimpl.h
index 6804bf24d4..8405232a87 100644
--- a/cpukit/score/include/rtems/score/watchdogimpl.h
+++ b/cpukit/score/include/rtems/score/watchdogimpl.h
@@ -138,6 +138,13 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Flash(
void _Watchdog_Handler_initialization( void );
/**
+ * @brief Triggers a watchdog tick.
+ *
+ * This routine executes TOD, watchdog and scheduler ticks.
+ */
+void _Watchdog_Tick( void );
+
+/**
* @brief Removes @a the_watchdog from the watchdog chain.
*
* This routine removes @a the_watchdog from the watchdog chain on which