libftdi-git Archives

Subject: A library to talk to FTDI chips branch, master, updated. v0.18-3-g1884225

From: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Wed, 7 Jul 2010 15:53:19 +0200 (CEST)
The branch, master has been updated
       via  1884225d860f2703fbd9a52af152e421f9081665 (commit)
       via  3b92d479565a413c7b9f830c34c93886ba366347 (commit)
      from  f96c8f971ad9d0fd2c5bc74ef8f0a4634b38add1 (commit)


- Log -----------------------------------------------------------------
commit 1884225d860f2703fbd9a52af152e421f9081665
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date:   Wed Jul 7 15:52:11 2010 +0200

    Fix compilation if async mode is disabled

commit 3b92d479565a413c7b9f830c34c93886ba366347
Author: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date:   Fri Jun 25 17:41:28 2010 +0200

    Let ftdi_read_data() honor usb_read_timeout

-----------------------------------------------------------------------

Summary of changes:
 src/ftdi.c |   49 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index 2db8d32..bbbeb9a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -38,7 +38,6 @@
 /* stuff needed for async write */
 #ifdef LIBFTDI_LINUX_ASYNC_MODE
 #include <sys/ioctl.h>
-#include <sys/time.h>
 #include <sys/select.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -51,6 +50,39 @@
    } while(0);
 
 
+#if defined( __WIN32__) && !defined(__MINGW32__)
+#include <windows.h>
+#define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
+struct timeval {
+        long    tv_sec;
+        long    tv_usec;
+};
+int gettimeofday(  struct timeval *tv, void null)
+{
+    FILETIME ft;
+    unsigned __int64 tmpres = 0;
+    if(tv)
+    {
+        GetSystemTimeAsFileTime(&ft);
+        tmpres |= ft.dwHighDateTime;
+        tmpres <<= 32;
+        tmpres |= ft.dwLowDateTime;
+
+        /*converting file time to unix epoch*/
+        tmpres /= 10;  /*convert into microseconds*/
+        tmpres -= DELTA_EPOCH_IN_MICROSECS; 
+        tv->tv_sec = (LONG)(tmpres / 1000000UL);
+        tv->tv_usec = (LONG)(tmpres % 1000000UL);
+    }
+    /* Warning: Timezone not handled (and not needed here) */
+    return 0;
+}
+#else
+    // Include sys/time.h on non-Windows platforms
+    // as gettimeofday() needs it.
+    #include <sys/time.h>
+#endif
+
 /**
     Internal function to close usb device pointer.
     Sets ftdi->usb_dev to NULL.
@@ -1528,6 +1560,7 @@ int ftdi_read_data(struct ftdi_context *ftdi, unsigned 
char *buf, int size)
 {
     int offset = 0, ret = 1, i, num_of_chunks, chunk_remains;
     int packet_size;
+    struct timeval tv_start, tv_current;
 
     if (ftdi == NULL || ftdi->usb_dev == NULL)
         ftdi_error_return(-666, "USB device unavailable");
@@ -1559,6 +1592,7 @@ int ftdi_read_data(struct ftdi_context *ftdi, unsigned 
char *buf, int size)
         offset += ftdi->readbuffer_remaining;
     }
     // do the actual USB read
+    gettimeofday(&tv_start,NULL);
     while (offset < size && ret > 0)
     {
         ftdi->readbuffer_remaining = 0;
@@ -1595,14 +1629,6 @@ int ftdi_read_data(struct ftdi_context *ftdi, unsigned 
char *buf, int size)
                 else
                     ret -= 2*(num_of_chunks-1)+chunk_remains;
             }
-        }
-        else if (ret <= 2)
-        {
-            // no more data to read?
-            return offset;
-        }
-        if (ret > 0)
-        {
             // data still fits in buf?
             if (offset+ret <= size)
             {
@@ -1629,9 +1655,12 @@ int ftdi_read_data(struct ftdi_context *ftdi, unsigned 
char *buf, int size)
                 /* printf("Returning part: %d - size: %d - offset: %d - ret: 
%d - remaining: %d\n",
                 part_size, size, offset, ret, ftdi->readbuffer_remaining); */
 
-                return offset;
             }
         }
+        gettimeofday(&tv_current,NULL);
+        if(((tv_current.tv_sec - tv_start.tv_sec)*1000000+(tv_current.tv_usec 
- tv_start.tv_usec)) 
+           > ftdi->usb_read_timeout)
+            return offset;
     }
     // never reached
     return -127;


hooks/post-receive
-- 
A library to talk to FTDI chips

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

Current Thread
  • A library to talk to FTDI chips branch, master, updated. v0.18-3-g1884225, libftdi-git <=