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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/score/object.h> |
---|
23 | #include <rtems/score/thread.h> |
---|
24 | #include <rtems/score/timestamp.h> |
---|
25 | #include <rtems/score/tod.h> |
---|
26 | #include <rtems/score/watchdog.h> |
---|
27 | |
---|
28 | void _TOD_Set_with_timestamp( |
---|
29 | const Timestamp_Control *tod |
---|
30 | ) |
---|
31 | { |
---|
32 | uint32_t nanoseconds = _Timestamp_Get_nanoseconds( tod ); |
---|
33 | Watchdog_Interval seconds_next = _Timestamp_Get_seconds( tod ); |
---|
34 | Watchdog_Interval seconds_now; |
---|
35 | |
---|
36 | _Thread_Disable_dispatch(); |
---|
37 | _TOD_Deactivate(); |
---|
38 | |
---|
39 | seconds_now = _TOD_Seconds_since_epoch(); |
---|
40 | |
---|
41 | if ( seconds_next < seconds_now ) |
---|
42 | _Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds_now - seconds_next ); |
---|
43 | else |
---|
44 | _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, seconds_next - seconds_now ); |
---|
45 | |
---|
46 | _TOD.now = *tod; |
---|
47 | _TOD.seconds_trigger = nanoseconds; |
---|
48 | _TOD.is_set = true; |
---|
49 | |
---|
50 | _TOD_Activate(); |
---|
51 | _Thread_Enable_dispatch(); |
---|
52 | } |
---|