📄 synth-new-target.html
字号:
</P></DD></DL></DIV><P>Typical usage would look like: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> if (!synth_auxiliary_running) { return; } id = synth_auxiliary_instantiate("devs/eth/synth/ecosynth", SYNTH_MAKESTRING(CYGPKG_DEVS_ETH_ECOSYNTH), "ethernet", "eth0", (const char*) 0);</PRE></TD></TR></TABLE><P>The return value will be a device identifier which can be used forsubsequent calls to <TTCLASS="FUNCTION">synth_auxiliary_xchgmsg</TT>. Ifthe device could not be instantiated then <TTCLASS="LITERAL">-1</TT> willbe returned. It is the responsibility of the host-side software toissue suitable diagnostics explaining what went wrong, so normally thetarget-side code should fail silently. </P><P>Once the desired device has been instantiated, often it will benecessary to do some additional initialization by a message exchange.For example an ethernet device might need information from thehost-side about the MAC address, the <AHREF="synth-new-target.html#SYNTH-NEW-TARGET-INTERRUPTS">interrupt vector</A>, andwhether or not multicasting is supported. </P></DIV><DIVCLASS="REFSECT1"><ANAME="SYNTH-NEW-TARGET-XCHGMSG"></A><H2>Communicating with a Device</H2><P>Once a device has been instantiated it is possible to perform I/O bysending messages to the appropriate Tcl script running inside theauxiliary, and optionally getting back replies. I/O operations arealways initiated by the eCos target-side, it is not possible for thehost-side software to initiate data transfers. However the host-sidecan raise interrupts, and the interrupt handler inside the target canthen exchange one or more messages with the host. </P><P>There is a single function to perform I/O operations,<TTCLASS="FUNCTION">synth_auxiliary_xchgmsg</TT>. This takes the followingarguments: </P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="VARNAME">device_id</TT></DT><DD><P>This should be one of the identifiers returned by a previouscall to <TTCLASS="FUNCTION">synth_auxiliary_instantiate</TT>, specifying theparticular device which should perform some I/O. </P></DD><DT><TTCLASS="VARNAME">request</TT></DT><DD><P>Request are just signed 32-bit integers that identify the particularI/O operation being requested. There is no fixed set of codes, insteadeach type of device can define its own. </P></DD><DT><TTCLASS="VARNAME">arg1</TT>, <TTCLASS="VARNAME">arg2</TT></DT><DD><P>For some requests it is convenient to pass one or two additionalparameters alongside the request code. For example an ethernet devicecould define a multicast-all request, with <TTCLASS="VARNAME">arg1</TT>controlling whether this mode should be enabled or disabled. Both<TTCLASS="VARNAME">arg1</TT> and <TTCLASS="VARNAME">arg2</TT> should be signed32-bit integers, and their values are interpreted only by thedevice-specific Tcl script. </P></DD><DT><TTCLASS="VARNAME">txdata</TT>, <TTCLASS="VARNAME">txlen</TT></DT><DD><P>Some I/O operations may involve sending additional data, for examplean ethernet packet. Alternatively a control operation may require manymore parameters than can easily be encoded in <TTCLASS="VARNAME">arg1</TT>and <TTCLASS="VARNAME">arg2</TT>, so those parameters have to be placed ina suitable buffer and extracted at the other end.<TTCLASS="VARNAME">txdata</TT> is an arbitrary buffer of<TTCLASS="VARNAME">txlen</TT> bytes that should be sent to the host-side.There is no specific upper bound on the number of bytes that can besent, but usually it is a good idea to allocate the transmit bufferstatically and keep transfers down to at most several kilobytes. </P></DD><DT><TTCLASS="VARNAME">reply</TT></DT><DD><P>If the host-side is expected to send a reply message then<TTCLASS="VARNAME">reply</TT> should be a pointer to an integer variableand will be updated with a reply code, a simple 32-bit integer. Thesynthetic target HAL code assumes that the host-side and target-sideagree on the protocol being used: if the host-side will not send areply to this message then the <TTCLASS="VARNAME">reply</TT> argumentshould be a NULL pointer; otherwise the host-side must always senda reply code and the <TTCLASS="VARNAME">reply</TT> argument must be valid. </P></DD><DT><TTCLASS="VARNAME">rxdata</TT>, <TTCLASS="VARNAME">rxlen</TT></DT><DD><P>Some operations may involve additional data coming from the host-side,for example an incoming ethernet packet. <TTCLASS="VARNAME">rxdata</TT>should be a suitably-sized buffer, and <TTCLASS="VARNAME">rxlen</TT> apointer to an integer variable that will end up containing the numberof bytes that were actually received. These arguments will only beused if the host-side is expected to send a reply and hence the<TTCLASS="VARNAME">reply</TT> argument was not NULL. </P></DD><DT><TTCLASS="VARNAME">max_rxlen</TT></DT><DD><P>If a reply to this message is expected and that reply may involveadditional data, <TTCLASS="VARNAME">max_rxlen</TT> limits the size of thatreply. In other words, it corresponds to the size of the<TTCLASS="VARNAME">rxdata</TT> buffer. </P></DD></DL></DIV><P>Most I/O operations involve only some of the arguments. For exampletransmitting an ethernet packet would use the<TTCLASS="VARNAME">request</TT>, <TTCLASS="VARNAME">txdata</TT> and<TTCLASS="VARNAME">txlen</TT> fields (in addition to<TTCLASS="VARNAME">device_id</TT> which is always required), but would notinvolve <TTCLASS="VARNAME">arg1</TT> or <TTCLASS="VARNAME">arg2</TT> and noreply would be expected. Receiving an ethernet packet would involve<TTCLASS="VARNAME">request</TT>, <TTCLASS="VARNAME">rxdata</TT>,<TTCLASS="VARNAME">rxlen</TT> and <TTCLASS="VARNAME">max_rxlen</TT>; in addition<TTCLASS="VARNAME">reply</TT> is needed to get any reply from the host-sideat all, and could be used to indicate whether or not any more packetsare buffered up. A control operation such as enabling multicast modewould involve <TTCLASS="VARNAME">request</TT> and <TTCLASS="VARNAME">arg1</TT>,but none of the remaining arguments. </P></DIV><DIVCLASS="REFSECT1"><ANAME="SYNTH-NEW-TARGET-INTERRUPTS"></A><H2>Interrupt Handling</H2><P>Interrupt handling in the synthetic target is much the same as on areal target. An interrupt object is created using<TTCLASS="FUNCTION">cyg_drv_interrupt_create</TT>, attached, and unmasked.The emulated device - in other words the Tcl script running inside theI/O auxiliary - can raise an interrupt. Subject to interrupts beingdisabled and the appropriate vector being masked, the system willinvoke the specified ISR function. The synthetic target HALimplementation does have some limitations: there is no support fornested interrupts, interrupt priorities, or a separate interruptstack. Supporting those might be appropriate when targetting asimulator that attempts to model real hardware accurately, but not forthe simple emulation provided by the synthetic target. </P><P>Of course the actual implementation of the ISR and DSR functions willbe rather different for a synthetic target device driver. For realhardware the device driver will interact with the device by readingand writing device registers, managing DMA engines, and the like. Asynthetic target driver will instead call<TTCLASS="FUNCTION">synth_auxiliary_xchgmsg</TT> to perform the I/Ooperations. </P><P>There is one other significant difference between interrupt handlingon the synthetic target and on real hardware. Usually the eCos codewill know which interrupt vectors are used for which devices. Thatinformation is fixed when the target hardware is designed. With thesynthetic target interrupt vectors are assigned to devices on the hostside, either via the target definition file or dynamically when thedevice is instantiated. Therefore the initialization code for atarget-side device driver will need to request interrupt vectorinformation from the host-side, via a message exchange. Such interruptvectors will be in the range 1 to 31 inclusive, with interrupt 0 beingreserved for the real-time clock. </P></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="synth-syscalls.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="synth-new-host.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">System Calls</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="hal-synth-arch.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Writing New Devices - host</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -