Skip to content

ISO-transfer and USB HUB #41

@KasperLJ1

Description

@KasperLJ1

Hi

I developing both the device and host end for an embedded system, where the host will serve as a control "panel" for the device.

I am using C# binding for libusbK, where i am having some issues, which i now believe i have point pointed to somewhere in my host application.

The issue:
I am using iso-transfers between the host and device to "steam" process data. This works fine without a hub attached, but once the host and device communicates through any usb HUB i get issues. Based on my USB analysis tool (Beagle 480), it seems that the following code generates 2 iso-transfer requests:

public int SubmitNextRead()
        {
            // Pull from head of Completed list and push to end of Outstanding list
            IsoTransferItem isoTransferItem = Completed.First.Value;
            Completed.RemoveFirst();
            Outstanding.AddLast(isoTransferItem);

            // Prepare the OvlK handle to be submitted.
            OvlK.ReUse(isoTransferItem.Ovl);

            // Set the frame number this transfer will be submitted on (used for logging only)

            //isoTransferItem.FrameNumber = isoTransferItem.Container.FrameNumber;
            uint currentFrameNumber = 0;
            this.Usb.GetCurrentFrameNumber(out currentFrameNumber);
            //Program.Test.LogLn("#StartFrame={0:X8}h, currentFrame={1:X8}h", isoTransferItem.Container.FrameNumber, currentFrameNumber);
            currentFrameNumber += 10;
            // submit the transfer. use 0 for length and 0 for number of packets to use the values the isoch handle was initialized with
            //Usb.IsochReadPipe(isoTransferItem.Iso.Handle, 0, ref isoTransferItem.Container.FrameNumber, 0, isoTransferItem.Ovl);
            Usb.IsochReadPipe(isoTransferItem.Iso.Handle, 0, ref currentFrameNumber, 1, isoTransferItem.Ovl);
            //Usb.IsochReadPipe();

            //byte[] test = new byte[1500];
            //Usb.IsoReadPipe(0x82, ref test, 1500, isoTransferItem.Iso.Handle, null);
            // IsochReadPipe will always return false so we need to check the error code
            int errorCode = Marshal.GetLastWin32Error();

            // 997 is ERROR_IO_PENDING. For async, this means so far so good.
            // IE: The transfer is submitted but we won't know if a problem occurs until it is completed.
            if (errorCode != ErrorCodes.IoPending)
            {
                //Completed.RemoveFirst();
                //Outstanding.AddLast(isoTransferItem);
                Completed.AddFirst(isoTransferItem);
                Outstanding.RemoveLast();
                return errorCode;
            }

            return 0;
        }

I came to that conclusion by placing a breakpoint right after this line, but the USB-sniffer report that the request was made twice. see the screenshot below. Because 2 requests are quickly after each other, the device if unable to re-arm the endpoint in time, and the resulting in a data payload of 0-bytes for the following transfer request. How, this does not always happens.
image

The issues get worse with large data payload, and do not occur for every transfer. I am really puzzled by this, and it might not be related to libusbK, but i was hoping someone might have an idea. Does anyone know if there exists some tool/software where i could quickly test this issue?

The screenshot below shows that this "double" event does not always occur. Ideally, I am trying to send a request every 10 frames, which can also be seen on the timestamp. However, when i have the double event the second event is always right after the first..

image

The device: microchip DSPIC33.

If this is outside the scope of this library, i am sorry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions