1 | /* |
---|
2 | * Copyright (c) 2015, 2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/score/watchdogimpl.h> |
---|
20 | #include <rtems/score/schedulerimpl.h> |
---|
21 | #include <rtems/score/threaddispatch.h> |
---|
22 | #include <rtems/score/timecounter.h> |
---|
23 | |
---|
24 | void _Watchdog_Do_tickle( |
---|
25 | Watchdog_Header *header, |
---|
26 | Watchdog_Control *first, |
---|
27 | uint64_t now, |
---|
28 | #ifdef RTEMS_SMP |
---|
29 | ISR_lock_Control *lock, |
---|
30 | #endif |
---|
31 | ISR_lock_Context *lock_context |
---|
32 | ) |
---|
33 | { |
---|
34 | do { |
---|
35 | if ( first->expire <= now ) { |
---|
36 | Watchdog_Service_routine_entry routine; |
---|
37 | |
---|
38 | _Watchdog_Next_first( header, first ); |
---|
39 | _RBTree_Extract( &header->Watchdogs, &first->Node.RBTree ); |
---|
40 | _Watchdog_Set_state( first, WATCHDOG_INACTIVE ); |
---|
41 | routine = first->routine; |
---|
42 | |
---|
43 | _ISR_lock_Release_and_ISR_enable( lock, lock_context ); |
---|
44 | ( *routine )( first ); |
---|
45 | _ISR_lock_ISR_disable_and_acquire( lock, lock_context ); |
---|
46 | } else { |
---|
47 | break; |
---|
48 | } |
---|
49 | |
---|
50 | first = _Watchdog_Header_first( header ); |
---|
51 | } while ( first != NULL ); |
---|
52 | } |
---|
53 | |
---|
54 | void _Watchdog_Tick( Per_CPU_Control *cpu ) |
---|
55 | { |
---|
56 | ISR_lock_Context lock_context; |
---|
57 | Watchdog_Header *header; |
---|
58 | Watchdog_Control *first; |
---|
59 | uint64_t ticks; |
---|
60 | struct timespec now; |
---|
61 | |
---|
62 | if ( _Per_CPU_Is_boot_processor( cpu ) ) { |
---|
63 | ++_Watchdog_Ticks_since_boot; |
---|
64 | } |
---|
65 | |
---|
66 | _ISR_lock_ISR_disable_and_acquire( &cpu->Watchdog.Lock, &lock_context ); |
---|
67 | |
---|
68 | ticks = cpu->Watchdog.ticks; |
---|
69 | _Assert( ticks < UINT64_MAX ); |
---|
70 | ++ticks; |
---|
71 | cpu->Watchdog.ticks = ticks; |
---|
72 | |
---|
73 | header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ]; |
---|
74 | first = _Watchdog_Header_first( header ); |
---|
75 | |
---|
76 | if ( first != NULL ) { |
---|
77 | _Watchdog_Tickle( |
---|
78 | header, |
---|
79 | first, |
---|
80 | ticks, |
---|
81 | &cpu->Watchdog.Lock, |
---|
82 | &lock_context |
---|
83 | ); |
---|
84 | } |
---|
85 | |
---|
86 | header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; |
---|
87 | first = _Watchdog_Header_first( header ); |
---|
88 | |
---|
89 | if ( first != NULL ) { |
---|
90 | _Timecounter_Getnanouptime( &now ); |
---|
91 | _Watchdog_Tickle( |
---|
92 | header, |
---|
93 | first, |
---|
94 | _Watchdog_Ticks_from_timespec( &now ), |
---|
95 | &cpu->Watchdog.Lock, |
---|
96 | &lock_context |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ]; |
---|
101 | first = _Watchdog_Header_first( header ); |
---|
102 | |
---|
103 | if ( first != NULL ) { |
---|
104 | _Timecounter_Getnanotime( &now ); |
---|
105 | _Watchdog_Tickle( |
---|
106 | header, |
---|
107 | first, |
---|
108 | _Watchdog_Ticks_from_timespec( &now ), |
---|
109 | &cpu->Watchdog.Lock, |
---|
110 | &lock_context |
---|
111 | ); |
---|
112 | } |
---|
113 | |
---|
114 | _ISR_lock_Release_and_ISR_enable( &cpu->Watchdog.Lock, &lock_context ); |
---|
115 | |
---|
116 | _Scheduler_Tick( cpu ); |
---|
117 | } |
---|