OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [rtems/] [src/] [timerfirewhen.c] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  Timer Manager - rtems_timer_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
 *  timerfirewhen.c,v 1.3 2002/01/16 22:09:50 joel Exp
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_fire_when
27
 *
28
 *  This directive allows a thread to start a timer.
29
 *
30
 *  Input parameters:
31
 *    id        - timer id
32
 *    wall_time - time of day to fire timer
33
 *    routine   - routine to schedule
34
 *    user_data - passed as argument to routine when it is fired
35
 *
36
 *  Output parameters:
37
 *    RTEMS_SUCCESSFUL - if successful
38
 *    error code       - if unsuccessful
39
 */
40
 
41
rtems_status_code rtems_timer_fire_when(
42
  Objects_Id                          id,
43
  rtems_time_of_day                  *wall_time,
44
  rtems_timer_service_routine_entry   routine,
45
  void                               *user_data
46
)
47
{
48
  Timer_Control       *the_timer;
49
  Objects_Locations    location;
50
  rtems_interval       seconds;
51
 
52
  if ( !_TOD_Is_set )
53
    return RTEMS_NOT_DEFINED;
54
 
55
  if ( !_TOD_Validate( wall_time ) )
56
    return RTEMS_INVALID_CLOCK;
57
 
58
  seconds = _TOD_To_seconds( wall_time );
59
  if ( seconds <= _TOD_Seconds_since_epoch )
60
    return RTEMS_INVALID_CLOCK;
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
      the_timer->the_class = TIMER_TIME_OF_DAY;
73
      _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
74
      _Watchdog_Insert_seconds(
75
         &the_timer->Ticker,
76
         seconds - _TOD_Seconds_since_epoch
77
       );
78
      _Thread_Enable_dispatch();
79
      return RTEMS_SUCCESSFUL;
80
  }
81
 
82
  return RTEMS_INTERNAL_ERROR;   /* unreached - only to remove warnings */
83
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.