On Sat, Jun 26, 2010 at 12:03 AM, Uwe Bonnes
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> Appended patch for libusb-0 now loops until the timeout has been hit or all
> bytes read or a hard error happened.
>
> I don't know about the exact status of gettimeofday on WIN32 outside of
> MINGW, so I have ifdef'd some gettimeofday implementation inspired by notes
> on the net. I tested with Linux and XP/Mingw32.
Other than MinGW 32bit (and possible MinGW 64bit), I think Cygwin is
the only supported compiler for libftdi. Am I right? I do not know if
libftdi supports MSVC or not.
In that case, MinGW and Cygwin both have gettimeofday. I do not
know how good it is though.
> If found usefull and acceptable, it should be applied to libusb-1 too.
>
> +#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 nneded here) */
Typo here, should be "needed".
> + return 0;
> +}
> +#endif
> +
> /**
Since both MinGW and Cygwin have this one, maybe the above
is needed.
On the other hand, from what I read, the function gettimeofday
under MinGW/Cygwin may not provide good resolution for timeout
(>10ms). If that is not good enough, people seems to use
QueryPerformanceCounter.
Reference:
1) http://msdn.microsoft.com/en-us/magazine/cc163996.aspx
2)
http://git.libusb.org/?p=libusb-pbatard.git;a=blob;f=libusb/os/windows_usb.c;h=97a1e56a8f77afb351875e2a7bb8e2271121ead6;hb=master
--
Xiaofan http://sourceforge.net/projects/libusb-win32/
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|