1 Reply Latest reply on Jan 10, 2018 6:59 AM by madhul_36

    How does host app know if USB data is available to read

      I've created a 'test' (HID) USB PCB using CY8C3446PVI-076 and have a simple 'test' app (C#) on a Windows 10 box (using CyUSB.dll). I can connect to the device and can send/recv data via a "Send"/"Recv" buttons on the app, so communication to/from device is confirmed. What I can't figure out, nor can I find any info about it, is.. how can the app tell if there is data available from the USB device without requesting it? For example, say I add a push button to the device. I can fill the IN buffer with the data I want to send to the PC app but how does the app know data is available?  Is there some interrupt flag I can test, or do I have to poll the device (and test some status bit) to see if data is available. I'd prefer not to poll as that leaves (n)mSec intervals where data could be pending and hat may cause a lag from the time the button is pushed to the time the app acks the push .. at some point increasing poll time, to reduce the lag, will make the app sluggish to user inputs.

      This is probably one of those solutions that is staring me in the face, but I just can't see it.


      For example; from PSoC Creator things are simple enough; To see if data was sent from PC I can do something like;

      if (USB_GetEPState(OUT_EP) == USB_OUT_BUFFER_FULL) .. process the app's data..

      So, is there something similar I can do from the app? Something like;

      if (myHidDev.????? == IN_BUFFER_FULL) .. process device data..

        • 1. Re: How does host app know if USB data is available to read



          In USB protocol, there is no way for the USB device to send interrupt or information to the host of it's own. The Host has to ping for data.

          Usually the hosts call the DataTransfer APIs to get the data which is called along with a time out. If the data is not available in the device within the timeout the API will fail with timeout error. Then the host needs to call again.


          Or you can have a variable (flag) on the device side which is set when the device has data. The host needs to keep polling for this flag. If set, the host should call the datatrasnfer APIs to receive the data. This polling can be done though Vendor Specific Setup Requests. After the host sends vendor specific setup request, the USBSetupCallback is triggered in the device. Inside the callback the device sends the status of the flag.



          -Madhu Sudhan