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

📄 hal-porting-architecture.html

📁 有关ecos2。0介绍了实时嵌入式的结构以及线程调度的实现和内存的管理等
💻 HTML
📖 第 1 页 / 共 3 页
字号:
>Define interrupt enable/disable macros. These are normally inlineassembly fragments to execute the instructions, or manipulate the CPUregister, that contains the CPU interrupt enable bit.</P></LI><LI><P>A feature that many HALs support is the ability to execute DSRs on theinterrupt stack. This is not an essential feature, and is better leftunimplemented in the initial porting effort. If this is required, thenthe macro <TTCLASS="LITERAL">HAL_INTERRUPT_STACK_CALL_PENDING_DSRS()</TT>should be defined to call a function in<TTCLASS="FILENAME">vectors.S</TT>.</P></LI><LI><P>Define the interrupt and VSR attachment macros. If the same arrays asfor other HALs have been used for VSR and interrupt vectors, thenthese macro can be copied across unchanged.</P></LI></UL></LI><LI><P>A number of other header files also need to be filled in:</P><P></P><UL><LI><P><TTCLASS="FILENAME">basetype.h</TT>. This file defines the basic typesused by eCos, together with the endianness and some othercharacteristics. This file only really needs to contain definitionsif the architecture differs significantly from the defaults definedin <TTCLASS="FILENAME">cyg_type.h</TT></P></LI><LI><P><TTCLASS="FILENAME">hal_io.h</TT>. This file contains macros for accessingdevice IO registers. If the architecture uses memory mapped IO, thenthese can be copied unchanged from an existing HAL such as MIPS. Ifthe architecture uses special IO instructions, then these macros mustbe defined as inline assembler fragments. See the I386 HAL for anexample. PCI bus access macros are usually defined in the variant orplatform HALs.</P></LI><LI><P><TTCLASS="FILENAME">hal_cache.h</TT>. This file contains cache accessmacros. If the architecture defines cache instructions, or controlregisters, then the access macros should be defined here. Otherwisethey must be defined in the variant or platform HAL. Usually the cachedimensions (total size, line size, ways etc.) are defined in thevariant HAL.</P></LI><LI><P><TTCLASS="FILENAME">arch.inc</TT> and<TTCLASS="FILENAME">&lt;architecture&gt;.inc</TT>. These files areassembler headers used by <TTCLASS="FILENAME">vectors.S</TT> and<TTCLASS="FILENAME">context.S</TT>.<TTCLASS="FILENAME">&lt;architecture&gt;.inc</TT> is a general purposeheader that should contain things like register aliases, ABIdefinitions and macros useful to general assemblycode. If there are no such definitions, then this file need not beprovided. <TTCLASS="FILENAME">arch.inc</TT> contains macros for performingvarious eCos related operations such as initializing the CPU, caches,FPU etc. The definitions here may often be configured or overridden bydefinitions in the variant or platform HALs. See the MIPS HAL for anexample of this.</P></LI></UL></LI><LI><P>Write <TTCLASS="FILENAME">vectors.S</TT>. This is the most important filein the HAL. It contains the CPU initialization code, exception andinterrupt handlers. While other HALs should be consulted forstructures and techniques, there is very little here that can becopied over without major edits.</P><P>The main pieces of code that need to be defined here are:</P><P></P><UL><LI><P>Reset vector. This usually need to be positioned at the start of theROM or FLASH, so should be in a linker section of its own. It can then beplaced correctly by the linker script. Normally this code is littlemore than a jump to the label <TTCLASS="LITERAL">_start</TT>.</P></LI><LI><P>Exception vectors. These are the trampoline routines connected to thehardware exception entry points that vector through the VSR table. Inmany architectures these are adjacent to the reset vector, and shouldoccupy the same linker section. If the architecture allow the vectorsto be moved then it may be necessary for these trampolines to beposition independent so they can be relocated at runtime.</P><P>The trampolines should do the minimum necessary to transfer controlfrom the hardware vector to the VSR pointed to by the matching tableentry. Exactly how this is done depends on the architecture. Usuallythe trampoline needs to get some working registers by either savingthem to CPU special registers (e.g. PowerPC SPRs), using reservedgeneral registers (MIPS K0 and K1), using only memory basedoperations (IA32), or just jumping directly (ARM). The VSR table indexto be used is either implicit in the entry point taken (PowerPC, IA32,ARM), or must be determined from a CPU register (MIPS).</P></LI><LI><P>Write kernel startup code. This is the location the reset vector jumpsto, and can be in the main text section of the executable, rather thana special section. The code here should first initialize the CPU and otherhardware subsystems. The best approach is to use a set of macrocalls that are defined either in <TTCLASS="FILENAME">arch.inc</TT> oroverridden in the variant or platform HALs. Other jobs that this codeshould do are: initialize stack pointer; copy the data section fromROM to RAM if necessary; zero the BSS; call variant and platforminitializers; call <TTCLASS="FUNCTION">cyg_hal_invoke_constructors()</TT>;call <TTCLASS="FUNCTION">initialize_stub()</TT> if necessary. Finally itshould call <TTCLASS="FUNCTION">cyg_start()</TT>. See <AHREF="hal-exception-handling.html#HAL-STARTUP">the Section called <I>HAL Startup</I> in Chapter 10</A> for details.</P></LI><LI><P>Write the default exception VSR. This VSR is installed in the VSRtable for all synchronous exception vectors. See <AHREF="hal-default-synchronous-exception-handling.html">the Section called <I>Default Synchronous Exception Handling</I> in Chapter 10</A> for details ofwhat this VSR does.</P></LI><LI><P>Write the default interrupt VSR. This is installed in all VSR tableentries that correspond to external interrupts. See <AHREF="hal-default-synchronous-exception-handling.html">the Section called <I>Default Synchronous Exception Handling</I> in Chapter 10</A> for details ofwhat this VSR does.</P></LI><LI><P>Write<TTCLASS="FUNCTION">hal_interrupt_stack_call_pending_dsrs()</TT>. If thisfunction is defined in <TTCLASS="FILENAME">hal_arch.h</TT> then it shouldappear here. The purpose of this function is to call DSRs on theinterrupt stack rather than the current thread's stack. This is not anessential feature, and may be left until later. However it interactswith the stack switching that goes on in the interrupt VSR, so it maymake sense to write these pieces of code at the same time to ensureconsistency.</P><P>When this function is implemented it should do the following:</P><P></P><UL><LI><P>Take a copy of the current SP and then switch to the interrupt stack.</P></LI><LI><P>Save the old SP, together with the CPU status register (or whateverregister contains the interrupt enable status) and any otherregisters that may be corrupted by a function call (such as any linkregister) to locations in the interrupt stack.</P></LI><LI><P>Enable interrupts.</P></LI><LI><P>Call <TTCLASS="FUNCTION">cyg_interrupt_call_pending_DSRs()</TT>. This is akernel functions that actually calls any pending DSRs.</P></LI><LI><P>Retrieve saved registers from the interrupt stack and switch back tothe current thread stack.</P></LI><LI><P>Merge the interrupt enable state recorded in the save CPU statusregister with the current value of the status register to restore theprevious enable state. If the status register does not contain anyother persistent state then this can be a simple restore of theregister. However if the register contains other state bits that mighthave been changed by a DSR, then care must be taken not to disturbthese.</P></LI></UL></LI><LI><P>Define any data items needed. Typically <TTCLASS="FILENAME">vectors.S</TT>may contain definitions for the VSR table, the interrupt tables and theinterrupt stack. Sometimes these are only default definitions that maybe overridden by the variant or platform HALs.</P></LI></UL></LI><LI><P>Write <TTCLASS="FILENAME">context.S</TT>. This file contains the contextswitch code. See <AHREF="hal-architecture-characterization.html#HAL-CONTEXT-SWITCH">the Section called <I>Thread Context Switching</I> in Chapter 9</A> for details ofhow these functions operate. This file may also contain theimplementation of <TTCLASS="FUNCTION">hal_setjmp()</TT> and<TTCLASS="FUNCTION">hal_longjmp()</TT>.</P></LI><LI><P>Write <TTCLASS="FILENAME">hal_misc.c</TT>. This file contains any Cdata and functions needed by the HAL. These might include:</P><P></P><UL><LI><P><TTCLASS="VARNAME">hal_interrupt_*[]</TT>. In some HALs, if these arraysare not defined in <TTCLASS="FILENAME">vectors.S</TT> then they must bedefined here.</P></LI><LI><P><TTCLASS="FUNCTION">cyg_hal_exception_handler()</TT>. This function iscalled from the exception VSR. It usually does extra decoding of theexception and invokes any special handlers for things like FPU traps,bus errors or memory exceptions. If there is nothing special to bedone for an exception, then it either calls into the GDB stubs, bycalling <TTCLASS="FUNCTION">__handle_exception()</TT>, orinvokes the kernel by calling<TTCLASS="FUNCTION">cyg_hal_deliver_exception()</TT>.</P></LI><LI><P><TTCLASS="FUNCTION">hal_arch_default_isr()</TT>. The<TTCLASS="VARNAME">hal_interrupt_handlers[]</TT> array is usuallyinitialized with pointers to <TTCLASS="FILENAME">hal_default_isr()</TT>,which is defined in the common HAL. This function handles things likeCtrl-C processing, but if that is not relevant, then it will call<TTCLASS="FUNCTION">hal_arch_default_isr()</TT>. Normally this functionshould just return zero.</P></LI><LI><P><TTCLASS="FUNCTION">cyg_hal_invoke_constructors()</TT>. This calls theconstructors for all static objects before the program starts. eCosrelies on these being called in the correct order for it to functioncorrectly. The exact way in which constructors are handled may differbetween architectures, although most use a simple table of functionpointers between labels <TTCLASS="LITERAL">__CTOR_LIST__</TT> and<TTCLASS="LITERAL">__CTOR_END__</TT> which must called in order from thetop down. Generally, this function can be copied directly from anexisting architecture HAL.</P></LI><LI><P>Bit indexing functions. If the macros<TTCLASS="LITERAL">HAL_LSBIT_INDEX()</TT> and<TTCLASS="LITERAL">HAL_MSBIT_INDEX()</TT> are defined as function calls,then the functions should appear here. The main reason for doing thisis that the architecture does not have support for bit indexing andthese functions must provide the functionality by conventionalmeans. While the trivial implementation is a simple for loop, it isexpensive and non-deterministic. Better, constant time,implementations can be found in several HALs (MIPS for example).</P></LI><LI><P><TTCLASS="FUNCTION">hal_delay_us()</TT>. If the macro<TTCLASS="LITERAL">HAL_DELAY_US()</TT> is defined in <TTCLASS="FILENAME">hal_intr.h</TT> then it should be defined tocall this function. While most of the time this function is calledwith very small values, occasionally (particularly in some ethernetdrivers) it is called with values of several seconds. Hence thefunction should take care to avoid overflow in any calculations.</P></LI><LI><P><TTCLASS="FUNCTION">hal_idle_thread_action()</TT>. This function is calledfrom the idle thread via the<TTCLASS="LITERAL">HAL_IDLE_THREAD_ACTION()</TT> macro, if sodefined. While normally this function does nothing, during developmentthis is often a good place to report various important systemparameters on LCDs, LED or other displays. This function can alsomonitor system state and report any anomalies. If the architecturesupports a <TTCLASS="LITERAL">halt</TT> instruction then this is a goodplace to put an inline assembly fragment to execute it. It is also agood place to handle any power saving activity.</P></LI></UL></LI

⌨️ 快捷键说明

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