1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Timer Reset |
---|
5 | * @ingroup ClassicTimer Timers |
---|
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.org/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 | /* |
---|
29 | * rtems_timer_reset |
---|
30 | * |
---|
31 | * This directive allows a thread to reset a timer. |
---|
32 | * |
---|
33 | * Input parameters: |
---|
34 | * id - timer id |
---|
35 | * |
---|
36 | * Output parameters: |
---|
37 | * RTEMS_SUCCESSFUL - if successful |
---|
38 | * error code - if unsuccessful |
---|
39 | */ |
---|
40 | |
---|
41 | rtems_status_code rtems_timer_reset( |
---|
42 | rtems_id id |
---|
43 | ) |
---|
44 | { |
---|
45 | Timer_Control *the_timer; |
---|
46 | Objects_Locations location; |
---|
47 | rtems_status_code status = RTEMS_SUCCESSFUL; |
---|
48 | |
---|
49 | the_timer = _Timer_Get( id, &location ); |
---|
50 | switch ( location ) { |
---|
51 | |
---|
52 | case OBJECTS_LOCAL: |
---|
53 | if ( the_timer->the_class == TIMER_INTERVAL ) { |
---|
54 | _Watchdog_Remove( &the_timer->Ticker ); |
---|
55 | _Watchdog_Insert( &_Watchdog_Ticks_chain, &the_timer->Ticker ); |
---|
56 | } else if ( the_timer->the_class == TIMER_INTERVAL_ON_TASK ) { |
---|
57 | Timer_server_Control *timer_server = _Timer_server; |
---|
58 | |
---|
59 | /* |
---|
60 | * There is no way for a timer to have this class unless |
---|
61 | * it was scheduled as a server fire. That requires that |
---|
62 | * the Timer Server be initiated. So this error cannot |
---|
63 | * occur unless something is internally wrong. |
---|
64 | */ |
---|
65 | #if defined(RTEMS_DEBUG) |
---|
66 | if ( !timer_server ) { |
---|
67 | _Objects_Put( &the_timer->Object ); |
---|
68 | return RTEMS_INCORRECT_STATE; |
---|
69 | } |
---|
70 | #endif |
---|
71 | _Watchdog_Remove( &the_timer->Ticker ); |
---|
72 | (*timer_server->schedule_operation)( timer_server, the_timer ); |
---|
73 | } else { |
---|
74 | /* |
---|
75 | * Must be dormant or time of day timer (e.g. TIMER_DORMANT, |
---|
76 | * TIMER_TIME_OF_DAY, or TIMER_TIME_OF_DAY_ON_TASK). We |
---|
77 | * can only reset active interval timers. |
---|
78 | */ |
---|
79 | status = RTEMS_NOT_DEFINED; |
---|
80 | } |
---|
81 | _Objects_Put( &the_timer->Object ); |
---|
82 | return status; |
---|
83 | |
---|
84 | #if defined(RTEMS_MULTIPROCESSING) |
---|
85 | case OBJECTS_REMOTE: /* should never return this */ |
---|
86 | #endif |
---|
87 | case OBJECTS_ERROR: |
---|
88 | break; |
---|
89 | } |
---|
90 | |
---|
91 | return RTEMS_INVALID_ID; |
---|
92 | } |
---|