libftdi Archives

Subject: Latency issues with ftdi_read_data() and ftdi_write_data() using libftdi-0.19

From: KrishnaMohan Bandi <krishnamohan.bandi@xxxxxxxxx>
To: libftdi+help@xxxxxxxxxxxxxxxxxxxxxxx, libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Thu, 22 Sep 2011 11:20:57 +0100
Hi all,

   I have a program that uses libftdi-0.19 library to read and write from/to a FTDI device, which on the other end is connected to an FPGA. I do not have more than 20 bytes of data at any time to send/receive to/from the FTDI device, however I do very frequent reads and writes (approximately every 15ms)  from/to the FTDI device to read the GPS clock time and some other registers from the FPGA.

The read and write are together taking about 5-8ms and sometimes it goes up to as high as 15ms. This means the transfer rate is not even 9600bits/sec. However, the baud rate has been set to 921600. On the FPGA side, the time to read, process, and write back the data to the FTDI does not take more than 100uS. So, for the program the data is available as soon as the data is written to the FTDI device.

The strange behaviour I noticed is that when ftdi_read_data() is called, it returns zero as the number of bytes read. Only, the third (always) time the ftdi_read_data() actually reads the data and about 3ms is elapsed between the time the data is available and the ftdi_read_data() is actually able to read the data from the FIFO.

What I want to know from you guys is why is ftdi_read_data() takes so much time to read  small amount of data? What should be done to reduce the read/write time to the FTDI?

The below is the code I am using to initialize the FTDI device.

        struct ftdi_context ftdic;
        int baudrate = 921600;
        unsigned char latency = 1;

        /* Initialise a ftdi_context */
        if(ftdi_init(&ftdic) < 0)
        {         
            return FTDI_INIT_FAILED;
        }
   
        /* Select any channel on the chip */
        if(ftdi_set_interface(&ftdic, interface) < 0)
        {
            return FTDI_SET_INTERFACE_FAILED;
        }
   
        /* Open connection to FT245R via USB port */
        result = ftdi_usb_open(&ftdic, vid, pid);
        if(result < 0)
        {         
            return FTDI_USB_OPEN_FAILED;
        }
   
        /* Set baudrate */
        result = ftdi_set_baudrate(&ftdic, baudrate);
        if(result < 0)
        {          
            return FTDI_SET_BAUDRATE_FAILED;
        }
       
        /* Set the latency timer to 1ms to reduce the amount
           of delay for reading and writing */
        result = ftdi_set_latency_timer(&ftdic, latency);
        if(result < 0)
        {
            return FTDI_SET_LATENCY_FAILED;
        }

Then, in another function I call the ftdi_write_data() and try to read the response back from the FPGA using ftdi_read_data()

Any ideas/suggestions to use the libftdi to improve the read/write timings would be highly appreciated.

Thanks,
KM


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread