Discussion:
ftdi_write_data_submit and empty transfers
Uwe Bonnes
2018-07-19 09:10:46 UTC
Permalink
Hello,

can anybody comment on the appended patchset.
After adding an empty transfer in the async example, only the first run
succeeds. After adding a case for empty transfers with the second patch,
consecutive runs of the sync example succeed.

Bye
--
Uwe Bonnes ***@elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
From 4da9e37309058ace7c354b7ac109c69df7678afa Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <***@elektron.ikp.physik.tu-darmstadt.de>
Date: Wed, 18 Jul 2018 21:35:19 +0200
Subject: examples/async.c: Test empty write transfer.

Running "async -b" will fail after the first run.
---
examples/async.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/examples/async.c b/examples/async.c
index 0589479..9143155 100644
--- a/examples/async.c
+++ b/examples/async.c
@@ -132,7 +132,7 @@ int main(int argc, char **argv)
struct ftdi_transfer_control *tc_write;
uint8_t data[3];
if (do_read) {
- tc_read = ftdi_read_data_submit(ftdi, data, DATA_TO_READ);
+ tc_read = ftdi_read_data_submit(ftdi, data, DATA_TO_READ - 1);
}
if (do_write) {
tc_write = ftdi_write_data_submit(ftdi, ftdi_init, sizeof(ftdi_init));
@@ -140,6 +140,12 @@ int main(int argc, char **argv)
if (transfer != sizeof(ftdi_init)) {
printf("Async write failed : %d\n", transfer);
}
+ /* Test empty transfer.*/
+ tc_write = ftdi_write_data_submit(ftdi, ftdi_init, 0);
+ transfer = ftdi_transfer_data_done(tc_write);
+ if (transfer != 0) {
+ printf("Async empty write failed : %d\n", transfer);
+ }
} else {
int written = ftdi_write_data(ftdi, ftdi_init, sizeof(ftdi_init));
if (written != sizeof(ftdi_init)) {
@@ -148,17 +154,23 @@ int main(int argc, char **argv)
}
if (do_read) {
int transfer = ftdi_transfer_data_done(tc_read);
- if (transfer != DATA_TO_READ) {
+ if (transfer != DATA_TO_READ - 1) {
printf("Async Read failed:%d\n", transfer);
}
+ /* Test splitted read transfer.*/
+ tc_read = ftdi_read_data_submit(ftdi, data + DATA_TO_READ - 1, 1);
+ transfer = ftdi_transfer_data_done(tc_read);
+ if (transfer != 1) {
+ printf("Async Read remainder failed:%d\n", transfer);
+ }
} else {
int index = 0;
- ftdi->usb_read_timeout = 1;
- int i = 1000; /* Fail if read did not succeed in 1 second.*/
+ ftdi->usb_read_timeout = 10;
+ int i = 100; /* Fail if read did not succeed in 1 second.*/
while (i--) {
int res = ftdi_read_data(ftdi, data + index, 3 - index);
if (res < 0) {
- printf("Async read failure at %d\n", index);
+ printf("Sync read timeout at %d\n", index);
} else {
index += res;
}
--
2.13.7

From 89d9684fd4dfde0fdc6d11f7ee957383b39aa954 Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <***@elektron.ikp.physik.tu-darmstadt.de>
Date: Wed, 18 Jul 2018 21:35:40 +0200
Subject: ftdi_write_data_submit: Handle empty transfers.

---
src/ftdi.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/src/ftdi.c b/src/ftdi.c
index 52266d0..e2efc3a 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -1660,6 +1660,12 @@ struct ftdi_transfer_control *ftdi_write_data_submit(struct ftdi_context *ftdi,
if (!tc)
return NULL;

+ if (!size) {
+ tc->completed = 1;
+ tc->offset = 0;
+ tc->transfer = 0;
+ return tc;
+ }
transfer = libusb_alloc_transfer(0);
if (!transfer)
{
--
2.13.7


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