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

📄 kernel-interrupts.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
          </P><P>The return value of an ISR is normally one of<TTCLASS="LITERAL">CYG_ISR_CALL_DSR</TT> or<TTCLASS="LITERAL">CYG_ISR_HANDLED</TT>. The former indicates that furtherprocessing is required at DSR level, and the interrupt handler's DSRwill be run as soon as possible. The latter indicates that theinterrupt has been fully handled and no further effort is required.          </P><P>An ISR is allowed to make very few kernel calls. It can manipulate theinterrupt mask, and on SMP systems it can use spinlocks. However anISR must not make higher-level kernel calls such as posting to asemaphore, instead any such calls must be made from the DSR. Thisavoids having to disable interrupts throughout the kernel and thusimproves interrupt latency.          </P></DD><DT>cyg_DSR_t <TTCLASS="PARAMETER"><I>dsr</I></TT></DT><DD><P>If an interrupt has occurred and the ISR has returned a value<TTCLASS="LITERAL">CYG_ISR_CALL_DSR</TT>, the system will call thedeferred service routine or DSR associated with this interrupthandler. If the scheduler is not currently locked then the DSR willrun immediately. However if the interrupted thread was in the middleof a kernel call and had locked the scheduler, then the DSR will bedeferred until the scheduler is again unlocked. This allows theDSR to make certain kernel calls safely, for example posting to asemaphore or signalling a condition variable. A DSR is a C functionwhich takes the following form:          </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">voiddsr_function(cyg_vector_t vector,             cyg_ucount32 count,             cyg_addrword_t data){}          </PRE></TD></TR></TABLE><P>The first argument identifies the specific interrupt that has causedthe DSR to run. The second argument indicates the number of theseinterrupts that have occurred and for which the ISR requested a DSR.Usually this will be <TTCLASS="LITERAL">1</TT>, unless the system issuffering from a very heavy load. The third argument is the<TTCLASS="PARAMETER"><I>data</I></TT> field passed to<TTCLASS="FUNCTION">cyg_interrupt_create</TT>.           </P></DD><DT>cyg_handle_t* <TTCLASS="PARAMETER"><I>handle</I></TT></DT><DD><P>The kernel will return a handle to the newly created interrupt handlervia this argument. Subsequent operations on the interrupt handler suchas attaching it to the interrupt source will use this handle.          </P></DD><DT>cyg_interrupt* <TTCLASS="PARAMETER"><I>intr</I></TT></DT><DD><P>This provides the kernel with an area of memory for holding thisinterrupt handler and associated data.          </P></DD></DL></DIV><P>The call to <TTCLASS="FUNCTION">cyg_interrupt_create</TT> simply fills ina kernel data structure. A typical next step is to call<TTCLASS="FUNCTION">cyg_interrupt_attach</TT> using the handle returned bythe create operation. This makes it possible to have several differentinterrupt handlers for a given vector, attaching whichever one iscurrently appropriate. Replacing an interrupt handler requires a callto <TTCLASS="FUNCTION">cyg_interrupt_detach</TT>, followed by another callto <TTCLASS="FUNCTION">cyg_interrupt_attach</TT> for the replacementhandler. <TTCLASS="FUNCTION">cyg_interrupt_delete</TT> can be used if aninterrupt handler is no longer required.      </P><P>Some hardware may allow for further control over specific interrupts,for example whether an interrupt is level or edge triggered. Any suchhardware functionality can be accessed using<TTCLASS="FUNCTION">cyg_interrupt_configure</TT>: the<TTCLASS="PARAMETER"><I>level</I></TT> argument selects between level versusedge triggered; the <TTCLASS="PARAMETER"><I>up</I></TT> argument selects betweenhigh and low level, or between rising and falling edges.      </P><P>Usually interrupt handlers are created, attached and configured duringsystem initialization, while global interrupts are still disabled. Onmost hardware it will also be necessary to call<TTCLASS="FUNCTION">cyg_interrupt_unmask</TT>, since the sensible defaultfor interrupt masking is to ignore any interrupts for which no handleris installed.      </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-INTERRUPTS-ENABLE"></A><H2>Controlling Interrupts</H2><P>eCos provides two ways of controlling whether or not interruptshappen. It is possible to disable and reenable all interruptsglobally, using <TTCLASS="FUNCTION">cyg_interrupt_disable</TT> and<TTCLASS="FUNCTION">cyg_interrupt_enable</TT>. Typically this works bymanipulating state inside the cpu itself, for example setting a flagin a status register or executing special instructions. Alternativelyit may be possible to mask a specific interrupt source by writing toone or to several interrupt mask registers. Hardware-specificdocumentation should be consulted for the exact details of howinterrupt masking works, because a full implementation is not possibleon all hardware.      </P><P>The primary use for these functions is to allow data to be sharedbetween ISRs and other code such as DSRs or threads. If both a threadand an ISR need to manipulate either a data structure or the hardwareitself, there is a possible conflict if an interrupt happens just whenthe thread is doing such manipulation. Problems can be avoided by thethread either disabling or masking interrupts during the criticalregion. If this critical region requires only a few instructions thenusually it is more efficient to disable interrupts. For largercritical regions it may be more appropriate to use interrupt masking,allowing other interrupts to occur. There are other uses for interruptmasking. For example if a device is not currently being used by theapplication then it may be desirable to mask all interrupts generatedby that device.      </P><P>There are two functions for masking a specific interrupt source,<TTCLASS="FUNCTION">cyg_interrupt_mask</TT> and<TTCLASS="FUNCTION">cyg_interrupt_mask_intunsafe</TT>. On typical hardwaremasking an interrupt is not an atomic operation, so if two threadswere to perform interrupt masking operations at the same time therecould be problems. <TTCLASS="FUNCTION">cyg_interrupt_mask</TT> disablesall interrupts while it manipulates the interrupt mask. In situationswhere interrupts are already know to be disabled,<TTCLASS="FUNCTION">cyg_interrupt_mask_intunsafe</TT> can be usedinstead. There are matching functions<TTCLASS="FUNCTION">cyg_interrupt_unmask</TT> and<TTCLASS="FUNCTION">cyg_interrupt_unmask_intsafe</TT>.      </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-INTERRUPTS-SMP"></A><H2>SMP Support</H2><P>On SMP systems the kernel provides an additional two functions relatedto interrupt handling. <TTCLASS="FUNCTION">cyg_interrupt_set_cpu</TT>specifies that a particular hardware interrupt should always behandled on one specific processor in the system. In other words whenthe interrupt triggers it is only that processor which detects it, andit is only on that processor that the VSR and ISR will run. If a DSRis requested then it will also run on the same CPU. Thefunction <TTCLASS="FUNCTION">cyg_interrupt_get_cpu</TT> can be used tofind out which interrupts are handled on which processor.       </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-INTERRUPTS-VSR"></A><H2>VSR Support</H2><P>When an interrupt occurs the hardware will transfer control to a pieceof code known as the VSR, or Vector Service Routine. By default thiscode is provided by eCos. Usually it is written in assembler, but onsome architectures it may be possible to implement VSRs in C byspecifying an interrupt attribute. Compiler documentation should beconsulted for more information on this. The default eCos VSR will workout which ISR function should process the interrupt, and set up a Cenvironment suitable for this ISR.      </P><P>For some applications it may be desirable to replace the default eCosVSR and handle some interrupts directly. This minimizes interruptlatency, but it requires application developers to program at a lowerlevel. Usually the best way to write a custom VSR is to copy theexisting one supplied by eCos and then make appropriate modifications.The function <TTCLASS="FUNCTION">cyg_interrupt_get_vsr</TT> can be used toget hold of the current VSR for a given interrupt vector, allowing itto be restored if the custom VSR is no longer required.<TTCLASS="FUNCTION">cyg_interrupt_set_vsr</TT> can be used to install areplacement VSR. Usually the <TTCLASS="PARAMETER"><I>vsr</I></TT> argument willcorrespond to an exported label in an assembler source file.      </P></DIV><DIVCLASS="REFSECT1"><ANAME="KERNEL-INTERRUPTS-CONTEXT"></A><H2>Valid contexts</H2><P>In a typical configuration interrupt handlers are created and attachedduring system initialization, and never detached or deleted. Howeverit is possible to perform these operations at thread level, ifdesired. Similarly <TTCLASS="FUNCTION">cyg_interrupt_configure</TT>,<TTCLASS="FUNCTION">cyg_interrupt_set_vsr</TT>, and<TTCLASS="FUNCTION">cyg_interrupt_set_cpu</TT> are usually called onlyduring system initialization, but on typical hardware may be called atany time. <TTCLASS="FUNCTION">cyg_interrupt_get_vsr</TT> and<TTCLASS="FUNCTION">cyg_interrupt_get_cpu</TT> may be called at any time.      </P><P>The functions for enabling, disabling, masking and unmaskinginterrupts can be called in any context, when appropriate. It is theresponsibility of application developers to determine when the use ofthese functions is appropriate.      </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-schedcontrol.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-characterization.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Scheduler Control</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="kernel.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Kernel Real-time Characterization</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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