From 6e989181373db5093e8b1c712b7eaf7904bccce5 Mon Sep 17 00:00:00 2001 From: Fabien Le Mentec Date: Sun, 11 Sep 2011 00:58:24 -0500 Subject: [PATCH] [update] submit_wait timeout --- stm32l/src/main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/stm32l/src/main.c b/stm32l/src/main.c index 7deb328..1e9ded1 100644 --- a/stm32l/src/main.c +++ b/stm32l/src/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "stlink-hw.h" @@ -106,6 +107,9 @@ static void on_trans_done(struct libusb_transfer* trans) static int submit_wait(struct libusb_transfer* trans) { + struct timeval start; + struct timeval now; + struct timeval diff; struct trans_ctx trans_ctx; enum libusb_error error; @@ -121,6 +125,8 @@ static int submit_wait(struct libusb_transfer* trans) return -1; } + gettimeofday(&start, NULL); + while (!(trans_ctx.flags & TRANS_FLAGS_IS_DONE)) { if (libusb_handle_events(NULL)) @@ -128,6 +134,14 @@ static int submit_wait(struct libusb_transfer* trans) printf("libusb_handle_events()\n"); return -1; } + + gettimeofday(&now, NULL); + timersub(&now, &start, &diff); + if (diff.tv_sec >= 3) + { + printf("libusb_handle_events() timeout\n"); + return -1; + } } return 0; -- 2.30.2