mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2025-04-21 12:27:27 +03:00
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c (wait_for_interrupt): replaced sleep_us*timeout limiting mechanism with a single timeout value in milliseconds - lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead of polling - lib/misctxrx.c (wait_for_interrupt): cleaned up control flow - lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run" to more specific "sigint" - atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds, not deciseconds - atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep), atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap, receive, transmit, transmit_pattern, ping_tx, ping_rx), atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one), lib/cwtest.c (enter_test_mode_230, start_test_mode_231): updated use of wait_for_interrupt
This commit is contained in:
@@ -49,7 +49,7 @@ static void enter_test_mode_230(struct atrf_dsc *dsc, uint8_t cont_tx)
|
||||
}
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 0);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 0);
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ static void start_test_mode_231(struct atrf_dsc *dsc)
|
||||
atrf_reg_write(dsc, REG_PART_NUM, 0x46); /*14 */
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON); /*15 */
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 0); /*16 */
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 0); /*16 */
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START); /*17 */
|
||||
}
|
||||
|
||||
@@ -20,18 +20,22 @@
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "atrf.h"
|
||||
#include "timeout.h"
|
||||
#include "misctxrx.h"
|
||||
|
||||
|
||||
#define MAX_WAIT_MS 100 /* make sure we respond to ^C */
|
||||
|
||||
|
||||
/* ----- Interrupts -------------------------------------------------------- */
|
||||
|
||||
|
||||
static volatile int run = 1;
|
||||
static volatile int sigint;
|
||||
|
||||
|
||||
static void die(int sig)
|
||||
{
|
||||
run = 0;
|
||||
sigint = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,56 +51,68 @@ void flush_interrupts(struct atrf_dsc *dsc)
|
||||
|
||||
|
||||
uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
|
||||
uint8_t ignore, int sleep_us, int timeout)
|
||||
uint8_t ignore, int timeout_ms)
|
||||
{
|
||||
struct timeout to;
|
||||
uint8_t irq = 0, show;
|
||||
void (*old_sig)(int);
|
||||
int ms;
|
||||
int timedout = 0;
|
||||
|
||||
run = 1;
|
||||
sigint = 0;
|
||||
old_sig = signal(SIGINT, die);
|
||||
while (run) {
|
||||
while (run && !atrf_interrupt(dsc)) {
|
||||
usleep(sleep_us);
|
||||
if (timeout && !--timeout) {
|
||||
irq = 0;
|
||||
goto out;
|
||||
if (timeout_ms)
|
||||
timeout_start(&to, timeout_ms);
|
||||
while (!sigint && !timedout) {
|
||||
while (!sigint && !timedout) {
|
||||
if (timeout_ms) {
|
||||
ms = timeout_left_ms(&to);
|
||||
if (ms > 0) {
|
||||
if (ms > MAX_WAIT_MS)
|
||||
ms = MAX_WAIT_MS;
|
||||
} else {
|
||||
timedout = 1;
|
||||
ms = 1;
|
||||
}
|
||||
} else {
|
||||
ms = MAX_WAIT_MS;
|
||||
}
|
||||
irq = atrf_interrupt_wait(dsc, ms);
|
||||
if (irq)
|
||||
break;
|
||||
}
|
||||
irq = atrf_reg_read(dsc, REG_IRQ_STATUS);
|
||||
|
||||
if (atrf_error(dsc))
|
||||
exit(1);
|
||||
if (!irq)
|
||||
continue;
|
||||
|
||||
show = irq & ~ignore;
|
||||
if (!show) {
|
||||
if (irq & wait_for)
|
||||
break;
|
||||
continue;
|
||||
if (show) {
|
||||
fprintf(stderr, "IRQ (0x%02x):", irq);
|
||||
if (irq & IRQ_PLL_LOCK)
|
||||
fprintf(stderr, " PLL_LOCK");
|
||||
if (irq & IRQ_PLL_UNLOCK)
|
||||
fprintf(stderr, " PLL_UNLOCK");
|
||||
if (irq & IRQ_RX_START)
|
||||
fprintf(stderr, " RX_START");
|
||||
if (irq & IRQ_TRX_END)
|
||||
fprintf(stderr, " TRX_END");
|
||||
if (irq & IRQ_CCA_ED_DONE)
|
||||
fprintf(stderr, " CCA_ED_DONE");
|
||||
if (irq & IRQ_AMI)
|
||||
fprintf(stderr, " AMI");
|
||||
if (irq & IRQ_TRX_UR)
|
||||
fprintf(stderr, " TRX_UR");
|
||||
if (irq & IRQ_BAT_LOW)
|
||||
fprintf(stderr, " BAT_LOW");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
fprintf(stderr, "IRQ (0x%02x):", irq);
|
||||
if (irq & IRQ_PLL_LOCK)
|
||||
fprintf(stderr, " PLL_LOCK");
|
||||
if (irq & IRQ_PLL_UNLOCK)
|
||||
fprintf(stderr, " PLL_UNLOCK");
|
||||
if (irq & IRQ_RX_START)
|
||||
fprintf(stderr, " RX_START");
|
||||
if (irq & IRQ_TRX_END)
|
||||
fprintf(stderr, " TRX_END");
|
||||
if (irq & IRQ_CCA_ED_DONE)
|
||||
fprintf(stderr, " CCA_ED_DONE");
|
||||
if (irq & IRQ_AMI)
|
||||
fprintf(stderr, " AMI");
|
||||
if (irq & IRQ_TRX_UR)
|
||||
fprintf(stderr, " TRX_UR");
|
||||
if (irq & IRQ_BAT_LOW)
|
||||
fprintf(stderr, " BAT_LOW");
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
if (irq & wait_for)
|
||||
break;
|
||||
}
|
||||
out:
|
||||
signal(SIGINT, old_sig);
|
||||
if (!run)
|
||||
if (sigint)
|
||||
raise(SIGINT);
|
||||
return irq;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user