lib_usb Wait for ACK

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
aneves
Experienced Member
Posts: 93
Joined: Wed Sep 16, 2015 2:38 pm

lib_usb Wait for ACK

Post by aneves »

Hello,

In the example code provided with lib_usb, I found this piece of code where we handle a SetAddress request from the host:

Code: Select all

 /* Note: Really we should wait until ACK is received for status stage before changing address
                   * We will just wait some time... */
                  delay_ticks(50000);
My question is, how can I actually wait for an ACK during the Status Stage on endpoint 0 before attempting to set my device's address? I would rather not depend on a hard coded wait time.

Thanks!


henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi aneves,

At a guess, you have to wait for the ACK to be received by the host; the device cannot tell when that is?

Cheers,
Henk
User avatar
aneves
Experienced Member
Posts: 93
Joined: Wed Sep 16, 2015 2:38 pm

Post by aneves »

Would it be reasonable to wait for the next SOF or SETUP packet?
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Difficult question!

You could, but I don't think there is a requirement on the host to have processed the SETADDR on the next SOF? I guess the next SETUP would be there; but that would go into endpoint0 which is the place where you are waiting for it; i.e., a bit late?
User avatar
aneves
Experienced Member
Posts: 93
Joined: Wed Sep 16, 2015 2:38 pm

Post by aneves »

henk wrote:Hi aneves,

At a guess, you have to wait for the ACK to be received by the host; the device cannot tell when that is?

Cheers,
Henk
I think we're getting confused. When a SetAddress request is sent, the following sequence of events occur:
[SetAddress]
     --> Setup Transaction:     //Setup Stage. Host requests device to set its address to the number stored in  wValue
          --> SETUP packet
          --> DATA0 packet
          <-- ACK packet
     --> IN Transaction:     //Status Stage. Device acknowledges request and will set its address AFTER status stage
          --> IN packet
          <-- DATA1 packet   //No data
          --> ACK packet     // Once device sees this packet, set address
Does this make sense? We should be waiting for the ACK sent by the host to be received by the device during the status stage. Is there a way to do this with lib_usb?

In other words, in my handler which handles SetAddress request from the host, how can I detect the ack sent back by the host after my device sends the zero length packet? It is at this point we should assign the address of the device.

Thanks.
henk
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi aneves

yes, I was getting confused (you probably weren't).

I think the answer to your original question is sort of no: the ACK gets handled deep down by the Low Level Driver, and is not explicitly acknowledged to the layer above; this is probably the only case where you want that acknowledgment. There is an implicit acknowledgement in that the buffer is freed, so I guess one could wait for that to happen, but that is not an event that you can wait for.

Cheers,
Henk