IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2010-09-09 22:56:04 (13 years 6 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 | ||
---|---|---|
13 | 13 | |
14 | 14 | #include <stdlib.h> |
15 | 15 | #include <stdio.h> |
16 | #include <signal.h> | |
16 | 17 | #include <sys/time.h> |
17 | 18 | |
18 | 19 | #include "at86rf230.h" |
19 | #include "atspi/ep0.h" | |
20 | 20 | #include "atspi.h" |
21 | #include "misctxrx.h" | |
21 | 22 | |
22 | 23 | |
23 | 24 | static struct timeval t0; |
25 | static volatile int run = 1; | |
24 | 26 | |
25 | 27 | |
26 | 28 | static void sweep(struct atspi_dsc *dsc) |
... | ... | |
31 | 33 | for (chan = 11; chan <= 26; chan++) { |
32 | 34 | atspi_reg_write(dsc, REG_PHY_CC_CCA, chan); |
33 | 35 | /* 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 | ||
35 | 38 | /* |
36 | 39 | * No need to explicitly wait for the PPL lock - going USB-SPI |
37 | 40 | * is pretty slow, leaving the transceiver plenty of time. |
... | ... | |
49 | 52 | } |
50 | 53 | |
51 | 54 | |
55 | static void die(int sig) | |
56 | { | |
57 | run = 0; | |
58 | } | |
59 | ||
60 | ||
52 | 61 | static void usage(const char *name) |
53 | 62 | { |
54 | fprintf(stderr, "%s sweeps \n", name); | |
63 | fprintf(stderr, "usage: %s sweeps \n", name); | |
55 | 64 | exit(1); |
56 | 65 | } |
57 | 66 | |
... | ... | |
68 | 77 | if (*end) |
69 | 78 | usage(*argv); |
70 | 79 | |
80 | signal(SIGINT, die); | |
81 | ||
71 | 82 | dsc = atspi_open(); |
72 | 83 | if (!dsc) |
73 | 84 | return 1; |
74 | 85 | |
75 | 86 | atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF); |
87 | atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON); | |
76 | 88 | /* |
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. | |
79 | 90 | */ |
80 | atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON); | |
81 | 91 | |
82 | 92 | gettimeofday(&t0, NULL); |
83 | for (i = 0; i != sweeps; i++) | |
93 | for (i = 0; run && i != sweeps; i++) | |
84 | 94 | sweep(dsc); |
85 | 95 | |
86 | 96 | atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF); |
87 | 97 | |
98 | atspi_close(dsc); | |
99 | ||
88 | 100 | return 0; |
89 | 101 | } |