Author Topic: Short packet  (Read 14176 times)

rum

  • Member
  • ***
  • Posts: 3
Short packet
« on: June 08, 2015, 02:41:49 pm »
I have a question regarding your test application winusb_cs which I use to test my device.
I have modified "InitializeDevice" to send to OUT pipe for bulk transfer also ZERO PACKET by setting property SHORT_PACKET_TERMINATE.

SetPipePolicy
(winUsbHandle,
 myDeviceInfo.BulkOutPipe,
Convert.ToUInt32(NativeMethods.POLICY_TYPE.SHORT_PACKET_TERMINATE),
Convert.ToByte(true));

But I never see this packet comming out on USB monitor. My USB device has 64 byte IN/OUT packets lenght.

So according to USB specification when I send 64bytes these should be automatically terminated.


Which packets are terminated? Why this property is not working correctly in WINUSB.

How to send ZLP? Do I have to do it or stack will take care of it?

How device know that transfer is terminated? Should I use ZLP?


Why

RequestToSendDataViaBulkTransfer(bytesToWrite, databuffer, ref bytesWritten, ref success);

 sucess is never true? even if transfer is correct.


Sorry I am not expert, maybe you will illuminate me. Thank you very much.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Short packet
« Reply #1 on: June 09, 2015, 09:14:59 pm »
Are you using a hardware-based monitor to view the traffic (not a software-only monitor)?

A ZLP provides a way for the device to know that the transfer is finished. Other ways to indicate length are to use defined transfer lengths that the host and device agree on or include the transfer length in the data, typically in a header.

RequestToSendDataViaBulkTransfer is defined as void, so it has no return value.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Short packet
« Reply #2 on: June 09, 2015, 09:29:54 pm »
I just tried it and didn't see the ZLP either so perhaps it's not implemented. If the option is set, the WinUSB driver should send the ZLP after any transfer that is a multiple of the packet size.

rum

  • Member
  • ***
  • Posts: 3
Re: Short packet
« Reply #3 on: June 10, 2015, 05:56:59 am »
Please keep me post it about what you find about ZLP.

I was hoping to use ZLP to let device know host has finished sending data.


I am using software monitor "Bus Hound". It is able to detect ZLP when device is sending.

RequestToSendDataViaBulkTransfer(bytesToWrite, databuffer, ref bytesWritten, ref success);

I was hoping that two reference parameters get updated based on result of transmision.

rum

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Short packet
« Reply #4 on: June 10, 2015, 10:26:06 am »
Sorry, I see what you mean now.

RequestToSendDataViaBulkTransfer calls BeginInvoke on SendDataViaBulkTransfer and ends before the result is available.

In SendDataViaBulkTransfer, success returns true and bytesWritten is valid.

The GetBulkDataSent routine, which is called on completion of the send, has the correct values for success and bytesWritten.

So I should delete success and bytesWritten from the parameter list for RequestToSendDataViaBulkTransfer.

Thank you for finding that.

rum

  • Member
  • ***
  • Posts: 3
Re: Short packet
« Reply #5 on: June 10, 2015, 12:34:59 pm »
Please keep me informed about ZLP. In the document from Microsoft see bellow (attachement don't work for this forum) this functionality is implemented in WINUSB.

If the library does not send it, can I send it from your application? But how?

WinUSB driver allows modifications to its default behavior through policies that can be applied to a pipe (endpoint). 

Defined policies include:
0x01 – SHORT_PACKET_TERMINATE    (Default: Off)
0x02 – AUTO_CLEAR_STALL      (Default: Off)
0x03 – PIPE_TRANSFER_TIMEOUT   (Default: 5 Seconds for Control, 0 for others)
0x04 – IGNORE_SHORT_PACKETS   (Default: Off)
0x05 – ALLOW_PARTIAL_READS    (Default: On)
0x06 – AUTO_FLUSH         (Default: Off)
0x07 – RAW_IO         (Default: Off)
0x09 – RESET_PIPE_ON_RESUME    (Default: Off)


Pipe Policy – SHORT_PACKET_TERMINATE

When should it be used?
If your device requires that OUT transfers be terminated with a short packet (most don’t require this)
Only valid for bulk and interrupt OUT endpoints (setting on IN endpoints has no effect)
Impact of enabling this policy
All writes to the endpoint will be terminated with a short packet
When an OUT transfer completes back to WinUSB, if the transfer was an exact multiple of the endpoint’s MaxPacketSize, WinUSB resubmits the request to the USB stack, but this time with the length set to 0 bytes.
Results in performance penalty only for writes that are an exact multiple of MaxPacketSize (all writes are serialized by WinUsb anyway)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Short packet
« Reply #6 on: June 10, 2015, 06:08:53 pm »
Applications can't send a short packet. It has to be implemented in a lower-level driver.

It seemed to work for this person:

http://www.lpcware.com/content/forum/usbevtout-and-buffer-size