[PATCH] Wait until device is ready after status request
Tormod Volden
lists.tormod at gmail.com
Sun Nov 7 18:53:51 CET 2010
From: Tormod Volden <debian.tormod at gmail.com>
DFU devices tell the host in the status request answer for
how long to wait before another request.
---
Another patch for dfu-util:
The usleep will in many cases be a NOP since the device sends a
zero bwPollTimeout, but better be safe and strict in all cases.
In one case below it replaces a hardcoded 5 ms wait. If a device
is broken and needs more time than it says, we should add quirks
for the specific device.
Tormod
src/main.c | 3 +++
src/sam7dfu.c | 3 ++-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/main.c b/src/main.c
index c1d6256..ef420a7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -636,6 +636,7 @@ int main(int argc, char **argv)
}
printf("state = %s, status = %d\n",
dfu_state_to_string(status.bState), status.bStatus);
+ usleep(status.bwPollTimeout * 1000);
switch (status.bState) {
case DFU_STATE_appIDLE:
@@ -784,6 +785,7 @@ status_again:
}
printf("state = %s, status = %d\n",
dfu_state_to_string(status.bState), status.bStatus);
+ usleep(status.bwPollTimeout * 1000);
switch (status.bState) {
case DFU_STATE_appIDLE:
@@ -843,6 +845,7 @@ status_again:
fprintf(stderr, "Error: %d\n", status.bStatus);
exit(1);
}
+ usleep(status.bwPollTimeout * 1000);
}
switch (mode) {
diff --git a/src/sam7dfu.c b/src/sam7dfu.c
index 177ba7b..e652f95 100644
--- a/src/sam7dfu.c
+++ b/src/sam7dfu.c
@@ -142,7 +142,7 @@ int sam7dfu_do_dnload(struct usb_dev_handle *usb_handle, int interface,
fprintf(stderr, "Error during download get_status\n");
goto out_close;
}
- usleep(5000);
+ usleep(dst.bwPollTimeout * 1000);
} while (dst.bState != DFU_STATE_dfuDNLOAD_IDLE &&
dst.bState != DFU_STATE_dfuERROR);
if (dst.bStatus != DFU_STATUS_OK) {
@@ -181,6 +181,7 @@ get_status:
printf("state(%u) = %s, status(%u) = %s\n", dst.bState,
dfu_state_to_string(dst.bState), dst.bStatus,
dfu_status_to_string(dst.bStatus));
+ usleep(dst.bwPollTimeout * 1000);
/* FIXME: deal correctly with ManifestationTolerant=0 / WillDetach bits */
switch (dst.bState) {
--
1.7.0.4
More information about the devel
mailing list