Changeset 3b6352d in rtems
- Timestamp:
- 07/19/14 00:46:59 (9 years ago)
- Branches:
- 4.11, 5, master
- Children:
- 875fff0a
- Parents:
- 8abbbdde
- git-author:
- Joel Sherrill <joel.sherrill@…> (07/19/14 00:46:59)
- git-committer:
- Joel Sherrill <joel.sherrill@…> (07/23/14 19:24:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/posix/src/adjtime.c
r8abbbdde r3b6352d 2 2 * @file 3 3 * 4 * @brief Correct the Time to Synchronize the System Clock4 * @brief Adjust the Time to Synchronize the System Clock 5 5 * @ingroup POSIXAPI 6 6 */ 7 7 8 8 /* 9 * COPYRIGHT (c) 1989-20 07.9 * COPYRIGHT (c) 1989-2014. 10 10 * On-Line Applications Research Corporation (OAR). 11 11 * … … 19 19 #endif 20 20 21 #define _BSD_SOURCE 21 22 #include <time.h> 22 23 #include <sys/time.h> … … 31 32 /** 32 33 * This method was initially added as part of porting NTP to RTEMS. 33 * 34 * 34 * It is a BSD compatability function and now is available on 35 * GNU/Linux. 35 36 * 36 * 37 * 38 * 37 * At one point there was a static variable named adjustment 38 * used by this implementation. I don't see any reason for it 39 * to be here based upon the GNU/Linux documentation. 39 40 */ 40 int 41 int adjtime( 41 42 const struct timeval *delta, 42 struct timeval *olddelta43 struct timeval *olddelta 43 44 ) 44 45 { 45 struct timespec ts; 46 long adjustment; 46 Timestamp_Control delta_as_timestamp; 47 Timestamp_Control tod_as_timestamp; 48 Timestamp_Control *tod_as_timestamp_ptr; 47 49 48 50 /* … … 52 54 rtems_set_errno_and_return_minus_one( EINVAL ); 53 55 54 if ( delta->tv_usec >= TOD_MICROSECONDS_PER_SECOND ) 55 rtems_set_errno_and_return_minus_one( EINVAL ); 56 56 /* 57 * Currently, RTEMS does the adjustment in one movement. 58 * Given interest, requirements, and sponsorship, a future 59 * enhancement would be to adjust the time in smaller increments 60 * at each clock tick. Until then, there is no outstanding 61 * adjustment. 62 */ 57 63 if ( olddelta ) { 58 64 olddelta->tv_sec = 0; … … 60 66 } 61 67 62 /* convert delta to microseconds */ 63 adjustment = (delta->tv_sec * TOD_MICROSECONDS_PER_SECOND); 64 adjustment += delta->tv_usec; 65 66 /* too small to account for */ 67 if ( adjustment < rtems_configuration_get_microseconds_per_tick() ) 68 return 0; 68 /* 69 * convert delta timeval to internal timestamp 70 */ 71 _Timestamp_Set( &delta_as_timestamp, delta->tv_sec, delta->tv_usec * 1000 ); 69 72 70 73 /* … … 74 77 _Thread_Disable_dispatch(); 75 78 76 _TOD_Get( &ts ); 79 tod_as_timestamp_ptr = 80 _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now ); 77 81 78 ts.tv_sec += delta->tv_sec;79 ts.tv_nsec += delta->tv_usec * TOD_NANOSECONDS_PER_MICROSECOND;80 82 81 /* if adjustment is too much positive */ 82 while ( ts.tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) { 83 ts.tv_nsec -= TOD_NANOSECONDS_PER_SECOND; 84 ts.tv_sec++; 85 } 83 _Timestamp_Add_to( tod_as_timestamp_ptr, &delta_as_timestamp ); 86 84 87 /* if adjustment is too much negative */ 88 while ( ts.tv_nsec <= (-1 * TOD_NANOSECONDS_PER_SECOND) ) { 89 ts.tv_nsec += TOD_NANOSECONDS_PER_SECOND; 90 ts.tv_sec--; 91 } 92 93 _TOD_Set( &ts ); 85 _TOD_Set_with_timestamp( tod_as_timestamp_ptr ); 94 86 95 87 _Thread_Enable_dispatch(); 96 88 97 /* set the user's output */98 if ( olddelta )99 *olddelta = *delta;100 101 89 return 0; 102 90 }
Note: See TracChangeset
for help on using the changeset viewer.