RTEMS
timercreate.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20 
21 #include <rtems/rtems/timerimpl.h>
22 #include <rtems/rtems/clock.h>
23 #include <rtems/rtems/status.h>
24 #include <rtems/rtems/support.h>
25 #include <rtems/score/assert.h>
26 #include <rtems/score/chainimpl.h>
27 #include <rtems/score/thread.h>
28 #include <rtems/score/todimpl.h>
30 #include <rtems/sysinit.h>
31 
35 );
36 
38 
39 void _Timer_Routine_adaptor( Watchdog_Control *the_watchdog )
40 {
41  Timer_Control *the_timer;
42  Per_CPU_Control *cpu;
43 
44  the_timer = RTEMS_CONTAINER_OF( the_watchdog, Timer_Control, Ticker );
45  cpu = _Watchdog_Get_CPU( &the_timer->Ticker );
46  the_timer->stop_time = _Timer_Get_CPU_ticks( cpu );
47 
48  ( *the_timer->routine )( the_timer->Object.id, the_timer->user_data );
49 }
50 
51 rtems_status_code _Timer_Fire(
52  rtems_id id,
53  rtems_interval interval,
55  void *user_data,
56  Timer_Classes the_class,
58 )
59 {
60  Timer_Control *the_timer;
61  ISR_lock_Context lock_context;
62 
63  the_timer = _Timer_Get( id, &lock_context );
64  if ( the_timer != NULL ) {
65  Per_CPU_Control *cpu;
66 
67  cpu = _Timer_Acquire_critical( the_timer, &lock_context );
68  _Timer_Cancel( cpu, the_timer );
69  _Watchdog_Initialize( &the_timer->Ticker, adaptor );
70  the_timer->the_class = the_class;
71  the_timer->routine = routine;
72  the_timer->user_data = user_data;
73  the_timer->initial = interval;
74  the_timer->start_time = _Timer_Get_CPU_ticks( cpu );
75 
76  if ( _Timer_Is_interval_class( the_class ) ) {
79  &the_timer->Ticker,
80  cpu->Watchdog.ticks + interval
81  );
82  } else {
85  &the_timer->Ticker,
87  );
88  }
89 
90  _Timer_Release( cpu, &lock_context );
91  return RTEMS_SUCCESSFUL;
92  }
93 
94  return RTEMS_INVALID_ID;
95 }
96 
97 rtems_status_code _Timer_Fire_after(
98  rtems_id id,
99  rtems_interval ticks,
101  void *user_data,
102  Timer_Classes the_class,
104 )
105 {
106  if ( ticks == 0 )
107  return RTEMS_INVALID_NUMBER;
108 
109  if ( !routine )
110  return RTEMS_INVALID_ADDRESS;
111 
112  return _Timer_Fire(
113  id,
114  ticks,
115  routine,
116  user_data,
117  the_class,
118  adaptor
119  );
120 }
121 
122 rtems_status_code _Timer_Fire_when(
123  rtems_id id,
124  const rtems_time_of_day *wall_time,
126  void *user_data,
127  Timer_Classes the_class,
129 )
130 {
131  rtems_interval seconds;
132 
133  if ( !_TOD_Is_set() )
134  return RTEMS_NOT_DEFINED;
135 
136  if ( !routine )
137  return RTEMS_INVALID_ADDRESS;
138 
139  if ( !_TOD_Validate( wall_time ) )
140  return RTEMS_INVALID_CLOCK;
141 
142  seconds = _TOD_To_seconds( wall_time );
143  if ( seconds <= _TOD_Seconds_since_epoch() )
144  return RTEMS_INVALID_CLOCK;
145 
146  return _Timer_Fire(
147  id,
148  seconds,
149  routine,
150  user_data,
151  the_class,
152  adaptor
153  );
154 }
155 
156 void _Timer_Cancel( Per_CPU_Control *cpu, Timer_Control *the_timer )
157 {
158  Timer_Classes the_class;
159 
160  the_class = the_timer->the_class;
161 
162  if ( _Watchdog_Is_scheduled( &the_timer->Ticker ) ) {
163  the_timer->stop_time = _Timer_Get_CPU_ticks( cpu );
165  &cpu->Watchdog.Header[ _Timer_Watchdog_header_index( the_class ) ],
166  &the_timer->Ticker
167  );
168  } else if ( _Timer_Is_on_task_class( the_class ) ) {
169  Timer_server_Control *timer_server;
170  ISR_lock_Context lock_context;
171 
172  timer_server = _Timer_server;
173  _Assert( timer_server != NULL );
174  _Timer_server_Acquire_critical( timer_server, &lock_context );
175 
176  if ( _Watchdog_Get_state( &the_timer->Ticker ) == WATCHDOG_PENDING ) {
179  }
180 
181  _Timer_server_Release_critical( timer_server, &lock_context );
182  }
183 }
184 
186  rtems_name name,
187  rtems_id *id
188 )
189 {
190  Timer_Control *the_timer;
191 
192  if ( !rtems_is_name_valid( name ) )
193  return RTEMS_INVALID_NAME;
194 
195  if ( !id )
196  return RTEMS_INVALID_ADDRESS;
197 
198  the_timer = _Timer_Allocate();
199 
200  if ( !the_timer ) {
202  return RTEMS_TOO_MANY;
203  }
204 
205  the_timer->the_class = TIMER_DORMANT;
206  _Watchdog_Preinitialize( &the_timer->Ticker, _Per_CPU_Get_snapshot() );
207 
210  &the_timer->Object,
211  (Objects_Name) name
212  );
213 
214  *id = the_timer->Object.id;
216  return RTEMS_SUCCESSFUL;
217 }
218 
219 static void _Timer_Manager_initialization( void )
220 {
222 }
223 
224 RTEMS_SYSINIT_ITEM(
225  _Timer_Manager_initialization,
226  RTEMS_SYSINIT_CLASSIC_TIMER,
227  RTEMS_SYSINIT_ORDER_MIDDLE
228 );
union Watchdog_Control::@33 Node
Nodes for the watchdog.
This status code indicates you have attempted to create too many instances of a particular object cla...
Definition: status.h:112
static __inline__ void _Objects_Allocator_unlock(void)
Unlocks the object allocator mutex.
Definition: objectimpl.h:846
static __inline__ bool _TOD_Is_set(void)
Check if the TOD is Set.
Definition: todimpl.h:333
This header file defines support services of the API.
Watchdog_Service_routine(* Watchdog_Service_routine_entry)(Watchdog_Control *)
Pointer to a watchdog service routine.
Definition: watchdog.h:66
Index for realtime clock per-CPU watchdog header.
Definition: percpu.h:325
The watchdog is inactive.
Definition: watchdogimpl.h:61
This header file defines the Clock Manager API.
Watchdog_Header Header[PER_CPU_WATCHDOG_COUNT]
Header for watchdogs.
Definition: percpu.h:474
void _Watchdog_Insert(Watchdog_Header *header, Watchdog_Control *the_watchdog, uint64_t expire)
Inserts a watchdog into the set of scheduled watchdogs according to the specified expiration time...
Watchdog_Interval stop_time
Definition: timerdata.h:57
#define TIMER_CLASS_BIT_TIME_OF_DAY
%
Definition: timer.h:84
Timer_Classes
%
Definition: timer.h:120
uint32_t rtems_name
This type is used to represent a Classic API object name.
Definition: types.h:227
Inlined Routines in the Watchdog Handler.
void _Objects_Initialize_information(Objects_Information *information)
Initializes the specified objects information.
static __inline__ Watchdog_State _Watchdog_Get_state(const Watchdog_Control *the_watchdog)
Gets the state of the watchdog.
Definition: watchdogimpl.h:149
uint64_t ticks
Protects all watchdog operations on this processor.
Definition: percpu.h:467
Objects_Information _Timer_Information
The Classic Timer objects information.
The control block used to manage each watchdog timer.
Definition: watchdog.h:90
static bool rtems_is_name_valid(rtems_status_code name)
Returns true, if the specified object name is valid, otherwise returns false.
Definition: support.h:126
Classic Timer Implementation.
void _Watchdog_Remove(Watchdog_Header *header, Watchdog_Control *the_watchdog)
In the case the watchdog is scheduled, then it is removed from the set of scheduled watchdogs...
Objects_Control Object
Definition: timerdata.h:43
This status code indicates that a specified number was invalid.
Definition: status.h:138
rtems_timer_service_routine_entry routine
Definition: timerdata.h:49
Chain_Node Chain
this field is a chain node structure and allows this to be placed on a chain used to manage pending w...
Definition: watchdog.h:105
This header file defines the status codes and support functions of the Classic API.
static __inline__ bool _Watchdog_Is_scheduled(const Watchdog_Control *the_watchdog)
Checks if the watchdog is scheduled.
Definition: watchdogimpl.h:348
static __inline__ void _Watchdog_Preinitialize(Watchdog_Control *the_watchdog, Per_CPU_Control *cpu)
Pre-initializes a watchdog.
Definition: watchdogimpl.h:214
Information for the Assert Handler.
static __inline__ Timer_Control * _Timer_Allocate(void)
Timer_Allocate.
Definition: timerimpl.h:61
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)
Returns the pointer to the container of a specified member pointer.
Definition: basedefs.h:550
This status code indicates successful completion.
Definition: status.h:86
Watchdog_Interval _TOD_To_seconds(const rtems_time_of_day *the_tod)
%
This type is used to represent the calendar time in the Classic API.
Definition: types.h:258
static __inline__ void _Objects_Open(Objects_Information *information, Objects_Control *the_object, Objects_Name name)
Places the_object control pointer and object name in the Local Pointer and Local Name Tables...
Definition: objectimpl.h:750
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
Watchdog_Control Ticker
Definition: timerdata.h:45
static __inline__ Per_CPU_Control * _Watchdog_Get_CPU(const Watchdog_Control *the_watchdog)
Gets the watchdog&#39;s cpu.
Definition: watchdogimpl.h:177
Per CPU Core Structure.
Definition: percpu.h:347
static __inline__ uint64_t _Watchdog_Ticks_from_seconds(uint32_t seconds)
Converts the seconds to ticks.
Definition: watchdogimpl.h:504
Timer_server_Control *volatile _Timer_server
Pointer to default timer server control block.
Definition: timercreate.c:37
This status code indicates that a specified date/time was invalid.
Definition: status.h:194
struct Per_CPU_Control::@13 Watchdog
Watchdog state for this processor.
static __inline__ void _Chain_Extract_unprotected(Chain_Node *the_node)
Extracts this node (unprotected).
Definition: chainimpl.h:558
#define RTEMS_STATIC_ASSERT(_cond, _msg)
Asserts at compile time that the specified condition is satisfied.
Definition: basedefs.h:838
Chain Handler API.
The watchdog is on a chain of pending watchdogs.
Definition: watchdogimpl.h:68
static __inline__ void _Watchdog_Initialize(Watchdog_Control *the_watchdog, Watchdog_Service_routine_entry routine)
Initializes a watchdog with a new service routine.
Definition: watchdogimpl.h:236
Time of Day Handler API.
This status code indicates that a specified address was invalid.
Definition: status.h:133
void * user_data
Definition: timerdata.h:51
Watchdog_Interval rtems_interval
This type is used to represent clock tick intervals.
Definition: types.h:90
rtems_status_code rtems_timer_create(rtems_name name, rtems_id *id)
%
Definition: timercreate.c:185
This status code indicates that the item has not been initialized.
Definition: status.h:143
This status code indicates that an object identifier was invalid.
Definition: status.h:106
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
static uint32_t _TOD_Seconds_since_epoch(void)
Returns Number of seconds Since RTEMS epoch.
Definition: todimpl.h:275
Watchdog_Interval start_time
Definition: timerdata.h:55
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Timer_Classes the_class
Definition: timerdata.h:47
Index for tick clock per-CPU watchdog header.
Definition: percpu.h:316
rtems_timer_service_routine(* rtems_timer_service_routine_entry)(rtems_id, void *)
%
Definition: timer.h:158
This status code indicates that an object name was invalid.
Definition: status.h:101
Watchdog_Interval initial
Definition: timerdata.h:53
Constants and Structures Related with the Thread Control Block.
static __inline__ void _Watchdog_Set_state(Watchdog_Control *the_watchdog, Watchdog_State state)
Sets the state of the watchdog.
Definition: watchdogimpl.h:162
bool _TOD_Validate(const rtems_time_of_day *the_tod)
%
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
Objects_Id id
Definition: objectdata.h:43