mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-25 18:57:11 +02: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:
parent
55354c7f91
commit
b4a6e8ef46
@ -36,7 +36,7 @@ static void sweep(struct atrf_dsc *dsc)
|
||||
for (chan = 11; chan <= 26; chan++) {
|
||||
atrf_reg_write(dsc, REG_PHY_CC_CCA, chan);
|
||||
/* 150 us, according to AVR2001 section 3.5 */
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
|
||||
gettimeofday(&t, NULL);
|
||||
rssi = atrf_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
|
||||
|
@ -74,7 +74,7 @@ static void sweep(struct atrf_dsc *dsc, int *z)
|
||||
for (chan = 11; chan <= 26; chan++) {
|
||||
atrf_reg_write(dsc, REG_PHY_CC_CCA, chan);
|
||||
/* 150 us, according to AVR2001 section 3.5 */
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
|
||||
*z++ = Z_STEP*atrf_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
|
||||
#if 0
|
||||
|
@ -100,8 +100,8 @@ static struct atrf_dsc *init_txrx(const char *driver, int trim, unsigned mhz)
|
||||
|
||||
flush_interrupts(dsc);
|
||||
if (atrf_identify(dsc) == artf_at86rf231)
|
||||
wait_for_interrupt(dsc, IRQ_CCA_ED_DONE, IRQ_CCA_ED_DONE,
|
||||
10, 50); /* according to table 7-1, 37 us max */
|
||||
wait_for_interrupt(dsc, IRQ_CCA_ED_DONE, IRQ_CCA_ED_DONE, 1);
|
||||
/* according to table 7-1, 37 us max */
|
||||
|
||||
return dsc;
|
||||
}
|
||||
@ -138,7 +138,7 @@ static void receive_message(struct atrf_dsc *dsc)
|
||||
|
||||
fprintf(stderr, "Ready.\n");
|
||||
wait_for_interrupt(dsc, IRQ_TRX_END,
|
||||
IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 10, 0);
|
||||
IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 0);
|
||||
if (!run)
|
||||
return;
|
||||
|
||||
@ -216,8 +216,7 @@ static void receive_pcap(struct atrf_dsc *dsc, const char *name)
|
||||
write_pcap_hdr(file);
|
||||
while (run) {
|
||||
wait_for_interrupt(dsc,
|
||||
IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START | IRQ_AMI,
|
||||
10, 0);
|
||||
IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 0);
|
||||
if (!run)
|
||||
break;
|
||||
gettimeofday(&now, NULL);
|
||||
@ -248,7 +247,7 @@ static void receive(struct atrf_dsc *dsc, const char *name)
|
||||
* 180 us, according to AVR2001 section 4.2. We time out after
|
||||
* nominally 200 us.
|
||||
*/
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
|
||||
if (name)
|
||||
receive_pcap(dsc, name);
|
||||
@ -266,7 +265,7 @@ static void transmit(struct atrf_dsc *dsc, const char *msg, int times)
|
||||
* 180 us, according to AVR2001 section 4.3. We time out after
|
||||
* nominally 200 us.
|
||||
*/
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
|
||||
/*
|
||||
* We need to copy the message to append the CRC placeholders.
|
||||
@ -280,7 +279,7 @@ static void transmit(struct atrf_dsc *dsc, const char *msg, int times)
|
||||
|
||||
/* wait up to 10 ms (nominally) */
|
||||
wait_for_interrupt(dsc, IRQ_TRX_END,
|
||||
IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000);
|
||||
IRQ_TRX_END | IRQ_PLL_LOCK, 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +295,7 @@ static void transmit_pattern(struct atrf_dsc *dsc, double pause_s, int times)
|
||||
* 180 us, according to AVR2001 section 4.3. We time out after
|
||||
* nominally 200 us.
|
||||
*/
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
|
||||
while (run) {
|
||||
memset(buf, n, sizeof(buf));
|
||||
@ -306,7 +305,7 @@ static void transmit_pattern(struct atrf_dsc *dsc, double pause_s, int times)
|
||||
|
||||
/* wait up to 10 ms (nominally) */
|
||||
wait_for_interrupt(dsc, IRQ_TRX_END,
|
||||
IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000);
|
||||
IRQ_TRX_END | IRQ_PLL_LOCK, 10);
|
||||
|
||||
if (pause_s >= 1)
|
||||
sleep(pause_s);
|
||||
@ -327,26 +326,25 @@ static void ping_tx(struct atrf_dsc *dsc, const struct ping *pck)
|
||||
* 180 us, according to AVR2001 section 4.3. We time out after
|
||||
* nominally 200 us.
|
||||
*/
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
|
||||
atrf_buf_write(dsc, pck, sizeof(*pck));
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
||||
|
||||
/* wait up to 10 ms (nominally) */
|
||||
wait_for_interrupt(dsc, IRQ_TRX_END,
|
||||
IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000);
|
||||
IRQ_TRX_END | IRQ_PLL_LOCK, 10);
|
||||
}
|
||||
|
||||
|
||||
static enum rx_res ping_rx(struct atrf_dsc *dsc, struct ping *pck, int wait_ds)
|
||||
static enum rx_res ping_rx(struct atrf_dsc *dsc, struct ping *pck, int wait_ms)
|
||||
{
|
||||
uint8_t irq;
|
||||
int n;
|
||||
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
|
||||
irq = wait_for_interrupt(dsc, IRQ_TRX_END,
|
||||
IRQ_TRX_END | IRQ_RX_START | IRQ_PLL_LOCK,
|
||||
100000, wait_ds);
|
||||
IRQ_TRX_END | IRQ_RX_START | IRQ_PLL_LOCK, wait_ms);
|
||||
if (!run)
|
||||
return rx_exit;
|
||||
if (!irq)
|
||||
@ -382,7 +380,7 @@ static void ping(struct atrf_dsc *dsc, double max_wait_s, int master)
|
||||
break;
|
||||
}
|
||||
first = 0;
|
||||
res = ping_rx(dsc, &rx_pck, master ? max_wait_s*10 : 0);
|
||||
res = ping_rx(dsc, &rx_pck, master ? max_wait_s*1000 : 0);
|
||||
switch (res) {
|
||||
case rx_good:
|
||||
tx_pck.ack = rx_pck.seq;
|
||||
|
@ -54,7 +54,7 @@ static void init_tx(struct atrf_dsc *dsc, int trim, int channel, int power)
|
||||
buf[i] = i;
|
||||
atrf_buf_write(dsc, buf, sizeof(buf));
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ static void init_rx(struct atrf_dsc *dsc, int trim, int channel)
|
||||
{
|
||||
init_common(dsc, trim, channel);
|
||||
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
||||
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ static int xfer_one(struct atrf_dsc *tx, struct atrf_dsc *rx)
|
||||
atrf_slp_tr(tx, 1, 1);
|
||||
#if 1
|
||||
irq = wait_for_interrupt(rx, IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START,
|
||||
1000, 0);
|
||||
0);
|
||||
#else
|
||||
/*
|
||||
* Just waiting for the maximum time is much faster than polling the
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
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);
|
||||
|
||||
int tx_power_dBm2step(struct atrf_dsc *dsc, double power);
|
||||
double tx_power_step2dBm(struct atrf_dsc *dsc, int step);
|
||||
|
@ -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,32 +51,42 @@ 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_reg_read(dsc, REG_IRQ_STATUS);
|
||||
irq = atrf_interrupt_wait(dsc, ms);
|
||||
if (irq)
|
||||
break;
|
||||
}
|
||||
|
||||
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");
|
||||
@ -91,12 +105,14 @@ uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user