1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="The eCos Kernel"
23 HREF="kernel.html"><LINK
26 HREF="kernel-clocks.html"><LINK
29 HREF="kernel-mutexes.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="kernel-clocks.html"
71 HREF="kernel-mutexes.html"
82 NAME="KERNEL-ALARMS">Alarms</H1
90 >cyg_alarm_create, cyg_alarm_delete, cyg_alarm_initialize, cyg_alarm_enable, cyg_alarm_disable -- Run an alarm function when a number of events have occurred</DIV
92 CLASS="REFSYNOPSISDIV"
108 CLASS="FUNCSYNOPSISINFO"
109 >#include <cyg/kernel/kapi.h>
118 >void cyg_alarm_create</CODE
119 >(cyg_handle_t counter, cyg_alarm_t* alarmfn, cyg_addrword_t data, cyg_handle_t* handle, cyg_alarm* alarm);</CODE
125 >void cyg_alarm_delete</CODE
126 >(cyg_handle_t alarm);</CODE
132 >void cyg_alarm_initialize</CODE
133 >(cyg_handle_t alarm, cyg_tick_count_t trigger, cyg_tick_count_t interval);</CODE
139 >void cyg_alarm_enable</CODE
140 >(cyg_handle_t alarm);</CODE
146 >void cyg_alarm_disable</CODE
147 >(cyg_handle_t alarm);</CODE
156 NAME="KERNEL-ALARMS-DESCRIPTION"
161 >Kernel alarms are used together with counters and allow for action to
162 be taken when a certain number of events have occurred. If the counter
163 is associated with a clock then the alarm action happens when the
164 appropriate number of clock ticks have occurred, in other words after
165 a certain period of time.
168 >Setting up an alarm involves a two-step process. First the alarm must
169 be created with a call to <TT
171 >cyg_alarm_create</TT
173 takes five arguments. The first identifies the counter to which the
174 alarm should be attached. If the alarm should be attached to the
175 system's real-time clock then <TT
177 >cyg_real_time_clock</TT
181 >cyg_clock_to_counter</TT
182 > can be used to get hold
183 of the appropriate handle. The next two arguments specify the action
184 to be taken when the alarm is triggered, in the form of a function
185 pointer and some data. This function should take the form:
194 CLASS="PROGRAMLISTING"
196 alarm_handler(cyg_handle_t alarm, cyg_addrword_t data)
205 >The data argument passed to the alarm function corresponds to the
206 third argument passed to <TT
208 >cyg_alarm_create</TT
210 The fourth argument to <TT
212 >cyg_alarm_create</TT
214 to return a handle to the newly-created alarm object, and the final
215 argument provides the memory needed for the alarm object and thus
216 avoids any need for dynamic memory allocation within the kernel.
219 >Once an alarm has been created a further call to
222 >cyg_alarm_initialize</TT
223 > is needed to activate it.
224 The first argument specifies the alarm. The second argument indicates
225 the number of events, for example clock ticks, that need to occur
226 before the alarm triggers. If the third argument is 0 then the alarm
227 will only trigger once. A non-zero value specifies that the alarm
228 should trigger repeatedly, with an interval of the specified number of
232 >Alarms can be temporarily disabled and reenabled using
235 >cyg_alarm_disable</TT
239 >cyg_alarm_enable</TT
240 >. Alternatively another call to
243 >cyg_alarm_initialize</TT
244 > can be used to modify the
245 behaviour of an existing alarm. If an alarm is no longer required then
246 the associated resources can be released using
249 >cyg_alarm_delete</TT
253 >The alarm function is invoked when a counter tick occurs, in other
254 words when there is a call to <TT
256 >cyg_counter_tick</TT
258 and will happen in the same context. If the alarm is associated with
259 the system's real-time clock then this will be DSR context, following
260 a clock interrupt. If the alarm is associated with some other
261 application-specific counter then the details will depend on how that
265 >If two or more alarms are registered for precisely the same counter tick,
266 the order of execution of the alarm functions is unspecified.
272 NAME="KERNEL-ALARMS-CONTEXT"
279 >cyg_alarm_create</TT
283 >cyg_alarm_initialize</TT
284 > is typically called during
285 system initialization but may also be called in thread context. The
288 >cyg_alarm_delete</TT
292 >cyg_alarm_initialize</TT
296 >cyg_alarm_disable</TT
300 >cyg_alarm_enable</TT
301 > may be called during
302 initialization or from thread or DSR context, but
305 >cyg_alarm_enable</TT
309 >cyg_alarm_initialize</TT
310 > may be expensive operations
311 and should only be called when necessary.
319 SUMMARY="Footer navigation table"
330 HREF="kernel-clocks.html"
348 HREF="kernel-mutexes.html"