Date:2011-06-21 00:58:31 (9 years 1 month ago)
Author:Werner Almesberger
Commit:b4a6e8ef460975999b30aef6e75d337b046984d1
Message: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
Files: tools/atrf-rssi/atrf-rssi.c (1 diff)
tools/atrf-rssi/gui.c (1 diff)
tools/atrf-txrx/atrf-txrx.c (10 diffs)
tools/atrf-xmit/atrf-xmit.c (3 diffs)
tools/include/misctxrx.h (1 diff)
tools/lib/cwtest.c (2 diffs)
tools/lib/misctxrx.c (2 diffs)

Change Details

tools/atrf-rssi/atrf-rssi.c
3636    for (chan = 11; chan <= 26; chan++) {
3737        atrf_reg_write(dsc, REG_PHY_CC_CCA, chan);
3838        /* 150 us, according to AVR2001 section 3.5 */
39        wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
39        wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
4040
4141        gettimeofday(&t, NULL);
4242        rssi = atrf_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
tools/atrf-rssi/gui.c
7474    for (chan = 11; chan <= 26; chan++) {
7575        atrf_reg_write(dsc, REG_PHY_CC_CCA, chan);
7676        /* 150 us, according to AVR2001 section 3.5 */
77        wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
77        wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
7878
7979        *z++ = Z_STEP*atrf_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
8080#if 0
tools/atrf-txrx/atrf-txrx.c
100100
101101    flush_interrupts(dsc);
102102    if (atrf_identify(dsc) == artf_at86rf231)
103        wait_for_interrupt(dsc, IRQ_CCA_ED_DONE, IRQ_CCA_ED_DONE,
104            10, 50); /* according to table 7-1, 37 us max */
103        wait_for_interrupt(dsc, IRQ_CCA_ED_DONE, IRQ_CCA_ED_DONE, 1);
104            /* according to table 7-1, 37 us max */
105105
106106    return dsc;
107107}
...... 
138138
139139    fprintf(stderr, "Ready.\n");
140140    wait_for_interrupt(dsc, IRQ_TRX_END,
141        IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 10, 0);
141        IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 0);
142142    if (!run)
143143        return;
144144
...... 
216216    write_pcap_hdr(file);
217217    while (run) {
218218        wait_for_interrupt(dsc,
219            IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START | IRQ_AMI,
220            10, 0);
219            IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 0);
221220        if (!run)
222221            break;
223222        gettimeofday(&now, NULL);
...... 
248247     * 180 us, according to AVR2001 section 4.2. We time out after
249248     * nominally 200 us.
250249     */
251    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
250    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
252251
253252    if (name)
254253        receive_pcap(dsc, name);
...... 
266265     * 180 us, according to AVR2001 section 4.3. We time out after
267266     * nominally 200 us.
268267     */
269    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
268    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
270269
271270    /*
272271     * We need to copy the message to append the CRC placeholders.
...... 
280279
281280        /* wait up to 10 ms (nominally) */
282281        wait_for_interrupt(dsc, IRQ_TRX_END,
283           IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000);
282           IRQ_TRX_END | IRQ_PLL_LOCK, 10);
284283    }
285284}
286285
...... 
296295     * 180 us, according to AVR2001 section 4.3. We time out after
297296     * nominally 200 us.
298297     */
299    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
298    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
300299
301300    while (run) {
302301        memset(buf, n, sizeof(buf));
...... 
306305
307306        /* wait up to 10 ms (nominally) */
308307        wait_for_interrupt(dsc, IRQ_TRX_END,
309           IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000);
308           IRQ_TRX_END | IRQ_PLL_LOCK, 10);
310309
311310        if (pause_s >= 1)
312311            sleep(pause_s);
...... 
327326     * 180 us, according to AVR2001 section 4.3. We time out after
328327     * nominally 200 us.
329328     */
330    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
329    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
331330
332331    atrf_buf_write(dsc, pck, sizeof(*pck));
333332    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
334333
335334    /* wait up to 10 ms (nominally) */
336335    wait_for_interrupt(dsc, IRQ_TRX_END,
337       IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000);
336       IRQ_TRX_END | IRQ_PLL_LOCK, 10);
338337}
339338
340339
341static enum rx_res ping_rx(struct atrf_dsc *dsc, struct ping *pck, int wait_ds)
340static enum rx_res ping_rx(struct atrf_dsc *dsc, struct ping *pck, int wait_ms)
342341{
343342    uint8_t irq;
344343    int n;
345344
346345    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
347346    irq = wait_for_interrupt(dsc, IRQ_TRX_END,
348        IRQ_TRX_END | IRQ_RX_START | IRQ_PLL_LOCK,
349        100000, wait_ds);
347        IRQ_TRX_END | IRQ_RX_START | IRQ_PLL_LOCK, wait_ms);
350348    if (!run)
351349        return rx_exit;
352350    if (!irq)
...... 
382380                break;
383381        }
384382        first = 0;
385        res = ping_rx(dsc, &rx_pck, master ? max_wait_s*10 : 0);
383        res = ping_rx(dsc, &rx_pck, master ? max_wait_s*1000 : 0);
386384        switch (res) {
387385        case rx_good:
388386            tx_pck.ack = rx_pck.seq;
tools/atrf-xmit/atrf-xmit.c
5454        buf[i] = i;
5555    atrf_buf_write(dsc, buf, sizeof(buf));
5656    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
57    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
57    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
5858}
5959
6060
...... 
6262{
6363    init_common(dsc, trim, channel);
6464    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
65    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
65    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
6666}
6767
6868
...... 
8484    atrf_slp_tr(tx, 1, 1);
8585#if 1
8686    irq = wait_for_interrupt(rx, IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START,
87        1000, 0);
87        0);
8888#else
8989    /*
9090     * Just waiting for the maximum time is much faster than polling the
tools/include/misctxrx.h
2020
2121void flush_interrupts(struct atrf_dsc *dsc);
2222uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
23    uint8_t ignore, int sleep_us, int timeout);
23    uint8_t ignore, int timeout_ms);
2424
2525int tx_power_dBm2step(struct atrf_dsc *dsc, double power);
2626double tx_power_step2dBm(struct atrf_dsc *dsc, int step);
tools/lib/cwtest.c
4949    }
5050
5151    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
52    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 0);
52    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 0);
5353
5454    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
5555}
...... 
102102    atrf_reg_write(dsc, REG_PART_NUM, 0x46); /*14 */
103103
104104    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON); /*15 */
105    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 0); /*16 */
105    wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 0); /*16 */
106106
107107    atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START); /*17 */
108108}
tools/lib/misctxrx.c
2020
2121#include "at86rf230.h"
2222#include "atrf.h"
23#include "timeout.h"
2324#include "misctxrx.h"
2425
2526
27#define MAX_WAIT_MS 100 /* make sure we respond to ^C */
28
29
2630/* ----- Interrupts -------------------------------------------------------- */
2731
2832
29static volatile int run = 1;
33static volatile int sigint;
3034
3135
3236static void die(int sig)
3337{
34    run = 0;
38    sigint = 1;
3539}
3640
3741
...... 
4751
4852
4953uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
50    uint8_t ignore, int sleep_us, int timeout)
54    uint8_t ignore, int timeout_ms)
5155{
56    struct timeout to;
5257    uint8_t irq = 0, show;
5358    void (*old_sig)(int);
59    int ms;
60    int timedout = 0;
5461
55    run = 1;
62    sigint = 0;
5663    old_sig = signal(SIGINT, die);
57    while (run) {
58        while (run && !atrf_interrupt(dsc)) {
59            usleep(sleep_us);
60            if (timeout && !--timeout) {
61                irq = 0;
62                goto out;
64    if (timeout_ms)
65        timeout_start(&to, timeout_ms);
66    while (!sigint && !timedout) {
67        while (!sigint && !timedout) {
68            if (timeout_ms) {
69                ms = timeout_left_ms(&to);
70                if (ms > 0) {
71                    if (ms > MAX_WAIT_MS)
72                        ms = MAX_WAIT_MS;
73                } else {
74                    timedout = 1;
75                    ms = 1;
76                }
77            } else {
78                ms = MAX_WAIT_MS;
6379            }
80            irq = atrf_interrupt_wait(dsc, ms);
81            if (irq)
82                break;
6483        }
65        irq = atrf_reg_read(dsc, REG_IRQ_STATUS);
84
6685        if (atrf_error(dsc))
6786            exit(1);
68        if (!irq)
69            continue;
87
7088        show = irq & ~ignore;
71        if (!show) {
72            if (irq & wait_for)
73                break;
74            continue;
89        if (show) {
90            fprintf(stderr, "IRQ (0x%02x):", irq);
91            if (irq & IRQ_PLL_LOCK)
92                fprintf(stderr, " PLL_LOCK");
93            if (irq & IRQ_PLL_UNLOCK)
94                fprintf(stderr, " PLL_UNLOCK");
95            if (irq & IRQ_RX_START)
96                fprintf(stderr, " RX_START");
97            if (irq & IRQ_TRX_END)
98                fprintf(stderr, " TRX_END");
99            if (irq & IRQ_CCA_ED_DONE)
100                fprintf(stderr, " CCA_ED_DONE");
101            if (irq & IRQ_AMI)
102                fprintf(stderr, " AMI");
103            if (irq & IRQ_TRX_UR)
104                fprintf(stderr, " TRX_UR");
105            if (irq & IRQ_BAT_LOW)
106                fprintf(stderr, " BAT_LOW");
107            fprintf(stderr, "\n");
75108        }
76        fprintf(stderr, "IRQ (0x%02x):", irq);
77        if (irq & IRQ_PLL_LOCK)
78            fprintf(stderr, " PLL_LOCK");
79        if (irq & IRQ_PLL_UNLOCK)
80            fprintf(stderr, " PLL_UNLOCK");
81        if (irq & IRQ_RX_START)
82            fprintf(stderr, " RX_START");
83        if (irq & IRQ_TRX_END)
84            fprintf(stderr, " TRX_END");
85        if (irq & IRQ_CCA_ED_DONE)
86            fprintf(stderr, " CCA_ED_DONE");
87        if (irq & IRQ_AMI)
88            fprintf(stderr, " AMI");
89        if (irq & IRQ_TRX_UR)
90            fprintf(stderr, " TRX_UR");
91        if (irq & IRQ_BAT_LOW)
92            fprintf(stderr, " BAT_LOW");
93        fprintf(stderr, "\n");
109
94110        if (irq & wait_for)
95111            break;
96112    }
97113out:
98114    signal(SIGINT, old_sig);
99    if (!run)
115    if (sigint)
100116        raise(SIGINT);
101117    return irq;
102118}

Archive Download the corresponding diff file



interactive