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

📄 kernel-interrupts.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- 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>Interrupt Handling</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="Scheduler Control"HREF="kernel-schedcontrol.html"><LINKREL="NEXT"TITLE="Kernel Real-time Characterization"HREF="kernel-characterization.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-schedcontrol.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="kernel-characterization.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="KERNEL-INTERRUPTS">Interrupt Handling</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN1834"></A><H2>Name</H2>cyg_interrupt_create, cyg_interrupt_delete, cyg_interrupt_attach, cyg_interrupt_detach, cyg_interrupt_configure, cyg_interrupt_acknowledge, cyg_interrupt_enable, cyg_interrupt_disable, cyg_interrupt_mask, cyg_interrupt_mask_intunsafe, cyg_interrupt_unmask, cyg_interrupt_unmask_intunsafe, cyg_interrupt_set_cpu, cyg_interrupt_get_cpu, cyg_interrupt_get_vsr, cyg_interrupt_set_vsr&nbsp;--&nbsp;Manage interrupt handlers</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN1852"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN1853"><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_interrupt_create</CODE>(cyg_vector_t vector, cyg_priority_t priority, cyg_addrword_t data, cyg_ISR_t* isr, cyg_DSR_t* dsr, cyg_handle_t* handle, cyg_interrupt* intr);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_delete</CODE>(cyg_handle_t interrupt);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_attach</CODE>(cyg_handle_t interrupt);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_detach</CODE>(cyg_handle_t interrupt);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_configure</CODE>(cyg_vector_t vector, cyg_bool_t level, cyg_bool_t up);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_acknowledge</CODE>(cyg_vector_t vector);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_disable</CODE>(void);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_enable</CODE>(void);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_mask</CODE>(cyg_vector_t vector);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_mask_intunsafe</CODE>(cyg_vector_t vector);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_unmask</CODE>(cyg_vector_t vector);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_unmask_intunsafe</CODE>(cyg_vector_t vector);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_set_cpu</CODE>(cyg_vector_t vector, cyg_cpu_t cpu);</CODE></P><P><CODE><CODECLASS="FUNCDEF">cyg_cpu_t cyg_interrupt_get_cpu</CODE>(cyg_vector_t vector);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_get_vsr</CODE>(cyg_vector_t vector, cyg_VSR_t** vsr);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void cyg_interrupt_set_vsr</CODE>(cyg_vector_t vector, cyg_VSR_t* vsr);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-INTERRUPTS-DESCRIPTION"></A><H2>Description</H2><P>The kernel provides an interface for installing interrupt handlers andcontrolling when interrupts occur. This functionality is usedprimarily by eCos device drivers and by any application code thatinteracts directly with hardware. However in most cases it is betterto avoid using this kernel functionality directly, and instead thedevice driver API provided by the common HAL package should be used.Use of the kernel package is optional, and some applications such asRedBoot work with no need for multiple threads or synchronizationprimitives. Any code which calls the kernel directly rather than thedevice driver API will not function in such a configuration. When thekernel package is present the device driver API is implemented as<TTCLASS="LITERAL">#define</TT>'s to the equivalent kernel calls, otherwiseit is implemented inside the common HAL package. The latterimplementation can be simpler than the kernel one because there is noneed to consider thread preemption and similar issues.      </P><P>The exact details of interrupt handling vary widely betweenarchitectures. The functionality provided by the kernel abstracts awayfrom many of the details of the underlying hardware, thus simplifyingapplication development. However this is not always successful. Forexample, if some hardware does not provide any support at all formasking specific interrupts then calling<TTCLASS="FUNCTION">cyg_interrupt_mask</TT> may not behave as intended:instead of masking just the one interrupt source it might disable allinterrupts, because that is as close to the desired behaviour as ispossible given the hardware restrictions. Another possibility is thatmasking a given interrupt source also affects all lower-priorityinterrupts, but still allows higher-priority ones. The documentationfor the appropriate HAL packages should be consulted for moreinformation about exactly how interrupts are handled on any givenhardware. The HAL header files will also contain useful information.       </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-INTERRUPTS-HANDLERS"></A><H2>Interrupt Handlers</H2><P>Interrupt handlers are created by a call to<TTCLASS="FUNCTION">cyg_interrupt_create</TT>. This takes the followingarguments:       </P><P></P><DIVCLASS="VARIABLELIST"><DL><DT>cyg_vector_t <TTCLASS="PARAMETER"><I>vector</I></TT></DT><DD><P>The interrupt vector, a small integer, identifies the specificinterrupt source. The appropriate hardware documentation or HAL headerfiles should be consulted for details of which vector corresponds towhich device.          </P></DD><DT>cyg_priority_t <TTCLASS="PARAMETER"><I>priority</I></TT></DT><DD><P>Some hardware may support interrupt priorities, where a low priorityinterrupt handler can in turn be interrupted by a higher priority one.Again hardware-specific documentation should be consulted for detailsabout what the valid interrupt priority levels are.          </P></DD><DT>cyg_addrword_t <TTCLASS="PARAMETER"><I>data</I></TT></DT><DD><P>When an interrupt occurs eCos will first call the associatedinterrupt service routine or ISR, then optionally a deferred serviceroutine or DSR. The <TTCLASS="PARAMETER"><I>data</I></TT> argument to<TTCLASS="FUNCTION">cyg_interrupt_create</TT> will be passed to both thesefunctions. Typically it will be a pointer to some data structure.          </P></DD><DT>cyg_ISR_t <TTCLASS="PARAMETER"><I>isr</I></TT></DT><DD><P>When an interrupt occurs the hardware will transfer control to theappropriate vector service routine or VSR, which is usually providedby eCos. This performs any appropriate processing, for example to workout exactly which interrupt occurred, and then as quickly as possibletransfers control the installed ISR. An ISR is a C function whichtakes the following form:          </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">cyg_uint32isr_function(cyg_vector_t vector, cyg_addrword_t data){    cyg_bool_t dsr_required = 0;    &#8230;    return dsr_required ? CYG_ISR_CALL_DSR : CYG_ISR_HANDLED;}          </PRE></TD></TR></TABLE><P>The first argument identifies the particular interrupt source,especially useful if there multiple instances of a given device and asingle ISR can be used for several different interrupt vectors. Thesecond argument is the <TTCLASS="PARAMETER"><I>data</I></TT> field passed to<TTCLASS="FUNCTION">cyg_interrupt_create</TT>, usually a pointer to somedata structure. The exact conditions under which an ISR runs willdepend partly on the hardware and partly on configuration options.Interrupts may currently be disabled globally, especially if thehardware does not support interrupt priorities. Alternativelyinterrupts may be enabled such that higher priority interrupts areallowed through. The ISR may be running on a separate interrupt stack,or on the stack of whichever thread was running at the time theinterrupt happened.          </P><P>A typical ISR will do as little work as possible, just enough to meetthe needs of the hardware and then acknowledge the interrupt bycalling <TTCLASS="FUNCTION">cyg_interrupt_acknowledge</TT>. This ensuresthat interrupts will be quickly reenabled, so higher priority devicescan be serviced. For some applications there may be one device whichis especially important and whose ISR can take much longer thannormal. However eCos device drivers usually will not assume that theyare especially important, so their ISRs will be as short as possible.

⌨️ 快捷键说明

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