source: rtems/cpukit/rtems/src/timerserverfirewhen.c @ 54d540f

4.104.114.84.95
Last change on this file since 54d540f was 894d01c, checked in by Joel Sherrill <joel.sherrill@…>, on 03/29/02 at 15:32:18

2001-03-29 Joel Sherrill <joel@…>

  • Per PR147 addressed problems when reseting and inserting a timer into a timer chain that did not honor time passage since the last time the timer server was scheduled and the new insertion.
  • include/rtems/rtems/timer.h, src/timerreset.c, src/timerserver.c, src/timerserverfireafter.c, src/timerserverfirewhen.c: Broke up the "reset server" routine into a set of very specific routines that allowed the server to be unscheduled, timer chains to be "synchronized" with the current time before inserting a new timer.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  Timer Manager - rtems_timer_server fire_when 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.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/rtems/status.h>
17#include <rtems/rtems/support.h>
18#include <rtems/score/object.h>
19#include <rtems/score/thread.h>
20#include <rtems/rtems/timer.h>
21#include <rtems/score/tod.h>
22#include <rtems/score/watchdog.h>
23
24/*PAGE
25 *
26 *  rtems_timer_server_fire_when
27 *
28 *  This directive allows a thread to start a timer which will by
29 *  executed by the Timer Server when it fires.
30 *
31 *  Input parameters:
32 *    id        - timer id
33 *    wall_time - time of day to fire timer
34 *    routine   - routine to schedule
35 *    user_data - passed as argument to routine when it is fired
36 *
37 *  Output parameters:
38 *    RTEMS_SUCCESSFUL - if successful
39 *    error code       - if unsuccessful
40 */
41
42rtems_status_code rtems_timer_server_fire_when(
43  Objects_Id                         id,
44  rtems_time_of_day                  *wall_time,
45  rtems_timer_service_routine_entry  routine,
46  void                              *user_data
47)
48{
49  Timer_Control        *the_timer;
50  Objects_Locations     location;
51  rtems_interval        seconds;
52  extern Chain_Control  _Timer_Seconds_chain;
53
54  if ( !_Timer_Server )
55    return RTEMS_INCORRECT_STATE;
56
57  if ( !_TOD_Is_set )
58    return RTEMS_NOT_DEFINED;
59
60  if ( !_TOD_Validate( wall_time ) )
61    return RTEMS_INVALID_CLOCK;
62
63  seconds = _TOD_To_seconds( wall_time );
64  if ( seconds <= _TOD_Seconds_since_epoch )
65    return RTEMS_INVALID_CLOCK;
66
67  the_timer = _Timer_Get( id, &location );
68  switch ( location ) {
69    case OBJECTS_REMOTE:            /* should never return this */
70      return RTEMS_INTERNAL_ERROR;
71
72    case OBJECTS_ERROR:
73      return RTEMS_INVALID_ID;
74
75    case OBJECTS_LOCAL:
76      (void) _Watchdog_Remove( &the_timer->Ticker );
77      the_timer->the_class = TIMER_TIME_OF_DAY_ON_TASK;
78      _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
79      the_timer->Ticker.initial = seconds - _TOD_Seconds_since_epoch;
80
81      _Timer_Server_stop_seconds_timer();
82      _Timer_Server_process_seconds_chain();
83      _Watchdog_Insert( &_Timer_Seconds_chain, &the_timer->Ticker );
84       _Timer_Server_reset_seconds_timer();
85
86      _Thread_Enable_dispatch();
87      return RTEMS_SUCCESSFUL;
88  }
89
90  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
91}
Note: See TracBrowser for help on using the repository browser.