source: rtems/cpukit/rtems/src/timerserverfireafter.c @ 6e51c4c

4.104.115
Last change on this file since 6e51c4c was 6e51c4c, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 11/30/09 at 09:08:35

Added timer server control block
Removed _Timer_Server thread pointer
Added _Timer_server pointer to the default timer server control block
Rework of the timer server implementation.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  Timer Manager - rtems_timer_server fire_after directive
3 *
4 *
5 *  COPYRIGHT (c) 1989-2007.
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_server_fire_after
31 *
32 *  This directive allows a thread to start a timer which will by
33 *  executed by the Timer Server when it fires.
34 *
35 *  Input parameters:
36 *    id        - timer id
37 *    ticks     - interval until routine is fired
38 *    routine   - routine to schedule
39 *    user_data - passed as argument to routine when it is fired
40 *
41 *  Output parameters:
42 *    RTEMS_SUCCESSFUL - if successful
43 *    error code       - if unsuccessful
44 */
45
46rtems_status_code rtems_timer_server_fire_after(
47  Objects_Id                         id,
48  rtems_interval                     ticks,
49  rtems_timer_service_routine_entry  routine,
50  void                              *user_data
51)
52{
53  Timer_Control        *the_timer;
54  Objects_Locations     location;
55  ISR_Level             level;
56  Timer_server_Control *timer_server = _Timer_server;
57
58  if ( !timer_server )
59    return RTEMS_INCORRECT_STATE;
60
61  if ( !routine )
62    return RTEMS_INVALID_ADDRESS;
63
64  if ( ticks == 0 )
65    return RTEMS_INVALID_NUMBER;
66
67  the_timer = _Timer_Get( id, &location );
68  switch ( location ) {
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_ON_TASK;
92        _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
93        the_timer->Ticker.initial = ticks;
94      _ISR_Enable( level );
95
96      (*timer_server->schedule_operation)( timer_server, the_timer );
97
98      _Thread_Enable_dispatch();
99      return RTEMS_SUCCESSFUL;
100
101#if defined(RTEMS_MULTIPROCESSING)
102    case OBJECTS_REMOTE:            /* should never return this */
103#endif
104    case OBJECTS_ERROR:
105      break;
106  }
107
108  return RTEMS_INVALID_ID;
109}
Note: See TracBrowser for help on using the repository browser.