source: rtems/cpukit/rtems/src/rtemstimer.c @ 3235ad9

4.104.114.84.95
Last change on this file since 3235ad9 was 3235ad9, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 23, 1995 at 7:30:23 PM

Support for variable length names added to Object Handler. This supports
both fixed length "raw" names and strings from the API's point of view.

Both inline and macro implementations were tested.

  • Property mode set to 100644
File size: 8.2 KB
Line 
1/*
2 *  Timer Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
6 *  On-Line Applications Research Corporation (OAR).
7 *  All rights assigned to U.S. Government, 1994.
8 *
9 *  This material may be reproduced by or for the U.S. Government pursuant
10 *  to the copyright license under the clause at DFARS 252.227-7013.  This
11 *  notice must appear in all copies of this file and its derivatives.
12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
17#include <rtems/support.h>
18#include <rtems/object.h>
19#include <rtems/thread.h>
20#include <rtems/timer.h>
21#include <rtems/tod.h>
22#include <rtems/watchdog.h>
23
24/*PAGE
25 *
26 *  _Timer_Manager_initialization
27 *
28 *  This routine initializes all timer manager related data structures.
29 *
30 *  Input parameters:
31 *    maximum_timers - number of timers to initialize
32 *
33 *  Output parameters:  NONE
34 */
35
36void _Timer_Manager_initialization(
37  unsigned32 maximum_timers
38)
39{
40  _Objects_Initialize_information(
41    &_Timer_Information,
42    OBJECTS_RTEMS_TIMERS,
43    FALSE,
44    maximum_timers,
45    sizeof( Timer_Control ),
46    FALSE,
47    RTEMS_MAXIMUM_NAME_LENGTH
48  );
49}
50
51/*PAGE
52 *
53 *  rtems_timer_create
54 *
55 *  This directive creates a timer and performs some initialization.
56 *
57 *  Input parameters:
58 *    name - timer name
59 *    id   - pointer to timer id
60 *
61 *  Output parameters:
62 *    id                - timer id
63 *    RTEMS_SUCCESSFUL - if successful
64 *    error code        - if unsuccessful
65 */
66
67rtems_status_code rtems_timer_create(
68  rtems_name    name,
69  Objects_Id   *id
70)
71{
72  Timer_Control *the_timer;
73
74  if ( !rtems_is_name_valid( name ) )
75    return ( RTEMS_INVALID_NAME );
76
77  _Thread_Disable_dispatch();         /* to prevent deletion */
78
79  the_timer = _Timer_Allocate();
80
81  if ( !the_timer ) {
82    _Thread_Enable_dispatch();
83    return( RTEMS_TOO_MANY );
84  }
85
86  the_timer->the_class = TIMER_DORMANT;
87
88  _Objects_Open( &_Timer_Information, &the_timer->Object, &name );
89
90  *id = the_timer->Object.id;
91  _Thread_Enable_dispatch();
92  return( RTEMS_SUCCESSFUL );
93}
94
95/*PAGE
96 *
97 *  rtems_timer_ident
98 *
99 *  This directive returns the system ID associated with
100 *  the timer name.
101 *
102 *  Input parameters:
103 *    name - user defined message queue name
104 *    id   - pointer to timer id
105 *
106 *  Output parameters:
107 *    *id               - message queue id
108 *    RTEMS_SUCCESSFUL - if successful
109 *    error code        - if unsuccessful
110 */
111
112rtems_status_code rtems_timer_ident(
113  rtems_name    name,
114  Objects_Id   *id
115)
116{
117  return _Objects_Name_to_id(
118    &_Timer_Information,
119    &name,
120    RTEMS_SEARCH_LOCAL_NODE,
121    id
122  );
123}
124
125/*PAGE
126 *
127 *  rtems_timer_cancel
128 *
129 *  This directive allows a thread to cancel a timer.
130 *
131 *  Input parameters:
132 *    id - timer id
133 *
134 *  Output parameters:
135 *    RTEMS_SUCCESSFUL - if successful
136 *    error code - if unsuccessful
137 */
138
139rtems_status_code rtems_timer_cancel(
140  Objects_Id id
141)
142{
143  Timer_Control   *the_timer;
144  Objects_Locations       location;
145
146  the_timer = _Timer_Get( id, &location );
147  switch ( location ) {
148    case OBJECTS_ERROR:
149      return( RTEMS_INVALID_ID );
150    case OBJECTS_REMOTE:            /* should never return this */
151      return( RTEMS_INTERNAL_ERROR );
152    case OBJECTS_LOCAL:
153      if ( !_Timer_Is_dormant_class( the_timer->the_class ) ) 
154        (void) _Watchdog_Remove( &the_timer->Ticker );
155      _Thread_Enable_dispatch();
156      return( RTEMS_SUCCESSFUL );
157  }
158
159  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
160}
161
162/*PAGE
163 *
164 *  rtems_timer_delete
165 *
166 *  This directive allows a thread to delete a timer.
167 *
168 *  Input parameters:
169 *    id - timer id
170 *
171 *  Output parameters:
172 *    RTEMS_SUCCESSFUL - if successful
173 *    error code - if unsuccessful
174 */
175
176rtems_status_code rtems_timer_delete(
177  Objects_Id id
178)
179{
180  Timer_Control   *the_timer;
181  Objects_Locations       location;
182
183  the_timer = _Timer_Get( id, &location );
184  switch ( location ) {
185    case OBJECTS_ERROR:
186      return( RTEMS_INVALID_ID );
187    case OBJECTS_REMOTE:            /* should never return this */
188      return( RTEMS_INTERNAL_ERROR );
189    case OBJECTS_LOCAL:
190      _Objects_Close( &_Timer_Information, &the_timer->Object );
191      (void) _Watchdog_Remove( &the_timer->Ticker );
192      _Timer_Free( the_timer );
193      _Thread_Enable_dispatch();
194      return( RTEMS_SUCCESSFUL );
195  }
196
197  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
198}
199
200/*PAGE
201 *
202 *  rtems_timer_fire_after
203 *
204 *  This directive allows a thread to start a timer.
205 *
206 *  Input parameters:
207 *    id      - timer id
208 *    ticks   - interval until routine is fired
209 *    routine - routine to schedule
210 *
211 *  Output parameters:
212 *    RTEMS_SUCCESSFUL - if successful
213 *    error code        - if unsuccessful
214 */
215
216rtems_status_code rtems_timer_fire_after(
217  Objects_Id         id,
218  rtems_interval  ticks,
219  Timer_Service      routine,
220  void              *user_data
221)
222{
223  Timer_Control   *the_timer;
224  Objects_Locations       location;
225
226  if ( ticks == 0 )
227    return( RTEMS_INVALID_NUMBER );
228
229  the_timer = _Timer_Get( id, &location );
230  switch ( location ) {
231    case OBJECTS_ERROR:
232      return( RTEMS_INVALID_ID );
233    case OBJECTS_REMOTE:            /* should never return this */
234      return( RTEMS_INTERNAL_ERROR );
235    case OBJECTS_LOCAL:
236      (void) _Watchdog_Remove( &the_timer->Ticker );
237      the_timer->the_class = TIMER_INTERVAL;
238      _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
239      _Watchdog_Insert_ticks( &the_timer->Ticker,
240                                 ticks, WATCHDOG_ACTIVATE_NOW );
241      _Thread_Enable_dispatch();
242      return( RTEMS_SUCCESSFUL );
243  }
244
245  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
246}
247
248/*PAGE
249 *
250 *  rtems_timer_fire_when
251 *
252 *  This directive allows a thread to start a timer.
253 *
254 *  Input parameters:
255 *    id        - timer id
256 *    wall_time - time of day to fire timer
257 *    routine   - routine to schedule
258 *
259 *  Output parameters:
260 *    RTEMS_SUCCESSFUL - if successful
261 *    error code        - if unsuccessful
262 */
263
264rtems_status_code rtems_timer_fire_when(
265  Objects_Id          id,
266  rtems_time_of_day        *wall_time,
267  Timer_Service       routine,
268  void               *user_data
269)
270{
271  Timer_Control   *the_timer;
272  Objects_Locations       location;
273  rtems_status_code            validate_status;
274  rtems_interval       seconds;
275
276  if ( !_TOD_Is_set() )
277    return( RTEMS_NOT_DEFINED );
278
279  validate_status = _TOD_Validate( wall_time );
280  if ( !rtems_is_status_successful( validate_status ) )
281    return( validate_status );
282
283  seconds = _TOD_To_seconds( wall_time );
284  if ( seconds <= _TOD_Seconds_since_epoch )
285    return( RTEMS_INVALID_CLOCK );
286
287  the_timer = _Timer_Get( id, &location );
288  switch ( location ) {
289    case OBJECTS_ERROR:
290      return( RTEMS_INVALID_ID );
291    case OBJECTS_REMOTE:            /* should never return this */
292      return( RTEMS_INTERNAL_ERROR );
293    case OBJECTS_LOCAL:
294      (void) _Watchdog_Remove( &the_timer->Ticker );
295      the_timer->the_class = TIMER_TIME_OF_DAY;
296      _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
297      _Watchdog_Insert_seconds( &the_timer->Ticker,
298                seconds - _TOD_Seconds_since_epoch, WATCHDOG_ACTIVATE_NOW );
299      _Thread_Enable_dispatch();
300      return( RTEMS_SUCCESSFUL );
301  }
302
303  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
304}
305
306/*PAGE
307 *
308 *  rtems_timer_reset
309 *
310 *  This directive allows a thread to reset a timer.
311 *
312 *  Input parameters:
313 *    id - timer id
314 *
315 *  Output parameters:
316 *    RTEMS_SUCCESSFUL - if successful
317 *    error code        - if unsuccessful
318 */
319
320rtems_status_code rtems_timer_reset(
321  Objects_Id id
322)
323{
324  Timer_Control *the_timer;
325  Objects_Locations     location;
326
327  the_timer = _Timer_Get( id, &location );
328  switch ( location ) {
329    case OBJECTS_ERROR:
330      return( RTEMS_INVALID_ID );
331    case OBJECTS_REMOTE:            /* should never return this */
332      return( RTEMS_INTERNAL_ERROR );
333    case OBJECTS_LOCAL:
334      if ( _Timer_Is_interval_class( the_timer->the_class ) ) {
335        _Watchdog_Reset( &the_timer->Ticker );
336        _Thread_Enable_dispatch();
337        return( RTEMS_SUCCESSFUL );
338      }
339      _Thread_Enable_dispatch();
340      return( RTEMS_NOT_DEFINED );
341  }
342
343  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
344}
Note: See TracBrowser for help on using the repository browser.