diff options
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/posix/src/adjtime.c | 30 | ||||
-rw-r--r-- | cpukit/score/Makefile.am | 4 | ||||
-rw-r--r-- | cpukit/score/include/rtems/score/todimpl.h | 12 | ||||
-rw-r--r-- | cpukit/score/src/coretodadjust.c | 51 |
4 files changed, 79 insertions, 18 deletions
diff --git a/cpukit/posix/src/adjtime.c b/cpukit/posix/src/adjtime.c index d5a5589418..1ebecce79c 100644 --- a/cpukit/posix/src/adjtime.c +++ b/cpukit/posix/src/adjtime.c @@ -44,8 +44,6 @@ int adjtime( ) { Timestamp_Control delta_as_timestamp; - Timestamp_Control tod_as_timestamp; - Timestamp_Control *tod_as_timestamp_ptr; /* * Simple validations @@ -53,8 +51,19 @@ int adjtime( if ( !delta ) rtems_set_errno_and_return_minus_one( EINVAL ); + if ( delta->tv_usec >= TOD_MICROSECONDS_PER_SECOND ) + rtems_set_errno_and_return_minus_one( EINVAL ); + + /* + * An adjustment of zero is pretty easy. + */ + if ( delta->tv_sec == 0 && delta->tv_usec == 0 ) + return 0; + /* - * Currently, RTEMS does the adjustment in one movement. + * Currently, RTEMS does the adjustment in one movement so there + * is no way an adjustment was currently underway. + * * Given interest, requirements, and sponsorship, a future * enhancement would be to adjust the time in smaller increments * at each clock tick. Until then, there is no outstanding @@ -71,20 +80,9 @@ int adjtime( _Timestamp_Set( &delta_as_timestamp, delta->tv_sec, delta->tv_usec * 1000 ); /* - * This prevents context switches while we are adjusting the TOD + * Now apply the adjustment */ - - _Thread_Disable_dispatch(); - - tod_as_timestamp_ptr = - _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now ); - - - _Timestamp_Add_to( tod_as_timestamp_ptr, &delta_as_timestamp ); - - _TOD_Set_with_timestamp( tod_as_timestamp_ptr ); - - _Thread_Enable_dispatch(); + _TOD_Adjust( delta_as_timestamp ); return 0; } diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 431dade665..55e10e9c4c 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -319,8 +319,8 @@ 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/coretodgetuptimetimespec.c src/coretodtickle.c \ - src/coretodsecondssinceepoch.c \ - src/coretodtickspersec.c + src/coretodsecondssinceepoch.c src/coretodtickspersec.c \ + src/coretodadjust.c ## WATCHDOG_C_FILES libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \ diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h index 9284d45501..68a2d15dd4 100644 --- a/cpukit/score/include/rtems/score/todimpl.h +++ b/cpukit/score/include/rtems/score/todimpl.h @@ -322,6 +322,18 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval( _Timestamp_To_timeval( snapshot_as_timestamp_ptr, time ); } +/** + * @brief Adjust the Time of Time + * + * This method is used to adjust the current time of day by the + * specified amount. + * + * @param[in] delta is the amount to adjust + */ +void _TOD_Adjust( + const Timestamp_Control timestamp +); + RTEMS_INLINE_ROUTINE void _TOD_Set_nanoseconds_since_last_tick_handler( TOD_Nanoseconds_since_last_tick_routine routine ) diff --git a/cpukit/score/src/coretodadjust.c b/cpukit/score/src/coretodadjust.c new file mode 100644 index 0000000000..09cf01ad7c --- /dev/null +++ b/cpukit/score/src/coretodadjust.c @@ -0,0 +1,51 @@ +/** + * @file + * + * @brief Adjust the Time of Time + * @ingroup ScoreTOD + */ + +/* + * COPYRIGHT (c) 1989-2014. + * 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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/score/threaddispatch.h> +#include <rtems/score/todimpl.h> + +void _TOD_Adjust( + const Timestamp_Control delta +) +{ + Timestamp_Control tod; + Timestamp_Control *tod_ptr; + + /* + * Currently, RTEMS does the adjustment in one movement. + * Given interest, requirements, and sponsorship, a future + * enhancement would be to adjust the time in smaller increments + * at each clock tick. Until then, there is no outstanding + * adjustment. + */ + + /* + * This prevents context switches while we are adjusting the TOD + */ + _Thread_Disable_dispatch(); + + tod_ptr = _TOD_Get_with_nanoseconds( &tod, &_TOD.now ); + + _Timestamp_Add_to( tod_ptr, &delta ); + + _TOD_Set_with_timestamp( tod_ptr ); + + _Thread_Enable_dispatch(); +} |