2010-08-21 07:42:58 +03:00
|
|
|
/*
|
2010-11-11 15:24:22 +02:00
|
|
|
* atrf-txrx/atrf-txrx.c - ben-wpan AT86RF230 TX/RX
|
2010-08-21 07:42:58 +03:00
|
|
|
*
|
2011-01-07 18:49:52 +02:00
|
|
|
* Written 2010-2011 by Werner Almesberger
|
|
|
|
* Copyright 2010-2011 Werner Almesberger
|
2010-08-21 07:42:58 +03:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-09-09 23:42:47 +03:00
|
|
|
#include <stdint.h>
|
2010-08-21 07:42:58 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
#include <unistd.h>
|
2010-08-24 12:16:48 +03:00
|
|
|
#include <string.h>
|
2010-09-14 23:12:03 +03:00
|
|
|
#include <math.h>
|
|
|
|
#include <signal.h>
|
2010-11-12 02:31:15 +02:00
|
|
|
#include <sys/wait.h>
|
2011-01-19 08:22:24 +02:00
|
|
|
#include <sys/time.h>
|
2010-08-21 07:42:58 +03:00
|
|
|
|
|
|
|
#include "at86rf230.h"
|
The Great ATSPI Renaming, part 4: rename include/atspi.h to include/atrf.h
- include/atspi.h: renamed to include/atrf.h
- include/misctxrx.h, lib/atrf.c, lib/misctxrx.c, atspi-id/atspi-id.c,
atspi-reset/atspi-reset.c, atspi-rssi/atspi-rssi.c, atspi-rssi/gui.c,
atspi-rssi/gui.h, atspi-trim/atspi-trim.c, atspi-txrx/atspi-txrx.c:
change #include "atspi.h" to #include "atrf.h"
2010-11-11 13:58:47 +02:00
|
|
|
#include "atrf.h"
|
2010-09-09 23:42:47 +03:00
|
|
|
#include "misctxrx.h"
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2011-01-19 08:22:24 +02:00
|
|
|
#include "pcap.h"
|
|
|
|
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
/*
|
|
|
|
* According to IEEE 802.15.4-2003 section E.2.6, channel 15 is the only
|
|
|
|
* channel that falls into the 802.11 guard bands in North America an Europe.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_CHANNEL 15 /* channel 15, 2425 MHz */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit power, dBm. IEEE 802.15.4-2003 section E.3.1.3 specifies a transmit
|
|
|
|
* power of 0 dBm for IEEE 802.15.4. We assume an antenna gain of 3 dB or
|
|
|
|
* better.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_POWER -3.2 /* transmit power, dBm */
|
|
|
|
|
|
|
|
|
2011-01-07 18:49:52 +02:00
|
|
|
static double tx_pwr_230[] = {
|
2010-08-24 12:16:48 +03:00
|
|
|
3.0, 2.6, 2.1, 1.6,
|
|
|
|
1.1, 0.5, -0.2, -1.2,
|
|
|
|
-2.2, -3.2, -4.2, -5.2,
|
|
|
|
-7.2, -9.2, -12.2, -17.2
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-07 18:49:52 +02:00
|
|
|
static double tx_pwr_231[] = {
|
|
|
|
3.0, 2.8, 2.3, 1.8,
|
|
|
|
1.3, 0.7, 0.0, -1,
|
|
|
|
-2, -3, -4, -5,
|
|
|
|
-7, -9, -12, -17
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
static volatile int run = 1;
|
|
|
|
|
|
|
|
|
2011-01-13 00:13:21 +02:00
|
|
|
/*
|
|
|
|
* clkm: 0 disable CLKM
|
|
|
|
* >0 output 2^(clkm-1) MHz signal
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct atrf_dsc *init_txrx(int trim, unsigned clkm)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
struct atrf_dsc *dsc;
|
2010-08-24 12:16:48 +03:00
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
dsc = atrf_open();
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
if (!dsc)
|
2010-08-24 12:16:48 +03:00
|
|
|
exit(1);
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reset_rf(dsc);
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
|
2011-01-13 00:13:21 +02:00
|
|
|
|
2011-01-16 21:03:11 +02:00
|
|
|
#if 1 // def HAVE_USB /* @@@ yeah, ugly */
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_XOSC_CTRL,
|
2010-08-24 12:16:48 +03:00
|
|
|
(XTAL_MODE_INT << XTAL_MODE_SHIFT) | trim);
|
Updated atusd driver for new hardware. Make use of the interrupt line.
- tools/lib/atusd.c (spi_send_partial, spi_send): removed the old spi_send
and renamed spi_send_partial to spi_send
- tools/lib/atusd.c (atusd_cycle, spi_send, spi_recv, atusd_open): updated
for removal of SLP_TR and split of MxSx into MOSI and MISO
- tools/lib/atusd.c (atusd_reset_rf, atusd_open): added delays to precharge
the capacitors
- tools/lib/atusd.c (atusd_reset, spi_data_in, spi_data_out, spi_finish):
removed functions for obsolete hardware features
- tools/lib/atusd.c (atusd_reg_read): removed calls to removed functions
- tools/lib/atusd.c (atusd_buf_write, atusd_buf_read, atusd_driver): new
buffer read/write functions
- tools/atspi-txrx/atspi-txrx.c (init_txrx): set the internal osciallator
trim only in the USB version. Switch to the external oscillator in the
uSD version.
- tools/atspi-rssi/atspi-rssi.c (sweep), tools/atspi-txrx/atspi-txrx.c
(set_channel): wait for the PLL to settle after setting the channel
- tools/include/atspi.h, tools/lib/atspi.c (atspi_interrupt),
tools/lib/driver.h (struct atspi_driver), tools/lib/atusd.c
(atusd_interrupt): new function to poll the interrupt line
- tools/atspi-txrx/atspi-txrx.c (receive): only read REG_IRQ_STATUS if
there is a pending interrupt
- tools/atspi-id/atspi-id.c (usage): print "usage:" as well
- tools/Makefile (upload): upload the atspi tools to the Ben
2010-09-09 15:19:06 +03:00
|
|
|
#else
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_XOSC_CTRL, XTAL_MODE_EXT << XTAL_MODE_SHIFT);
|
Updated atusd driver for new hardware. Make use of the interrupt line.
- tools/lib/atusd.c (spi_send_partial, spi_send): removed the old spi_send
and renamed spi_send_partial to spi_send
- tools/lib/atusd.c (atusd_cycle, spi_send, spi_recv, atusd_open): updated
for removal of SLP_TR and split of MxSx into MOSI and MISO
- tools/lib/atusd.c (atusd_reset_rf, atusd_open): added delays to precharge
the capacitors
- tools/lib/atusd.c (atusd_reset, spi_data_in, spi_data_out, spi_finish):
removed functions for obsolete hardware features
- tools/lib/atusd.c (atusd_reg_read): removed calls to removed functions
- tools/lib/atusd.c (atusd_buf_write, atusd_buf_read, atusd_driver): new
buffer read/write functions
- tools/atspi-txrx/atspi-txrx.c (init_txrx): set the internal osciallator
trim only in the USB version. Switch to the external oscillator in the
uSD version.
- tools/atspi-rssi/atspi-rssi.c (sweep), tools/atspi-txrx/atspi-txrx.c
(set_channel): wait for the PLL to settle after setting the channel
- tools/include/atspi.h, tools/lib/atspi.c (atspi_interrupt),
tools/lib/driver.h (struct atspi_driver), tools/lib/atusd.c
(atusd_interrupt): new function to poll the interrupt line
- tools/atspi-txrx/atspi-txrx.c (receive): only read REG_IRQ_STATUS if
there is a pending interrupt
- tools/atspi-id/atspi-id.c (usage): print "usage:" as well
- tools/Makefile (upload): upload the atspi tools to the Ben
2010-09-09 15:19:06 +03:00
|
|
|
#endif
|
2011-01-13 00:13:21 +02:00
|
|
|
|
|
|
|
if (!clkm)
|
|
|
|
atrf_reg_write(dsc, REG_TRX_CTRL_0, 0); /* disable CLKM */
|
|
|
|
else
|
|
|
|
atrf_reg_write(dsc, REG_TRX_CTRL_0,
|
|
|
|
(PAD_IO_8mA << PAD_IO_CLKM_SHIFT) | clkm);
|
2010-08-24 12:16:48 +03:00
|
|
|
|
2011-01-10 00:32:05 +02:00
|
|
|
/* We want to see all interrupts, not only the ones we're expecting. */
|
|
|
|
atrf_reg_write(dsc, REG_IRQ_MASK, 0xff);
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
(void) atrf_reg_read(dsc, REG_IRQ_STATUS);
|
2011-01-10 00:32:05 +02:00
|
|
|
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 */
|
2010-09-09 23:23:47 +03:00
|
|
|
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
return dsc;
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
static void set_channel(struct atrf_dsc *dsc, int channel)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
static void set_power(struct atrf_dsc *dsc, double power, int crc)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
2011-01-07 18:49:52 +02:00
|
|
|
const double *tx_pwr;
|
2010-08-24 12:16:48 +03:00
|
|
|
int n;
|
2011-01-07 18:49:52 +02:00
|
|
|
uint8_t tmp;
|
|
|
|
|
|
|
|
switch (atrf_identify(dsc)) {
|
|
|
|
case artf_at86rf230:
|
|
|
|
tx_pwr = tx_pwr_230;
|
|
|
|
break;
|
|
|
|
case artf_at86rf231:
|
|
|
|
tx_pwr = tx_pwr_231;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n != sizeof(tx_pwr_230)/sizeof(*tx_pwr_230)-1; n++)
|
2010-08-24 12:16:48 +03:00
|
|
|
if (tx_pwr[n] <= power)
|
|
|
|
break;
|
2010-09-14 23:12:03 +03:00
|
|
|
if (fabs(tx_pwr[n]-power) > 0.01)
|
|
|
|
fprintf(stderr, "TX power %.1f dBm\n", tx_pwr[n]);
|
2011-01-07 18:49:52 +02:00
|
|
|
|
|
|
|
switch (atrf_identify(dsc)) {
|
|
|
|
case artf_at86rf230:
|
|
|
|
atrf_reg_write(dsc, REG_PHY_TX_PWR,
|
2011-01-07 19:31:27 +02:00
|
|
|
(crc ? TX_AUTO_CRC_ON_230 : 0) | n);
|
2011-01-07 18:49:52 +02:00
|
|
|
break;
|
|
|
|
case artf_at86rf231:
|
|
|
|
tmp = atrf_reg_read(dsc, REG_PHY_TX_PWR);
|
|
|
|
tmp = (tmp & ~TX_PWR_MASK) | n;
|
|
|
|
atrf_reg_write(dsc, REG_PHY_TX_PWR, tmp);
|
|
|
|
atrf_reg_write(dsc, REG_TRX_CTRL_1,
|
2011-01-07 19:31:27 +02:00
|
|
|
crc ? TX_AUTO_CRC_ON : 0);
|
2011-01-07 18:49:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 08:22:24 +02:00
|
|
|
static void receive_message(struct atrf_dsc *dsc)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
2010-08-25 03:03:39 +03:00
|
|
|
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
|
2010-08-24 12:16:48 +03:00
|
|
|
int n, ok, i;
|
2010-09-09 23:23:47 +03:00
|
|
|
uint8_t ed, lqi;
|
2010-08-24 12:16:48 +03:00
|
|
|
|
|
|
|
fprintf(stderr, "Ready.\n");
|
2010-09-09 23:23:47 +03:00
|
|
|
wait_for_interrupt(dsc, IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START,
|
|
|
|
10, 0);
|
2010-09-14 23:12:03 +03:00
|
|
|
if (!run)
|
|
|
|
return;
|
2010-08-24 12:16:48 +03:00
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
n = atrf_buf_read(dsc, buf, sizeof(buf));
|
2010-08-24 12:16:48 +03:00
|
|
|
if (n < 0)
|
|
|
|
exit(1);
|
|
|
|
if (n < 3) {
|
|
|
|
fprintf(stderr, "%d bytes received\n", n);
|
|
|
|
exit(1);
|
|
|
|
}
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
ed = atrf_reg_read(dsc, REG_PHY_ED_LEVEL);
|
|
|
|
ok = !!(atrf_reg_read(dsc, REG_PHY_RSSI) & RX_CRC_VALID);
|
2010-09-09 23:23:47 +03:00
|
|
|
lqi = buf[n-1];
|
|
|
|
fprintf(stderr, "%d bytes payload, CRC %s, LQI %u, ED %d dBm\n",
|
|
|
|
n-3, ok ? "OK" : "BAD", lqi, -91+ed);
|
2010-08-24 12:16:48 +03:00
|
|
|
for (i = 0; i != n-3; i++)
|
|
|
|
putchar(buf[i] < ' ' || buf[i] > '~' ? '?' : buf[i]);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 08:22:24 +02:00
|
|
|
static void write_pcap_hdr(FILE *file)
|
|
|
|
{
|
|
|
|
struct pcap_file_header hdr = {
|
|
|
|
.magic = 0xa1b2c3d4,
|
|
|
|
.version_major = 2,
|
|
|
|
.version_minor = 4,
|
|
|
|
.thiszone = 0,
|
|
|
|
.sigfigs = 0,
|
|
|
|
.snaplen = MAX_PSDU,
|
|
|
|
.linktype = DLT_IEEE802_15_4
|
|
|
|
};
|
|
|
|
|
|
|
|
if (fwrite(&hdr, sizeof(hdr), 1, file) != 1) {
|
|
|
|
perror("fwrite");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_pcap_rec(FILE *file, const struct timeval *tv,
|
|
|
|
const void *buf, int n)
|
|
|
|
{
|
|
|
|
struct pcap_pkthdr hdr = {
|
|
|
|
.ts_sec = tv->tv_sec,
|
|
|
|
.ts_usec = tv->tv_usec,
|
|
|
|
.caplen = n,
|
|
|
|
.len = n
|
|
|
|
};
|
|
|
|
|
|
|
|
if (fwrite(&hdr, sizeof(hdr), 1, file) != 1) {
|
|
|
|
perror("fwrite");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (fwrite(buf, n, 1, file) != 1) {
|
|
|
|
perror("fwrite");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void receive_pcap(struct atrf_dsc *dsc, const char *name)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
|
|
|
|
struct timeval now;
|
|
|
|
int n;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
file = fopen(name, "w");
|
|
|
|
if (!file) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
write_pcap_hdr(file);
|
|
|
|
while (run) {
|
|
|
|
wait_for_interrupt(dsc,
|
|
|
|
IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START,
|
|
|
|
10, 0);
|
|
|
|
if (!run)
|
|
|
|
break;
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
n = atrf_buf_read(dsc, buf, sizeof(buf));
|
|
|
|
if (n < 0)
|
|
|
|
exit(1);
|
|
|
|
if (n < 2) {
|
|
|
|
fprintf(stderr, "%d bytes received\n", n);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
write_pcap_rec(file, &now, buf, n-1);
|
|
|
|
(void) write(2, ".", 1);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (fclose(file) == EOF) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%sreceived %d message%s\n", count ? "\n" : "",
|
|
|
|
count, count == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void receive(struct atrf_dsc *dsc, const char *name)
|
|
|
|
{
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
receive_pcap(dsc, name);
|
|
|
|
else
|
|
|
|
receive_message(dsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
static void transmit(struct atrf_dsc *dsc, const char *msg, int times)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
|
|
|
uint8_t buf[MAX_PSDU];
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
2010-09-09 23:23:47 +03:00
|
|
|
/*
|
|
|
|
* 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);
|
2010-08-24 12:16:48 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to copy the message to append the CRC placeholders.
|
|
|
|
*/
|
|
|
|
strcpy((void *) buf, msg);
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_buf_write(dsc, buf, strlen(msg)+2);
|
2010-08-24 12:16:48 +03:00
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
while (run && times--) {
|
|
|
|
/* @@@ should wait for clear channel */
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
2010-09-09 23:23:47 +03:00
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
/* wait up to 10 ms (nominally) */
|
|
|
|
wait_for_interrupt(dsc, IRQ_TRX_END,
|
|
|
|
IRQ_TRX_END | IRQ_PLL_LOCK, 10, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-07 19:59:23 +02:00
|
|
|
static void enter_test_mode_230(struct atrf_dsc *dsc, uint8_t cont_tx)
|
2010-11-11 07:32:09 +02:00
|
|
|
{
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_buf_write(dsc, "", 1);
|
|
|
|
atrf_reg_write(dsc, REG_CONT_TX_0, CONT_TX_MAGIC);
|
|
|
|
atrf_reg_write(dsc, REG_CONT_TX_1, cont_tx);
|
2010-11-11 07:32:09 +02:00
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
if (!atrf_test_mode(dsc)) {
|
|
|
|
atrf_reset_rf(dsc);
|
2010-11-11 07:32:09 +02:00
|
|
|
fprintf(stderr, "device does not support test mode\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
2010-11-11 07:32:09 +02:00
|
|
|
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
2011-01-07 19:59:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void enter_test_mode_231(struct atrf_dsc *dsc, uint8_t cont_tx)
|
|
|
|
{
|
|
|
|
uint8_t buf[127];
|
2011-01-10 01:16:11 +02:00
|
|
|
uint8_t status;
|
2011-01-07 19:59:23 +02:00
|
|
|
|
|
|
|
switch (cont_tx) {
|
|
|
|
case CONT_TX_M2M:
|
|
|
|
fprintf(stderr,
|
|
|
|
"-2 MHz mode is not supported by the AT86RF231\n");
|
2011-01-10 05:14:35 +02:00
|
|
|
atrf_close(dsc);
|
|
|
|
exit(1);
|
2011-01-07 19:59:23 +02:00
|
|
|
case CONT_TX_M500K:
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
break;
|
|
|
|
case CONT_TX_P500K:
|
|
|
|
memset(buf, 0xff, sizeof(buf));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_IRQ_MASK, IRQ_PLL_LOCK); /* 2 */
|
|
|
|
atrf_reg_write(dsc, REG_TRX_CTRL_1, 0); /* 3 */
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_FORCE_TRX_OFF); /* 4 */
|
2011-01-13 00:23:53 +02:00
|
|
|
/* deleted step 5 - we don't need to enable CLKM */
|
2011-01-10 01:16:11 +02:00
|
|
|
|
|
|
|
status = atrf_reg_read(dsc, REG_TRX_STATUS) & TRX_STATUS_MASK; /* 8 */
|
|
|
|
if (status != TRX_STATUS_TRX_OFF) {
|
|
|
|
fprintf(stderr, "expected status 0x%02x, got 0x%02x\n",
|
|
|
|
TRX_STATUS_TRX_OFF, status);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-01-07 19:59:23 +02:00
|
|
|
atrf_reg_write(dsc, REG_CONT_TX_0, CONT_TX_MAGIC); /* 9 */
|
|
|
|
atrf_reg_write(dsc, REG_TRX_CTRL_2, OQPSK_DATA_RATE_2000); /*10 */
|
|
|
|
atrf_reg_write(dsc, REG_RX_CTRL, 0xa7); /*11 */
|
|
|
|
|
|
|
|
atrf_buf_write(dsc, buf, sizeof(buf)); /*12 */
|
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_PART_NUM, 0x54); /*13 */
|
|
|
|
atrf_reg_write(dsc, REG_PART_NUM, 0x46); /*14 */
|
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON); /*15 */
|
2011-01-10 01:16:11 +02:00
|
|
|
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 0); /*16 */
|
2011-01-07 19:59:23 +02:00
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START); /*17 */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 17:24:20 +02:00
|
|
|
static void transmit_pattern(struct atrf_dsc *dsc, double pause_s, int times)
|
|
|
|
{
|
|
|
|
uint8_t buf[MAX_PSDU];
|
|
|
|
uint8_t n = 0;
|
|
|
|
int us = fmod(pause_s, 1)*1000000;
|
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
while (run) {
|
|
|
|
memset(buf, n, sizeof(buf));
|
|
|
|
atrf_buf_write(dsc, buf, sizeof(buf));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (pause_s >= 1)
|
|
|
|
sleep(pause_s);
|
|
|
|
if (us)
|
|
|
|
usleep(us);
|
|
|
|
|
|
|
|
if (times && !--times)
|
|
|
|
break;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-07 19:59:23 +02:00
|
|
|
|
|
|
|
static int test_mode(struct atrf_dsc *dsc, uint8_t cont_tx, const char *cmd)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
switch (atrf_identify(dsc)) {
|
|
|
|
case artf_at86rf230:
|
|
|
|
enter_test_mode_230(dsc, cont_tx);
|
|
|
|
break;
|
|
|
|
case artf_at86rf231:
|
|
|
|
enter_test_mode_231(dsc, cont_tx);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2010-11-11 07:32:09 +02:00
|
|
|
|
2010-11-12 02:31:15 +02:00
|
|
|
if (cmd)
|
|
|
|
status = system(cmd);
|
|
|
|
else {
|
|
|
|
while (run)
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
2011-01-07 19:59:23 +02:00
|
|
|
if (atrf_identify(dsc) == artf_at86rf231)
|
|
|
|
atrf_reg_write(dsc, REG_PART_NUM, 0);
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reset_rf(dsc);
|
2010-11-12 02:31:15 +02:00
|
|
|
|
|
|
|
return status;
|
2010-11-11 07:32:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
static void die(int sig)
|
|
|
|
{
|
|
|
|
run = 0;
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
2010-08-24 12:16:48 +03:00
|
|
|
fprintf(stderr,
|
2011-01-19 06:11:48 +02:00
|
|
|
"usage: %s [common_options] [message [repetitions]]\n"
|
2011-01-19 17:24:20 +02:00
|
|
|
" %s [common_options] -B pause_s [repetitions]\n"
|
2011-01-19 06:11:48 +02:00
|
|
|
" %s [common_options] -T offset [command]\n\n"
|
|
|
|
" text message mode:\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" message message string to send (if absent, receive)\n"
|
2011-01-19 06:11:48 +02:00
|
|
|
" repetitions number of times the message is sent (default 1)\n\n"
|
2011-01-19 17:24:20 +02:00
|
|
|
" BER test mode (transmit only):\n"
|
|
|
|
" -B pause_s seconds to pause between frames (floating-point)\n"
|
|
|
|
" repetitions number of messages to send (default: infinite)\n\n"
|
2011-01-19 06:11:48 +02:00
|
|
|
" constant wave test mode (transmit only):\n"
|
|
|
|
" -T offset test mode. offset is the frequency offset of the constant\n"
|
|
|
|
" wave in MHz: -2, -0.5, or +0.5\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" command shell command to run while transmitting (default: wait for\n"
|
|
|
|
" SIGINT instead)\n\n"
|
2011-01-19 08:22:24 +02:00
|
|
|
" common options: [-c channel|-f freq] [-C mhz] [-o file] [-p power] "
|
|
|
|
"[-t trim]\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" -c channel channel number, 11 to 26 (default %d)\n"
|
2011-01-13 00:13:21 +02:00
|
|
|
" -C mhz output clock at 1, 2, 4, 8, or 16 MHz (default: off)\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" -f freq frequency in MHz, 2405 to 2480 (default %d)\n"
|
2011-01-19 08:22:24 +02:00
|
|
|
" -o file write received data to a file in pcap format\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" -p power transmit power, -17.2 to 3.0 dBm (default %.1f)\n"
|
|
|
|
" -t trim trim capacitor, 0 to 15 (default 0)\n"
|
2011-01-19 17:24:20 +02:00
|
|
|
, name, name, name, DEFAULT_CHANNEL, 2405+5*(DEFAULT_CHANNEL-11),
|
2010-11-11 07:44:33 +02:00
|
|
|
DEFAULT_POWER);
|
2010-08-21 07:42:58 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
int main(int argc, char *const *argv)
|
2010-08-21 07:42:58 +03:00
|
|
|
{
|
2011-01-19 17:24:20 +02:00
|
|
|
enum {
|
|
|
|
mode_msg,
|
|
|
|
mode_ber,
|
|
|
|
mode_cont_tx,
|
|
|
|
} mode = mode_msg;
|
2010-08-24 12:16:48 +03:00
|
|
|
int channel = DEFAULT_CHANNEL;
|
|
|
|
double power = DEFAULT_POWER;
|
2010-09-14 23:12:03 +03:00
|
|
|
int trim = 0, times = 1;
|
2010-11-11 07:32:09 +02:00
|
|
|
uint8_t cont_tx = 0;
|
2011-01-19 17:24:20 +02:00
|
|
|
double pause_s = 0;
|
2010-08-24 12:16:48 +03:00
|
|
|
char *end;
|
2010-11-11 07:44:33 +02:00
|
|
|
int c, freq;
|
2011-01-13 00:13:21 +02:00
|
|
|
unsigned tmp, clkm = 0;
|
2010-11-12 02:31:15 +02:00
|
|
|
int status = 0;
|
2011-01-19 08:22:24 +02:00
|
|
|
const char *pcap_file = NULL;
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
struct atrf_dsc *dsc;
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2011-01-19 17:24:20 +02:00
|
|
|
while ((c = getopt(argc, argv, "B:c:C:f:o:p:t:T:")) != EOF)
|
2010-08-24 12:16:48 +03:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
channel = strtoul(optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
if (channel < 11 || channel > 26)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2010-11-11 07:44:33 +02:00
|
|
|
case 'f':
|
|
|
|
freq = strtoul(optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
if (freq % 5)
|
|
|
|
usage(*argv);
|
|
|
|
channel = (freq-2405)/5+11;
|
|
|
|
if (channel < 11 || channel > 26)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-01-19 08:22:24 +02:00
|
|
|
case 'o':
|
|
|
|
pcap_file = optarg;
|
|
|
|
break;
|
2010-08-24 12:16:48 +03:00
|
|
|
case 'p':
|
|
|
|
power = strtod(optarg, &end);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
trim = strtoul(optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
if (trim > 15)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-01-19 17:24:20 +02:00
|
|
|
case 'B':
|
|
|
|
mode = mode_ber;
|
|
|
|
pause_s = strtof(optarg, &end);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-01-13 00:13:21 +02:00
|
|
|
case 'C':
|
|
|
|
tmp = strtol(optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
if (!tmp)
|
|
|
|
usage(*argv);
|
|
|
|
for (clkm = 1; !(tmp & 1); tmp >>= 1)
|
|
|
|
clkm++;
|
|
|
|
if (tmp != 1 || clkm > 5)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2010-11-11 07:32:09 +02:00
|
|
|
case 'T':
|
2011-01-19 17:24:20 +02:00
|
|
|
mode = mode_cont_tx;
|
2010-11-11 07:32:09 +02:00
|
|
|
if (!strcmp(optarg, "-2"))
|
|
|
|
cont_tx = CONT_TX_M2M;
|
|
|
|
else if (!strcmp(optarg, "-0.5"))
|
|
|
|
cont_tx = CONT_TX_M500K;
|
|
|
|
else if (!strcmp(optarg, "+0.5"))
|
|
|
|
cont_tx = CONT_TX_P500K;
|
|
|
|
else
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2010-08-24 12:16:48 +03:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
signal(SIGINT, die);
|
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
switch (argc-optind) {
|
|
|
|
case 0:
|
2011-01-13 00:13:21 +02:00
|
|
|
dsc = init_txrx(trim, clkm);
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
set_channel(dsc, channel);
|
2011-01-19 17:24:20 +02:00
|
|
|
switch (mode) {
|
|
|
|
case mode_msg:
|
2011-01-19 08:22:24 +02:00
|
|
|
receive(dsc, pcap_file);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
|
|
|
case mode_ber:
|
|
|
|
set_power(dsc, power, 0);
|
|
|
|
transmit_pattern(dsc, pause_s, 0);
|
|
|
|
break;
|
|
|
|
case mode_cont_tx:
|
2010-11-11 07:32:09 +02:00
|
|
|
set_power(dsc, power, 0);
|
2010-11-12 02:31:15 +02:00
|
|
|
status = test_mode(dsc, cont_tx, NULL);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
2010-11-11 07:32:09 +02:00
|
|
|
}
|
2010-08-24 12:16:48 +03:00
|
|
|
break;
|
2010-09-14 23:12:03 +03:00
|
|
|
case 2:
|
2011-01-19 17:24:20 +02:00
|
|
|
switch (mode) {
|
|
|
|
case mode_msg:
|
|
|
|
break;
|
|
|
|
case mode_ber:
|
|
|
|
/* fall through */
|
|
|
|
case mode_cont_tx:
|
2010-11-12 02:31:15 +02:00
|
|
|
usage(*argv);
|
2011-01-19 17:24:20 +02:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2010-09-14 23:12:03 +03:00
|
|
|
times = strtoul(argv[optind+1], &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
/* fall through */
|
2010-08-24 12:16:48 +03:00
|
|
|
case 1:
|
2011-01-13 00:13:21 +02:00
|
|
|
dsc = init_txrx(trim, clkm);
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
set_channel(dsc, channel);
|
2011-01-19 17:24:20 +02:00
|
|
|
switch (mode) {
|
|
|
|
case mode_msg:
|
2010-11-12 02:31:15 +02:00
|
|
|
set_power(dsc, power, 1);
|
|
|
|
transmit(dsc, argv[optind], times);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
|
|
|
case mode_ber:
|
|
|
|
times = strtoul(argv[optind+1], &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
set_power(dsc, power, 0);
|
|
|
|
transmit_pattern(dsc, pause_s, times);
|
|
|
|
break;
|
|
|
|
case mode_cont_tx:
|
2010-11-12 02:31:15 +02:00
|
|
|
set_power(dsc, power, 0);
|
|
|
|
status = test_mode(dsc, cont_tx, argv[optind]);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
|
2010-11-12 02:31:15 +02:00
|
|
|
}
|
2010-08-24 12:16:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_close(dsc);
|
2010-09-09 23:23:47 +03:00
|
|
|
|
2010-11-12 02:31:15 +02:00
|
|
|
if (status) {
|
|
|
|
if (WIFEXITED(status))
|
|
|
|
return WEXITSTATUS(status);
|
|
|
|
if (WIFSIGNALED(status))
|
|
|
|
raise(WTERMSIG(status));
|
|
|
|
fprintf(stderr, "unexpected exit status %d\n", status);
|
|
|
|
abort();
|
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
return 0;
|
|
|
|
}
|