source: rtems/cpukit/rtems/src/rtemstimer.c @ 98e4ebf5

4.104.114.84.95
Last change on this file since 98e4ebf5 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

  • Property mode set to 100644
File size: 8.1 KB
RevLine 
[ac7d5ef0]1/*
2 *  Timer Manager
3 *
4 *
[03f2154e]5 *  COPYRIGHT (c) 1989-1997.
[ac7d5ef0]6 *  On-Line Applications Research Corporation (OAR).
[03f2154e]7 *  Copyright assigned to U.S. Government, 1994.
[ac7d5ef0]8 *
[98e4ebf5]9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
[03f2154e]11 *  http://www.OARcorp.com/rtems/license.html.
[ac7d5ef0]12 *
13 *  $Id$
14 */
15
16#include <rtems/system.h>
[3a4ae6c]17#include <rtems/rtems/status.h>
18#include <rtems/rtems/support.h>
[5e9b32b]19#include <rtems/score/object.h>
20#include <rtems/score/thread.h>
[3a4ae6c]21#include <rtems/rtems/timer.h>
[5e9b32b]22#include <rtems/score/tod.h>
23#include <rtems/score/watchdog.h>
[ac7d5ef0]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(
[3235ad9]42    &_Timer_Information,
43    OBJECTS_RTEMS_TIMERS,
44    FALSE,
45    maximum_timers,
46    sizeof( Timer_Control ),
47    FALSE,
[5250ff39]48    RTEMS_MAXIMUM_NAME_LENGTH,
49    FALSE
[ac7d5ef0]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(
[3235ad9]70  rtems_name    name,
[ac7d5ef0]71  Objects_Id   *id
72)
73{
74  Timer_Control *the_timer;
75
[3235ad9]76  if ( !rtems_is_name_valid( name ) )
[3a4ae6c]77    return RTEMS_INVALID_NAME;
[ac7d5ef0]78
79  _Thread_Disable_dispatch();         /* to prevent deletion */
80
81  the_timer = _Timer_Allocate();
82
83  if ( !the_timer ) {
84    _Thread_Enable_dispatch();
[3a4ae6c]85    return RTEMS_TOO_MANY;
[ac7d5ef0]86  }
87
88  the_timer->the_class = TIMER_DORMANT;
89
[3235ad9]90  _Objects_Open( &_Timer_Information, &the_timer->Object, &name );
[ac7d5ef0]91
92  *id = the_timer->Object.id;
93  _Thread_Enable_dispatch();
[3a4ae6c]94  return RTEMS_SUCCESSFUL;
[ac7d5ef0]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(
[3235ad9]115  rtems_name    name,
[ac7d5ef0]116  Objects_Id   *id
117)
118{
[3a4ae6c]119  Objects_Name_to_id_errors  status;
120
121  status = _Objects_Name_to_id(
[ac7d5ef0]122    &_Timer_Information,
[3235ad9]123    &name,
[3a4ae6c]124    OBJECTS_SEARCH_LOCAL_NODE,
[ac7d5ef0]125    id
126  );
[3a4ae6c]127
128  return _Status_Object_name_errors_to_status[ status ];
[ac7d5ef0]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_ERROR:
[3a4ae6c]155      return RTEMS_INVALID_ID;
[ac7d5ef0]156    case OBJECTS_REMOTE:            /* should never return this */
[3a4ae6c]157      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]158    case OBJECTS_LOCAL:
[88d594a]159      if ( !_Timer_Is_dormant_class( the_timer->the_class ) )
[ac7d5ef0]160        (void) _Watchdog_Remove( &the_timer->Ticker );
161      _Thread_Enable_dispatch();
[3a4ae6c]162      return RTEMS_SUCCESSFUL;
[ac7d5ef0]163  }
164
[3a4ae6c]165  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]166}
167
168/*PAGE
169 *
170 *  rtems_timer_delete
171 *
172 *  This directive allows a thread to delete a timer.
173 *
174 *  Input parameters:
175 *    id - timer id
176 *
177 *  Output parameters:
178 *    RTEMS_SUCCESSFUL - if successful
179 *    error code - if unsuccessful
180 */
181
182rtems_status_code rtems_timer_delete(
183  Objects_Id id
184)
185{
186  Timer_Control   *the_timer;
187  Objects_Locations       location;
188
189  the_timer = _Timer_Get( id, &location );
190  switch ( location ) {
191    case OBJECTS_ERROR:
[3a4ae6c]192      return RTEMS_INVALID_ID;
[ac7d5ef0]193    case OBJECTS_REMOTE:            /* should never return this */
[3a4ae6c]194      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]195    case OBJECTS_LOCAL:
196      _Objects_Close( &_Timer_Information, &the_timer->Object );
197      (void) _Watchdog_Remove( &the_timer->Ticker );
198      _Timer_Free( the_timer );
199      _Thread_Enable_dispatch();
[3a4ae6c]200      return RTEMS_SUCCESSFUL;
[ac7d5ef0]201  }
202
[3a4ae6c]203  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]204}
205
206/*PAGE
207 *
208 *  rtems_timer_fire_after
209 *
210 *  This directive allows a thread to start a timer.
211 *
212 *  Input parameters:
213 *    id      - timer id
214 *    ticks   - interval until routine is fired
215 *    routine - routine to schedule
216 *
217 *  Output parameters:
218 *    RTEMS_SUCCESSFUL - if successful
219 *    error code        - if unsuccessful
220 */
221
222rtems_status_code rtems_timer_fire_after(
[3a4ae6c]223  Objects_Id                         id,
224  rtems_interval                     ticks,
225  rtems_timer_service_routine_entry  routine,
226  void                              *user_data
[ac7d5ef0]227)
228{
[e24e9b5]229  Timer_Control      *the_timer;
230  Objects_Locations   location;
[ac7d5ef0]231
232  if ( ticks == 0 )
[3a4ae6c]233    return RTEMS_INVALID_NUMBER;
[ac7d5ef0]234
235  the_timer = _Timer_Get( id, &location );
236  switch ( location ) {
237    case OBJECTS_ERROR:
[3a4ae6c]238      return RTEMS_INVALID_ID;
[ac7d5ef0]239    case OBJECTS_REMOTE:            /* should never return this */
[3a4ae6c]240      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]241    case OBJECTS_LOCAL:
242      (void) _Watchdog_Remove( &the_timer->Ticker );
243      the_timer->the_class = TIMER_INTERVAL;
244      _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
[8d0b7d96]245      _Watchdog_Insert_ticks( &the_timer->Ticker, ticks );
[ac7d5ef0]246      _Thread_Enable_dispatch();
[3a4ae6c]247      return RTEMS_SUCCESSFUL;
[ac7d5ef0]248  }
249
[3a4ae6c]250  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]251}
252
253/*PAGE
254 *
255 *  rtems_timer_fire_when
256 *
257 *  This directive allows a thread to start a timer.
258 *
259 *  Input parameters:
260 *    id        - timer id
261 *    wall_time - time of day to fire timer
262 *    routine   - routine to schedule
263 *
264 *  Output parameters:
265 *    RTEMS_SUCCESSFUL - if successful
266 *    error code        - if unsuccessful
267 */
268
269rtems_status_code rtems_timer_fire_when(
[3a4ae6c]270  Objects_Id                          id,
271  rtems_time_of_day                  *wall_time,
272  rtems_timer_service_routine_entry   routine,
273  void                               *user_data
[ac7d5ef0]274)
275{
[3a4ae6c]276  Timer_Control       *the_timer;
277  Objects_Locations    location;
[ac7d5ef0]278  rtems_interval       seconds;
279
[7fea679b]280  if ( !_TOD_Is_set )
[3a4ae6c]281    return RTEMS_NOT_DEFINED;
[ac7d5ef0]282
[3a4ae6c]283  if ( !_TOD_Validate( wall_time ) )
284    return RTEMS_INVALID_CLOCK;
[ac7d5ef0]285
286  seconds = _TOD_To_seconds( wall_time );
287  if ( seconds <= _TOD_Seconds_since_epoch )
[3a4ae6c]288    return RTEMS_INVALID_CLOCK;
[ac7d5ef0]289
290  the_timer = _Timer_Get( id, &location );
291  switch ( location ) {
292    case OBJECTS_ERROR:
[3a4ae6c]293      return RTEMS_INVALID_ID;
[ac7d5ef0]294    case OBJECTS_REMOTE:            /* should never return this */
[3a4ae6c]295      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]296    case OBJECTS_LOCAL:
297      (void) _Watchdog_Remove( &the_timer->Ticker );
298      the_timer->the_class = TIMER_TIME_OF_DAY;
299      _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
[8d0b7d96]300      _Watchdog_Insert_seconds(
301         &the_timer->Ticker,
302         seconds - _TOD_Seconds_since_epoch
303       );
[ac7d5ef0]304      _Thread_Enable_dispatch();
[3a4ae6c]305      return RTEMS_SUCCESSFUL;
[ac7d5ef0]306  }
307
[3a4ae6c]308  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]309}
310
311/*PAGE
312 *
313 *  rtems_timer_reset
314 *
315 *  This directive allows a thread to reset a timer.
316 *
317 *  Input parameters:
318 *    id - timer id
319 *
320 *  Output parameters:
321 *    RTEMS_SUCCESSFUL - if successful
322 *    error code        - if unsuccessful
323 */
324
325rtems_status_code rtems_timer_reset(
326  Objects_Id id
327)
328{
[e24e9b5]329  Timer_Control     *the_timer;
330  Objects_Locations  location;
[ac7d5ef0]331
332  the_timer = _Timer_Get( id, &location );
333  switch ( location ) {
334    case OBJECTS_ERROR:
[3a4ae6c]335      return RTEMS_INVALID_ID;
[ac7d5ef0]336    case OBJECTS_REMOTE:            /* should never return this */
[3a4ae6c]337      return RTEMS_INTERNAL_ERROR;
[ac7d5ef0]338    case OBJECTS_LOCAL:
339      if ( _Timer_Is_interval_class( the_timer->the_class ) ) {
340        _Watchdog_Reset( &the_timer->Ticker );
341        _Thread_Enable_dispatch();
[3a4ae6c]342        return RTEMS_SUCCESSFUL;
[ac7d5ef0]343      }
344      _Thread_Enable_dispatch();
[3a4ae6c]345      return RTEMS_NOT_DEFINED;
[ac7d5ef0]346  }
347
[3a4ae6c]348  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
[ac7d5ef0]349}
Note: See TracBrowser for help on using the repository browser.