Date:2010-09-09 22:56:04 (9 years 2 months ago)
Author:Werner Almesberger
Commit:4df6d2c2f976b41233768ab7fe6d37e4e166330e
Message:atspi-rssi cleanup: wait for interrupt, exit cleanly.

- tools/atspi-rssi/atspi-rssi.c: removed unnecessary inclusion of
atspi/ep0.h
- tools/atspi-rssi/atspi-rssi.c (sweep): instead of fixed delay, wait for
the PLL lock interrupt
- tools/atspi-rssi/atspi-rssi.c (die, main): catch SIGINT to exit cleanly
- tools/atspi-rssi/atspi-rssi.c (main): shut down properly when done
- tools/atspi-rssi/atspi-rssi.c (usage): print "usage:" before the program's
name
Files: tools/atspi-rssi/atspi-rssi.c (4 diffs)

Change Details

tools/atspi-rssi/atspi-rssi.c
1313
1414#include <stdlib.h>
1515#include <stdio.h>
16#include <signal.h>
1617#include <sys/time.h>
1718
1819#include "at86rf230.h"
19#include "atspi/ep0.h"
2020#include "atspi.h"
21#include "misctxrx.h"
2122
2223
2324static struct timeval t0;
25static volatile int run = 1;
2426
2527
2628static void sweep(struct atspi_dsc *dsc)
...... 
3133    for (chan = 11; chan <= 26; chan++) {
3234        atspi_reg_write(dsc, REG_PHY_CC_CCA, chan);
3335        /* 150 us, according to AVR2001 section 3.5 */
34        usleep(1000);
36        wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
37
3538        /*
3639         * No need to explicitly wait for the PPL lock - going USB-SPI
3740         * is pretty slow, leaving the transceiver plenty of time.
...... 
4952}
5053
5154
55static void die(int sig)
56{
57    run = 0;
58}
59
60
5261static void usage(const char *name)
5362{
54    fprintf(stderr, "%s sweeps \n", name);
63    fprintf(stderr, "usage: %s sweeps \n", name);
5564    exit(1);
5665}
5766
...... 
6877    if (*end)
6978        usage(*argv);
7079
80    signal(SIGINT, die);
81
7182    dsc = atspi_open();
7283    if (!dsc)
7384        return 1;
7485
7586    atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
87    atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
7688    /*
77     * No need to explicitly wait for things to stabilize - going USB-SPI
78     * is pretty slow, leaving the transceiver more than enough time.
89     * We'll wait for the PLL lock after selecting the channel.
7990     */
80    atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
8191
8292    gettimeofday(&t0, NULL);
83    for (i = 0; i != sweeps; i++)
93    for (i = 0; run && i != sweeps; i++)
8494        sweep(dsc);
8595
8696    atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
8797
98    atspi_close(dsc);
99
88100    return 0;
89101}

Archive Download the corresponding diff file



interactive