1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Adjust the Time to Synchronize the System Clock |
---|
5 | * @ingroup POSIXAPI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #define _BSD_SOURCE |
---|
22 | #include <time.h> |
---|
23 | #include <sys/time.h> |
---|
24 | #include <errno.h> |
---|
25 | |
---|
26 | #include <rtems/score/timespec.h> |
---|
27 | #include <rtems/score/threaddispatch.h> |
---|
28 | #include <rtems/score/todimpl.h> |
---|
29 | #include <rtems/config.h> |
---|
30 | #include <rtems/seterr.h> |
---|
31 | |
---|
32 | /** |
---|
33 | * This method was initially added as part of porting NTP to RTEMS. |
---|
34 | * It is a BSD compatability function and now is available on |
---|
35 | * GNU/Linux. |
---|
36 | * |
---|
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. |
---|
40 | */ |
---|
41 | int adjtime( |
---|
42 | const struct timeval *delta, |
---|
43 | struct timeval *olddelta |
---|
44 | ) |
---|
45 | { |
---|
46 | Timestamp_Control delta_as_timestamp; |
---|
47 | |
---|
48 | /* |
---|
49 | * Simple validations |
---|
50 | */ |
---|
51 | if ( !delta ) |
---|
52 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
53 | |
---|
54 | if ( delta->tv_usec >= TOD_MICROSECONDS_PER_SECOND ) |
---|
55 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
56 | |
---|
57 | /* |
---|
58 | * An adjustment of zero is pretty easy. |
---|
59 | */ |
---|
60 | if ( delta->tv_sec == 0 && delta->tv_usec == 0 ) |
---|
61 | return 0; |
---|
62 | |
---|
63 | /* |
---|
64 | * Currently, RTEMS does the adjustment in one movement so there |
---|
65 | * is no way an adjustment was currently underway. |
---|
66 | * |
---|
67 | * Given interest, requirements, and sponsorship, a future |
---|
68 | * enhancement would be to adjust the time in smaller increments |
---|
69 | * at each clock tick. Until then, there is no outstanding |
---|
70 | * adjustment. |
---|
71 | */ |
---|
72 | if ( olddelta ) { |
---|
73 | olddelta->tv_sec = 0; |
---|
74 | olddelta->tv_usec = 0; |
---|
75 | } |
---|
76 | |
---|
77 | /* |
---|
78 | * convert delta timeval to internal timestamp |
---|
79 | */ |
---|
80 | _Timestamp_Set( &delta_as_timestamp, delta->tv_sec, delta->tv_usec * 1000 ); |
---|
81 | |
---|
82 | /* |
---|
83 | * Now apply the adjustment |
---|
84 | */ |
---|
85 | _TOD_Adjust( &delta_as_timestamp ); |
---|
86 | |
---|
87 | return 0; |
---|
88 | } |
---|