aboutsummaryrefslogtreecommitdiffstats
path: root/halfkay.c
diff options
context:
space:
mode:
Diffstat (limited to 'halfkay.c')
-rw-r--r--halfkay.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/halfkay.c b/halfkay.c
index 8158888..3f0aeec 100644
--- a/halfkay.c
+++ b/halfkay.c
@@ -86,16 +86,32 @@ static void usbclose(void)
hk_usb_hnd = NULL;
}
+/* TODO: move somewhere or consider a cleaner replacement */
+/* udelay: usleep replacement */
+static void udelay(unsigned long usec)
+{
+ enum { USECSEC = 1000000, NSECUSEC = 1000, };
+ struct timespec ts = {
+ .tv_sec = usec / USECSEC,
+ .tv_nsec = usec % USECSEC * NSECUSEC,
+ };
+ /* If we get interrupted, oh well */
+ nanosleep(&ts, NULL);
+}
+
static void usbsendcmd(void *data, size_t size, bool firstxfer)
{
unsigned int timeout = firstxfer ? TIMEOUT_FIRST : TIMEOUT;
int rc, attempt = 0;
- useconds_t delay = SEND_DELAY;
+ unsigned long delay = SEND_DELAY;
+
+ _Static_assert(SEND_DELAY << SEND_ATTEMPTS <= (1UL << 32) - 1,
+ "SEND_DELAY << SEND_ATTEMPTS > 2^32 - 1");
do {
rc = libusb_control_transfer(hk_usb_hnd, HK_USB_REQTYP, HK_USB_REQ,
HK_USB_VAL, 0, data, size, timeout);
- usleep(delay);
+ udelay(delay);
delay *= 2;
} while (rc == LIBUSB_ERROR_PIPE && ++attempt < SEND_ATTEMPTS);