1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Timer Fire When |
---|
5 | * @ingroup ClassicTimer |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/rtems/status.h> |
---|
23 | #include <rtems/rtems/support.h> |
---|
24 | #include <rtems/score/thread.h> |
---|
25 | #include <rtems/rtems/timerimpl.h> |
---|
26 | #include <rtems/rtems/clock.h> |
---|
27 | #include <rtems/score/tod.h> |
---|
28 | #include <rtems/score/watchdogimpl.h> |
---|
29 | |
---|
30 | rtems_status_code rtems_timer_fire_when( |
---|
31 | rtems_id id, |
---|
32 | rtems_time_of_day *wall_time, |
---|
33 | rtems_timer_service_routine_entry routine, |
---|
34 | void *user_data |
---|
35 | ) |
---|
36 | { |
---|
37 | Timer_Control *the_timer; |
---|
38 | Objects_Locations location; |
---|
39 | rtems_interval seconds; |
---|
40 | |
---|
41 | if ( !_TOD.is_set ) |
---|
42 | return RTEMS_NOT_DEFINED; |
---|
43 | |
---|
44 | if ( !_TOD_Validate( wall_time ) ) |
---|
45 | return RTEMS_INVALID_CLOCK; |
---|
46 | |
---|
47 | if ( !routine ) |
---|
48 | return RTEMS_INVALID_ADDRESS; |
---|
49 | |
---|
50 | seconds = _TOD_To_seconds( wall_time ); |
---|
51 | if ( seconds <= _TOD_Seconds_since_epoch() ) |
---|
52 | return RTEMS_INVALID_CLOCK; |
---|
53 | |
---|
54 | the_timer = _Timer_Get( id, &location ); |
---|
55 | switch ( location ) { |
---|
56 | |
---|
57 | case OBJECTS_LOCAL: |
---|
58 | (void) _Watchdog_Remove( &the_timer->Ticker ); |
---|
59 | the_timer->the_class = TIMER_TIME_OF_DAY; |
---|
60 | _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data ); |
---|
61 | _Watchdog_Insert_seconds( |
---|
62 | &the_timer->Ticker, |
---|
63 | seconds - _TOD_Seconds_since_epoch() |
---|
64 | ); |
---|
65 | _Objects_Put( &the_timer->Object ); |
---|
66 | return RTEMS_SUCCESSFUL; |
---|
67 | |
---|
68 | #if defined(RTEMS_MULTIPROCESSING) |
---|
69 | case OBJECTS_REMOTE: /* should never return this */ |
---|
70 | #endif |
---|
71 | case OBJECTS_ERROR: |
---|
72 | break; |
---|
73 | } |
---|
74 | |
---|
75 | return RTEMS_INVALID_ID; |
---|
76 | } |
---|