source: rtems/cpukit/rtems/src/rtemstimer.c @ 97e2729d

4.104.114.84.95
Last change on this file since 97e2729d was 97e2729d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 17:38:09

Added --disable-multiprocessing flag and modified a lot of files to make
it work.

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