1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-22 08:48:26 +02:00

tools/lib/: aggressive polling for wait_for_interrupt, if timeout_ms = -1

This commit is contained in:
Werner Almesberger 2013-07-30 19:59:11 -03:00
parent 7fd9044d94
commit 07b1da29ec
4 changed files with 19 additions and 9 deletions

View File

@ -19,6 +19,14 @@
void flush_interrupts(struct atrf_dsc *dsc);
/*
* timeout_ms:
* > 0: time out after that many milliseconds
* == 0: wait forever
* < 0: wait forever and eliminate poll delays (for high-speed capture)
*/
uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
uint8_t ignore, int timeout_ms);

View File

@ -1,8 +1,8 @@
/*
* lib/atben.c - ATRF access functions library (Ben 8:10 card version)
*
* Written 2010-2011 by Werner Almesberger
* Copyright 2010-2011 Werner Almesberger
* Written 2010-2011, 2013 by Werner Almesberger
* Copyright 2010-2011, 2013 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -439,10 +439,10 @@ int atben_interrupt_wait(void *handle, int timeout_ms)
int timedout = 0;
uint8_t irq;
if (timeout_ms)
if (timeout_ms > 0)
timeout_start(&to, timeout_ms);
while (1) {
if (timeout_ms)
if (timeout_ms > 0)
timedout = timeout_reached(&to);
if (atben_interrupt(handle)) {
irq = atben_reg_read(handle, REG_IRQ_STATUS);
@ -452,6 +452,7 @@ int atben_interrupt_wait(void *handle, int timeout_ms)
}
if (timedout)
return 0;
if (timeout_ms >= 0)
usleep(1000);
}

View File

@ -221,7 +221,7 @@ int atusb_interrupt_wait(void *handle, int timeout_ms)
return 0;
res = usb_bulk_read(dsc->dev, 1,
(char *) &buf, sizeof(buf), timeout_ms);
(char *) &buf, sizeof(buf), timeout_ms < 0 : 0 : timeout_ms);
if (res == -ETIMEDOUT)
return 0;
if (res < 0) {

View File

@ -62,14 +62,14 @@ uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
sigint = 0;
old_sig = signal(SIGINT, die);
if (timeout_ms) {
if (timeout_ms > 0) {
if (timeout_ms < MIN_TIMEOUT_MS)
timeout_ms = MIN_TIMEOUT_MS;
timeout_start(&to, timeout_ms);
}
while (!sigint && !timedout) {
while (!sigint && !timedout) {
if (timeout_ms) {
if (timeout_ms > 0) {
ms = timeout_left_ms(&to);
if (ms <= 0) {
timedout = 1;
@ -78,7 +78,8 @@ uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
} else {
ms = 0;
}
irq = atrf_interrupt_wait(dsc, ms);
irq = atrf_interrupt_wait(dsc,
timeout_ms < 0 ? -1 : ms);
if (irq)
break;
}