...
The second reason is that probably the FPGA imposes your minimum packet size. In a properly used write test mode (using FX22MB_REG0_START_RX and therefore attaching the FPGA), TE_USB_FX2_SetData() is unable to write less than 1024 byte. In a improperly used read test mode (not using FX22MB_REG0_START_RX and therefore detaching the FPGA), TE_USB_FX2_SetData() is able to write a packet size down to 64 byte. The same CyAPI method XferData() used (under the hood) in TE_USB_FX2_SendCommand() is able to read a packet size of 64 byte. These facts prove that the minimum packet size is imposed by FPGA. To be safe, we recommend to use this function with a size multiple of 1 kbyte.
Code Block | ||
---|---|---|
| ||
public static bool TE_USB_FX2_CYAPISetData(ref intCyUSBDevice TE_USB_FX2_SetDataUSBDevice, (CCyBulkEndPoint *BulkOutEP, byteref byte[] DataWrite, ref longint DataWriteLength);, int PipeNo, uint Timeout, int BufferSize) |
Your application program shall call this function like this:
Code Block | ||
---|---|---|
| ||
TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SetData (&BulkOutEP, DataWrite ,DataWriteLength(ref TE_USB_FX2_USBDevice, ref DataWrite, ref DataWriteLength, PI_EP8, Timeout, BufferSize); |
Code Block | |
---|---|
|
...
|
...
CCyBulkEndPoint **BulkOutEP
ref CyUSBDevice TE_USB_FX2_ |
...
USBDevice |
This parameter is passed by reference (ref). It points to the module selected by TE_USB_FX2_
...
Open(). See pages 70-93 of CyUSB.NET.pdf (Cypress CyUSB .NET DLL Programmer's Reference)
Code Block | |
---|---|
|
...
| |
ref byte |
...
[] DataWrite |
...
This parameter is passed by reference (ref). C# applications use directly TE_USB_FX2_
...
CyUSB.dll based on
...
CyUSB.
...
dll. To avoid copying back and forth large amount of data between these two DLLs, data is passed by reference and not by value.
This parameter points to the byte array that
...
contains the data to be written
...
to buffer EP8 (0x08) of USB FX2 microcontroller.
...
Data contained in EP8
...
are then read by the
...
FPGA.
Code Block | |
---|---|
|
...
|
...
ref int DataWriteLength |
This parameter is passed by reference (ref). This parameter is the length (in bytes) of the previous byte array; it is the length of the packet read from FX2 USB endpoint EP6 (0x86). Normally it is PacketLength.
Code Block | ||
---|---|---|
| ||
int PipeNumber |
This parameter is the value that identify the endpoint used for the data transfer. It is called PipeNumber because it identifies the buffer (pipe) used by the USB FX2 microcontroller.
Code Block | ||
---|---|---|
| ||
uint Timeout |
The unsigned integer value is the time in milliseconds assigned to the synchronous method XferData() of data transfer used by CyUSB.dll.
Timeout is the time that is allowed to the function for sending/receiving the data packet passed to the function; this timeout shall be large enough to allow the data/command transmission/reception. Otherwise the transmission/reception will fail. See Timeout Setting.
Code Block | ||
---|---|---|
| ||
int BufferSize |
The integer value is the dimension (in bytes) of the driver buffer (SW) used in data transmission of a single endpoint (EP8 0x08 in this case); the total buffer size is the sum of all BufferSize of every endpoint used.
The BufferSize has a strong influence on DataThroughput. If BufferSize is too small, DataThroughput can be 1/3-1/2 of the maximum value (from a maximum value of 24 Mbyte/s for write transactions to an actual value of 14 Mbyte/s). If BufferSize has a large value (a roomy buffer), the program shall be able to cope with the non-deterministic behavior of C# without losing packets.
int bool: integer logical type
This function returns true (ST_OK = 0) if it is able to write the data to buffer EP8 within Timeout milliseconds. This function returns false (ST_ERROR = 1) otherwise.
Code Block | ||
---|---|---|
| ||
enum ST_Status
{
ST_OK = 0,
ST_ERROR = 1
}; |
Code Block | ||
---|---|---|
| ||
PACKETLENGTH=100000; packets=1200; byte[] data = new byte[packetlen*packets]; byte[] buffer = new byte[packetlen]; for (int i = 0; i < packets; i++) { Buffer.BlockCopy(data, total_cnt, buffer, 0, packetlen); TE_USB_FX2_SetData(ref TE_USB_FX2_USBDevice, ref buffer, ref packetlen, PI_EP8, TIMEOUT_MS,BUFFER_SIZE); total_cnt += packetlen; } |
...
Code Block | ||
---|---|---|
| ||
SendFPGAcommand(ref TE_USB_FX2_USBDevice, MB_Commands.FX22MB_REG0_START_RX, TIMEOUT_MS); //ElapsedTime.Start(); //StopWatch startstarts Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < packets; i++) { packetlen = PACKETLENGTH; Buffer.BlockCopy(data, total_cnt, buffer, 0, packetlen); if (TE_USB_FX2.TE_USB_FX2.TE_USB_FX2_SetData(ref TE_USB_FX2_USBDevice, ref buffer, ref packetlen, PI_EP8, TIMEOUT_MS, BUFFER_SIZE) == false) errors++; else total_cnt += packetlen; } //total_cnt += (packetlen * packets);StopWatch stops stopWatch.Stop(); |