Skip to content

Commit 35eed36

Browse files
authored
Merge pull request #301 from riscv/mpsse_flush
Add wall clock timeout to mpsse_flush()
2 parents 933cb87 + d6a1e27 commit 35eed36

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/jtag/drivers/mpsse.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "mpsse.h"
2424
#include "helper/log.h"
25+
#include "helper/time_support.h"
2526
#include <libusb.h>
2627

2728
/* Compatibility define for older libusb-1.0 */
@@ -892,6 +893,7 @@ int mpsse_flush(struct mpsse_ctx *ctx)
892893
}
893894

894895
/* Polling loop, more or less taken from libftdi */
896+
int64_t start = timeval_ms();
895897
while (!write_result.done || !read_result.done) {
896898
struct timeval timeout_usb;
897899

@@ -914,6 +916,11 @@ int mpsse_flush(struct mpsse_ctx *ctx)
914916
break;
915917
}
916918
}
919+
920+
if (timeval_ms() - start > 2000) {
921+
LOG_ERROR("Timed out handling USB events in mpsse_flush().");
922+
break;
923+
}
917924
}
918925

919926
error_check:

0 commit comments

Comments
 (0)