1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Create Timer |
---|
5 | * @ingroup ClassicTimer |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2002. |
---|
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/assert.h> |
---|
25 | #include <rtems/score/thread.h> |
---|
26 | #include <rtems/rtems/timerimpl.h> |
---|
27 | #include <rtems/score/watchdogimpl.h> |
---|
28 | |
---|
29 | void _Timer_Cancel( Timer_Control *the_timer ) |
---|
30 | { |
---|
31 | Timer_server_Control *timer_server; |
---|
32 | ISR_Level level; |
---|
33 | |
---|
34 | /* The timer class must not change during the cancel operation */ |
---|
35 | _ISR_Disable( level ); |
---|
36 | |
---|
37 | switch ( the_timer->the_class ) { |
---|
38 | case TIMER_INTERVAL: |
---|
39 | _Watchdog_Remove_ticks( &the_timer->Ticker ); |
---|
40 | break; |
---|
41 | case TIMER_TIME_OF_DAY: |
---|
42 | _Watchdog_Remove_seconds( &the_timer->Ticker ); |
---|
43 | break; |
---|
44 | case TIMER_INTERVAL_ON_TASK: |
---|
45 | case TIMER_TIME_OF_DAY_ON_TASK: |
---|
46 | timer_server = _Timer_server; |
---|
47 | (*timer_server->cancel)( timer_server, the_timer ); |
---|
48 | break; |
---|
49 | default: |
---|
50 | _Assert( the_timer->the_class == TIMER_DORMANT ); |
---|
51 | break; |
---|
52 | } |
---|
53 | |
---|
54 | _ISR_Enable( level ); |
---|
55 | } |
---|
56 | |
---|
57 | rtems_status_code rtems_timer_create( |
---|
58 | rtems_name name, |
---|
59 | rtems_id *id |
---|
60 | ) |
---|
61 | { |
---|
62 | Timer_Control *the_timer; |
---|
63 | |
---|
64 | if ( !rtems_is_name_valid( name ) ) |
---|
65 | return RTEMS_INVALID_NAME; |
---|
66 | |
---|
67 | if ( !id ) |
---|
68 | return RTEMS_INVALID_ADDRESS; |
---|
69 | |
---|
70 | the_timer = _Timer_Allocate(); |
---|
71 | |
---|
72 | if ( !the_timer ) { |
---|
73 | _Objects_Allocator_unlock(); |
---|
74 | return RTEMS_TOO_MANY; |
---|
75 | } |
---|
76 | |
---|
77 | the_timer->the_class = TIMER_DORMANT; |
---|
78 | _Watchdog_Preinitialize( &the_timer->Ticker ); |
---|
79 | |
---|
80 | _Objects_Open( |
---|
81 | &_Timer_Information, |
---|
82 | &the_timer->Object, |
---|
83 | (Objects_Name) name |
---|
84 | ); |
---|
85 | |
---|
86 | *id = the_timer->Object.id; |
---|
87 | _Objects_Allocator_unlock(); |
---|
88 | return RTEMS_SUCCESSFUL; |
---|
89 | } |
---|