questions about USB Continuous reader

Dear All,

I’ve developed a KMDF USB driver and I have implemented a continuous reader on a bulk

endpoint, and configured the reader as the sample code did.

PrepareHardware():
WdfUsbTargetPipeSetNoMaximumPacketSizeCheck(BulkPipe);
WDF_USB_CONTINUOUS_READER_CONFIG_INIT (EvtUsbDeviceBulkInComplete,BulkinMaxPackageSize);
WdfUsbTargetPipeConfigContinuousReader((BulkPipe );

D0Entry():
WdfIoTargetStart();

D0Exit()
WdfIoTargetStop();

EvtUsbDeviceBulkInComplete(WDFUSBPIPE Pipe,WDFMEMORY Buffer,size_t

NumBytesTransferred,WDFCONTEXT Context)
{
Printf("Call BulkinComplete times : number.);
spinlockacquire();
WdfMemoryGetBuffer();
DumpData(); //<=Log
spinlockrelease();

PushData(); <=to internal buffer

if(leftbuf {
IncreaseBufToLarger();
WdfWorkItemEnqueue(StopReaderItem);
}

if(hadIncrease && leftData < BulkinMaxPackageSize)
{
ReduceBufToRaw()
}
}

EvtStopTargetIoWorkItem(StopReaderItem)
{
WdfIoTargetStop(iotarget,WdfIoTargetWaitForSentIoToComplete);
}

Now to the questions :

It runs well in most of the time, nevertheless,It lost data sometimes,or transfer the data

in a bad order. (I have read some topic talking the continuous reader .and knowing that is

better to keep the WDFMemory with List_Entry and WDFCollection. I will try that later, that

is out of my question.)

Look at the Log file .

I trying to figure out what is the framework doing when stop the reader. In my

understanding .When i called WdfIoTargetStop with flag=WdfIoTargetWaitForSentIoToComplete .It

won’t stop reader until the request to be completed. so I won’t lost any request,I found that never call the EvtUsbTargetPipeReadersFailed.

LOG_1(Lost Data) :

Call Bulkin Complete times : 178 .
[178]Dump Data length = 512 ,DATA: Index :19, 200 …]
Push length =512 to Data and DataLen Left= 7240 .

Call Bulkin Complete times : 179 .
[179]Dump Data length = 512 ,DATA: Index :20, 200 …]
Push length =512 to Data and DataLen Left= 7752 .

Increase Buffer Size.

Enqueue Stop Work Item .
Enter EvtStopTargetIoWorkItem.

Call Bulkin Complete times : 180 .
[180]Dump Data length = 351 ,DATA: Index :21, 200…]
Push length =351 to Data and DataLen Left= 8103 .

Call Bulkin Complete times : 181 .
[181]Dump Data length = 512 ,DATA: Index :22, 200…]
Push length =512 to Data and DataLen Left= 8615 .

Complete a read request of 512 bytes and DataLen Left= 8103
Exit EvtStopTargetIoWorkItem.
Complete a read request of 512 bytes and DataLen Left= 7591
Complete a read request of 512 bytes and DataLen Left= 7079

Complete a read request of 512 bytes and DataLen Left= 2471

Reduce Circular Buffer to normal Size.

Enqueue wdfRestartIoTargetWorkItem
Enter EvtRestartTargetIoWorkItem.
Restart Reader Successfully.

Call Bulkin Complete times : 182 .
[182]Dump Data length = 512 ,DATA: Index :24, 200…]
Push length =512 to Data and DataLen Left= 2983 .

Call Bulkin Complete times : 183 .
[183]Dump Data length = 512 ,DATA: Index :25, 200…]
Push length =512 to Data and DataLen Left= 3495 .
Exit EvtRestartTargetIoWorkItem.

Call Bulkin Complete times : 184 .
[184]Dump Data length = 160 ,DATA: Index :26, 160…]
Push length =160 to Data and DataLen Left= 3655.

LOG_2 (Bad Order)
Just like the LOG_1
between" Enter EvtStopTargetIoWorkItem.“
and " Exit EvtStopTargetIoWorkItem.”

Call Bulkin Complete times : 183 .
[183]Dump Data length = 512 ,DATA: Index :59, 200…]
Push length =512 to Data and DataLen Left= 3495 .
Exit EvtRestartTargetIoWorkItem.

Call Bulkin Complete times : 184 .
[184]Dump Data length = 512 ,DATA: Index :58, 200…]
Push length =512 to Data and DataLen Left= 4077.

Call Bulkin Complete times : 185 .
[185]Dump Data length = 512 ,DATA: Index :60, 200…]
Push length =512 to Data and DataLen Left= 4589.

Is there anything happened between the Read operation? or the wdfIoTargetStop()?
It doesn’t happened everytimes, about (1/1000).