📄 hal-interrupt-handling.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>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="HAL Interfaces"HREF="hal-interfaces.html"><LINKREL="PREVIOUS"TITLE="Architecture Characterization"HREF="hal-architecture-characterization.html"><LINKREL="NEXT"TITLE="HAL I/O"HREF="hal-input-and-output.html"></HEAD><BODYCLASS="SECTION"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="hal-architecture-characterization.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. HAL Interfaces</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="hal-input-and-output.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECTION"><H1CLASS="SECTION"><ANAME="HAL-INTERRUPT-HANDLING">Interrupt Handling</H1><P>These interfaces contain definitions related to interrupthandling. They include definitions of exception and interrupt numbers,interrupt enabling and masking, and realtime clock operations.</P><P>These definitions are normally found in<TTCLASS="FILENAME">cyg/hal/hal_intr.h</TT>. This file is supplied by thearchitecture HAL. Any variant or platform specific definitions willbe found in <TTCLASS="FILENAME">cyg/hal/var_intr.h</TT>,<TTCLASS="FILENAME">cyg/hal/plf_intr.h</TT> or<TTCLASS="FILENAME">cyg/hal/hal_platform_ints.h</TT> in the variant or platformHAL, depending on the exact target. These files are includeautomatically by this header, so need not be included explicitly.</P><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN7921">Vector numbers</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">CYGNUM_HAL_VECTOR_XXXXCYGNUM_HAL_VSR_MINCYGNUM_HAL_VSR_MAXCYGNUM_HAL_VSR_COUNTCYGNUM_HAL_INTERRUPT_XXXXCYGNUM_HAL_ISR_MINCYGNUM_HAL_ISR_MAXCYGNUM_HAL_ISR_COUNTCYGNUM_HAL_EXCEPTION_XXXXCYGNUM_HAL_EXCEPTION_MINCYGNUM_HAL_EXCEPTION_MAXCYGNUM_HAL_EXCEPTION_COUNT</PRE></TD></TR></TABLE><P>All possible VSR, interrupt and exception vectors are specified here,together with maximum and minimum values for range checking. While theVSR and exception numbers will be defined in this file, the interruptnumbers will normally be defined in the variant or platform HAL filethat is included by this header. </P><P>There are two ranges of numbers, those for the vector serviceroutines and those for the interrupt service routines. The relationshipbetween these two ranges is undefined, and no equivalence shouldbe assumed if vectors from the two ranges coincide.</P><P>The VSR vectors correspond to the set of exception vectors that can bedelivered by the CPU architecture, many of these will be internalexception traps. The ISR vectors correspond to the set of externalinterrupts that can be delivered and are usually determined by extradecoding of the interrupt controller by the interrupt VSR.</P><P>Where a CPU supports synchronous exceptions, the range of suchexceptions allowed are defined by <TTCLASS="LITERAL">CYGNUM_HAL_EXCEPTION_MIN</TT> and<TTCLASS="LITERAL">CYGNUM_HAL_EXCEPTION_MAX</TT>. The<TTCLASS="LITERAL">CYGNUM_HAL_EXCEPTION_XXXX</TT> definitions arestandard names used by target independent code to test for thepresence of particular exceptions in the architecture. The actualexception numbers will normally correspond to the VSR exceptionrange. In future other exceptions generated by the system software(such as stack overflow) may be added.</P><P><TTCLASS="LITERAL">CYGNUM_HAL_ISR_COUNT</TT>, <TTCLASS="LITERAL">CYGNUM_HAL_VSR_COUNT</TT> and<TTCLASS="LITERAL">CYGNUM_HAL_EXCEPTION_COUNT</TT> define the number ofISRs, VSRs and EXCEPTIONs respectively for the purposes of definingarrays etc. There might be a translation from the supplied vectornumbers into array offsets. Hence<TTCLASS="LITERAL">CYGNUM_HAL_XXX_COUNT</TT> may not simply be<TTCLASS="LITERAL">CYGNUM_HAL_XXX_MAX</TT> - <TTCLASS="LITERAL">CYGNUM_HAL_XXX_MIN</TT> or <TTCLASS="LITERAL">CYGNUM_HAL_XXX_MAX</TT>+1.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN7939">Interrupt state control</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">CYG_INTERRUPT_STATEHAL_DISABLE_INTERRUPTS( old )HAL_RESTORE_INTERRUPTS( old )HAL_ENABLE_INTERRUPTS()HAL_QUERY_INTERRUPTS( state )</PRE></TD></TR></TABLE><P>These macros provide control over the state of the CPUs interrupt maskmechanism. They should normally manipulate a CPU status register toenable and disable interrupt delivery. They should not access aninterrupt controller.</P><P><TTCLASS="LITERAL">CYG_INTERRUPT_STATE</TT> is a data type that should beused to store the interrupt state returned by<TTCLASS="FUNCTION">HAL_DISABLE_INTERRUPTS()</TT> and<TTCLASS="FUNCTION">HAL_QUERY_INTERRUPTS()</TT> and passed to<TTCLASS="FUNCTION">HAL_RESTORE_INTERRUPTS()</TT>.</P><P><TTCLASS="FUNCTION">HAL_DISABLE_INTERRUPTS()</TT> disables the delivery ofinterrupts and stores the original state of the interrupt mask in thevariable passed in the <TTCLASS="PARAMETER"><I>old</I></TT> argument.</P><P><TTCLASS="FUNCTION">HAL_RESTORE_INTERRUPTS()</TT> restores the state ofthe interrupt mask to that recorded in <TTCLASS="PARAMETER"><I>old</I></TT>.</P><P><TTCLASS="FUNCTION">HAL_ENABLE_INTERRUPTS()</TT> simply enables interruptsregardless of the current state of the mask.</P><P><TTCLASS="FUNCTION">HAL_QUERY_INTERRUPTS()</TT> stores the state of theinterrupt mask in the variable passed in the <TTCLASS="PARAMETER"><I>state</I></TT> argument. The state stored here should also becapable of being passed to<TTCLASS="FUNCTION">HAL_RESTORE_INTERRUPTS()</TT> at a later point.</P><P>It is at the HAL implementer’s discretion exactlywhich interrupts are masked by this mechanism. Where a CPU has morethan one interrupt type that may be masked separately (e.g. theARM's IRQ and FIQ) only those that can raise DSRs needto be masked here. A separate architecture specific mechanism maythen be used to control the other interrupt types.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="AEN7961">ISR and VSR management</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">HAL_INTERRUPT_IN_USE( vector, state )HAL_INTERRUPT_ATTACH( vector, isr, data, object )HAL_INTERRUPT_DETACH( vector, isr )HAL_VSR_SET( vector, vsr, poldvsr )HAL_VSR_GET( vector, pvsr )HAL_VSR_SET_TO_ECOS_HANDLER( vector, poldvsr )</PRE></TD></TR></TABLE><P>These macros manage the attachment of interrupt and vector serviceroutines to interrupt and exception vectors respectively.</P><P><TTCLASS="FUNCTION">HAL_INTERRUPT_IN_USE()</TT> tests the state of thesupplied interrupt vector and sets the value of the state parameter toeither 1 or 0 depending on whether there is already an ISR attached tothe vector. The HAL will only allow one ISR to be attached to eachvector, so it is a good idea to use this function before using<TTCLASS="FUNCTION">HAL_INTERRUPT_ATTACH()</TT>.</P><P><TTCLASS="FUNCTION">HAL_INTERRUPT_ATTACH()</TT> attachesthe ISR, data pointer and object pointer to the given<TTCLASS="PARAMETER"><I>vector</I></TT>. When an interrupt occurs on thisvector the ISR is called using the C calling convention and the vectornumber and data pointer are passed to it as the first and secondarguments respectively.</P><P><TTCLASS="FUNCTION">HAL_INTERRUPT_DETACH()</TT> detaches the ISR from thevector.</P><P><TTCLASS="FUNCTION">HAL_VSR_SET()</TT> replaces the VSR attached to the<TTCLASS="PARAMETER"><I>vector</I></TT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -