⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel-alarms.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
字号:
<!-- Copyright (C) 2003 Red Hat, Inc.                                --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/).                           --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission is obtained from the copyright holder.               --><HTML><HEAD><TITLE>Alarms</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="The eCos Kernel"HREF="kernel.html"><LINKREL="PREVIOUS"TITLE="Clocks"HREF="kernel-clocks.html"><LINKREL="NEXT"TITLE="Mutexes"HREF="kernel-mutexes.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="kernel-clocks.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="kernel-mutexes.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="KERNEL-ALARMS">Alarms</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN1016"></A><H2>Name</H2>cyg_alarm_create, cyg_alarm_delete, cyg_alarm_initialize, cyg_alarm_enable, cyg_alarm_disable&nbsp;--&nbsp;Run an alarm function when a number of events have occurred</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN1023"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN1024"><P></P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="FUNCSYNOPSISINFO">#include &lt;cyg/kernel/kapi.h&gt;        </PRE></TD></TR></TABLE><P><CODE><CODECLASS="FUNCDEF">void cyg_alarm_create</CODE>(cyg_handle_t counter, cyg_alarm_t* alarmfn, cyg_addrword_t data, cyg_handle_t* handle, cyg_alarm* alarm);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_alarm_delete</CODE>(cyg_handle_t alarm);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_alarm_initialize</CODE>(cyg_handle_t alarm, cyg_tick_count_t trigger, cyg_tick_count_t interval);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_alarm_enable</CODE>(cyg_handle_t alarm);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_alarm_disable</CODE>(cyg_handle_t alarm);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-ALARMS-DESCRIPTION"></A><H2>Description</H2><P>Kernel alarms are used together with counters and allow for action tobe taken when a certain number of events have occurred. If the counteris associated with a clock then the alarm action happens when theappropriate number of clock ticks have occurred, in other words aftera certain period of time.      </P><P>Setting up an alarm involves a two-step process. First the alarm mustbe created with a call to <TTCLASS="FUNCTION">cyg_alarm_create</TT>. Thistakes five arguments. The first identifies the counter to which thealarm should be attached. If the alarm should be attached to thesystem's real-time clock then <TTCLASS="FUNCTION">cyg_real_time_clock</TT>and <TTCLASS="FUNCTION">cyg_clock_to_counter</TT> can be used to get holdof the appropriate handle. The next two arguments specify the actionto be taken when the alarm is triggered, in the form of a functionpointer and some data. This function should take the form:      </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">voidalarm_handler(cyg_handle_t alarm, cyg_addrword_t data){    &#8230;}      </PRE></TD></TR></TABLE><P>The data argument passed to the alarm function corresponds to thethird argument passed to <TTCLASS="FUNCTION">cyg_alarm_create</TT>.The fourth argument to <TTCLASS="FUNCTION">cyg_alarm_create</TT> is usedto return a handle to the newly-created alarm object, and the finalargument provides the memory needed for the alarm object and thusavoids any need for dynamic memory allocation within the kernel.      </P><P>Once an alarm has been created a further call to<TTCLASS="FUNCTION">cyg_alarm_initialize</TT> is needed to activate it.The first argument specifies the alarm. The second argument indicatesthe number of events, for example clock ticks, that need to occurbefore the alarm triggers. If the third argument is 0 then the alarmwill only trigger once. A non-zero value specifies that the alarmshould trigger repeatedly, with an interval of the specified number ofevents.      </P><P>Alarms can be temporarily disabled and reenabled using<TTCLASS="FUNCTION">cyg_alarm_disable</TT> and<TTCLASS="FUNCTION">cyg_alarm_enable</TT>. Alternatively another call to<TTCLASS="FUNCTION">cyg_alarm_initialize</TT> can be used to modify thebehaviour of an existing alarm. If an alarm is no longer required thenthe associated resources can be released using<TTCLASS="FUNCTION">cyg_alarm_delete</TT>.       </P><P>The alarm function is invoked when a counter tick occurs, in otherwords when there is a call to <TTCLASS="FUNCTION">cyg_counter_tick</TT>,and will happen in the same context. If the alarm is associated withthe system's real-time clock then this will be DSR context, followinga clock interrupt. If the alarm is associated with some otherapplication-specific counter then the details will depend on how thatcounter is updated.      </P><P>If two or more alarms are registered for precisely the same counter tick,the order of execution of the alarm functions is unspecified.      </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-ALARMS-CONTEXT"></A><H2>Valid contexts</H2><P><TTCLASS="FUNCTION">cyg_alarm_create</TT><TTCLASS="FUNCTION">cyg_alarm_initialize</TT> is typically called duringsystem initialization but may also be called in thread context. Thesame applies to <TTCLASS="FUNCTION">cyg_alarm_delete</TT>.<TTCLASS="FUNCTION">cyg_alarm_initialize</TT>,<TTCLASS="FUNCTION">cyg_alarm_disable</TT> and<TTCLASS="FUNCTION">cyg_alarm_enable</TT> may be called duringinitialization or from thread or DSR context, but<TTCLASS="FUNCTION">cyg_alarm_enable</TT> and<TTCLASS="FUNCTION">cyg_alarm_initialize</TT> may be expensive operationsand should only be called when necessary.      </P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="kernel-clocks.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="kernel-mutexes.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Clocks</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="kernel.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Mutexes</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -