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