source: rtems/cpukit/rtems/src/timerfireafter.c @ 60bf9c0

4.104.114.84.95
Last change on this file since 60bf9c0 was 60bf9c0, checked in by Joel Sherrill <joel.sherrill@…>, on 08/18/05 at 13:46:38

2005-08-18 Andrew Sinclair <Andrew.Sinclair@…>

PR 807/rtems

  • rtems/src/timerfireafter.c, rtems/src/timerserverfireafter.c: First patch returned without exitting dispatching critical section.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  Timer Manager - rtems_timer_fire_after directive
3 *
4 *
5 *  COPYRIGHT (c) 1989-2002.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/rtems/status.h>
21#include <rtems/rtems/support.h>
22#include <rtems/score/object.h>
23#include <rtems/score/thread.h>
24#include <rtems/rtems/timer.h>
25#include <rtems/score/tod.h>
26#include <rtems/score/watchdog.h>
27
28/*PAGE
29 *
30 *  rtems_timer_fire_after
31 *
32 *  This directive allows a thread to start a timer.
33 *
34 *  Input parameters:
35 *    id        - timer id
36 *    ticks     - interval until routine is fired
37 *    routine   - routine to schedule
38 *    user_data - passed as argument to routine when it is fired
39 *
40 *  Output parameters:
41 *    RTEMS_SUCCESSFUL - if successful
42 *    error code       - if unsuccessful
43 */
44
45rtems_status_code rtems_timer_fire_after(
46  Objects_Id                         id,
47  rtems_interval                     ticks,
48  rtems_timer_service_routine_entry  routine,
49  void                              *user_data
50)
51{
52  Timer_Control      *the_timer;
53  Objects_Locations   location;
54  ISR_Level           level;
55
56  if ( ticks == 0 )
57    return RTEMS_INVALID_NUMBER;
58
59  if ( !routine )
60    return RTEMS_INVALID_ADDRESS;
61
62  the_timer = _Timer_Get( id, &location );
63  switch ( location ) {
64    case OBJECTS_REMOTE:            /* should never return this */
65      return RTEMS_INTERNAL_ERROR;
66
67    case OBJECTS_ERROR:
68      return RTEMS_INVALID_ID;
69
70    case OBJECTS_LOCAL:
71      (void) _Watchdog_Remove( &the_timer->Ticker );
72
73      _ISR_Disable( level );
74
75        /*
76         *  Check to see if the watchdog has just been inserted by a
77         *  higher priority interrupt.  If so, abandon this insert.
78         */
79
80        if ( the_timer->Ticker.state != WATCHDOG_INACTIVE ) {
81          _ISR_Enable( level );
82          _Thread_Enable_dispatch();
83          return RTEMS_SUCCESSFUL;
84        }
85
86        /*
87         *  OK.  Now we now the timer was not rescheduled by an interrupt
88         *  so we can atomically initialize it as in use.
89         */
90
91        the_timer->the_class = TIMER_INTERVAL;
92        _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
93      _ISR_Enable( level );
94
95
96      _Watchdog_Insert_ticks( &the_timer->Ticker, ticks );
97      _Thread_Enable_dispatch();
98      return RTEMS_SUCCESSFUL;
99  }
100
101  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
102}
Note: See TracBrowser for help on using the repository browser.