1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Timer Fire After |
---|
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/score/watchdogimpl.h> |
---|
27 | |
---|
28 | rtems_status_code rtems_timer_fire_after( |
---|
29 | rtems_id id, |
---|
30 | rtems_interval ticks, |
---|
31 | rtems_timer_service_routine_entry routine, |
---|
32 | void *user_data |
---|
33 | ) |
---|
34 | { |
---|
35 | Timer_Control *the_timer; |
---|
36 | Objects_Locations location; |
---|
37 | ISR_Level level; |
---|
38 | |
---|
39 | if ( ticks == 0 ) |
---|
40 | return RTEMS_INVALID_NUMBER; |
---|
41 | |
---|
42 | if ( !routine ) |
---|
43 | return RTEMS_INVALID_ADDRESS; |
---|
44 | |
---|
45 | the_timer = _Timer_Get( id, &location ); |
---|
46 | switch ( location ) { |
---|
47 | |
---|
48 | case OBJECTS_LOCAL: |
---|
49 | (void) _Watchdog_Remove( &the_timer->Ticker ); |
---|
50 | |
---|
51 | _ISR_Disable( level ); |
---|
52 | |
---|
53 | /* |
---|
54 | * Check to see if the watchdog has just been inserted by a |
---|
55 | * higher priority interrupt. If so, abandon this insert. |
---|
56 | */ |
---|
57 | |
---|
58 | if ( the_timer->Ticker.state != WATCHDOG_INACTIVE ) { |
---|
59 | _ISR_Enable( level ); |
---|
60 | _Objects_Put( &the_timer->Object ); |
---|
61 | return RTEMS_SUCCESSFUL; |
---|
62 | } |
---|
63 | |
---|
64 | /* |
---|
65 | * OK. Now we now the timer was not rescheduled by an interrupt |
---|
66 | * so we can atomically initialize it as in use. |
---|
67 | */ |
---|
68 | |
---|
69 | the_timer->the_class = TIMER_INTERVAL; |
---|
70 | _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data ); |
---|
71 | _ISR_Enable( level ); |
---|
72 | |
---|
73 | |
---|
74 | _Watchdog_Insert_ticks( &the_timer->Ticker, ticks ); |
---|
75 | _Objects_Put( &the_timer->Object ); |
---|
76 | return RTEMS_SUCCESSFUL; |
---|
77 | |
---|
78 | #if defined(RTEMS_MULTIPROCESSING) |
---|
79 | case OBJECTS_REMOTE: /* should never return this */ |
---|
80 | #endif |
---|
81 | case OBJECTS_ERROR: |
---|
82 | break; |
---|
83 | } |
---|
84 | |
---|
85 | return RTEMS_INVALID_ID; |
---|
86 | } |
---|