1 | /** |
---|
2 | * @file rtems/score/watchdog.h |
---|
3 | * |
---|
4 | * This include file contains all the constants and structures associated |
---|
5 | * with watchdog timers. This Handler provides mechanisms which can be |
---|
6 | * used to initialize and manipulate watchdog timers. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2007. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | * |
---|
17 | * $Id$ |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef _RTEMS_SCORE_WATCHDOG_H |
---|
21 | #define _RTEMS_SCORE_WATCHDOG_H |
---|
22 | |
---|
23 | /** |
---|
24 | * @defgroup ScoreWatchdog Watchdog Handler |
---|
25 | * |
---|
26 | * This handler encapsulates functionality related to the scheduling of |
---|
27 | * watchdog functions to be called at specific times in the future. |
---|
28 | * |
---|
29 | * @note This handler does not have anything to do with hardware watchdog |
---|
30 | * timers. |
---|
31 | */ |
---|
32 | /**@{*/ |
---|
33 | |
---|
34 | #include <rtems/score/object.h> |
---|
35 | |
---|
36 | #ifdef __cplusplus |
---|
37 | extern "C" { |
---|
38 | #endif |
---|
39 | |
---|
40 | /** @brief Maximum Interval Length |
---|
41 | * |
---|
42 | * The following type defines the control block used to manage |
---|
43 | * intervals. |
---|
44 | */ |
---|
45 | #define WATCHDOG_MAXIMUM_INTERVAL ((Watchdog_Interval) 0xffffffff) |
---|
46 | |
---|
47 | /** @brief Watchdog Interval Type |
---|
48 | * |
---|
49 | * This type is used to specify the length of intervals. |
---|
50 | */ |
---|
51 | typedef uint32_t Watchdog_Interval; |
---|
52 | |
---|
53 | /** @brief Watchdog Nanoseconds Since Last Tick Extension |
---|
54 | * |
---|
55 | * This type defines a pointer to the BSP plugin to obtain the number |
---|
56 | * of nanoseconds since the last clock tick. |
---|
57 | */ |
---|
58 | typedef uint32_t (*Watchdog_Nanoseconds_since_last_tick_routine)(void); |
---|
59 | |
---|
60 | /** @brief Watchdog Service Routine Return Type |
---|
61 | * |
---|
62 | * This type defines the return type from a Watchdog Service Routine. |
---|
63 | */ |
---|
64 | typedef void Watchdog_Service_routine; |
---|
65 | |
---|
66 | /** @brief Watchdog Service Routine Pointer Type |
---|
67 | * |
---|
68 | * This type define a pointer to a watchdog service routine. |
---|
69 | */ |
---|
70 | typedef Watchdog_Service_routine ( *Watchdog_Service_routine_entry )( |
---|
71 | Objects_Id, |
---|
72 | void * |
---|
73 | ); |
---|
74 | |
---|
75 | /** @brief No timeout constant |
---|
76 | * |
---|
77 | * This is the constant for indefinite wait. It is actually an |
---|
78 | * illegal interval. |
---|
79 | */ |
---|
80 | #define WATCHDOG_NO_TIMEOUT 0 |
---|
81 | |
---|
82 | /** @brief Watchdog States Type |
---|
83 | * |
---|
84 | * This enumerated type is the set of the states in which a |
---|
85 | * watchdog timer may be at any given time. |
---|
86 | */ |
---|
87 | |
---|
88 | typedef enum { |
---|
89 | /** This is the state when the watchdog is off all chains */ |
---|
90 | WATCHDOG_INACTIVE, |
---|
91 | /** This is the state when the watchdog is off all chains, but we are |
---|
92 | * currently searching for the insertion point. |
---|
93 | */ |
---|
94 | WATCHDOG_BEING_INSERTED, |
---|
95 | /** This is the state when the watchdog is on a chain, and allowed to fire. */ |
---|
96 | WATCHDOG_ACTIVE, |
---|
97 | /** This is the state when the watchdog is on a chain, but we should |
---|
98 | * remove without firing if it expires. |
---|
99 | */ |
---|
100 | WATCHDOG_REMOVE_IT |
---|
101 | } Watchdog_States; |
---|
102 | |
---|
103 | /** @brief Watchdog Adjustment Directions Type |
---|
104 | * |
---|
105 | * The following enumerated type details the manner in which |
---|
106 | * a watchdog chain may be adjusted by the @ref _Watchdog_Adjust |
---|
107 | * routine. The direction indicates a movement FORWARD |
---|
108 | * or BACKWARD in time. |
---|
109 | */ |
---|
110 | typedef enum { |
---|
111 | /** adjust delta value forward */ |
---|
112 | WATCHDOG_FORWARD, |
---|
113 | /** adjust delta value backward */ |
---|
114 | WATCHDOG_BACKWARD |
---|
115 | } Watchdog_Adjust_directions; |
---|
116 | |
---|
117 | /** @brief Watchdog Control Structure |
---|
118 | * |
---|
119 | * The following record defines the control block used |
---|
120 | * to manage each watchdog timer. |
---|
121 | */ |
---|
122 | typedef struct { |
---|
123 | /** This field is a Chain Node structure and allows this to be placed on |
---|
124 | * chains for set management. |
---|
125 | */ |
---|
126 | Chain_Node Node; |
---|
127 | /** This field is the state of the watchdog. */ |
---|
128 | Watchdog_States state; |
---|
129 | /** This field is the initially requested interval. */ |
---|
130 | Watchdog_Interval initial; |
---|
131 | /** This field is the remaining portion of the interval. */ |
---|
132 | Watchdog_Interval delta_interval; |
---|
133 | /** This field is the number of system clock ticks when this was scheduled. */ |
---|
134 | Watchdog_Interval start_time; |
---|
135 | /** This field is the number of system clock ticks when this was suspended. */ |
---|
136 | Watchdog_Interval stop_time; |
---|
137 | /** This field is the function to invoke. */ |
---|
138 | Watchdog_Service_routine_entry routine; |
---|
139 | /** This field is the Id to pass as an argument to the routine. */ |
---|
140 | Objects_Id id; |
---|
141 | /** This field is an untyped pointer to user data that is passed to the |
---|
142 | * watchdog handler routine. |
---|
143 | */ |
---|
144 | void *user_data; |
---|
145 | } Watchdog_Control; |
---|
146 | |
---|
147 | /** @brief Watchdog Synchronization Level |
---|
148 | * |
---|
149 | * This used for synchronization purposes |
---|
150 | * during an insert on a watchdog delta chain. |
---|
151 | */ |
---|
152 | SCORE_EXTERN volatile uint32_t _Watchdog_Sync_level; |
---|
153 | |
---|
154 | /** @brief Watchdog Synchronization Count |
---|
155 | * |
---|
156 | * This used for synchronization purposes |
---|
157 | * during an insert on a watchdog delta chain. |
---|
158 | */ |
---|
159 | SCORE_EXTERN volatile uint32_t _Watchdog_Sync_count; |
---|
160 | |
---|
161 | /** @brief Ticks Since System Boot |
---|
162 | * |
---|
163 | * This contains the number of ticks since the system was booted. |
---|
164 | */ |
---|
165 | |
---|
166 | SCORE_EXTERN volatile Watchdog_Interval _Watchdog_Ticks_since_boot; |
---|
167 | |
---|
168 | /** @brief Watchdog Nanoseconds Since Last Tick Handler |
---|
169 | * |
---|
170 | * This is a pointer to the optional BSP plugin to obtain the number |
---|
171 | * of nanoseconds since the last clock tick. |
---|
172 | */ |
---|
173 | extern Watchdog_Nanoseconds_since_last_tick_routine |
---|
174 | _Watchdog_Nanoseconds_since_tick_handler; |
---|
175 | |
---|
176 | /** @brief Per Ticks Watchdog List |
---|
177 | * |
---|
178 | * This is the watchdog chain which is managed at ticks. |
---|
179 | */ |
---|
180 | SCORE_EXTERN Chain_Control _Watchdog_Ticks_chain; |
---|
181 | |
---|
182 | /** @brief Per Seconds Watchdog List |
---|
183 | * |
---|
184 | * This is the watchdog chain which is managed at second boundaries. |
---|
185 | */ |
---|
186 | SCORE_EXTERN Chain_Control _Watchdog_Seconds_chain; |
---|
187 | |
---|
188 | /** @brief Watchdog Handler Initialization |
---|
189 | * |
---|
190 | * This routine initializes the watchdog handler. The watchdog |
---|
191 | * synchronization flag is initialized and the watchdog chains are |
---|
192 | * initialized and emptied. |
---|
193 | */ |
---|
194 | void _Watchdog_Handler_initialization( void ); |
---|
195 | |
---|
196 | /** @brief Remove Watchdog from List |
---|
197 | * |
---|
198 | * This routine removes @a the_watchdog from the watchdog chain on which |
---|
199 | * it resides and returns the state @a the_watchdog timer was in. |
---|
200 | * |
---|
201 | * @param[in] the_watchdog will be removed |
---|
202 | * @return the state in which @a the_watchdog was in when removed |
---|
203 | */ |
---|
204 | Watchdog_States _Watchdog_Remove ( |
---|
205 | Watchdog_Control *the_watchdog |
---|
206 | ); |
---|
207 | |
---|
208 | /** @brief Watchdog Adjust |
---|
209 | * |
---|
210 | * This routine adjusts the @a header watchdog chain in the forward |
---|
211 | * or backward @a direction for @a units ticks. |
---|
212 | * |
---|
213 | * @param[in] header is the watchdog chain to adjust |
---|
214 | * @param[in] direction is the direction to adjust @a header |
---|
215 | * @param[in] units is the number of units to adjust @a header |
---|
216 | */ |
---|
217 | void _Watchdog_Adjust ( |
---|
218 | Chain_Control *header, |
---|
219 | Watchdog_Adjust_directions direction, |
---|
220 | Watchdog_Interval units |
---|
221 | ); |
---|
222 | |
---|
223 | /** @brief Watchdog Adjust to Chain |
---|
224 | * |
---|
225 | * This routine adjusts the @a header watchdog chain in the forward |
---|
226 | * @a direction for @a units_arg ticks. |
---|
227 | * |
---|
228 | * @param[in] header is the watchdog chain to adjust |
---|
229 | * @param[in] units_arg is the number of units to adjust @a header |
---|
230 | * @param[in] to_fire is a pointer to an initialized Chain_Control to which |
---|
231 | * all watchdog instances that are to be fired will be placed. |
---|
232 | * |
---|
233 | * @note This always adjusts forward. |
---|
234 | */ |
---|
235 | void _Watchdog_Adjust_to_chain( |
---|
236 | Chain_Control *header, |
---|
237 | Watchdog_Interval units_arg, |
---|
238 | Chain_Control *to_fire |
---|
239 | |
---|
240 | ); |
---|
241 | |
---|
242 | /** @brief Watchdog Insert |
---|
243 | * |
---|
244 | * This routine inserts @a the_watchdog into the @a header watchdog chain |
---|
245 | * for a time of @a units. |
---|
246 | * |
---|
247 | * @param[in] header is @a the_watchdog list to insert @a the_watchdog on |
---|
248 | * @param[in] the_watchdog is the watchdog to insert |
---|
249 | */ |
---|
250 | void _Watchdog_Insert ( |
---|
251 | Chain_Control *header, |
---|
252 | Watchdog_Control *the_watchdog |
---|
253 | ); |
---|
254 | |
---|
255 | /** @brief Watchdog Tickle |
---|
256 | * |
---|
257 | * This routine is invoked at appropriate intervals to update |
---|
258 | * the @a header watchdog chain. |
---|
259 | * |
---|
260 | * @param[in] header is the watchdog chain to tickle |
---|
261 | */ |
---|
262 | void _Watchdog_Tickle ( |
---|
263 | Chain_Control *header |
---|
264 | ); |
---|
265 | |
---|
266 | /** |
---|
267 | * @brief Report Information on a Single Watchdog Instance |
---|
268 | * |
---|
269 | * This method prints a one line report on the watchdog instance |
---|
270 | * provided. The @a name may be used to identify the watchdog and |
---|
271 | * a space will be printed after @a name if it is not NULL. |
---|
272 | * |
---|
273 | * @param[in] name is a string to prefix the line with. If NULL, |
---|
274 | * nothing is printed. |
---|
275 | * @param[in] watch is the watchdog instance to be printed. |
---|
276 | * |
---|
277 | * @note This is a debug routine. It uses printk() and prudence should |
---|
278 | * exercised when using it. |
---|
279 | */ |
---|
280 | void _Watchdog_Report( |
---|
281 | const char *name, |
---|
282 | Watchdog_Control *watch |
---|
283 | ); |
---|
284 | |
---|
285 | /** |
---|
286 | * @brief Report Information on a Watchdog Chain |
---|
287 | * |
---|
288 | * This method prints report on the watchdog chain provided. |
---|
289 | * The @a name may be used to identify the watchdog chain and |
---|
290 | * a space will be printed after @a name if it is not NULL. |
---|
291 | * |
---|
292 | * @param[in] name is a string to prefix the line with. If NULL, |
---|
293 | * nothing is printed. |
---|
294 | * @param[in] header is the watchdog chain to be printed. |
---|
295 | * |
---|
296 | * @note This is a debug routine. It uses printk() and prudence should |
---|
297 | * exercised when using it. It also disables interrupts so the |
---|
298 | * chain can be traversed in a single atomic pass. |
---|
299 | */ |
---|
300 | void _Watchdog_Report_chain( |
---|
301 | const char *name, |
---|
302 | Chain_Control *header |
---|
303 | ); |
---|
304 | |
---|
305 | /** |
---|
306 | * @brief Default nanoseconds since last tick handler. |
---|
307 | * |
---|
308 | * @retval 0 Always. |
---|
309 | */ |
---|
310 | uint32_t _Watchdog_Nanoseconds_since_tick_default_handler( void ); |
---|
311 | |
---|
312 | #ifndef __RTEMS_APPLICATION__ |
---|
313 | #include <rtems/score/watchdog.inl> |
---|
314 | #endif |
---|
315 | |
---|
316 | #ifdef __cplusplus |
---|
317 | } |
---|
318 | #endif |
---|
319 | |
---|
320 | /**@}*/ |
---|
321 | |
---|
322 | #endif |
---|
323 | /* end of include file */ |
---|