📄 hal-calling-if.html
字号:
allowing a ROM monitor to provided all the needed IO routines. Atthe same time, this makes it easy to switch console/debugger channelsat run-time (the old implementation had hardwired drivers for consoleand debugger IO, preventing these to change at run-time).</P><P>The hal_if provides wrappers which interface these services to theeCos infrastructure diagnostics routines. This is done in a way whichensures proper string mangling of the diagnostics output when required(e.g. O-packetization when using a GDB compatible ROM monitor).</P><DIVCLASS="SECTION"><H3CLASS="SECTION"><ANAME="AEN9223">Available Procedures</H3><P>This is a brief description of the procedures</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">CH_DATA</TT></DT><DD><P>Pointer to the controller IO base (or a pointer to a per-device structure if more data than the IO base is required). All the procedures below are called with this data item as the first argument.</P></DD><DT><TTCLASS="LITERAL">WRITE</TT></DT><DD><P>Writes the buffer to the device.</P></DD><DT><TTCLASS="LITERAL">READ</TT></DT><DD><P>Fills a buffer from the device.</P></DD><DT><TTCLASS="LITERAL">PUTC</TT></DT><DD><P>Write a character to the device.</P></DD><DT><TTCLASS="LITERAL">GETC</TT></DT><DD><P>Read a character from the device.</P></DD><DT><TTCLASS="LITERAL">CONTROL</TT></DT><DD><P>Device feature control. Second argument specifies function:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">SETBAUD</TT></DT><DD><P>Changes baud rate.</P></DD><DT><TTCLASS="LITERAL">GETBAUD</TT></DT><DD><P>Returns the current baud rate.</P></DD><DT><TTCLASS="LITERAL">INSTALL_DBG_ISR</TT></DT><DD><P>[Unused]</P></DD><DT><TTCLASS="LITERAL">REMOVE_DBG_ISR</TT></DT><DD><P>[Unused]</P></DD><DT><TTCLASS="LITERAL">IRQ_DISABLE</TT></DT><DD><P>Disable debugging receive interrupts on the device.</P></DD><DT><TTCLASS="LITERAL">IRQ_ENABLE</TT></DT><DD><P>Enable debugging receive interrupts on the device.</P></DD><DT><TTCLASS="LITERAL">DBG_ISR_VECTOR</TT></DT><DD><P>Returns the ISR vector used by the device for debugging receive interrupts.</P></DD><DT><TTCLASS="LITERAL">SET_TIMEOUT</TT></DT><DD><P>Set GETC timeout in milliseconds.</P></DD><DT><TTCLASS="LITERAL">FLUSH_OUTPUT</TT></DT><DD><P>Forces driver to flush data in its buffers. Note that this may not affect hardware buffers (e.g. FIFOs).</P></DD></DL></DIV></DD><DT><TTCLASS="LITERAL">DBG_ISR</TT></DT><DD><P>ISR used to handle receive interrupts from the device (see ).</P></DD><DT><TTCLASS="LITERAL">GETC_TIMEOUT</TT></DT><DD><P>Read a character from the device with timeout.</P></DD></DL></DIV></DIV><DIVCLASS="SECTION"><H3CLASS="SECTION"><ANAME="AEN9313">Usage</H3><P>The standard eCos diagnostics IO functions use the channelprocedure table when <TTCLASS="LITERAL">CYGSEM_HAL_VIRTUAL_VECTOR_DIAG</TT> is enabled. Thatmeans that when you use diag_printf (or the libc printf function) thestream goes through the selected console procedure table. If you usethe virtual vector function SET_CONSOLE_COMM you can change the devicewhich the diagnostics output goes to at run-time.</P><P>You can also use the table functions directly if desired(regardless of the <TTCLASS="LITERAL">CYGSEM_HAL_VIRTUAL_VECTOR_DIAG</TT> setting - assumingthe ROM monitor provides the services). Here is a small example whichchanges the console to use channel 2, fetches the comm procs pointerand calls the write function from that table, then restores theconsole to the original channel:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">#define T "Hello World!\n"intmain(void){ hal_virtual_comm_table_t* comm; int cur = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT); CYGACC_CALL_IF_SET_CONSOLE_COMM(2); comm = CYGACC_CALL_IF_CONSOLE_PROCS(); CYGACC_COMM_IF_WRITE(*comm, T, strlen(T)); CYGACC_CALL_IF_SET_CONSOLE_COMM(cur);}</PRE></TD></TR></TABLE><P>Beware that if doing something like the above, you should only doit to a channel which does not have GDB at the other end: GDB ignoresraw data, so you would not see the output.</P></DIV><DIVCLASS="SECTION"><H3CLASS="SECTION"><ANAME="AEN9321">Compatibility</H3><P>The use of this service is controlled by the option<TTCLASS="LITERAL">CYGSEM_HAL_VIRTUAL_VECTOR_DIAG</TT> which is disabled per default on mostolder platforms (thus preserving backwards compatibility with olderstubs). On newer ports, this option should always be set.</P></DIV><DIVCLASS="SECTION"><H3CLASS="SECTION"><ANAME="AEN9325">Implementation Details</H3><P>There is an array of procedure tables (raw comm channels) for eachIO device of the platform which get initialized by the ROM monitor, oroptionally by a RAM startup configuration (allowing the RAMconfiguration to take full control of the target). In addition tothis, there's a special table which is used to hold manglerprocedures.</P><P>The vector table defines which of these channels are selected forconsole and debugging IO respectively: console entry can be empty,point to mangler channel, or point to a raw channel. The debuggerentry should always point to a raw channel.</P><P>During normal console output (i.e., diagnostic output) the consoletable will be used to handle IO if defined. If not defined, the debugtable will be used.</P><P>This means that debuggers (such as GDB) which require text streamsto be mangled (O-packetized in the case of GDB), can rely on the ROMmonitor install mangling IO routines in the special mangler table andselect this for console output. The mangler will pass the mangled dataon to the selected debugging channel.</P><P>If the eCos configuration specifies a different console channelfrom that used by the debugger, the console entry will point to theselected raw channel, thus overriding any mangler provided by the ROMmonitor.</P><P>See hal_if_diag_* routines in hal_if.c for more details of the streampath of diagnostic output. See <TTCLASS="FUNCTION">cyg_hal_gdb_diag_*()</TT> routines in<TTCLASS="FILENAME">hal_stub.c</TT> for the mangler used for GDB communication.</P></DIV><DIVCLASS="SECTION"><H3CLASS="SECTION"><ANAME="AEN9335">New Platform Ports</H3><P>Define CDL options <TTCLASS="LITERAL">CYGNUM_HAL_VIRTUAL_VECTOR_COMM_CHANNELS</TT>,<TTCLASS="LITERAL">CYGNUM_HAL_VIRTUAL_VECTOR_DEBUG_CHANNEL</TT>, and<TTCLASS="LITERAL">CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL</TT>.</P><P>If <TTCLASS="LITERAL">CYGSEM_HAL_VIRTUAL_VECTOR_DIAG</TT> is set, make sure the infra diagcode uses the hal_if diag functions:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> #define HAL_DIAG_INIT() hal_if_diag_init() #define HAL_DIAG_WRITE_CHAR(_c_) hal_if_diag_write_char(_c_) #define HAL_DIAG_READ_CHAR(_c_) hal_if_diag_read_char(&_c_)</PRE></TD></TR></TABLE><P>In addition to the above functions, the platform HAL must alsoprovide a function cyg_hal_plf_comms_init which initializes thedrivers and the channel procedure tables.</P><P>Most of the other functionality in the table is more or lesspossible to copy unchanged from existing ports. Some care is necessarythough to ensure the proper handling of interrupt vectors and timeoutsfor various devices handled by the same driver. See PowerPC/Cogentplatform HAL for an example implementation.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note:: </B> When vector table console code is <SPANCLASS="emphasis"><ICLASS="EMPHASIS">not</I></SPAN> used,the platform HAL must map the HAL_DIAG_INIT, HAL_DIAG_WRITE_CHAR andHAL_DIAG_READ_CHAR macros directly to the low-level IO functions,hardwired to use a compile-time configured channel.</P></BLOCKQUOTE></DIV><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note:: </B> On old ports the hardwired <TTCLASS="LITERAL">HAL_DIAG_INIT</TT>,<TTCLASS="LITERAL">HAL_DIAG_WRITE_CHAR</TT> and<TTCLASS="LITERAL">HAL_DIAG_READ_CHAR</TT> implementations will alsocontain code to O-packetize the output for GDB. This should<SPANCLASS="emphasis"><ICLASS="EMPHASIS">not</I></SPAN> be adopted for new ports! On new ports theROM monitor is guaranteed to provide the necessary mangling via thevector table. The hardwired configuration should be reserved for ROMstartups where achieving minimal image size is crucial.</P></BLOCKQUOTE></DIV></DIV></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="hal-porting-structure.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="hal-porting-coding-conventions.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">HAL Structure</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="hal-porting-guide.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">HAL Coding Conventions</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -