📄 hal.sgml
字号:
1000000000 and a denominator of 100 means that there are 10000000nanoseconds (or 10 milliseconds) between clock interrupts. Expressingthe resolution as a fraction minimizes clock drift even forfrequencies that cannot be expressed as a simple integer. For examplea frequency of 60Hz corresponds to a clock resolution of16666666.66... nanoseconds. This can be expressed accurately as1000000000 over 60.</para><para><literal>CYGNUM_HAL_RTC_PERIOD</literal> specifies the exact valueused to initialize the clock hardware, it is the value passed as aparameter to <literal>HAL_CLOCK_INITIALIZE()</literal> and<literal>HAL_CLOCK_RESET()</literal>. The exact meaning of the valueand the range of legal values therefore depends on the targethardware, and the hardware documentation should be consulted forfurther details.</para><para>The default values for these macros in all HALs are calculated to givea clock interrupt frequency of 100Hz, or 10ms between interrupts. Tochange the clock frequency, the period needs to be changed, and theresolution needs to be adjusted accordingly. As an example considerthe i386 PC target. The default values for these macros are:</para><programlisting width=72>CYGNUM_HAL_RTC_NUMERATOR 1000000000CYGNUM_HAL_RTC_DENOMINATOR 100CYGNUM_HAL_RTC_PERIOD 11932</programlisting><para>To change to, say, a 200Hz clock the period needs to be halved to5966, and to compensate the denominator needs to be doubled to 200. Tochange to a 1KHz interrupt rate change the period to 1193 and thedenominator to 1000.</para><para>Some HALs make this process a little easier by deriving the periodarithmetically from the denominator. This calculation may also involvethe CPU clock frequency and possibly other factors. For example in theARM AT91 variant HAL the period is defined by the followingexpression:</para><programlisting width=72>((CYGNUM_HAL_ARM_AT91_CLOCK_SPEED/32) / CYGNUM_HAL_RTC_DENOMINATOR)</programlisting><para>In this case it is not necessary to change the period at all, justchange the denominator to select the desired clock frequency. However,note that for certain choices of frequency, rounding errors in thiscalculation may result in a small clock drift over time. This isusually negligible, but if perfect accuracy is required, it may benecessary to adjust the frequency or period by hand.</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>HAL_READ_XXX( register, value )HAL_READ_XXX_VECTOR( register, buffer, count, stride )</PROGRAMLISTING><PARA>These macros support the reading of I/O registers in varioussizes. The <replaceable>XXX</replaceable> component of the name may be<literal>UINT8</literal>, <literal>UINT16</literal>,<literal>UINT32</literal>.</PARA><PARA><FUNCTION>HAL_READ_XXX()</FUNCTION> reads the appropriately sizedvalue from the register and stores it in the variable passed as thesecond argument.</PARA><PARA><FUNCTION>HAL_READ_XXX_VECTOR()</FUNCTION> reads<parameter>count</parameter> values of the appropriate size into<parameter>buffer</parameter>. The <parameter>stride</parameter>controls how the pointer advances through the register space. A strideof zero will read the same register repeatedly, and a stride of onewill read adjacent registers of the given size. Greater strides willstep by larger amounts, to allow for sparsely mapped registers forexample.</PARA></SECTION><!-- =================================================================== --><SECTION><TITLE>Register write</TITLE><PROGRAMLISTING>HAL_WRITE_XXX( register, value )HAL_WRITE_XXX_VECTOR( register, buffer,count, stride )</PROGRAMLISTING><PARA>These macros support the writing of I/O registers in varioussizes. The <replaceable>XXX</replaceable> component of the name may be<LITERAL>UINT8</LITERAL>, <LITERAL>UINT16</LITERAL>,<LITERAL>UINT32</LITERAL>.</PARA><PARA><FUNCTION>HAL_WRITE_XXX()</FUNCTION> writesthe appropriately sized value from the variable passed as the second argumentstored it in the register.</PARA><PARA><FUNCTION>HAL_WRITE_XXX_VECTOR()</FUNCTION> writes<parameter>count</parameter> values of the appropriate size from <parameter>buffer</parameter>. The <parameter>stride</parameter> controlshow the pointer advances through the register space. A stride ofzero will write the same register repeatedly, and a stride of onewill write adjacent registers of the given size. Greater strideswill step by larger amounts, to allow for sparsely mapped registersfor example.</PARA></SECTION></SECTION><!-- }}} --><!-- {{{ Cache Control --><SECTION id="hal-cache-control"><TITLE>Cache Control</TITLE><PARA>This section contains definitions for supporting controlof the caches on the CPU.</PARA><para>These definitions are usually found in the header file<FILENAME>cyg/hal/hal_cache.h</FILENAME>. This file may be defined inthe architecture, variant or platform HAL, depending on where thecaches are implemented for the target. Often there will be a genericimplementation of the cache control macros in the architecture HALwith the ability to override or undefine them in the variant orplatform HAL. Even when the implementation of the cache macros is inthe architecture HAL, the cache dimensions will be defined in thevariant or platform HAL. As with other files, the variant or platformspecific definitions are usually found in<filename>cyg/hal/var_cache.h</filename> and<filename>cyg/hal/plf_cache.h</filename> respectively. These filesare include automatically by this header, so need not be includedexplicitly.</para><PARA>There are versions of the macros defined here for both the Data andInstruction caches. these are distinguished by the use of either<literal>DCACHE</literal> or <literal>ICACHE</literal> in the macronames. Some architectures have a unified cache, where both data andinstruction share the same cache. In these cases the control macrosuse <literal>UCACHE</literal> and the <literal>DCACHE</literal> and<literal>ICACHE</literal> macros will just be calls to the<literal>UCACHE</literal> version. In the following descriptions,<literal>XCACHE</literal> is used to stand for any of these. Wherethere are issues specific to a particular cache, this will beexplained in the text.</PARA><PARA>There might be target specific restrictions on the use of some of themacros which it is the user's responsibility to comply with. Suchrestrictions are documented in the header file with the macrodefinition.</PARA><PARA>Note that destructive cache macros should be used with caution.Preceding a cache invalidation with a cache synchronization is notsafe in itself since an interrupt may happen after the synchronizationbut before the invalidation. This might cause the state of dirty datalines created during the interrupt to be lost.</PARA><PARA>Depending on the architecture's capabilities, it may be possible totemporarily disable the cache while doing the synchronization andinvalidation which solves the problem (no new data would be cachedduring an interrupt). Otherwise it is necessary to disable interruptswhile manipulating the cache which may take a long time.</PARA><PARA>Some platform HALs now support a pair of cache state querymacros: <function>HAL_ICACHE_IS_ENABLED( x )</function> and<function>HAL_DCACHE_IS_ENABLED( x )</function> which set the argumentto true if the instruction or data cache is enabled,respectively. Like most cache control macros, these are optional,because the capabilities of different targets and boards can varyconsiderably. Code which uses them, if it is to be consideredportable, should test for their existence first by means of<literal>#ifdef</literal>. Be sure to include<filename><cyg/hal/hal_cache.h></filename> in order to do thistest and (maybe) use the macros.</PARA><!-- =================================================================== --><SECTION><TITLE>Cache Dimensions</TITLE><PROGRAMLISTING>HAL_XCACHE_SIZEHAL_XCACHE_LINE_SIZEHAL_XCACHE_WAYSHAL_XCACHE_SETS</PROGRAMLISTING><PARA>These macros define the size and dimensions of the Instructionand Data caches.</PARA><VARIABLELIST> <VARLISTENTRY> <TERM>HAL_XCACHE_SIZE </TERM> <LISTITEM> <PARA>Defines the total size of the cache in bytes.</PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_LINE_SIZE </TERM> <LISTITEM> <PARA>Defines the cache line size in bytes.</PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_WAYS </TERM> <LISTITEM> <PARA> Defines the number of ways in each set and defines its level of associativity. This would be 1 for a direct mapped cache, 2 for a 2-way cache, 4 for 4-way and so on. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_SETS </TERM> <LISTITEM> <PARA> Defines the number of sets in the cache, and is calculated from the previous values. </PARA> </LISTITEM> </VARLISTENTRY></VARIABLELIST></SECTION><!-- =================================================================== --><SECTION><TITLE>Global Cache Control</TITLE><PROGRAMLISTING>HAL_XCACHE_ENABLE()HAL_XCACHE_DISABLE()HAL_XCACHE_INVALIDATE_ALL()HAL_XCACHE_SYNC()HAL_XCACHE_BURST_SIZE( size )HAL_DCACHE_WRITE_MODE( mode )HAL_XCACHE_LOCK( base, size )HAL_XCACHE_UNLOCK( base, size )HAL_XCACHE_UNLOCK_ALL()</PROGRAMLISTING><PARA>These macros affect the state of the entire cache, or a large part ofit.</PARA><VARIABLELIST> <VARLISTENTRY> <TERM>HAL_XCACHE_ENABLE() and HAL_XCACHE_DISABLE()</TERM> <LISTITEM> <PARA>Enable and disable the cache.</PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_INVALIDATE_ALL()</TERM> <LISTITEM> <PARA> Causes the entire contents of the cache to be invalidated. Depending on the hardware, this may require the cache to be disabled during the invalidation process. If so, the implementation must use <function>HAL_XCACHE_IS_ENABLED()</function> to save and restore the previous state. </PARA> <note> <para> If this macro is called after <function>HAL_XCACHE_SYNC()</function> with the intention of clearing the cache (invalidating the cache after writing dirty data back to memory), you must prevent interrupts from happening between the two calls: </para><PROGRAMLISTING> ... HAL_DISABLE_INTERRUPTS(old); HAL_XCACHE_SYNC(); HAL_XCACHE_INVALIDATE_ALL(); HAL_RESTORE_INTERRUPTS(old); ...</PROGRAMLISTING> <para> Since the operation may take a very long time, real-time responsiveness could be affected, so only do this when it is absolutely required and you know the delay will not interfere with the operation of drivers or the application. </para> </note> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_SYNC()</TERM> <LISTITEM> <PARA> Causes the contents of the cache to be brought into synchronization with the contents of memory. In some implementations this may be equivalent to <function>HAL_XCACHE_INVALIDATE_ALL()</function>. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_BURST_SIZE()</TERM> <LISTITEM> <PARA> Allows the size of cache to/from memory bursts to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -