Esempio n. 1
0
        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);

            // If managing a start frame manually, set it here and update the the frame counter for the next transfer.
            SetNextFrameNumber(isoTransferItem);

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

            // The data buffer was pinned earlier when it was allocated.  Always pin managed memory before using it
            // in an asynchronous function to keep the framework from tampering with it.
            Usb.IsoReadPipe(PipeInfo.PipeId,
                            isoTransferItem.Buffer,
                            DataBufferSize,
                            isoTransferItem.Ovl,
                            isoTransferItem.Iso.Handle);

            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)
            {
                return(errorCode);
            }

            TotalSubmittedCount++;

            return(0);
        }
Esempio n. 2
0
        public int WaitRead(out IsoTransferItem isoTransferItem, int i, out int transferred)
        {
            isoTransferItem = Outstanding.First.Value;
            bool success = OvlPool.Wait(isoTransferItem.Ovl, 1000, KOVL_WAIT_FLAG.NONE, out transferred);

            if (!success)
            {
                return(Marshal.GetLastWin32Error());
            }

            Outstanding.RemoveFirst();
            Completed.AddLast(isoTransferItem);

            return(0);
        }
Esempio n. 3
0
        private static void IsoXferReport(ReadIsoTransferQueue readIsoTransfers, IsoTransferItem isoTransferItem, int transferLength)
        {
            int packetPos;

            Test.Dcs.Stop(transferLength);
            if (readIsoTransfers.LastStartFrame == 0)
            {
                Test.LogLn("#{0}: StartFrame={1:X8}h TransferLength={2} BPS-average:{3}",
                           readIsoTransfers.CompletedCount,
                           isoTransferItem.Iso.StartFrame,
                           transferLength,
                           Math.Round(Test.Dcs.Bps, 2));
            }
            else
            {
                int lastFrameCount = isoTransferItem.Iso.StartFrame - readIsoTransfers.LastStartFrame;
                Test.LogLn("#{0}: StartFrame={1:X8}h TransferLength={2} BPS-average:{3} LastFrameCount={4}",
                           readIsoTransfers.CompletedCount,
                           isoTransferItem.Iso.StartFrame,
                           transferLength,
                           Math.Round(Test.Dcs.Bps, 2),
                           lastFrameCount);
            }

            int numPackets = isoTransferItem.Iso.NumberOfPackets;

            for (packetPos = 0; packetPos < numPackets; packetPos++)
            {
                KISO_PACKET isoPacket;
                isoTransferItem.Iso.GetPacket(packetPos, out isoPacket);
                if (isoPacket.Length > 1)
                {
                    // This is somewhat specific to data that is returned by the benchmark firmware.
                    byte firstPacketByte  = isoTransferItem.Buffer[isoPacket.Offset];
                    byte secondPacketByte = isoTransferItem.Buffer[isoPacket.Offset + 1];
                    Test.LogLn("  [{0:000}] Length={1} B0={2:X2}h B1={3:X2}h", packetPos, isoPacket.Length, firstPacketByte, secondPacketByte);
                }
                else
                {
                    Test.LogLn("  [{0:000}] Empty Packet", packetPos);
                }
            }

            readIsoTransfers.CompletedCount++;
            readIsoTransfers.LastStartFrame = isoTransferItem.Iso.StartFrame;
        }
Esempio n. 4
0
        public ReadIsoTransferQueue(UsbK usb, ref WINUSB_PIPE_INFORMATION pipeInfo, int maxPendingTransfers, int numberOfPackets)
        {
            PipeInfo       = pipeInfo;
            Usb            = usb;
            OvlPool        = new OvlK(usb.Handle, maxPendingTransfers, KOVL_POOL_FLAG.NONE);
            DataBufferSize = (pipeInfo.MaximumPacketSize * numberOfPackets);
            for (int pos = 0; pos < maxPendingTransfers; pos++)
            {
                IsoTransferItem isoTransferItem = new IsoTransferItem();

                isoTransferItem.Buffer   = new byte[pipeInfo.MaximumPacketSize * numberOfPackets];
                isoTransferItem.BufferGC = GCHandle.Alloc(isoTransferItem.Buffer, GCHandleType.Pinned);

                isoTransferItem.Iso = new IsoK(numberOfPackets, 0);
                isoTransferItem.Iso.SetPackets(pipeInfo.MaximumPacketSize);

                OvlPool.Acquire(out isoTransferItem.Ovl);

                Master.AddLast(isoTransferItem);
                Completed.AddLast(isoTransferItem);
            }
        }
