source: rtems/c/src/exec/rtems/src/timer.c @ b3ac6a8d

4.104.114.84.95
Last change on this file since b3ac6a8d was 3a4ae6c, checked in by Joel Sherrill <joel.sherrill@…>, on 09/11/95 at 19:35:39

The word "RTEMS" almost completely removed from the core.

Configuration Table Template file added and all tests
modified to use this. All gvar.h and conftbl.h files
removed from test directories.

Configuration parameter maximum_devices added.

Core semaphore and mutex handlers added and RTEMS API Semaphore
Manager updated to reflect this.

Initialization sequence changed to invoke API specific initialization
routines. Initialization tasks table now owned by RTEMS Tasks Manager.

Added user extension for post-switch.

Utilized user extensions to implement API specific functionality
like signal dispatching.

Added extensions to the System Initialization Thread so that an
API can register a function to be invoked while the system
is being initialized. These are largely equivalent to the
pre-driver and post-driver hooks.

Added the Modules file oar-go32_p5, modified oar-go32, and modified
the file make/custom/go32.cfg to look at an environment varable which
determines what CPU model is being used.

All BSPs updated to reflect named devices and clock driver's IOCTL
used by the Shared Memory Driver. Also merged clock isr into
main file and removed ckisr.c where possible.

Updated spsize to reflect new and moved variables.

Makefiles for the executive source and include files updated to show
break down of files into Core, RTEMS API, and Neither.

Header and inline files installed into subdirectory based on whether
logically in the Core or a part of the RTEMS API.

  • Property mode set to 100644
File size: 8.3 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/rtems/status.h>
18#include <rtems/rtems/support.h>
19#include <rtems/core/object.h>
20#include <rtems/core/thread.h>
21#include <rtems/rtems/timer.h>
22#include <rtems/core/tod.h>
23#include <rtems/core/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_ERROR:
155      return RTEMS_INVALID_ID;
156    case OBJECTS_REMOTE:            /* should never return this */
157      return RTEMS_INTERNAL_ERROR;
158    case OBJECTS_LOCAL:
159      if ( !_Timer_Is_dormant_class( the_timer->the_class ) )
160        (void) _Watchdog_Remove( &the_timer->Ticker );
161      _Thread_Enable_dispatch();
162      return RTEMS_SUCCESSFUL;
163  }
164
165  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
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:
192      return RTEMS_INVALID_ID;
193    case OBJECTS_REMOTE:            /* should never return this */
194      return RTEMS_INTERNAL_ERROR;
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();
200      return RTEMS_SUCCESSFUL;
201  }
202
203  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
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(
223  Objects_Id                         id,
224  rtems_interval                     ticks,
225  rtems_timer_service_routine_entry  routine,
226  void                              *user_data
227)
228{
229  Timer_Control   *the_timer;
230  Objects_Locations       location;
231
232  if ( ticks == 0 )
233    return RTEMS_INVALID_NUMBER;
234
235  the_timer = _Timer_Get( id, &location );
236  switch ( location ) {
237    case OBJECTS_ERROR:
238      return RTEMS_INVALID_ID;
239    case OBJECTS_REMOTE:            /* should never return this */
240      return RTEMS_INTERNAL_ERROR;
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 );
245      _Watchdog_Insert_ticks( &the_timer->Ticker,
246                                 ticks, WATCHDOG_ACTIVATE_NOW );
247      _Thread_Enable_dispatch();
248      return RTEMS_SUCCESSFUL;
249  }
250
251  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
252}
253
254/*PAGE
255 *
256 *  rtems_timer_fire_when
257 *
258 *  This directive allows a thread to start a timer.
259 *
260 *  Input parameters:
261 *    id        - timer id
262 *    wall_time - time of day to fire timer
263 *    routine   - routine to schedule
264 *
265 *  Output parameters:
266 *    RTEMS_SUCCESSFUL - if successful
267 *    error code        - if unsuccessful
268 */
269
270rtems_status_code rtems_timer_fire_when(
271  Objects_Id                          id,
272  rtems_time_of_day                  *wall_time,
273  rtems_timer_service_routine_entry   routine,
274  void                               *user_data
275)
276{
277  Timer_Control       *the_timer;
278  Objects_Locations    location;
279  rtems_interval       seconds;
280
281  if ( !_TOD_Is_set() )
282    return RTEMS_NOT_DEFINED;
283
284  if ( !_TOD_Validate( wall_time ) )
285    return RTEMS_INVALID_CLOCK;
286
287  seconds = _TOD_To_seconds( wall_time );
288  if ( seconds <= _TOD_Seconds_since_epoch )
289    return RTEMS_INVALID_CLOCK;
290
291  the_timer = _Timer_Get( id, &location );
292  switch ( location ) {
293    case OBJECTS_ERROR:
294      return RTEMS_INVALID_ID;
295    case OBJECTS_REMOTE:            /* should never return this */
296      return RTEMS_INTERNAL_ERROR;
297    case OBJECTS_LOCAL:
298      (void) _Watchdog_Remove( &the_timer->Ticker );
299      the_timer->the_class = TIMER_TIME_OF_DAY;
300      _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
301      _Watchdog_Insert_seconds( &the_timer->Ticker,
302                seconds - _TOD_Seconds_since_epoch, WATCHDOG_ACTIVATE_NOW );
303      _Thread_Enable_dispatch();
304      return RTEMS_SUCCESSFUL;
305  }
306
307  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
308}
309
310/*PAGE
311 *
312 *  rtems_timer_reset
313 *
314 *  This directive allows a thread to reset a timer.
315 *
316 *  Input parameters:
317 *    id - timer id
318 *
319 *  Output parameters:
320 *    RTEMS_SUCCESSFUL - if successful
321 *    error code        - if unsuccessful
322 */
323
324rtems_status_code rtems_timer_reset(
325  Objects_Id id
326)
327{
328  Timer_Control *the_timer;
329  Objects_Locations     location;
330
331  the_timer = _Timer_Get( id, &location );
332  switch ( location ) {
333    case OBJECTS_ERROR:
334      return RTEMS_INVALID_ID;
335    case OBJECTS_REMOTE:            /* should never return this */
336      return RTEMS_INTERNAL_ERROR;
337    case OBJECTS_LOCAL:
338      if ( _Timer_Is_interval_class( the_timer->the_class ) ) {
339        _Watchdog_Reset( &the_timer->Ticker );
340        _Thread_Enable_dispatch();
341        return RTEMS_SUCCESSFUL;
342      }
343      _Thread_Enable_dispatch();
344      return RTEMS_NOT_DEFINED;
345  }
346
347  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
348}
Note: See TracBrowser for help on using the repository browser.