summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2020-04-25 20:04:51 +0200
committerPali Rohár <pali.rohar@gmail.com>2020-04-25 20:04:51 +0200
commitf37c2cd7e83c8e40576256d88ecc6b6f96dd72ee (patch)
tree39048632452ed8fb051432131bec25773b2db888 /src
parente94279eecbfdd1988912ac7ce24e6d4d702695a1 (diff)
download0xFFFF-f37c2cd7e83c8e40576256d88ecc6b6f96dd72ee.tar.bz2
all: Fix delays for all operations
Diffstat (limited to 'src')
-rw-r--r--src/cold-flash.c14
-rw-r--r--src/global.h2
-rw-r--r--src/mkii.c5
-rw-r--r--src/nolo.c2
-rw-r--r--src/usb-device.c2
5 files changed, 15 insertions, 10 deletions
diff --git a/src/cold-flash.c b/src/cold-flash.c
index 6338670..bfc31d0 100644
--- a/src/cold-flash.c
+++ b/src/cold-flash.c
@@ -191,14 +191,14 @@ static int send_2nd(usb_dev_handle * udev, struct image * image) {
if ( ret != sizeof(omap_peripheral_msg) )
ERROR_RETURN("Sending OMAP peripheral boot message failed", -1);
- SLEEP(5000);
+ MSLEEP(5);
printf("Sending 2nd X-Loader image size...\n");
ret = usb_bulk_write(udev, USB_WRITE_EP, (char *)&image->size, 4, WRITE_TIMEOUT);
if ( ret != 4 )
ERROR_RETURN("Sending 2nd X-Loader image size failed", -1);
- SLEEP(5000);
+ MSLEEP(5);
printf("Sending 2nd X-Loader image...\n");
printf_progressbar(0, image->size);
@@ -217,7 +217,7 @@ static int send_2nd(usb_dev_handle * udev, struct image * image) {
printf_progressbar(sent, image->size);
}
- SLEEP(50000);
+ MSLEEP(50);
return 0;
}
@@ -237,7 +237,7 @@ static int send_secondary(usb_dev_handle * udev, struct image * image) {
ERROR_RETURN("Sending X-Loader init message failed", -1);
printf("Waiting for X-Loader response...\n");
- SLEEP(5000);
+ MSLEEP(5);
ret = usb_bulk_read(udev, USB_READ_EP, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */
if ( ret != 4 )
ERROR_RETURN("No response", -1);
@@ -260,7 +260,7 @@ static int send_secondary(usb_dev_handle * udev, struct image * image) {
}
printf("Waiting for X-Loader response...\n");
- SLEEP(5000);
+ MSLEEP(5);
ret = usb_bulk_read(udev, USB_READ_EP, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */
if ( ret != 4 )
ERROR_RETURN("No response", -1);
@@ -296,7 +296,7 @@ static int ping_timeout(usb_dev_handle * udev) {
break;
}
- SLEEP(5000);
+ MSLEEP(5);
--try_read;
}
@@ -413,7 +413,7 @@ int leave_cold_flash(struct usb_device_info * dev) {
if ( ret != sizeof(omap_memory_msg) )
ERROR_RETURN("Sending OMAP memory boot message failed", -1);
- SLEEP(1000000);
+ MSLEEP(250);
return 0;
}
diff --git a/src/global.h b/src/global.h
index a26c88b..ab4b24d 100644
--- a/src/global.h
+++ b/src/global.h
@@ -22,7 +22,7 @@ extern int verbose;
#define ALLOC_ERROR() do { ERROR("Cannot allocate memory"); } while (0)
#define ALLOC_ERROR_RETURN(...) do { ALLOC_ERROR(); return __VA_ARGS__; } while (0)
-#define SLEEP(usec) do { struct timespec _t = { 0, (usec) }; nanosleep(&_t, NULL); } while (0)
+#define MSLEEP(msec) do { nanosleep(&(struct timespec){ (msec / 1000), (1000L * 1000L * (msec % 1000)) }, NULL); } while (0)
static inline void * MEMMEM(void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
for ( size_t i = 0; i < haystacklen; ++i ) {
diff --git a/src/mkii.c b/src/mkii.c
index 6c8a0d6..e50637e 100644
--- a/src/mkii.c
+++ b/src/mkii.c
@@ -361,6 +361,11 @@ int mkii_reboot_device(struct usb_device_info * dev, int update) {
if ( ret != 1 || msg->data[0] != 0 )
ERROR_RETURN("Cannot send reboot command", -1);
+ if (dev->data & MKII_UPDATE_MODE)
+ MSLEEP(100);
+ else
+ MSLEEP(3000);
+
return 0;
}
diff --git a/src/nolo.c b/src/nolo.c
index 9faea56..c30eb77 100644
--- a/src/nolo.c
+++ b/src/nolo.c
@@ -541,7 +541,7 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
}
- SLEEP(0xc350); // 0.5s
+ MSLEEP(50);
}
diff --git a/src/usb-device.c b/src/usb-device.c
index f7c16bb..691406f 100644
--- a/src/usb-device.c
+++ b/src/usb-device.c
@@ -361,7 +361,7 @@ struct usb_device_info * usb_open_and_wait_for_device(void) {
if ( ret )
break;
- SLEEP(0xc350); // 0.5s
+ MSLEEP(50);
}