diff options
author | Chris Johns <chrisj@rtems.org> | 2013-12-24 16:38:42 +1100 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2013-12-24 16:46:19 +1100 |
commit | 2d1bdc8f797db5ab6e3ba6945befaf73d9062798 (patch) | |
tree | e8a3eecc64c589a9d0495790e09092dc572f36cf | |
parent | mips/shared: added new doxygen (diff) | |
download | rtems-2d1bdc8f797db5ab6e3ba6945befaf73d9062798.tar.bz2 |
cpukit/rtems: Add rtems_clock_get_uptime_nanoseconds to the RTEMS API.
Add Timestamp support in the score to return a timestamp in nanoseconds.
Add a test.
Update the RTEMS API documentation.
-rw-r--r-- | cpukit/rtems/Makefile.am | 1 | ||||
-rw-r--r-- | cpukit/rtems/include/rtems/rtems/clock.h | 7 | ||||
-rw-r--r-- | cpukit/rtems/src/clockgetuptimenanoseconds.c | 35 | ||||
-rw-r--r-- | cpukit/score/Makefile.am | 6 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/timespec.h | 15 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/timestamp.h | 17 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/timestamp64.h | 20 | ||||
-rw-r--r-- | cpukit/score/src/timespecgetasnanoseconds.c | 29 | ||||
-rw-r--r-- | doc/user/clock.t | 62 | ||||
-rw-r--r-- | testsuites/sptests/sp09/screen02.c | 3 | ||||
-rw-r--r-- | testsuites/sptests/sp09/sp09.scn | 1 |
11 files changed, 177 insertions, 19 deletions
diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am index c8fcfa6bd2..fd5af5aaa1 100644 --- a/cpukit/rtems/Makefile.am +++ b/cpukit/rtems/Makefile.am @@ -151,6 +151,7 @@ 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/clockgetuptimenanoseconds.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 e933a5e31a..dc5901ab0d 100644 --- a/cpukit/rtems/include/rtems/rtems/clock.h +++ b/cpukit/rtems/include/rtems/rtems/clock.h @@ -257,6 +257,13 @@ void rtems_clock_get_uptime_timeval( struct timeval *uptime ); time_t rtems_clock_get_uptime_seconds( void ); /** + * @brief Returns the system uptime in nanoseconds. + * + * @retval The system uptime in nanoseconds. + */ +uint64_t rtems_clock_get_uptime_nanoseconds( void ); + +/** * @brief TOD Validate * * This support function returns true if @a the_tod contains diff --git a/cpukit/rtems/src/clockgetuptimenanoseconds.c b/cpukit/rtems/src/clockgetuptimenanoseconds.c new file mode 100644 index 0000000000..c07a4305db --- /dev/null +++ b/cpukit/rtems/src/clockgetuptimenanoseconds.c @@ -0,0 +1,35 @@ +/** + * @file + * + * @brief Returns the system uptime in seconds. + * @ingroup ClassicClock Clocks + */ + +/* + * Copyright (c) 2013 Chris Johns <chrisj@rtems.org>. All rights reserved. + * + * 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> +#include <rtems/score/todimpl.h> + +uint64_t rtems_clock_get_uptime_nanoseconds( void ) +{ + Timestamp_Control snapshot_as_timestamp; + uint32_t nanoseconds; + ISR_Level level; + + _TOD_Acquire( &_TOD, level ); + snapshot_as_timestamp = _TOD.uptime; + nanoseconds = ( *_TOD.nanoseconds_since_last_tick )(); + _TOD_Release( &_TOD, level ); + + return _Timestamp_Get_As_nanoseconds( &snapshot_as_timestamp, nanoseconds ); +} diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 4570ffd16a..4b221294d2 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -215,7 +215,7 @@ libscore_a_SOURCES += src/schedulersimple.c \ src/schedulersimplereadyqueueenqueuefirst.c \ src/schedulersimpleschedule.c \ src/schedulersimpleunblock.c \ - src/schedulersimpleyield.c + src/schedulersimpleyield.c ## SCHEDULEREDF_C_FILES libscore_a_SOURCES += src/scheduleredf.c \ @@ -275,7 +275,7 @@ libscore_a_SOURCES += src/thread.c src/threadchangepriority.c \ src/threadstackallocate.c src/threadstackfree.c src/threadstart.c \ src/threadstartmultitasking.c src/iterateoverthreads.c \ src/threadblockingoperationcancel.c - + if HAS_SMP libscore_a_SOURCES += src/threaddispatchdisablelevel.c endif @@ -294,7 +294,7 @@ libscore_a_SOURCES += src/threadq.c src/threadqdequeue.c \ libscore_a_SOURCES += src/timespecaddto.c src/timespecfromticks.c \ src/timespecisvalid.c src/timespeclessthan.c \ src/timespecsubtract.c src/timespectoticks.c src/timespecdivide.c \ - src/timespecdividebyinteger.c + src/timespecdividebyinteger.c src/timespecgetasnanoseconds.c ## TIMESTAMP_INT64_C_FILES libscore_a_SOURCES += src/ts64addto.c src/ts64dividebyinteger.c \ diff --git a/cpukit/score/include/rtems/score/timespec.h b/cpukit/score/include/rtems/score/timespec.h index e72ccb2b72..8dd1853511 100644 --- a/cpukit/score/include/rtems/score/timespec.h +++ b/cpukit/score/include/rtems/score/timespec.h @@ -89,6 +89,21 @@ extern "C" { ((_time)->tv_nsec) /** + * @brief Get the timestamp as nanoseconds. + * + * 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 +); + +/** * @brief Check if timespec is valid. * * This method determines the validity of a timespec. diff --git a/cpukit/score/include/rtems/score/timestamp.h b/cpukit/score/include/rtems/score/timestamp.h index 638ae7bf52..b920e69d47 100644 --- a/cpukit/score/include/rtems/score/timestamp.h +++ b/cpukit/score/include/rtems/score/timestamp.h @@ -330,6 +330,23 @@ extern "C" { #endif /** + * @brief Get the timestamp as nanoseconds. + * + * This method returns the timestamp as nanoseconds. + * + * @param[in] _time points to the timestamp + * + * @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 + +/** * @brief Convert timestamp to struct timespec. * * This method returns the seconds portion of the specified @a _timestamp. diff --git a/cpukit/score/include/rtems/score/timestamp64.h b/cpukit/score/include/rtems/score/timestamp64.h index 306ee35fee..bd37ec23e4 100644 --- a/cpukit/score/include/rtems/score/timestamp64.h +++ b/cpukit/score/include/rtems/score/timestamp64.h @@ -367,6 +367,26 @@ static inline uint32_t _Timestamp64_implementation_Get_nanoseconds( ); #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 diff --git a/cpukit/score/src/timespecgetasnanoseconds.c b/cpukit/score/src/timespecgetasnanoseconds.c new file mode 100644 index 0000000000..4ef1af4f62 --- /dev/null +++ b/cpukit/score/src/timespecgetasnanoseconds.c @@ -0,0 +1,29 @@ +/** + * @file + * + * @brief Get As Nanoseconds + * @ingroup Timespec + */ + +/* + * COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org> + * + * 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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/score/timespec.h> +#include <rtems/score/todimpl.h> + +uint64_t _Timespec_Get_As_nanoseconds( + const struct timespec *time, + const uint32_t nanoseconds +) +{ + return ( ((uint64_t) time->tv_sec) * 1000000000ULL ) + time->tv_nsec + nanoseconds; +} diff --git a/doc/user/clock.t b/doc/user/clock.t index 368e2874e8..fdbd91db21 100644 --- a/doc/user/clock.t +++ b/doc/user/clock.t @@ -18,12 +18,13 @@ the clock manager are: @item @code{@value{DIRPREFIX}clock_get} - Get date and time information @item @code{@value{DIRPREFIX}clock_get_tod} - Get date and time in TOD format @item @code{@value{DIRPREFIX}clock_get_tod_timeval} - Get date and time in timeval format -@item @code{@value{DIRPREFIX}clock_get_seconds_since_epoch} - Get seconds since epoch +@item @code{@value{DIRPREFIX}clock_get_seconds_since_epoch} - Get seconds since epoch @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 @item @code{@value{DIRPREFIX}clock_get_uptime_timeval} - Get time since boot in timeval format @item @code{@value{DIRPREFIX}clock_get_uptime_seconds} - Get seconds since boot +@item @code{@value{DIRPREFIX}clock_get_uptime_nanoseconds} - Get nanoseconds 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 @@ -85,11 +86,11 @@ type Time_Of_Day is The native date and time format is the only format supported when setting the system date and time using the @code{@value{DIRPREFIX}clock_set} directive. Some applications -expect to operate on a "UNIX-style" date and time data structure. The +expect to operate on a "UNIX-style" date and time data structure. The @code{@value{DIRPREFIX}clock_get_tod_timeval} always returns -the date and time in @code{struct timeval} format. The +the date and time in @code{struct timeval} format. The @code{@value{DIRPREFIX}clock_get} directive can optionally return -the current date and time in this format. +the current date and time in this format. The @code{struct timeval} data structure has two fields: @code{tv_sec} and @code{tv_usec} which are seconds and microseconds, respectively. @@ -142,8 +143,8 @@ created when the timeout option is used on the @code{@value{DIRPREFIX}message_queue_receive}, @code{@value{DIRPREFIX}event_receive}, @code{@value{DIRPREFIX}semaphore_obtain} and -@code{@value{DIRPREFIX}region_get_segment} directives. -Each task may have one and only one timeout active at a time. +@code{@value{DIRPREFIX}region_get_segment} directives. +Each task may have one and only one timeout active at a time. When a timeout expires, it unblocks the task with a timeout status code. @section Operations @@ -192,7 +193,7 @@ is specified using one of the following constants associated with the enumerated type @code{@value{DIRPREFIX}clock_get_options}: -@findex rtems_clock_get_options +@findex rtems_clock_get_options @itemize @bullet @item @code{@value{RPREFIX}CLOCK_GET_TOD} - obtain native style date and time @@ -322,7 +323,7 @@ option is set to either @code{@value{RPREFIX}CLOCK_GET_SECONDS_SINCE_EPOCH}, @code{@value{RPREFIX}CLOCK_GET_TIME_VALUE}) and the date and time has not been set with a previous call to @code{@value{DIRPREFIX}clock_set}, then the -@code{@value{RPREFIX}NOT_DEFINED} status code is returned. +@code{@value{RPREFIX}NOT_DEFINED} status code is returned. The caller can always obtain the number of ticks per second (option is @code{@value{RPREFIX}CLOCK_GET_TICKS_PER_SECOND}) and the number of ticks since the executive was initialized option is @@ -333,7 +334,7 @@ type @code{rtems_clock_get_options}. The data type expected for @code{time_buffer} is based on the value of @code{option} as indicated below: -@findex rtems_clock_get_options +@findex rtems_clock_get_options @ifset is-C @itemize @bullet @item @code{@value{RPREFIX}CLOCK_GET_TOD} - (rtems_time_of_day *) @@ -417,7 +418,7 @@ procedure Clock_Get_TOD ( This directive obtains the system date and time. If the date and time has not been set with a previous call to @code{@value{DIRPREFIX}clock_set}, then the -@code{@value{RPREFIX}NOT_DEFINED} status code is returned. +@code{@value{RPREFIX}NOT_DEFINED} status code is returned. @subheading NOTES: @@ -468,7 +469,7 @@ This directive obtains the system date and time in POSIX @code{struct timeval} format. If the date and time has not been set with a previous call to @code{@value{DIRPREFIX}clock_set}, then the -@code{@value{RPREFIX}NOT_DEFINED} status code is returned. +@code{@value{RPREFIX}NOT_DEFINED} status code is returned. @subheading NOTES: @@ -519,7 +520,7 @@ This directive returns the number of seconds since the RTEMS epoch and the current system date and time. If the date and time has not been set with a previous call to @code{@value{DIRPREFIX}clock_set}, then the -@code{@value{RPREFIX}NOT_DEFINED} status code is returned. +@code{@value{RPREFIX}NOT_DEFINED} status code is returned. @subheading NOTES: @@ -620,7 +621,7 @@ time to be reset to an uninitialized state. Another call to system date and time to application specific specifications. This directive simply returns the number of times the dirivective -@code{@value{DIRPREFIX}clock_tick} has been invoked since the +@code{@value{DIRPREFIX}clock_tick} has been invoked since the system was booted. @c @@ -736,6 +737,36 @@ This directive may be called from an ISR. @c @c @page +@subsection CLOCK_GET_UPTIME_NANOSECONDS - Get the nanoseconds since boot + +@cindex clock get nanoseconds uptime +@cindex uptime + +@subheading CALLING SEQUENCE: + +@ifset is-C +@findex rtems_clock_get_uptime_nanoseconds +@example +uint64_t rtems_clock_get_uptime_nanoseconds(void); +@end example +@end ifset + +@subheading DIRECTIVE STATUS CODES: + +The system uptime in nanoseconds. + +@subheading DESCRIPTION: + +This directive returns the nanoseconds since the system was booted. + +@subheading NOTES: + +This directive may be called from an ISR. + +@c +@c +@c +@page @subsection CLOCK_SET_NANOSECONDS_EXTENSION - Install the nanoseconds since last tick handler @cindex clock set nanoseconds extension @@ -765,7 +796,7 @@ NOT SUPPORTED FROM Ada BINDING @subheading DESCRIPTION: -This directive is used by the Clock device driver to install the +This directive is used by the Clock device driver to install the @code{routine} which will be invoked by the internal RTEMS method used to obtain a highly accurate time of day. It is usually called during the initialization of the driver. @@ -780,7 +811,7 @@ on the device used as a clock source. This directive may be called from an ISR. -This directive is called as part of every service to obtain the +This directive is called as part of every service to obtain the current date and time as well as timestamps. @c @@ -828,4 +859,3 @@ The @code{microseconds_per_tick} and @code{ticks_per_timeslice} parameters in the Configuration Table contain the number of microseconds per tick and number of ticks per timeslice, respectively. - diff --git a/testsuites/sptests/sp09/screen02.c b/testsuites/sptests/sp09/screen02.c index fb735dac2c..6ae78f80ea 100644 --- a/testsuites/sptests/sp09/screen02.c +++ b/testsuites/sptests/sp09/screen02.c @@ -89,6 +89,9 @@ void Screen2() puts( "TA1 - rtems_clock_get_uptime_seconds" ); rtems_clock_get_uptime_seconds(); + puts( "TA1 - rtems_clock_get_uptime_nanoseconds" ); + rtems_clock_get_uptime_nanoseconds(); + 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 80c4598a74..a414553b45 100644 --- a/testsuites/sptests/sp09/sp09.scn +++ b/testsuites/sptests/sp09/sp09.scn @@ -33,6 +33,7 @@ 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_uptime_nanoseconds 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 |