From 6a7e9769902a4a4e156ee034c4bea48bc2996cf8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sergi=20Hern=C3=A0ndez=20Juan?= <shernand@iri.upc.edu>
Date: Fri, 29 Jun 2012 09:32:10 +0000
Subject: [PATCH] Increased the default buffer length to improve performance.
 Added a special configuration of the ftdi module for high speed
 communications.

---
 src/cqueue.h                |  8 ++---
 src/usb_ftdi/ftdimodule.cpp | 72 ++++++++++++++++++++++++++-----------
 2 files changed, 56 insertions(+), 24 deletions(-)

diff --git a/src/cqueue.h b/src/cqueue.h
index 02ce135..cd2b94f 100755
--- a/src/cqueue.h
+++ b/src/cqueue.h
@@ -4,15 +4,15 @@
 #include <string.h>
 #include "mutex.h"
 
-#define QUEUE_DEFAULT_SIZE     1024
+#define QUEUE_DEFAULT_SIZE     256*1024
 
 class CQueue
 {
   private:
     int size;
-    int num_data;
-    int read_pointer;
-    int write_pointer;
+    long int num_data;
+    long int read_pointer;
+    long int write_pointer;
     unsigned char *data;
     CMutex queue_access;
   public:
diff --git a/src/usb_ftdi/ftdimodule.cpp b/src/usb_ftdi/ftdimodule.cpp
index 7520d5d..33bd12f 100644
--- a/src/usb_ftdi/ftdimodule.cpp
+++ b/src/usb_ftdi/ftdimodule.cpp
@@ -70,32 +70,64 @@ void CFTDI::hard_config(void *config)
       /* handle exceptions */
       throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
     }
-  }
-  //2. Set the data characteristics
-  if(ftdi_config->word_length!=-1 && ftdi_config->stop_bits!=-1 && ftdi_config->parity!=-1)
-  {
-    if((ft_status=FT_SetDataCharacteristics(this->ft_handle,ftdi_config->word_length,ftdi_config->stop_bits,ftdi_config->parity))!=FT_OK)
+    //2. Set the data characteristics
+    if(ftdi_config->word_length!=-1 && ftdi_config->stop_bits!=-1 && ftdi_config->parity!=-1)
+    {
+      if((ft_status=FT_SetDataCharacteristics(this->ft_handle,ftdi_config->word_length,ftdi_config->stop_bits,ftdi_config->parity))!=FT_OK)
+      {
+        /* handle exceptions */
+        throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+      }
+    }
+    //3. set read and write timeouts
+    if((ft_status=FT_SetTimeouts(this->ft_handle,ftdi_config->read_timeout,ftdi_config->write_timeout))!=FT_OK)
+    {
+      /* handle exceptions */
+      throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+    } 
+    //4. Set latency timer
+    if((ft_status=FT_SetLatencyTimer(this->ft_handle,ftdi_config->latency_timer))!=FT_OK)
+    {
+      /* handle exceptions */
+      throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+    }
+    if((ft_status=FT_SetFlowControl(this->ft_handle,FT_FLOW_NONE,0x00,0x00))!=FT_OK)
     {
       /* handle exceptions */
       throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
     }
   }
-  //3. set read and write timeouts
-  if((ft_status=FT_SetTimeouts(this->ft_handle,ftdi_config->read_timeout,ftdi_config->write_timeout))!=FT_OK)
-  {
-    /* handle exceptions */
-    throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
-  } 
-  //4. Set latency timer
-  if((ft_status=FT_SetLatencyTimer(this->ft_handle,ftdi_config->latency_timer))!=FT_OK)
-  {
-    /* handle exceptions */
-    throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
-  }
-  if((ft_status=FT_SetFlowControl(this->ft_handle,FT_FLOW_NONE,0x00,0x00))!=FT_OK)
+  else
   {
-    /* handle exceptions */
-    throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+    if((ft_status=FT_SetBitMode(this->ft_handle,0xFF,0x00))!=FT_OK)
+    {
+      /* handle exceptions */
+      throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+    }
+    usleep(100);
+
+    if((ft_status=FT_SetLatencyTimer(this->ft_handle,2))!=FT_OK)
+    {
+      /* handle exceptions */
+      throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+    }
+
+     if((ft_status=FT_SetUSBParameters(this->ft_handle,0x10000,0x10000))!=FT_OK)
+     {
+       /* handle exceptions */
+       throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+     }
+
+    if((ft_status=FT_SetFlowControl(this->ft_handle,FT_FLOW_RTS_CTS,0x00,0x00))!=FT_OK)
+    {
+      /* handle exceptions */
+      throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+    }
+    if((ft_status=FT_Purge(this->ft_handle,FT_PURGE_RX))!=FT_OK)
+    {
+      /* handle exceptions */
+      throw CFTDIException(_HERE_,error_messages[ft_status],this->comm_id);
+    }
   }
 }
 
-- 
GitLab