all: Use nanosleep (via SLEEP) instead usleep

This commit is contained in:
Pali Rohár committed 2014-11-26 15:46:03 +01:00
1 parent a9b1332f8f
commit bc9f42f559
4 files changed
+13 -10

No files matched your search

+8 -8
View File
@@ -189,13 +189,13 @@ static int send_2nd(usb_dev_handle * udev, struct image * image) {
printf("Sending OMAP peripheral boot message...\n"); printf("Sending OMAP peripheral boot message...\n");
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&omap_peripheral_msg, sizeof(omap_peripheral_msg), WRITE_TIMEOUT); ret = usb_bulk_write(udev, WRITE_DEV, (char *)&omap_peripheral_msg, sizeof(omap_peripheral_msg), WRITE_TIMEOUT);
usleep(5000); SLEEP(5000);
if ( ret != sizeof(omap_peripheral_msg) ) if ( ret != sizeof(omap_peripheral_msg) )
ERROR_RETURN("Sending OMAP peripheral boot message failed", -1); ERROR_RETURN("Sending OMAP peripheral boot message failed", -1);
printf("Sending 2nd X-Loader image size...\n"); printf("Sending 2nd X-Loader image size...\n");
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&image->size, 4, WRITE_TIMEOUT); ret = usb_bulk_write(udev, WRITE_DEV, (char *)&image->size, 4, WRITE_TIMEOUT);
usleep(5000); SLEEP(5000);
if ( ret != 4 ) if ( ret != 4 )
ERROR_RETURN("Sending 2nd X-Loader image size failed", -1); ERROR_RETURN("Sending 2nd X-Loader image size failed", -1);
@@ -215,7 +215,7 @@ static int send_2nd(usb_dev_handle * udev, struct image * image) {
readed += ret; readed += ret;
printf_progressbar(readed, image->size); printf_progressbar(readed, image->size);
} }
usleep(50000); SLEEP(50000);
return 0; return 0;
@@ -232,7 +232,7 @@ static int send_secondary(usb_dev_handle * udev, struct image * image) {
printf("Sending X-Loader init message...\n"); printf("Sending X-Loader init message...\n");
ret = usb_bulk_write(udev, WRITE_DEV, (char *)&init_msg, sizeof(init_msg), WRITE_TIMEOUT); ret = usb_bulk_write(udev, WRITE_DEV, (char *)&init_msg, sizeof(init_msg), WRITE_TIMEOUT);
usleep(5000); SLEEP(5000);
if ( ret != sizeof(init_msg) ) if ( ret != sizeof(init_msg) )
ERROR_RETURN("Sending X-Loader init message failed", -1); ERROR_RETURN("Sending X-Loader init message failed", -1);
@@ -257,7 +257,7 @@ static int send_secondary(usb_dev_handle * udev, struct image * image) {
readed += ret; readed += ret;
printf_progressbar(readed, image->size); printf_progressbar(readed, image->size);
} }
usleep(5000); SLEEP(5000);
printf("Waiting for X-Loader response...\n"); printf("Waiting for X-Loader response...\n");
ret = usb_bulk_read(udev, READ_DEV, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */ ret = usb_bulk_read(udev, READ_DEV, (char *)&buffer, 4, READ_TIMEOUT); /* 4 bytes - dummy value */
@@ -295,7 +295,7 @@ static int ping_timeout(usb_dev_handle * udev) {
break; break;
} }
usleep(5000); SLEEP(5000);
--try_read; --try_read;
} }
@@ -405,11 +405,11 @@ int leave_cold_flash(struct usb_device_info * dev) {
printf("Sending OMAP memory boot message...\n"); printf("Sending OMAP memory boot message...\n");
ret = usb_bulk_write(dev->udev, WRITE_DEV, (char *)&omap_memory_msg, sizeof(omap_memory_msg), WRITE_TIMEOUT); ret = usb_bulk_write(dev->udev, WRITE_DEV, (char *)&omap_memory_msg, sizeof(omap_memory_msg), WRITE_TIMEOUT);
usleep(5000); SLEEP(5000);
if ( ret != sizeof(omap_memory_msg) ) if ( ret != sizeof(omap_memory_msg) )
ERROR_RETURN("Sending OMAP memory boot message failed", -1); ERROR_RETURN("Sending OMAP memory boot message failed", -1);
usleep(250000); SLEEP(250000);
return 0; return 0;
} }
+3
View File
@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <time.h>
extern int simulate; extern int simulate;
extern int noverify; extern int noverify;
@@ -21,4 +22,6 @@ extern int verbose;
#define ALLOC_ERROR() do { ERROR("Cannot allocate memory"); } while (0) #define ALLOC_ERROR() do { ERROR("Cannot allocate memory"); } while (0)
#define ALLOC_ERROR_RETURN(...) do { ALLOC_ERROR(); return __VA_ARGS__; } 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)
#endif #endif
+1 -1
View File
@@ -537,7 +537,7 @@ int nolo_flash_image(struct usb_device_info * dev, struct image * image) {
} }
usleep(0xc350); // 0.5s SLEEP(0xc350); // 0.5s
} }
+1 -1
View File
@@ -325,7 +325,7 @@ struct usb_device_info * usb_open_and_wait_for_device(void) {
if ( ret ) if ( ret )
break; break;
usleep(0xc350); // 0.5s SLEEP(0xc350); // 0.5s
} }