libftdi Archives

Subject: Re: MSVC build of libftdi git

From: Xiaofan Chen <xiaofanc@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 6 Sep 2011 21:04:54 +0800
On Mon, Sep 5, 2011 at 11:46 PM, Uwe Bonnes
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>>>>>> "Xiaofan" == Xiaofan Chen <xiaofanc@xxxxxxxxx> writes:
>
>    Xiaofan> On Fri, Aug 26, 2011 at 10:42 PM, Xiaofan Chen
>    Xiaofan> <xiaofanc@xxxxxxxxx> wrote:
>    >> On Fri, Aug 26, 2011 at 10:30 PM, Xiaofan Chen <xiaofanc@xxxxxxxxx>
>    >> wrote:
>    >>> I remember Michael Plante mentioned that libfti was able to be built
>    >>> under Visual Studio. So out of curiosity, I used CMake to generate
>    >>> the VS2010 project file (32bit) and indeed the library build is
>    >>> okay. Only 2 examples can be built though.
>    >>>
>    >>> The generated dll file is ftdi.dll and the generated lib file is
>    >>> ftdi.lib but I think the proper name is actually libftdi.dll and
>    >>> libftdi.lib (for MSVC).
>    >>>
>
> Hello Xiaofan,
>
> can you send diffs for your changes? E.g.  I can only crossbuild with
> mingw32 on Linux, but have no MSVC.
>

The following diff is against libftdi-1.0 git
6eb32553b11d97f4a25825229ee51fedd3f33ee8.
I think it will be the same for latest git.

The first diff against CMake is probably not the correct solution
but it is necessary for MinGW, MinGW/MSys and MSVC.

Adding the LIBUSB_CALL is correct for libusb-1.0 git.

Last patch adding GETTIMEOFDAY is probably not the best
either.

diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 29646f5..93e6093 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,11 +1,6 @@
 option(EXAMPLES "Build example programs" ON)

 if (EXAMPLES)
-    # Includes
-    include( ${CMAKE_CURRENT_SOURCE_DIR}
-            ${CMAKE_CURRENT_BINARY_DIR}
-            )
-
     message(STATUS "Building example programs.")

     # Source includes
diff --git a/src/ftdi.c b/src/ftdi.c
index dca79e1..c709bbf 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -1270,7 +1270,7 @@ int ftdi_write_data(struct ftdi_context *ftdi,
unsigned char *buf, int size)
     return offset;
 }

-static void ftdi_read_data_cb(struct libusb_transfer *transfer)
+static void LIBUSB_CALL ftdi_read_data_cb(struct libusb_transfer *transfer)
 {
     struct ftdi_transfer_control *tc = (struct ftdi_transfer_control
*) transfer->user_data;
     struct ftdi_context *ftdi = tc->ftdi;
@@ -1352,7 +1352,7 @@ static void ftdi_read_data_cb(struct
libusb_transfer *transfer)
 }


-static void ftdi_write_data_cb(struct libusb_transfer *transfer)
+static void LIBUSB_CALL ftdi_write_data_cb(struct libusb_transfer *transfer)
 {
     struct ftdi_transfer_control *tc = (struct ftdi_transfer_control
*) transfer->user_data;
     struct ftdi_context *ftdi = tc->ftdi;
diff --git a/src/ftdi_stream.c b/src/ftdi_stream.c
index b949999..073de28 100644
--- a/src/ftdi_stream.c
+++ b/src/ftdi_stream.c
@@ -54,13 +54,75 @@ typedef struct
     FTDIProgressInfo progress;
 } FTDIStreamState;

+/* replacements for gettimeofday */
+#ifndef HAVE_GETTIMEOFDAY
+
+/* Windows */
+#ifdef _WIN32
+#include <time.h>
+#include <windows.h>
+
+const __int64 DELTA_EPOCH_IN_MICROSECS= 11644473600000000;
+
+/* IN UNIX the use of the timezone struct is obsolete;
+ I don't know why you use it. See
http://linux.about.com/od/commands/l/blcmdl2_gettime.htm
+ But if you want to use this structure to know about GMT(UTC)
diffrence from your local time
+ it will be next: tz_minuteswest is the real diffrence in minutes
from GMT(UTC) and a tz_dsttime is a flag
+ indicates whether daylight is now in use
+*/
+struct timezone2
+{
+  __int32  tz_minuteswest; /* minutes W of Greenwich */
+  BOOL  tz_dsttime;     /* type of dst correction */
+};
+
+struct timeval2 {
+__int32    tv_sec;         /* seconds */
+__int32    tv_usec;        /* microseconds */
+};
+
+int gettimeofday(struct timeval2 *tv/*in*/, struct timezone2 *tz/*in*/)
+{
+  FILETIME ft;
+  __int64 tmpres = 0;
+  TIME_ZONE_INFORMATION tz_winapi;
+  int rez=0;
+
+   ZeroMemory(&ft,sizeof(ft));
+   ZeroMemory(&tz_winapi,sizeof(tz_winapi));
+
+    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 = (__int32)(tmpres*0.000001);
+    tv->tv_usec =(tmpres%1000000);
+
+
+    //_tzset(),don't work properly, so we use GetTimeZoneInformation
+    rez=GetTimeZoneInformation(&tz_winapi);
+    tz->tz_dsttime=(rez==2)?TRUE:FALSE;
+    tz->tz_minuteswest = tz_winapi.Bias + ((rez==2)?tz_winapi.DaylightBias:0);
+
+  return 0;
+}
+
+#endif /* _WIN32 */
+
+#endif /* HAVE_GETTIMEOFDAY */
+
 /* Handle callbacks
  *
  * With Exit request, free memory and release the transfer
  *
  * state->result is only set when some error happens
  */
-static void
+static void LIBUSB_CALL
 ftdi_readstream_cb(struct libusb_transfer *transfer)
 {
    FTDIStreamState *state = transfer->user_data;



-- 
Xiaofan

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

Current Thread