✓ USB control transfer in EZ-USB (68013) Summary

Source: Internet
Author: User

Control transmission is useful when a small amount of control information is exchanged, such as sending commands and obtaining the status of the lower computer. It is convenient to use control transmission through the cypress standard firmware framework, you only need to add your own processing process to dr_vendorcmnd. For example:

Bool dr_vendorcmnd (void ){
Switch (setupdat [1]) {
Case vr_1: // custom command 1
Do_something ();
Break;
Case vr_2: // custom command 2
Do_something_else ();
Break;
Default:
Return (true );
}
Return (false); // No error; command handled OK
}

Control transmission is divided into three stages.

1. In the setup phase, use the setupdat 8-byte register,

Setupdat [0] = bmrequesttype
Setupdat [1] = bmrequest
Setupdat [2: 3] = wvalue
Setupdat [4: 5] = Windex
Setupdat [6: 7] = wlength

When we transmit custom commands, bmrequesttype does not need to be processed; bmrequest is our custom command, and the upper and lower computers can be unified; wvalue And Windex can be used freely, in a total of 4 bytes; wlength is the Data Length of the next "data phase.

2. Data phase. This phase is optional. If the wvalue And Windex data we transmit cannot accommodate, or the information needs to be read from the device, it needs to be carried out through the data phase, the data phase is implemented through the ep0buf, ep0bch, and ep0bcl registers. The data phase can transmit 64 bytes of data at a time.

This phase is often used incorrectly, especially when data is transmitted from the upper computer to the lower computer, which leads to a strange phenomenon: the correct data in the buffer zone needs to be transmitted twice in a row. The following is an example of incorrect use:

Case vr_1:
A = ep0buf [0];
B = ep0buf [1];
C = ep0buf [2];
D = ep0buf [3];
Ep0bch = 0;
Syncdelay;
Ep0bcl = 0;
Syncdelay;
Break;

This is intended to get some data from the host computer and tell ez-USB that the data has been read successfully through the last ep0bch = 0; ep0bcl = 0; but in fact, this will cause the above problems. Take a closer look at TRM and find the following:

Some control transfers do not have a data stage. therefore the 8051 code that processes the setup data shocould check the length field in the setup data (in the 8-byte buffer at setupdat) and arm endpoint zero for the data phase (by loading in0bc or out0bc) only if the length is non-zero. [1]

At this point, the problem is solved when the data is transmitted twice to obtain the correct data. The downstream data needs to be notified through ep0bch and ep0bcl to EZ-USB to start the data phase! Change to the followingCode:

Case vr_1:
// Start data phase, see TRM 7.2
If (setupdat [7]! = 0 | setupdat [6]! = 0 ){
Ep0bch = setupdat [7];
Syncdelay;
Ep0bcl = setupdat [6];
Syncdelay;
While (ep0cs & bmepbusy );
}
A = ep0buf [0];
B = ep0buf [1];
C = ep0buf [2];
D = ep0buf [3];
Break;

In addition, for data-free transmission, you do not need to use ep0bch = 0 at the end; ep0bcl = 0 to "Tell ez-USB that the data has been read ".

3. Status phase. Use the ep0cs register to inform the host computer whether the command is processed or not. If not, inform the host machine through ezusb_stall_ep0 (); send ACK for confirmation through ep0cs | = bmhsnk. (This stage does not need to be processed. It has been processed in FW. C)

EZ-USB TRM 7.2, P115

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.