Pausing continuous readers

Hi

I have a USB driver that needs to stream data from the target device as fast as possible and so have set up a WDF continuous reader.

I can’t guarantee that there will be pending Read Requests available to transfer the resultant data up to the application layer when the continuous reader returns so have built a small queue in the driver to buffer the incoming data. When a read request does come in, I check this small queue for available data and if present copy the data into the request’s output buffer and complete.

This all works fine unless/until the small queue fills up. Ideally at this point I would like to pause the continuous reader and then re-enable it once the queue has been partially emptied. The hardware can cope with reasonably long periods without transfers (a few seconds) but we can’t deal with lost data - so we need to pause the data flow otherwise we end up binning the incoming data.

The driver detects that the queue has filled up in the EvtUsbTargetPipeReadComplete function but this is typically running at DISPATCH_LEVEL so we can’t stop the reader from here. Is there a way I could tell the driver to stop the reader when it returns to PASSIVE_LEVEL? Should the reader be stopped and started at all outside of the D0 power event handlers? Would it be better to send a signal to the hardware to tell it to stop transmitting and if so how can you post to your own IOCTL queue (through which we normally talk to the device using vendor commands) from DISPATCH_LEVEL?

Any help gratfully appreciated!

cheers

James

You would need to queue a work item to go to passive to stop the reader. You can do this outside of d0entry/exit, but what you need to make sure of is that the work item is flushed (WdfWorkItemFlush) by the time you try to stop it again in D0Exit and before you return to KMDF.

Also, there is no need to copy the data into a new buffer. You can just ref the WDFMEMORY (WdfObjectReference) which keeps it alive in your queue until you deref (WdfObjectDereference) it. you can even define a header (set WDF_USB_CONTINUOUS_READER_CONFIG::HeaderLength to the size) on the buffer to contain a tracking structure so that you do not need to allocate a separate tracking struct for it. Hmm, a blog entry describing this would be a good idea…

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Thursday, March 12, 2009 11:14 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Pausing continuous readers

Hi

I have a USB driver that needs to stream data from the target device as fast as possible and so have set up a WDF continuous reader.

I can’t guarantee that there will be pending Read Requests available to transfer the resultant data up to the application layer when the continuous reader returns so have built a small queue in the driver to buffer the incoming data. When a read request does come in, I check this small queue for available data and if present copy the data into the request’s output buffer and complete.

This all works fine unless/until the small queue fills up. Ideally at this point I would like to pause the continuous reader and then re-enable it once the queue has been partially emptied. The hardware can cope with reasonably long periods without transfers (a few seconds) but we can’t deal with lost data - so we need to pause the data flow otherwise we end up binning the incoming data.

The driver detects that the queue has filled up in the EvtUsbTargetPipeReadComplete function but this is typically running at DISPATCH_LEVEL so we can’t stop the reader from here. Is there a way I could tell the driver to stop the reader when it returns to PASSIVE_LEVEL? Should the reader be stopped and started at all outside of the D0 power event handlers? Would it be better to send a signal to the hardware to tell it to stop transmitting and if so how can you post to your own IOCTL queue (through which we normally talk to the device using vendor commands) from DISPATCH_LEVEL?

Any help gratfully appreciated!

cheers

James


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi Doron

I somehow completely missed the WorkItem system, that’s perfect!

Thanks for all the help.

James