question on the details of an FX2 bulk read response from host | Cypress Semiconductor
question on the details of an FX2 bulk read response from host
I've had a working FX2 application that sends back data from a device over a quad-buffered bulk IN endpoint (EP2) for the past year. On the host side I'm using libusb with the usb_bulk_read() command to read the EP:
int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size, int timeout);
If data in the device has not yet filled the FIFO, the above request times out (after a period of timeout milliseconds) and this is the way I always assumed it had to work.
Recently however, I've been in touch with another person who explained that upon a bulk read on their device, the device automatically sends NACK tokens until the device is ready; apparently avoiding the necessity of a time out.
Likewise, on http://www.beyondlogic.org/usbnutshell/usb4.shtml#Bulk it says:
IN: When the host is ready to receive bulk data it issues an IN Token. If the function receives the IN token with an error, it ignores the packet. If the token was received correctly, the function can either reply with a DATA packet containing the bulk data to be sent, or a stall packet indicating the endpoint has had a error or a NAK packet indicating to the host that the endpoint is working, but temporary has no data to send.
I bolded the key phrase. So there seems to be 3 conditions, not 2 (data or timeout (stall?)). Perhaps my endpoint is configured to respond to the host with a Stall while perhaps it's possible for me to respond with a NACK and have the host just repeatedly request the packet until data shows up?
Can anyone help me understand this, especially in the context of how I might configure the FX2 Endpoints to respond differently to a bulk read request?
Note that I've read over the TRM (not always getting every detail understood) and do see some brief discussion on the STALL bit which might be the key, but little explanation on how a Stall packet vs. NACK packet would be interpreted by the host when doing a bulk-read command...