📄 hal.sgml
字号:
range. In future other exceptions generated by the system software(such as stack overflow) may be added.</PARA><PARA><literal>CYGNUM_HAL_ISR_COUNT</literal>, <literal>CYGNUM_HAL_VSR_COUNT</literal> and<literal>CYGNUM_HAL_EXCEPTION_COUNT</literal> 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<literal>CYGNUM_HAL_XXX_COUNT</literal> may not simply be<literal>CYGNUM_HAL_XXX_MAX</literal> - <literal>CYGNUM_HAL_XXX_MIN</literal> or <literal>CYGNUM_HAL_XXX_MAX</literal>+1.</PARA></SECTION><!-- =================================================================== --><SECTION><TITLE>Interrupt state control</TITLE><PROGRAMLISTING>CYG_INTERRUPT_STATEHAL_DISABLE_INTERRUPTS( old )HAL_RESTORE_INTERRUPTS( old )HAL_ENABLE_INTERRUPTS()HAL_QUERY_INTERRUPTS( state )</PROGRAMLISTING><PARA>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.</PARA><para><literal>CYG_INTERRUPT_STATE</literal> is a data type that should beused to store the interrupt state returned by<function>HAL_DISABLE_INTERRUPTS()</function> and<function>HAL_QUERY_INTERRUPTS()</function> and passed to<function>HAL_RESTORE_INTERRUPTS()</function>.</para><PARA><FUNCTION>HAL_DISABLE_INTERRUPTS()</FUNCTION> disables the delivery ofinterrupts and stores the original state of the interrupt mask in thevariable passed in the <parameter>old</parameter> argument.</PARA><PARA><FUNCTION>HAL_RESTORE_INTERRUPTS()</FUNCTION> restores the state ofthe interrupt mask to that recorded in <parameter>old</parameter>.</PARA><PARA><FUNCTION>HAL_ENABLE_INTERRUPTS()</FUNCTION> simply enables interruptsregardless of the current state of the mask.</PARA><PARA><FUNCTION>HAL_QUERY_INTERRUPTS()</FUNCTION> stores the state of theinterrupt mask in the variable passed in the <parameter>state</parameter> argument. The state stored here should also becapable of being passed to<function>HAL_RESTORE_INTERRUPTS()</function> at a later point.</PARA><PARA>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.</PARA></SECTION><!-- =================================================================== --><SECTION><TITLE>ISR and VSR management</TITLE><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 )</PROGRAMLISTING><PARA>These macros manage the attachment of interrupt and vector serviceroutines to interrupt and exception vectors respectively.</PARA><para><function>HAL_INTERRUPT_IN_USE()</function> 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<function>HAL_INTERRUPT_ATTACH()</function>.</para><PARA><FUNCTION>HAL_INTERRUPT_ATTACH()</FUNCTION> attachesthe ISR, data pointer and object pointer to the given<parameter>vector</parameter>. 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.</PARA><PARA><FUNCTION>HAL_INTERRUPT_DETACH()</FUNCTION> detaches the ISR from thevector.</PARA><PARA><FUNCTION>HAL_VSR_SET()</FUNCTION> replaces the VSR attached to the<parameter>vector</parameter> with the replacement supplied in<parameter>vsr</parameter>. The old VSR is returned in the locationpointed to by <parameter>pvsr</parameter>.</PARA><PARA><FUNCTION>HAL_VSR_GET()</FUNCTION> assignsa copy of the VSR to the location pointed to by <parameter>pvsr</parameter>.</PARA><para><function>HAL_VSR_SET_TO_ECOS_HANDLER()</function> ensures that theVSR for a specific exception is pointing at the eCos exception VSR andnot one for RedBoot or some other ROM monitor. The default whenrunning under RedBoot is for exceptions to be handled by RedBoot andpassed to GDB. This macro diverts the exception to eCos so that it maybe handled by application code. The arguments are the VSR vector to bereplaces, and a location in which to store the old VSR pointer, sothat it may be replaced at a later point.</para></SECTION><!-- =================================================================== --><SECTION><TITLE>Interrupt controller management</TITLE><PROGRAMLISTING>HAL_INTERRUPT_MASK( vector )HAL_INTERRUPT_UNMASK( vector )HAL_INTERRUPT_ACKNOWLEDGE( vector )HAL_INTERRUPT_CONFIGURE( vector, level, up )HAL_INTERRUPT_SET_LEVEL( vector, level )</PROGRAMLISTING><PARA>These macros exert control over any prioritized interruptcontroller that is present. If no priority controller exists, thenthese macros should be empty.</para><note> <para> These macros may not be reentrant, so care should be taken to prevent them being called while interrupts are enabled. This means that they can be safely used in initialization code before interrupts are enabled, and in ISRs. In DSRs, ASRs and thread code, however, interrupts must be disabled before these macros are called. Here is an example for use in a DSR where the interrupt source is unmasked after data processing: </para><PROGRAMLISTING> ... HAL_DISABLE_INTERRUPTS(old); HAL_INTERRUPT_UNMASK(CYGNUM_HAL_INTERRUPT_ETH); HAL_RESTORE_INTERRUPTS(old); ...</PROGRAMLISTING></note><PARA><FUNCTION>HAL_INTERRUPT_MASK()</FUNCTION> causes the interruptassociated with the given vector to be blocked.</PARA><PARA><FUNCTION>HAL_INTERRUPT_UNMASK()</FUNCTION> causes the interruptassociated with the given vector to be unblocked.</PARA><PARA><FUNCTION>HAL_INTERRUPT_ACKNOWLEDGE()</FUNCTION> acknowledges thecurrent interrupt from the given vector. This is usually executed fromthe ISR for this vector when it is prepared to allow furtherinterrupts. Most interrupt controllers need some form of acknowledgeaction before the next interrupt is allowed through. Executing thismacro may cause another interrupt to be delivered. Whether thisinterrupts the current code depends on the state of the CPU interruptmask.</PARA><PARA><FUNCTION>HAL_INTERRUPT_CONFIGURE()</FUNCTION> providescontrol over how an interrupt signal is detected. The argumentsare:</PARA><VARIABLELIST> <VARLISTENTRY> <TERM>vector</TERM> <LISTITEM> <PARA>The interrupt vector to be configured.</PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>level</TERM> <LISTITEM> <PARA> Set to <varname>true</varname> if the interrupt is detected by level, and <varname>false</varname> if it is edge triggered. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>up</TERM> <LISTITEM> <PARA> If the interrupt is set to level detect, then if this is <VARNAME>true</VARNAME> it is detected by a high signal level, and if <VARNAME>false</VARNAME> by a low signal level. If the interrupt is set to edge triggered, then if this is <VARNAME>true</VARNAME> it is triggered by a rising edge and if <VARNAME>false</VARNAME> by a falling edge. </PARA> </LISTITEM> </VARLISTENTRY></VARIABLELIST><PARA><FUNCTION>HAL_INTERRUPT_SET_LEVEL()</FUNCTION> provides control overthe hardware priority of the interrupt. The arguments are:</PARA><VARIABLELIST> <VARLISTENTRY> <TERM>vector</TERM> <LISTITEM> <PARA>The interrupt whose level is to be set.</PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>level</TERM> <LISTITEM> <PARA> The priority level to which the interrupt is to set. In some architectures the masking of an interrupt is achieved by changing its priority level. Hence this function, <FUNCTION>HAL_INTERRUPT_MASK()</FUNCTION> and <FUNCTION>HAL_INTERRUPT_UNMASK()</FUNCTION> may interfere with each other. </PARA> </LISTITEM> </VARLISTENTRY></VARIABLELIST></SECTION><!-- =================================================================== --><SECTION><TITLE>Clock control</TITLE><PROGRAMLISTING>HAL_CLOCK_INITIALIZE( period )HAL_CLOCK_RESET( vector, period )HAL_CLOCK_READ( pvalue )</PROGRAMLISTING><PARA>These macros provide control over a clock or timer device that may beused by the kernel to provide time-out, delay and schedulingservices. The clock is assumed to be implemented by some form ofcounter that is incremented or decremented by some external source andwhich raises an interrupt when it reaches a predetermined value.</PARA><PARA><FUNCTION>HAL_CLOCK_INITIALIZE()</FUNCTION> initializes the timerdevice to interrupt at the given period. The period is essentially thevalue used to initialize the timer counter and must be calculated fromthe timer frequency and the desired interrupt rate. The timer deviceshould generate an interrupt every <varname>period</varname> cycles.</PARA><PARA><FUNCTION>HAL_CLOCK_RESET()</FUNCTION> re-initializes the timer toprovoke the next interrupt. This macro is only really necessary whenthe timer device needs to be reset in some way after each interrupt.</PARA><PARA><FUNCTION>HAL_CLOCK_READ()</FUNCTION> reads the current value of thetimer counter and puts the value in the location pointed to by<parameter>pvalue</parameter>. The value stored will always be thenumber of timer cycles since the last interrupt, and hence rangesbetween zero and the initial period value. If this is a count-downcyclic timer, some arithmetic may be necessary to generate this value.</PARA></SECTION><!-- =================================================================== --><section><title>Microsecond Delay</title><programlisting width=72>HAL_DELAY_US(us)</programlisting><para>This is an optional definition. If defined the macro implements a busyloop delay for the given number of microseconds. This is usuallyimplemented by waiting for the required number of hardware timer ticksto pass. </para><para>This operation should normally be used when a very short delay isneeded when controlling hardware, programming FLASH devices and similarsituations where a wait/timeout loop would otherwise be used. Since itmay disable interrupts, and is implemented by busy waiting, it shouldnot be used in code that is sensitive to interrupt or context switchlatencies.</para></section></SECTION><!-- }}} --><!-- {{{ Input and Output --><SECTION id="hal-input-and-output"><TITLE>HAL I/O</TITLE><PARA>This section contains definitions for supporting accessto device control registers in an architecture neutralfashion.</PARA><para>These definitions are normally found in the header file<FILENAME>cyg/hal/hal_io.h</FILENAME>. This file itself containsmacros that are generic to the architecture. If there are variant orplatform specific IO access macros then these will be found in<filename>cyg/hal/var_io.h</filename> and<filename>cyg/hal/plf_io.h</filename> in the variant or platform HALsrespectively. These files are include automatically by this header, soneed not be included explicitly.</para><para>This header (or more likely <filename>cyg/hal/plf_io.h</filename>) alsodefines the PCI access macros. For more information on these see <xreflinkend="pci-library-reference">.</para><!-- =================================================================== --><SECTION><TITLE>Register address</TITLE><PROGRAMLISTING>HAL_IO_REGISTER</PROGRAMLISTING><PARA>This type is used to store the address of an I/O register. It willnormally be a memory address, an integer port address or an offsetinto an I/O space. More complex architectures may need to code anaddress space plus offset pair into a single word, or may represent itas a structure.</PARA><PARA>Values of variables and constants of this type will usually besupplied by configuration mechanisms or in target specific headers.</PARA></SECTION><!-- =================================================================== --><SECTION><TITLE>Register read</TITLE><PROGRAMLISTING>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -