1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #if HAVE_CONFIG_H |
---|
6 | #include "config.h" |
---|
7 | #endif |
---|
8 | |
---|
9 | #include <assert.h> |
---|
10 | #include <time.h> |
---|
11 | #include <errno.h> |
---|
12 | |
---|
13 | #include <rtems/system.h> |
---|
14 | #include <rtems/score/isr.h> |
---|
15 | #include <rtems/score/thread.h> |
---|
16 | #include <rtems/score/tod.h> |
---|
17 | |
---|
18 | #include <rtems/seterr.h> |
---|
19 | #include <rtems/posix/time.h> |
---|
20 | |
---|
21 | /*PAGE |
---|
22 | * |
---|
23 | * 14.2.1 Clocks, P1003.1b-1993, p. 263 |
---|
24 | */ |
---|
25 | |
---|
26 | int clock_settime( |
---|
27 | clockid_t clock_id, |
---|
28 | const struct timespec *tp |
---|
29 | ) |
---|
30 | { |
---|
31 | struct tm split_time; |
---|
32 | TOD_Control tod; |
---|
33 | Watchdog_Interval seconds; |
---|
34 | |
---|
35 | assert( tp ); |
---|
36 | |
---|
37 | switch ( clock_id ) { |
---|
38 | |
---|
39 | case CLOCK_REALTIME: |
---|
40 | (void) gmtime_r( &tp->tv_sec, &split_time ); |
---|
41 | |
---|
42 | /* |
---|
43 | * Convert the tm structure format to that used by the TOD Handler |
---|
44 | * |
---|
45 | * NOTE: TOD Handler does not honor leap seconds. |
---|
46 | */ |
---|
47 | |
---|
48 | tod.year = split_time.tm_year + 1900; /* RHS is years since 1900 */ |
---|
49 | tod.month = split_time.tm_mon + 1; /* RHS uses 0-11 */ |
---|
50 | tod.day = split_time.tm_mday; |
---|
51 | tod.hour = split_time.tm_hour; |
---|
52 | tod.minute = split_time.tm_min; |
---|
53 | tod.second = split_time.tm_sec; /* RHS allows 0-61 for leap seconds */ |
---|
54 | |
---|
55 | tod.ticks = (tp->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) / |
---|
56 | _TOD_Microseconds_per_tick; |
---|
57 | |
---|
58 | if ( !_TOD_Validate( &tod ) ) |
---|
59 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
60 | |
---|
61 | /* |
---|
62 | * We can't use the tp->tv_sec field because it is based on |
---|
63 | * a different EPOCH. |
---|
64 | */ |
---|
65 | |
---|
66 | seconds = _TOD_To_seconds( &tod ); |
---|
67 | _Thread_Disable_dispatch(); |
---|
68 | _TOD_Set( &tod, seconds ); |
---|
69 | _Thread_Enable_dispatch(); |
---|
70 | break; |
---|
71 | |
---|
72 | #ifdef _POSIX_CPUTIME |
---|
73 | case CLOCK_PROCESS_CPUTIME: |
---|
74 | return POSIX_NOT_IMPLEMENTED(); |
---|
75 | break; |
---|
76 | #endif |
---|
77 | |
---|
78 | #ifdef _POSIX_THREAD_CPUTIME |
---|
79 | case CLOCK_THREAD_CPUTIME: |
---|
80 | return POSIX_NOT_IMPLEMENTED(); |
---|
81 | break; |
---|
82 | #endif |
---|
83 | default: |
---|
84 | rtems_set_errno_and_return_minus_one( EINVAL ); |
---|
85 | |
---|
86 | } |
---|
87 | return 0; |
---|
88 | } |
---|