Stop using usleep().
Use nanosleep() on Unix-like systems, and Sleep() on Windows.
This commit is contained in:
parent
4ab905751c
commit
29dfb4da84
|
@ -388,7 +388,7 @@ static device_t bsl_open(const struct device_args *args)
|
|||
if (enter_via_fet(dev) < 0)
|
||||
printc_err("bsl: warning: FET firmware not responding\n");
|
||||
|
||||
usleep(500000);
|
||||
delay_ms(500);
|
||||
|
||||
/* Show chip info */
|
||||
if (bsl_xfer(dev, CMD_TX_DATA, 0xff0, NULL, 0x10) < 0) {
|
||||
|
|
|
@ -676,7 +676,7 @@ static device_status_t fet_poll(device_t dev_base)
|
|||
struct fet_device *dev = (struct fet_device *)dev_base;
|
||||
|
||||
ctrlc_reset();
|
||||
if ((usleep(50000) < 0) || ctrlc_check())
|
||||
if ((delay_ms(50) < 0) || ctrlc_check())
|
||||
return DEVICE_STATUS_INTR;
|
||||
|
||||
if (xfer(dev, C_STATE, NULL, 0, 1, 0) < 0) {
|
||||
|
@ -1002,9 +1002,9 @@ int try_open(struct fet_device *dev, const struct device_args *args,
|
|||
if (dev->flags & FET_PROTO_NOLEAD_SEND) {
|
||||
printc("Resetting Olimex command processor...\n");
|
||||
transport->send(dev->transport, (const uint8_t *)"\x7e", 1);
|
||||
usleep(5000);
|
||||
delay_ms(5);
|
||||
transport->send(dev->transport, (const uint8_t *)"\x7e", 1);
|
||||
usleep(5000);
|
||||
delay_ms(5);
|
||||
}
|
||||
|
||||
printc_dbg("Initializing FET...\n");
|
||||
|
@ -1064,7 +1064,7 @@ static device_t fet_open(const struct device_args *args,
|
|||
dev->flags = flags;
|
||||
|
||||
if (try_open(dev, args, flags & FET_PROTO_FORCE_RESET) < 0) {
|
||||
usleep(500000);
|
||||
delay_ms(500);
|
||||
printc("Trying again...\n");
|
||||
if (try_open(dev, args, 1) < 0)
|
||||
goto fail;
|
||||
|
|
|
@ -226,7 +226,7 @@ static int flash_bsl_recv(struct flash_bsl_device *dev,
|
|||
debug_hexdump("received message", recv_buf, recv_len);
|
||||
#endif
|
||||
|
||||
usleep(10000);
|
||||
delay_ms(10);
|
||||
return recv_len;
|
||||
}
|
||||
|
||||
|
@ -550,7 +550,7 @@ static int flash_bsl_writemem(device_t dev_base,
|
|||
|
||||
static void entry_delay(void)
|
||||
{
|
||||
usleep(1000);
|
||||
delay_ms(1);
|
||||
}
|
||||
|
||||
static int enter_via_dtr_rts(struct flash_bsl_device *dev)
|
||||
|
@ -657,7 +657,7 @@ static device_t flash_bsl_open(const struct device_args *args)
|
|||
if (enter_via_dtr_rts(dev) < 0)
|
||||
goto fail;
|
||||
|
||||
usleep(500000);
|
||||
delay_ms(500);
|
||||
|
||||
/* unlock device (erase then send password) */
|
||||
if (flash_bsl_unlock(dev) < 0) {
|
||||
|
|
|
@ -95,7 +95,7 @@ static int reset_sequence(sport_t fd)
|
|||
return -1;
|
||||
}
|
||||
|
||||
usleep(20000);
|
||||
delay_ms(20);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -578,7 +578,7 @@ static device_status_t goodfet_poll(device_t dev_base)
|
|||
(void)dev_base;
|
||||
|
||||
ctrlc_reset();
|
||||
if (usleep(100000) < 0 || ctrlc_check())
|
||||
if (delay_ms(100) < 0 || ctrlc_check())
|
||||
return DEVICE_STATUS_INTR;
|
||||
|
||||
return DEVICE_STATUS_RUNNING;
|
||||
|
|
|
@ -509,7 +509,7 @@ static int do_download(struct usb_device *dev, const struct firmware *f)
|
|||
offset += r;
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
delay_ms(100);
|
||||
if (usb_reset(hnd) < 0)
|
||||
pr_error("ti3410: warning: reset failed");
|
||||
|
||||
|
|
|
@ -472,7 +472,7 @@ static device_status_t tilib_poll(device_t dev_base)
|
|||
struct tilib_device *dev = (struct tilib_device *)dev_base;
|
||||
|
||||
ctrlc_reset();
|
||||
if ((usleep(50000) < 0) || ctrlc_check())
|
||||
if ((delay_ms(50) < 0) || ctrlc_check())
|
||||
return DEVICE_STATUS_INTR;
|
||||
|
||||
if (event_fetch(dev) & MID_HALT_ANY)
|
||||
|
|
32
util/util.c
32
util/util.c
|
@ -24,6 +24,7 @@
|
|||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __Windows__
|
||||
#include <windows.h>
|
||||
|
@ -360,3 +361,34 @@ char *expand_tilde(const char *path)
|
|||
/* Caller must free()! */
|
||||
return expanded;
|
||||
}
|
||||
|
||||
#ifdef __Windows__
|
||||
int delay_s(unsigned int s)
|
||||
{
|
||||
Sleep(s * 1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delay_ms(unsigned int s)
|
||||
{
|
||||
Sleep(s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int delay_s(unsigned int s)
|
||||
{
|
||||
return sleep(s);
|
||||
}
|
||||
|
||||
int delay_ms(unsigned int s)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
ts.tv_sec = s / 1000;
|
||||
ts.tv_nsec = (s % 1000) * 1000000;
|
||||
|
||||
return nanosleep(&ts, NULL);
|
||||
}
|
||||
#endif
|
||||
|
|
17
util/util.h
17
util/util.h
|
@ -24,8 +24,6 @@
|
|||
|
||||
#ifdef __Windows__
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
@ -71,17 +69,8 @@ HANDLE ctrlc_win32_event(void);
|
|||
/* Expand `~' in path names. Caller must free the returned ptr */
|
||||
char *expand_tilde(const char *path);
|
||||
|
||||
/* Sleep for a number of seconds */
|
||||
#ifdef __Windows__
|
||||
static inline void delay_s(unsigned int s)
|
||||
{
|
||||
Sleep(s * 1000);
|
||||
}
|
||||
#else
|
||||
static inline void delay_s(unsigned int s)
|
||||
{
|
||||
sleep(s);
|
||||
}
|
||||
#endif
|
||||
/* Sleep for a number of seconds (_s) or milliseconds (_ms) */
|
||||
int delay_s(unsigned int s);
|
||||
int delay_ms(unsigned int s);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue