1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Set Time of Day Given a Timestamp |
---|
5 | * |
---|
6 | * @ingroup ScoreTOD |
---|
7 | */ |
---|
8 | |
---|
9 | /* COPYRIGHT (c) 1989-2007. |
---|
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 | #include <rtems/score/todimpl.h> |
---|
22 | #include <rtems/score/threaddispatch.h> |
---|
23 | #include <rtems/score/watchdogimpl.h> |
---|
24 | |
---|
25 | void _TOD_Set_with_timestamp( |
---|
26 | const Timestamp_Control *tod_as_timestamp |
---|
27 | ) |
---|
28 | { |
---|
29 | struct timespec ts; |
---|
30 | uint32_t nanoseconds; |
---|
31 | Watchdog_Interval seconds_next; |
---|
32 | Watchdog_Interval seconds_now; |
---|
33 | Watchdog_Header *header; |
---|
34 | |
---|
35 | _Timestamp_To_timespec( tod_as_timestamp, &ts ); |
---|
36 | nanoseconds = ts.tv_nsec; |
---|
37 | seconds_next = ts.tv_sec; |
---|
38 | |
---|
39 | _Thread_Disable_dispatch(); |
---|
40 | |
---|
41 | seconds_now = _TOD_Seconds_since_epoch(); |
---|
42 | |
---|
43 | _Timecounter_Set_clock( &ts ); |
---|
44 | |
---|
45 | header = &_Watchdog_Seconds_header; |
---|
46 | |
---|
47 | if ( seconds_next < seconds_now ) |
---|
48 | _Watchdog_Adjust_backward( header, seconds_now - seconds_next ); |
---|
49 | else |
---|
50 | _Watchdog_Adjust_forward( header, seconds_next - seconds_now ); |
---|
51 | |
---|
52 | _TOD.seconds_trigger = nanoseconds; |
---|
53 | _TOD.is_set = true; |
---|
54 | |
---|
55 | _Thread_Enable_dispatch(); |
---|
56 | } |
---|