📄 usbs-testing.html
字号:
></TT> determines the size of the firsttransfer, and has a default value of 32 bytes. The size of the nexttransfer is calculated by first multiplying by the<TTCLASS="PARAMETER"><I>txsize*</I></TT> value, then dividing by the<TTCLASS="PARAMETER"><I>txsize/</I></TT> value, and finally adding the<TTCLASS="PARAMETER"><I>txsize+</I></TT> value. The defaults for these are<TTCLASS="LITERAL">1</TT>, <TTCLASS="LITERAL">1</TT>, and <TTCLASS="LITERAL">0</TT>respectively, which means that the transfer size will remainunchanged. If for example the transfer size should increase byapproximately 50 per cent each time then suitable values might be<TTCLASS="LITERAL">txsize* 3</TT>, <TTCLASS="LITERAL">txsize/ 2</TT>,and <TTCLASS="LITERAL">txsize+ 1</TT>. </P><P>The <TTCLASS="PARAMETER"><I>txsize>=</I></TT> and<TTCLASS="PARAMETER"><I>txsize<=</I></TT> arguments can be used to imposelower and upper bounds on the transfer. By default the<TTCLASS="LITERAL">min_size</TT> and <TTCLASS="LITERAL">max_size</TT> valuesappropriate for the endpoint will be used. If at any time thecurrent size falls outside the bounds then it will be normalized.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN17267"></A><H3>Receive Size</H3><P>The receive size, in other words the number of bytes that either hostor target will expect to receive as opposed to the number of bytesthat actually get sent, can be adjusted using a similar set ofarguments: <TTCLASS="PARAMETER"><I>rxsize1</I></TT>,<TTCLASS="PARAMETER"><I>rxsize>=</I></TT>,<TTCLASS="PARAMETER"><I>rxsize<=</I></TT>,<TTCLASS="PARAMETER"><I>rxsize*</I></TT>, <TTCLASS="PARAMETER"><I>rxsize/</I></TT> and<TTCLASS="PARAMETER"><I>rxsize+</I></TT>. The current receive size will beadjusted between transfers just like the transmit size. However whencommunicating over USB it is not a good idea to attempt to receiveless data than will actually be sent: typically neither the hardwarenor the software will be able to do anything useful with the excess,so there will be problems. Therefore if at any time the calculatedreceive size is less than the transmit size, the actual receive willbe for the exact number of bytes that will get transmitted. Howeverthis will not affect the calculations for the next receive size.</P><P>The default values for <TTCLASS="PARAMETER"><I>rxsize1</I></TT>,<TTCLASS="PARAMETER"><I>rxsize*</I></TT>, <TTCLASS="PARAMETER"><I>rxsize/</I></TT> and<TTCLASS="PARAMETER"><I>rxsize+</I></TT> are <TTCLASS="LITERAL">0</TT>,<TTCLASS="LITERAL">1</TT>, <TTCLASS="LITERAL">1</TT> and <TTCLASS="LITERAL">0</TT>respectively. This means that the calculated receive size will alwaysbe less than the transmit size, so the receive operation will be forthe exact number of bytes transmitted. For some USB protocols thiswould not accurately reflect the traffic that will happen. For examplewith USB-ethernet transfer sizes will vary between 16 and 1516 bytes,so the receiver will always expect up to 1516 bytes. This can beachieved using <TTCLASS="LITERAL">rxsize1 1516</TT>, leaving theother parameters at their default values.</P><P>For target hardware which involves non-zero<TTCLASS="LITERAL">max_in_padding</TT>, on the host side the padding willbe added automatically to the receive size if necessary.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN17288"></A><H3>Transmit and Receive Delays</H3><P>Typically during the testing there will be some minor delays betweentransfers on both host and target. Some of these delays will be causedby timeslicing, for example another process running on the host, or aconcurrent test thread running inside the target. Other delays will becaused by the USB bus itself, for example activity from another deviceon the bus. However it is desirable that test cases be allowed toinject additional and somewhat more controlled delays into the system,for example to make sure that the target behaves correctly even if thetarget is not yet ready to receive data from the host.</P><P>The transmit delay is controlled by six parameters:<TTCLASS="PARAMETER"><I>txdelay1</I></TT>, <TTCLASS="PARAMETER"><I>txdelay*</I></TT>,<TTCLASS="PARAMETER"><I>txdelay/</I></TT>, <TTCLASS="PARAMETER"><I>txdelay+</I></TT>,<TTCLASS="PARAMETER"><I>txdelay>=</I></TT> and<TTCLASS="PARAMETER"><I>txdelay<=</I></TT>. The default values for these are<TTCLASS="LITERAL">0</TT>, <TTCLASS="LITERAL">1</TT>, <TTCLASS="LITERAL">1</TT>,<TTCLASS="LITERAL">0</TT>, <TTCLASS="LITERAL">0</TT> and<TTCLASS="LITERAL">1000000000</TT> respectively, so that by defaulttransmits will happen as quickly as possible. Delays are measured innanoseconds, so a value of <TTCLASS="LITERAL">1000000</TT> would correspondto a delay of 0.001 seconds or one millisecond. By default delays havean upper bound of one second. Between transfers the transmit delay isupdated in much the same was as the transfer sizes.</P><P>The receive delay is controlled by a similar set of six parameters:<TTCLASS="PARAMETER"><I>rxdelay1</I></TT>, <TTCLASS="PARAMETER"><I>rxdelay*</I></TT>,<TTCLASS="PARAMETER"><I>rxdelay/</I></TT>, <TTCLASS="PARAMETER"><I>rxdelay+</I></TT>,<TTCLASS="PARAMETER"><I>rxdelay>=</I></TT> and<TTCLASS="PARAMETER"><I>rxdelay<=</I></TT>. The default values for these arethe same as for transmit delays.</P><P>The transmit delay is used on the side which sends data over the USBbus, so for a bulk IN transfer it is the target that sends data andhence sleeps for the specified transmit delay, while the host receivesdata sleeps for the receive delay. For an OUT transfer the positionsare reversed.</P><P>It should be noted that although the delays are measured innanoseconds, the actual delays will be much less precise and arelikely to be of the order of milliseconds. The exact details willdepend on the kernel clock speed.</P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN17314"></A><H2>Other Types of Transfer</H2><P>Support for testing other types of USB traffic such as isochronoustransfers is not yet implemented.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN17317"></A><H2>Starting a Test and Collecting Results</H2><P>A USB test script should prepare one or more transfers usingappropriate functions such as <TTCLASS="FUNCTION">usbtest::bulktest</TT>.Once all the individual tests have been prepared they can be startedby a call to <TTCLASS="FUNCTION">usbtest::start</TT>. This takes a singleargument, a maximum duration measured in seconds. If all transfershave not been completed in the specified time then any remainingtransfers will be aborted.</P><P><TTCLASS="FUNCTION">usbtest::start</TT> will return <TTCLASS="LITERAL">1</TT>if all the tests have succeeded, or <TTCLASS="LITERAL">0</TT> if any ofthem have failed. More detailed reports will be stored in theTcl variable <TTCLASS="VARNAME">usbtests::results</TT>, which will be alist of string messages.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN17327"></A><H2>Existing Test Scripts</H2><P>A number of test scripts are provided as standard. These are locatedin the <TTCLASS="FILENAME">host</TT> subdirectory of thecommon USB slave package, and will be installed as part of the processof building the host-side software. When a script is specified on thecommand line <SPANCLASS="APPLICATION">usbhost</SPAN> will first search forit in the current directory, then in the install tree. Standardtest scripts include the following:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="FILENAME">list.tcl</TT></DT><DD><P> This script simply displays information about the capabilities of the target platform, as provided by the target-side USB device driver. It can help with tracking down problems, but its primary purpose is to let users check that everything is working correctly: if running <BCLASS="COMMAND">usbhost list.tcl</B> outputs sensible information then the user knows that the target side is running correctly and that communication between host and target is possible. </P></DD><DT><TTCLASS="FILENAME">verbose.tcl</TT></DT><DD><P> The target-side code can provide information about what is happening while tests are prepared and run. This facility should not normally be used since the extra I/O involved will significantly affect the behaviour of the system, but in some circumstances it may prove useful. Since an eCos application cannot easily be given command-line arguments the target-side verbosity level cannot be controlled using <TTCLASS="PARAMETER"><I>-V</I></TT> or <TTCLASS="PARAMETER"><I>--verbose</I></TT> options. Instead it can be controlled from inside <SPANCLASS="APPLICATION">gdb</SPAN> by changing the integer variable <TTCLASS="VARNAME">verbose</TT>. Alternatively it can be manipulated by running the test script <TTCLASS="FILENAME">verbose.tcl</TT>. This script takes a single argument, the desired verbosity level, which should be a small integer. For example, to disable target-side run-time logging the command <BCLASS="COMMAND">usbhost verbose 0</B> can be used. </P></DD></DL></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN17350"></A><H2>Possible Problems</H2><P>If all transfers succeed within the specified time then both host andtarget remain in synch and further tests can be run without problem.However, if at any time a failure occurs then things get morecomplicated. For example, if the current test involves a series ofbulk OUT transfers and the target detects that for one of thesetransfers it received less data than was expected then the test hasfailed, and the target will stop accepting data on this endpoint.However the host-side software may not have detected anything wrongand is now blocked trying to send the next lot of data.</P><P>The test code goes to considerable effort to recover from problemssuch as these. On the host-side separate threads are used forconcurrent transfers, and on the target-side appropriate asynchronousI/O mechanisms are used. In addition there is a control thread on thehost that checks the state of all the main host-side threads, and thestate of the target using private control messages. If it discoversthat one side has stopped sending or receiving data because of anerror and the other side is blocked as a result, it will set certainflags and then cause one additional transfer to take place. Thatadditional transfer will have the effect of unblocking the other side,which then discovers that an error has occurred by checking theappropriate flags. In this way both host and target should end up backin synch, and it is possible to move on to the next set of tests.</P><P>However, the above assumes that the testing has not triggered anyserious hardware conditions. If instead the target-side hardware hasbeen left in some strange state so that, for example, it will nolonger raise an interrupt for traffic on a particular endpoint thenrecovery is not currently possible, and the testing software will justhang.</P><P>A possible future enhancement to the testing software would allow thehost-side to raise a USB reset signal whenever a failure occurs, inthe hope that this would clear any remaining problems within thetarget-side USB hardware.</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="usbs-writing.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="io-usb-slave-eth.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Writing a USB Device Driver</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-usb-slave.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">eCos Support for Developing USB-ethernet Peripherals</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -