libftdi: (tomj) make async code optional
authorThomas Jarosch <opensource@intra2net.com>
Sat, 1 Mar 2008 09:21:44 +0000 (09:21 +0000)
committerThomas Jarosch <opensource@intra2net.com>
Sat, 1 Mar 2008 09:21:44 +0000 (09:21 +0000)
ChangeLog
configure.in
src/ftdi.c

index 43358bf..1b92cc8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ New in 0.11
 -----------
 * Support for different EEPROM sizes (Andrew John Rogers, andrew@rogerstech.co.uk)
 * Async write support. Linux only and no error handling.
+  You have to enable it via --with-async-code.
 * Detection of R-type chips
 * FTDIChip-ID read support (Peter Holik)
 
index c6eb2a1..d49b77f 100644 (file)
@@ -32,6 +32,18 @@ else
    AC_MSG_RESULT(yes)
 fi
 
+AC_ARG_WITH(async-mode,
+[  --with-async-mode       enable experimental async mode. Linux only.],
+[
+  AC_MSG_CHECKING(for experimental linux async mode)
+  if test "$withval" != "no"; then
+    CFLAGS="$CFLAGS -DLIBFTDI_LINUX_ASYNC_MODE"
+    AC_MSG_RESULT(yes)
+  else
+    AC_MSG_RESULT(no)
+  fi
+])
+
 dnl check for doxygen
 AC_PATH_PROG(DOXYGEN, doxygen)
 AM_CONDITIONAL(HAVE_DOXYGEN, test -n $DOXYGEN)
index b284209..16d86d1 100644 (file)
 #include "ftdi.h"
 
 /* stuff needed for async write */
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/select.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <linux/usbdevice_fs.h>
+#ifdef LIBFTDI_LINUX_ASYNC_MODE
+    #include <sys/ioctl.h>
+    #include <sys/time.h>
+    #include <sys/select.h>
+    #include <sys/types.h>
+    #include <unistd.h>
+    #include <linux/usbdevice_fs.h>
+#endif
 
 #define ftdi_error_return(code, str) do {  \
         ftdi->error_str = str;             \
@@ -83,6 +85,7 @@ int ftdi_init(struct ftdi_context *ftdi)
 
     ftdi->error_str = NULL;
 
+#ifdef LIBFTDI_LINUX_ASYNC_MODE
     ftdi->async_usb_buffer_size=10;
     if ((ftdi->async_usb_buffer=malloc(sizeof(struct usbdevfs_urb)*ftdi->async_usb_buffer_size)) == NULL)
         ftdi_error_return(-1, "out of memory for async usb buffer");
@@ -90,6 +93,10 @@ int ftdi_init(struct ftdi_context *ftdi)
     /* initialize async usb buffer with unused-marker */
     for (i=0; i < ftdi->async_usb_buffer_size; i++)
         ((struct usbdevfs_urb*)ftdi->async_usb_buffer)[i].usercontext = FTDI_URB_USERCONTEXT_COOKIE;
+#else
+    ftdi->async_usb_buffer_size=0;
+    ftdi->async_usb_buffer = NULL;
+#endif
 
     ftdi->eeprom_size = FTDI_DEFAULT_EEPROM_SIZE;
 
@@ -495,8 +502,10 @@ int ftdi_usb_close(struct ftdi_context *ftdi)
 {
     int rtn = 0;
 
+#ifdef LIBFTDI_LINUX_ASYNC_MODE
     /* try to release some kernel resources */
     ftdi_async_complete(ftdi,1);
+#endif
 
     if (usb_release_interface(ftdi->usb_dev, ftdi->interface) != 0)
         rtn = -1;
@@ -731,6 +740,7 @@ int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size)
     return total_written;
 }
 
+#ifdef LIBFTDI_LINUX_ASYNC_MODE
 /* this is strongly dependent on libusb using the same struct layout. If libusb
    changes in some later version this may break horribly (this is for libusb 0.1.12) */
 struct usb_dev_handle {
@@ -923,7 +933,7 @@ int ftdi_write_data_async(struct ftdi_context *ftdi, unsigned char *buf, int siz
 
     return total_written;
 }
-
+#endif // LIBFTDI_LINUX_ASYNC_MODE
 
 /**
     Configure write buffer chunk size.
@@ -1405,7 +1415,7 @@ int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output)
     // Dynamic content
     i=0x14;
     if(eeprom->size>=256) i = 0x80;
-   
+
 
     // Output manufacturer 
     output[0x0E] = i | 0x80;  // calculate offset