1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Set Time of Day Given a Timestamp |
---|
5 | * |
---|
6 | * @ingroup RTEMSScoreTOD |
---|
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/assert.h> |
---|
23 | #include <rtems/score/watchdogimpl.h> |
---|
24 | |
---|
25 | bool _TOD_Set( |
---|
26 | const struct timespec *tod, |
---|
27 | ISR_lock_Context *lock_context |
---|
28 | ) |
---|
29 | { |
---|
30 | struct bintime tod_as_bintime; |
---|
31 | uint64_t tod_as_ticks; |
---|
32 | uint32_t cpu_max; |
---|
33 | uint32_t cpu_index; |
---|
34 | bool retval; |
---|
35 | |
---|
36 | _Assert( _TOD_Is_owner() ); |
---|
37 | |
---|
38 | retval = _TOD_Hook_Run( TOD_ACTION_SET_CLOCK, tod ); |
---|
39 | if ( retval == false ) { |
---|
40 | _TOD_Release( lock_context ); |
---|
41 | return false; |
---|
42 | } |
---|
43 | |
---|
44 | timespec2bintime( tod, &tod_as_bintime ); |
---|
45 | _Timecounter_Set_clock( &tod_as_bintime, lock_context ); |
---|
46 | |
---|
47 | tod_as_ticks = _Watchdog_Ticks_from_timespec( tod ); |
---|
48 | cpu_max = _SMP_Get_processor_maximum(); |
---|
49 | |
---|
50 | for ( cpu_index = 0 ; cpu_index < cpu_max ; ++cpu_index ) { |
---|
51 | Per_CPU_Control *cpu; |
---|
52 | Watchdog_Header *header; |
---|
53 | ISR_lock_Context lock_context; |
---|
54 | Watchdog_Control *first; |
---|
55 | |
---|
56 | cpu = _Per_CPU_Get_by_index( cpu_index ); |
---|
57 | header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ]; |
---|
58 | |
---|
59 | _ISR_lock_ISR_disable_and_acquire( &cpu->Watchdog.Lock, &lock_context ); |
---|
60 | |
---|
61 | first = _Watchdog_Header_first( header ); |
---|
62 | |
---|
63 | if ( first != NULL ) { |
---|
64 | _Watchdog_Tickle( |
---|
65 | header, |
---|
66 | first, |
---|
67 | tod_as_ticks, |
---|
68 | &cpu->Watchdog.Lock, |
---|
69 | &lock_context |
---|
70 | ); |
---|
71 | } |
---|
72 | |
---|
73 | _ISR_lock_Release_and_ISR_enable( &cpu->Watchdog.Lock, &lock_context ); |
---|
74 | } |
---|
75 | |
---|
76 | _TOD.is_set = true; |
---|
77 | |
---|
78 | return true; |
---|
79 | } |
---|