mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-25 18:57:11 +02:00
tools/lib/: aggressive polling for wait_for_interrupt, if timeout_ms = -1
This commit is contained in:
parent
7fd9044d94
commit
07b1da29ec
@ -19,6 +19,14 @@
|
|||||||
|
|
||||||
|
|
||||||
void flush_interrupts(struct atrf_dsc *dsc);
|
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 wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
|
||||||
uint8_t ignore, int timeout_ms);
|
uint8_t ignore, int timeout_ms);
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* lib/atben.c - ATRF access functions library (Ben 8:10 card version)
|
* lib/atben.c - ATRF access functions library (Ben 8:10 card version)
|
||||||
*
|
*
|
||||||
* Written 2010-2011 by Werner Almesberger
|
* Written 2010-2011, 2013 by Werner Almesberger
|
||||||
* Copyright 2010-2011 Werner Almesberger
|
* Copyright 2010-2011, 2013 Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* 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;
|
int timedout = 0;
|
||||||
uint8_t irq;
|
uint8_t irq;
|
||||||
|
|
||||||
if (timeout_ms)
|
if (timeout_ms > 0)
|
||||||
timeout_start(&to, timeout_ms);
|
timeout_start(&to, timeout_ms);
|
||||||
while (1) {
|
while (1) {
|
||||||
if (timeout_ms)
|
if (timeout_ms > 0)
|
||||||
timedout = timeout_reached(&to);
|
timedout = timeout_reached(&to);
|
||||||
if (atben_interrupt(handle)) {
|
if (atben_interrupt(handle)) {
|
||||||
irq = atben_reg_read(handle, REG_IRQ_STATUS);
|
irq = atben_reg_read(handle, REG_IRQ_STATUS);
|
||||||
@ -452,6 +452,7 @@ int atben_interrupt_wait(void *handle, int timeout_ms)
|
|||||||
}
|
}
|
||||||
if (timedout)
|
if (timedout)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (timeout_ms >= 0)
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ int atusb_interrupt_wait(void *handle, int timeout_ms)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
res = usb_bulk_read(dsc->dev, 1,
|
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)
|
if (res == -ETIMEDOUT)
|
||||||
return 0;
|
return 0;
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
@ -62,14 +62,14 @@ uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
|
|||||||
|
|
||||||
sigint = 0;
|
sigint = 0;
|
||||||
old_sig = signal(SIGINT, die);
|
old_sig = signal(SIGINT, die);
|
||||||
if (timeout_ms) {
|
if (timeout_ms > 0) {
|
||||||
if (timeout_ms < MIN_TIMEOUT_MS)
|
if (timeout_ms < MIN_TIMEOUT_MS)
|
||||||
timeout_ms = MIN_TIMEOUT_MS;
|
timeout_ms = MIN_TIMEOUT_MS;
|
||||||
timeout_start(&to, timeout_ms);
|
timeout_start(&to, timeout_ms);
|
||||||
}
|
}
|
||||||
while (!sigint && !timedout) {
|
while (!sigint && !timedout) {
|
||||||
while (!sigint && !timedout) {
|
while (!sigint && !timedout) {
|
||||||
if (timeout_ms) {
|
if (timeout_ms > 0) {
|
||||||
ms = timeout_left_ms(&to);
|
ms = timeout_left_ms(&to);
|
||||||
if (ms <= 0) {
|
if (ms <= 0) {
|
||||||
timedout = 1;
|
timedout = 1;
|
||||||
@ -78,7 +78,8 @@ uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
|
|||||||
} else {
|
} else {
|
||||||
ms = 0;
|
ms = 0;
|
||||||
}
|
}
|
||||||
irq = atrf_interrupt_wait(dsc, ms);
|
irq = atrf_interrupt_wait(dsc,
|
||||||
|
timeout_ms < 0 ? -1 : ms);
|
||||||
if (irq)
|
if (irq)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user