general USB driver questions


Thanks in advance to whoever answers these questions…

(1) When I call IoCallDriver() to pass it an IRP with the URB for a bulk write (I’m using the cool OSR usb board!) , I’ve seen that this call blocks infinitely until the device is ready to receive data (I.e. when the devices’ write buffer isn’t full) rather than immediately returning STATUS_PENDING. (The OSR documentation for their USB device says “the write request will wait in the Windows host (bus) driver until the endpoint buffer space is available on the board.” The board is in loopback mode.)

( a ) So, in regards to error recovery, say if the embedded device stops responding, what you you have to do? Could you call IoCancelIrp() to recover and then follow the error recovery suggestions in Oney’s book (issue ICOTL_INTERNAL_GET_POWER_STATUS, URB_FUNCTION_ABORT_PIPE, etc.) Or would you want to put the code in a separate thread (rather than using a system thread) and do something really drastic snf try to kill the thread yourself (yikes!)?

(2) My driver queues IRPs and pulls them off one at a time. Since this buffer contains both bulk in and bulk out IRP requests, I think that I could run into a situation I have a bottleneck: it seems like I should have two separate IRP queues, one for reads and writes, so that if the write IRP takes a long time to complete (because the device’s write buffer is full), I’m not delaying processing a read IRP that could have been serviced almost immediately. By having two queues, the read IRPs can still be processed independently of the write IRPS because they are being pulled off in a separate thread. Is this the case? Is this the right way to handle things.

(I do realize I need to look at throughput speed/demand, how often apps will call ReadFile/WriteFile, how big the buffers are on the embedded side, to determine what sort of buffering, if any, I need for the driver. )

(3) Any suggestions for buffering read/write data internally in the driver? Since I am required (lout of my control - long story) to poll an interrupt pipe for a notification from the device that is ready to send data, I thought to read the data from the device into a fifo (or some other data structure) so that it is ready for the next app’s ReadFile() call. I didn’t think I needed a buffer for the write data since it’s already buffered with the IRP on the IRP queues.