1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicTimer |
---|
5 | * |
---|
6 | * @brief Classic Timer Manager API |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * Copyright (c) 2009, 2016 embedded brains GmbH. |
---|
14 | * |
---|
15 | * The license and distribution terms for this file may be |
---|
16 | * found in the file LICENSE in this distribution or at |
---|
17 | * http://www.rtems.org/license/LICENSE. |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef _RTEMS_RTEMS_TIMER_H |
---|
21 | #define _RTEMS_RTEMS_TIMER_H |
---|
22 | |
---|
23 | #include <rtems/rtems/attr.h> |
---|
24 | #include <rtems/rtems/status.h> |
---|
25 | #include <rtems/rtems/tasks.h> |
---|
26 | #include <rtems/rtems/types.h> |
---|
27 | |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | /** |
---|
33 | * @defgroup ClassicTimer Timers |
---|
34 | * |
---|
35 | * @ingroup RTEMSAPIClassic |
---|
36 | * |
---|
37 | * This encapsulates functionality related to the Classic API Timer |
---|
38 | * Manager. This manager provides functionality which allows the |
---|
39 | * application to schedule the execution of methods at a specified |
---|
40 | * time in the future. These methods may be scheduled based upon |
---|
41 | * interval or wall time and may be executed in either the clock tick |
---|
42 | * ISR or in a special dedicated timer server task. |
---|
43 | */ |
---|
44 | /**@{*/ |
---|
45 | |
---|
46 | #define TIMER_CLASS_BIT_TIME_OF_DAY 0x1 |
---|
47 | |
---|
48 | #define TIMER_CLASS_BIT_ON_TASK 0x2 |
---|
49 | |
---|
50 | #define TIMER_CLASS_BIT_NOT_DORMANT 0x4 |
---|
51 | |
---|
52 | /** |
---|
53 | * The following enumerated type details the classes to which a timer |
---|
54 | * may belong. |
---|
55 | */ |
---|
56 | typedef enum { |
---|
57 | /** |
---|
58 | * This value indicates the timer is currently not in use. |
---|
59 | */ |
---|
60 | TIMER_DORMANT, |
---|
61 | |
---|
62 | /** |
---|
63 | * This value indicates the timer is currently in use as an interval |
---|
64 | * timer which will fire in the clock tick ISR. |
---|
65 | */ |
---|
66 | TIMER_INTERVAL = TIMER_CLASS_BIT_NOT_DORMANT, |
---|
67 | |
---|
68 | /** |
---|
69 | * This value indicates the timer is currently in use as an interval |
---|
70 | * timer which will fire in the timer server task. |
---|
71 | */ |
---|
72 | TIMER_INTERVAL_ON_TASK = |
---|
73 | TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_ON_TASK, |
---|
74 | |
---|
75 | /** |
---|
76 | * This value indicates the timer is currently in use as an time of day |
---|
77 | * timer which will fire in the clock tick ISR. |
---|
78 | */ |
---|
79 | TIMER_TIME_OF_DAY = |
---|
80 | TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_TIME_OF_DAY, |
---|
81 | |
---|
82 | /** |
---|
83 | * This value indicates the timer is currently in use as an time of day |
---|
84 | * timer which will fire in the timer server task. |
---|
85 | */ |
---|
86 | TIMER_TIME_OF_DAY_ON_TASK = |
---|
87 | TIMER_CLASS_BIT_NOT_DORMANT | TIMER_CLASS_BIT_TIME_OF_DAY | |
---|
88 | TIMER_CLASS_BIT_ON_TASK |
---|
89 | } Timer_Classes; |
---|
90 | |
---|
91 | /** |
---|
92 | * The following types define a pointer to a timer service routine. |
---|
93 | */ |
---|
94 | typedef void rtems_timer_service_routine; |
---|
95 | |
---|
96 | /** |
---|
97 | * This type defines the type used to manage and indirectly invoke |
---|
98 | * Timer Service Routines (TSRs). This defines the prototype and interface |
---|
99 | * for a function which is to be used as a TSR. |
---|
100 | */ |
---|
101 | typedef rtems_timer_service_routine ( *rtems_timer_service_routine_entry )( |
---|
102 | rtems_id, |
---|
103 | void * |
---|
104 | ); |
---|
105 | |
---|
106 | /** |
---|
107 | * @brief RTEMS Create Timer |
---|
108 | * |
---|
109 | * This routine implements the rtems_timer_create directive. The |
---|
110 | * timer will have the name name. It returns the id of the |
---|
111 | * created timer in ID. |
---|
112 | * |
---|
113 | * @param[in] name is the timer name |
---|
114 | * @param[out] id is the pointer to timer id |
---|
115 | * |
---|
116 | * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful |
---|
117 | */ |
---|
118 | rtems_status_code rtems_timer_create( |
---|
119 | rtems_name name, |
---|
120 | rtems_id *id |
---|
121 | ); |
---|
122 | |
---|
123 | /** |
---|
124 | * @brief RTEMS Timer Name to Id |
---|
125 | * |
---|
126 | * This routine implements the rtems_timer_ident directive. |
---|
127 | * This directive returns the timer ID associated with name. |
---|
128 | * If more than one timer is named name, then the timer |
---|
129 | * to which the ID belongs is arbitrary. |
---|
130 | * |
---|
131 | * @param[in] name is the user defined message queue name |
---|
132 | * @param[in] id is the pointer to timer id |
---|
133 | * |
---|
134 | * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful and |
---|
135 | * id filled with the message queue id |
---|
136 | */ |
---|
137 | rtems_status_code rtems_timer_ident( |
---|
138 | rtems_name name, |
---|
139 | rtems_id *id |
---|
140 | ); |
---|
141 | |
---|
142 | /** |
---|
143 | * @brief rtems_timer_cancel |
---|
144 | * |
---|
145 | * This routine implements the rtems_timer_cancel directive. It is used |
---|
146 | * to stop the timer associated with ID from firing. |
---|
147 | */ |
---|
148 | rtems_status_code rtems_timer_cancel( |
---|
149 | rtems_id id |
---|
150 | ); |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief RTEMS Delete Timer |
---|
154 | * |
---|
155 | * This routine implements the rtems_timer_delete directive. The |
---|
156 | * timer indicated by ID is deleted. |
---|
157 | * |
---|
158 | * @param[in] id is the timer id |
---|
159 | * |
---|
160 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
161 | * error. Otherwise, a status code is returned indicating the |
---|
162 | * source of the error. |
---|
163 | */ |
---|
164 | rtems_status_code rtems_timer_delete( |
---|
165 | rtems_id id |
---|
166 | ); |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief RTEMS Timer Fire After |
---|
170 | * |
---|
171 | * This routine implements the rtems_timer_fire_after directive. It |
---|
172 | * initiates the timer associated with ID to fire in ticks clock ticks. |
---|
173 | * When the timer fires, the routine will be invoked in the context |
---|
174 | * of the rtems_clock_tick directive which is normally invoked as |
---|
175 | * part of servicing a periodic interupt. |
---|
176 | * |
---|
177 | * @param[in] id is the timer id |
---|
178 | * @param[in] ticks is the interval until routine is fired |
---|
179 | * @param[in] routine is the routine to schedule |
---|
180 | * @param[in] user_data is the passed as argument to routine when it is fired |
---|
181 | * |
---|
182 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
183 | * error. Otherwise, a status code is returned indicating the |
---|
184 | * source of the error. |
---|
185 | */ |
---|
186 | rtems_status_code rtems_timer_fire_after( |
---|
187 | rtems_id id, |
---|
188 | rtems_interval ticks, |
---|
189 | rtems_timer_service_routine_entry routine, |
---|
190 | void *user_data |
---|
191 | ); |
---|
192 | |
---|
193 | /** |
---|
194 | * @brief RTEMS Timer Server Fire After |
---|
195 | * |
---|
196 | * This routine implements the rtems_timer_server_fire_after directive. It |
---|
197 | * initiates the timer associated with ID to fire in ticks clock |
---|
198 | * ticks. When the timer fires, the routine will be invoked by the |
---|
199 | * Timer Server in the context of a task NOT IN THE CONTEXT of the |
---|
200 | * clock tick interrupt. |
---|
201 | * |
---|
202 | * @param[in] id is the timer id |
---|
203 | * @param[in] ticks is the interval until routine is fired |
---|
204 | * @param[in] routine is the routine to schedule |
---|
205 | * @param[in] user_data is the passed as argument to routine when it is fired |
---|
206 | * |
---|
207 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
208 | * error. Otherwise, a status code is returned indicating the |
---|
209 | * source of the error. |
---|
210 | */ |
---|
211 | rtems_status_code rtems_timer_server_fire_after( |
---|
212 | rtems_id id, |
---|
213 | rtems_interval ticks, |
---|
214 | rtems_timer_service_routine_entry routine, |
---|
215 | void *user_data |
---|
216 | ); |
---|
217 | |
---|
218 | /** |
---|
219 | * @brief RTEMS Timer Fire When |
---|
220 | * |
---|
221 | * This routine implements the rtems_timer_fire_when directive. It |
---|
222 | * initiates the timer associated with ID to fire at wall_time |
---|
223 | * When the timer fires, the routine will be invoked in the context |
---|
224 | * of the rtems_clock_tick directive which is normally invoked as |
---|
225 | * part of servicing a periodic interupt. |
---|
226 | * |
---|
227 | * @param[in] id is the timer id |
---|
228 | * @param[in] wall_time is the time of day to fire timer |
---|
229 | * @param[in] routine is the routine to schedule |
---|
230 | * @param[in] user_data is the passed as argument to routine when it is fired |
---|
231 | * |
---|
232 | * @retval This method returns RTEMS_SUCCESSFUL if there was not an |
---|
233 | * error. Otherwise, a status code is returned indicating the |
---|
234 | * source of the error. |
---|
235 | */ |
---|
236 | rtems_status_code rtems_timer_fire_when( |
---|
237 | rtems_id id, |
---|
238 | rtems_time_of_day *wall_time, |
---|
239 | rtems_timer_service_routine_entry routine, |
---|
240 | void *user_data |
---|
241 | ); |
---|
242 | |
---|
243 | /** |
---|
244 | * @brief RTEMS Timer Server Fire When Directive |
---|
245 | * |
---|
246 | * Timer Manager - RTEMS Timer Server Fire When Directive |
---|
247 | * |
---|
248 | * This routine implements the rtems_timer_server_fire_when directive. It |
---|
249 | * initiates the timer associated with ID to fire at wall_time |
---|
250 | * When the timer fires, the routine will be invoked by the |
---|
251 | * Timer Server in the context of a task NOT IN THE CONTEXT of the |
---|
252 | * clock tick interrupt. |
---|
253 | */ |
---|
254 | rtems_status_code rtems_timer_server_fire_when( |
---|
255 | rtems_id id, |
---|
256 | rtems_time_of_day *wall_time, |
---|
257 | rtems_timer_service_routine_entry routine, |
---|
258 | void *user_data |
---|
259 | ); |
---|
260 | |
---|
261 | /** |
---|
262 | * @brief RTEMS Timer Reset |
---|
263 | * |
---|
264 | * Timer Manager - RTEMS Timer Reset |
---|
265 | * |
---|
266 | * This routine implements the rtems_timer_reset directive. It is used |
---|
267 | * to reinitialize the interval timer associated with ID just as if |
---|
268 | * rtems_timer_fire_after were re-invoked with the same arguments that |
---|
269 | * were used to initiate this timer. |
---|
270 | */ |
---|
271 | rtems_status_code rtems_timer_reset( |
---|
272 | rtems_id id |
---|
273 | ); |
---|
274 | |
---|
275 | /** |
---|
276 | * @brief Initiates the timer server. |
---|
277 | * |
---|
278 | * This directive creates and starts the server for task-based timers. |
---|
279 | * It must be invoked before any task-based timers can be initiated. |
---|
280 | * |
---|
281 | * @param priority The timer server task priority. |
---|
282 | * @param stack_size The stack size in bytes for the timer server task. |
---|
283 | * @param attribute_set The timer server task attributes. |
---|
284 | * |
---|
285 | * @return This method returns RTEMS_SUCCESSFUL if successful and an |
---|
286 | * error code otherwise. |
---|
287 | */ |
---|
288 | rtems_status_code rtems_timer_initiate_server( |
---|
289 | rtems_task_priority priority, |
---|
290 | size_t stack_size, |
---|
291 | rtems_attribute attribute_set |
---|
292 | ); |
---|
293 | |
---|
294 | /** |
---|
295 | * This is the default value for the priority of the Timer Server. |
---|
296 | * When given this priority, a special high priority not accessible |
---|
297 | * via the Classic API is used. |
---|
298 | */ |
---|
299 | #define RTEMS_TIMER_SERVER_DEFAULT_PRIORITY (uint32_t) -1 |
---|
300 | |
---|
301 | /** |
---|
302 | * This is the structure filled in by the timer get information |
---|
303 | * service. |
---|
304 | */ |
---|
305 | typedef struct { |
---|
306 | /** This indicates the current type of the timer. */ |
---|
307 | Timer_Classes the_class; |
---|
308 | /** This indicates the initial requested interval. */ |
---|
309 | Watchdog_Interval initial; |
---|
310 | /** This indicates the time the timer was initially scheduled. */ |
---|
311 | Watchdog_Interval start_time; |
---|
312 | /** This indicates the time the timer is scheduled to fire. */ |
---|
313 | Watchdog_Interval stop_time; |
---|
314 | } rtems_timer_information; |
---|
315 | |
---|
316 | /** |
---|
317 | * @brief RTEMS Get Timer Information |
---|
318 | * |
---|
319 | * This routine implements the rtems_timer_get_information directive. |
---|
320 | * This directive returns information about the timer. |
---|
321 | * |
---|
322 | * @param[in] id is the timer id |
---|
323 | * @param[in] the_info is the pointer to timer information block |
---|
324 | * |
---|
325 | * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful and |
---|
326 | * *the_info region information block filled in |
---|
327 | */ |
---|
328 | rtems_status_code rtems_timer_get_information( |
---|
329 | rtems_id id, |
---|
330 | rtems_timer_information *the_info |
---|
331 | ); |
---|
332 | |
---|
333 | /**@}*/ |
---|
334 | |
---|
335 | #ifdef __cplusplus |
---|
336 | } |
---|
337 | #endif |
---|
338 | |
---|
339 | #endif |
---|
340 | /* end of include file */ |
---|