Esempio n. 5
0
        public int WaitRead(out IsoTransferItem isoTransferItem, int i, out int transferred)
        {
            isoTransferItem = Outstanding.First.Value;
            bool success = OvlPool.Wait(isoTransferItem.Ovl, 1000, KOVL_WAIT_FLAG.NONE, out transferred);
            if (!success)
            {
                return Marshal.GetLastWin32Error();
            }

            Outstanding.RemoveFirst();
            Completed.AddLast(isoTransferItem);

            return 0;
        }
Esempio n. 6
0
 private static void SetNextFrameNumber(IsoTransferItem isoTransferItem)
 {
 }
Esempio n. 7
0
        public ReadIsoTransferQueue(UsbK usb, ref WINUSB_PIPE_INFORMATION pipeInfo, int maxPendingTransfers, int numberOfPackets)
        {
            PipeInfo = pipeInfo;
            Usb = usb;
            OvlPool = new OvlK(usb.Handle, maxPendingTransfers, KOVL_POOL_FLAG.NONE);
            DataBufferSize = (pipeInfo.MaximumPacketSize*numberOfPackets);
            for (int pos = 0; pos < maxPendingTransfers; pos++)
            {
                IsoTransferItem isoTransferItem = new IsoTransferItem();

                isoTransferItem.Buffer = new byte[pipeInfo.MaximumPacketSize*numberOfPackets];
                isoTransferItem.BufferGC = GCHandle.Alloc(isoTransferItem.Buffer, GCHandleType.Pinned);

                isoTransferItem.Iso = new IsoK(numberOfPackets, 0);
                isoTransferItem.Iso.SetPackets(pipeInfo.MaximumPacketSize);

                OvlPool.Acquire(out isoTransferItem.Ovl);

                Master.AddLast(isoTransferItem);
                Completed.AddLast(isoTransferItem);
            }
        }
Esempio n. 8
0
        private static void IsoXferReport(ReadIsoTransferQueue readIsoTransfers, IsoTransferItem isoTransferItem, int transferLength)
        {
            int packetPos;
            Test.Dcs.Stop(transferLength);
            if (readIsoTransfers.LastStartFrame == 0)
            {
                Test.LogLn("#{0}: StartFrame={1:X8}h TransferLength={2} BPS-average:{3}",
                           readIsoTransfers.CompletedCount,
                           isoTransferItem.Iso.StartFrame,
                           transferLength,
                           Math.Round(Test.Dcs.Bps, 2));
            }
            else
            {
                int lastFrameCount = isoTransferItem.Iso.StartFrame - readIsoTransfers.LastStartFrame;
                Test.LogLn("#{0}: StartFrame={1:X8}h TransferLength={2} BPS-average:{3} LastFrameCount={4}",
                           readIsoTransfers.CompletedCount,
                           isoTransferItem.Iso.StartFrame,
                           transferLength,
                           Math.Round(Test.Dcs.Bps, 2),
                           lastFrameCount);
            }

            int numPackets = isoTransferItem.Iso.NumberOfPackets;
            for (packetPos = 0; packetPos < numPackets; packetPos++)
            {
                KISO_PACKET isoPacket;
                isoTransferItem.Iso.GetPacket(packetPos, out isoPacket);
                if (isoPacket.Length > 1)
                {
                    // This is somewhat specific to data that is returned by the benchmark firmware.
                    byte firstPacketByte = isoTransferItem.Buffer[isoPacket.Offset];
                    byte secondPacketByte = isoTransferItem.Buffer[isoPacket.Offset + 1];
                    Test.LogLn("  [{0:000}] Length={1} B0={2:X2}h B1={3:X2}h", packetPos, isoPacket.Length, firstPacketByte, secondPacketByte);
                }
                else
                {
                    Test.LogLn("  [{0:000}] Empty Packet", packetPos);
                }
            }

            readIsoTransfers.CompletedCount++;
            readIsoTransfers.LastStartFrame = isoTransferItem.Iso.StartFrame;
        }
Esempio n. 9
0
 private static void SetNextFrameNumber(IsoTransferItem isoTransferItem)
 {
 }