At present, ftdi_read_data_submit() waits infinite until all the requested data
is read. Appended patch add a new call with added timeout and make the old
call a special case of the new call.
This allows gracefull exit when something unexpected happens.
--
Uwe Bonnes bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From 21d0d0c7e22a4c89d2c750532d88c39f268d61dd Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 29 Mar 2011 17:00:43 +0200
Subject: Implement ftdi_read_data_submit_to and make ftdi_read_data_submit()
a special case of the new function
---
src/ftdi.c | 20 +++++++++++++++++++-
src/ftdi.h | 2 ++
2 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/src/ftdi.c b/src/ftdi.c
index 8a7b2ba..3dd1712 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -1325,6 +1325,16 @@ static void ftdi_read_data_cb(struct libusb_transfer
*transfer)
}
}
}
+ else
+ {
+ if (tc->retries == 1)
+ {
+ tc->completed = 1;
+ return;
+ }
+ if (tc->retries > 0)
+ tc->retries --;
+ }
ret = libusb_submit_transfer (transfer);
if (ret < 0)
tc->completed = 1;
@@ -1430,12 +1440,14 @@ struct ftdi_transfer_control
*ftdi_write_data_submit(struct ftdi_context *ftdi,
\param ftdi pointer to ftdi_context
\param buf Buffer with the data
\param size Size of the buffer
+ \param reties Abort when latency timer expied "reties" times with no data
read.
+ Use '0' to wait infinite
\retval NULL: Some error happens when submit transfer
\retval !NULL: Pointer to a ftdi_transfer_control
*/
-struct ftdi_transfer_control *ftdi_read_data_submit(struct ftdi_context *ftdi,
unsigned char *buf, int size)
+struct ftdi_transfer_control *ftdi_read_data_submit_to(struct ftdi_context
*ftdi, unsigned char *buf, int size, int retries)
{
struct ftdi_transfer_control *tc;
struct libusb_transfer *transfer;
@@ -1469,6 +1481,7 @@ struct ftdi_transfer_control
*ftdi_read_data_submit(struct ftdi_context *ftdi, u
}
tc->completed = 0;
+ tc->retries = retries;
if (ftdi->readbuffer_remaining != 0)
{
memcpy (buf, ftdi->readbuffer+ftdi->readbuffer_offset,
ftdi->readbuffer_remaining);
@@ -1503,6 +1516,11 @@ struct ftdi_transfer_control
*ftdi_read_data_submit(struct ftdi_context *ftdi, u
return tc;
}
+struct ftdi_transfer_control *ftdi_read_data_submit(struct ftdi_context *ftdi,
unsigned char *buf, int size)
+{
+ return ftdi_read_data_submit_to(ftdi, buf, size, 0);
+}
+
/**
Wait for completion of the transfer.
diff --git a/src/ftdi.h b/src/ftdi.h
index b7c0113..ef44d58 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -161,6 +161,7 @@ enum ftdi_interface
struct ftdi_transfer_control
{
int completed;
+ int retries;
unsigned char *buf;
int size;
int offset;
@@ -499,6 +500,7 @@ extern "C"
int ftdi_write_data_async(struct ftdi_context *ftdi, unsigned char *buf,
int size);
void ftdi_async_complete(struct ftdi_context *ftdi, int wait_for_more);
+ struct ftdi_transfer_control *ftdi_read_data_submit_to(struct ftdi_context
*ftdi, unsigned char *buf, int size, int retries);
struct ftdi_transfer_control *ftdi_read_data_submit(struct ftdi_context
*ftdi, unsigned char *buf, int size);
int ftdi_transfer_data_done(struct ftdi_transfer_control *tc);
--
1.7.1
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|