1 | /* |
---|
2 | * Timer Manager - rtems_timer_server fire_when 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_when |
---|
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 | * wall_time - time of day to fire timer |
---|
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 | |
---|
46 | rtems_status_code rtems_timer_server_fire_when( |
---|
47 | Objects_Id id, |
---|
48 | rtems_time_of_day *wall_time, |
---|
49 | rtems_timer_service_routine_entry routine, |
---|
50 | void *user_data |
---|
51 | ) |
---|
52 | { |
---|
53 | Timer_Control *the_timer; |
---|
54 | Objects_Locations location; |
---|
55 | rtems_interval seconds; |
---|
56 | |
---|
57 | if ( !_Timer_Server ) |
---|
58 | return RTEMS_INCORRECT_STATE; |
---|
59 | |
---|
60 | if ( !_TOD_Is_set ) |
---|
61 | return RTEMS_NOT_DEFINED; |
---|
62 | |
---|
63 | if ( !routine ) |
---|
64 | return RTEMS_INVALID_ADDRESS; |
---|
65 | |
---|
66 | if ( !_TOD_Validate( wall_time ) ) |
---|
67 | return RTEMS_INVALID_CLOCK; |
---|
68 | |
---|
69 | seconds = _TOD_To_seconds( wall_time ); |
---|
70 | if ( seconds <= _TOD_Seconds_since_epoch ) |
---|
71 | return RTEMS_INVALID_CLOCK; |
---|
72 | |
---|
73 | the_timer = _Timer_Get( id, &location ); |
---|
74 | switch ( location ) { |
---|
75 | |
---|
76 | case OBJECTS_LOCAL: |
---|
77 | (void) _Watchdog_Remove( &the_timer->Ticker ); |
---|
78 | the_timer->the_class = TIMER_TIME_OF_DAY_ON_TASK; |
---|
79 | _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data ); |
---|
80 | the_timer->Ticker.initial = seconds - _TOD_Seconds_since_epoch; |
---|
81 | |
---|
82 | /* |
---|
83 | * _Timer_Server_schedule_operation != NULL because we checked that |
---|
84 | * _Timer_Server was != NULL above. Both are set at the same time. |
---|
85 | */ |
---|
86 | |
---|
87 | (*_Timer_Server_schedule_operation)( the_timer ); |
---|
88 | |
---|
89 | _Thread_Enable_dispatch(); |
---|
90 | return RTEMS_SUCCESSFUL; |
---|
91 | |
---|
92 | #if defined(RTEMS_MULTIPROCESSING) |
---|
93 | case OBJECTS_REMOTE: /* should never return this */ |
---|
94 | #endif |
---|
95 | case OBJECTS_ERROR: |
---|
96 | break; |
---|
97 | } |
---|
98 | |
---|
99 | return RTEMS_INVALID_ID; |
---|
100 | } |
---|