📄 hal.sgml
字号:
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 be controlled. This macro will only be defined if this functionality is available. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_DCACHE_WRITE_MODE()</TERM> <LISTITEM> <PARA> Controls the way in which data cache lines are written back to memory. There will be definitions for the possible modes. Typical definitions are <literal>HAL_DCACHE_WRITEBACK_MODE</literal> and <literal>HAL_DCACHE_WRITETHRU_MODE</literal>. This macro will only be defined if this functionality is available. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_LOCK()</TERM> <LISTITEM> <PARA> Causes data to be locked into the cache. The base and size arguments define the memory region that will be locked into the cache. It is architecture dependent whether more than one locked region is allowed at any one time, and whether this operation causes the cache to cease acting as a cache for addresses outside the region during the duration of the lock. This macro will only be defined if this functionality is available. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_UNLOCK()</TERM> <LISTITEM> <PARA> Cancels the locking of the memory region given. This should normally correspond to a region supplied in a matching lock call. This macro will only be defined if this functionality is available. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_UNLOCK_ALL()</TERM> <LISTITEM> <PARA> Cancels all existing locked memory regions. This may be required as part of the cache initialization on some architectures. This macro will only be defined if this functionality is available. </PARA> </LISTITEM> </VARLISTENTRY></VARIABLELIST></SECTION><!-- =================================================================== --><SECTION><TITLE>Cache Line Control</TITLE><PROGRAMLISTING>HAL_DCACHE_ALLOCATE( base , size )HAL_DCACHE_FLUSH( base , size )HAL_XCACHE_INVALIDATE( base , size )HAL_DCACHE_STORE( base , size )HAL_DCACHE_READ_HINT( base , size )HAL_DCACHE_WRITE_HINT( base , size )HAL_DCACHE_ZERO( base , size )</PROGRAMLISTING><PARA>All of these macros apply a cache operation to all cache lines thatmatch the memory address region defined by the base and sizearguments. These macros will only be defined if the describedfunctionality is available. Also, it is not guaranteed that the cachefunction will only be applied to just the described regions, in somearchitectures it may be applied to the whole cache.</PARA><VARIABLELIST> <VARLISTENTRY> <TERM>HAL_DCACHE_ALLOCATE()</TERM> <LISTITEM> <PARA> Allocates lines in the cache for the given region without reading their contents from memory, hence the contents of the lines is undefined. This is useful for preallocating lines which are to be completely overwritten, for example in a block copy operation. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_DCACHE_FLUSH()</TERM> <LISTITEM> <PARA> Invalidates all cache lines in the region after writing any dirty lines to memory. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_XCACHE_INVALIDATE() </TERM> <LISTITEM> <PARA> Invalidates all cache lines in the region. Any dirty lines are invalidated without being written to memory. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_DCACHE_STORE() </TERM> <LISTITEM> <PARA> Writes all dirty lines in the region to memory, but does not invalidate any lines. </PARA> </LISTITEM> </VARLISTENTRY> <VARLISTENTRY> <TERM>HAL_DCACHE_READ_HINT() </TERM> <LISTITEM>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -