1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-17 01:36:13 +02:00
ben-wpan/tools/atspi-txrx/atspi-txrx.c

241 lines
5.2 KiB
C
Raw Normal View History

/*
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
* atspi-txrx/atspi-txrx.c - ben-wpan AT86RF230 TX/RX
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
*
* 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.
*/
#include <stdint.h>
#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>
#include <string.h>
#include <math.h>
#include <signal.h>
#include "at86rf230.h"
#include "atspi.h"
#include "misctxrx.h"
/*
* 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 */
static double tx_pwr[] = {
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
};
static volatile int run = 1;
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
static struct atspi_dsc *init_txrx(int trim)
{
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
struct atspi_dsc *dsc;
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
dsc = atspi_open();
if (!dsc)
exit(1);
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
atspi_reset_rf(dsc);
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
#ifdef HAVE_USB /* @@@ yeah, ugly */
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
atspi_reg_write(dsc, REG_XOSC_CTRL,
(XTAL_MODE_INT << XTAL_MODE_SHIFT) | trim);
#else
atspi_reg_write(dsc, REG_XOSC_CTRL, XTAL_MODE_EXT << XTAL_MODE_SHIFT);
#endif
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
atspi_reg_write(dsc, REG_TRX_CTRL_0, 0); /* disable CLKM */
(void) atspi_reg_read(dsc, REG_IRQ_STATUS);
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;
}
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
static void set_channel(struct atspi_dsc *dsc, int channel)
{
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
atspi_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
}
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
static void set_power(struct atspi_dsc *dsc, double power)
{
int n;
for (n = 0; n != sizeof(tx_pwr)/sizeof(*tx_pwr)-1; n++)
if (tx_pwr[n] <= power)
break;
if (fabs(tx_pwr[n]-power) > 0.01)
fprintf(stderr, "TX power %.1f dBm\n", tx_pwr[n]);
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
atspi_reg_write(dsc, REG_PHY_TX_PWR, TX_AUTO_CRC_ON | n);
}
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
static void receive(struct atspi_dsc *dsc)
{
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
int n, ok, i;
uint8_t ed, lqi;
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
atspi_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);
fprintf(stderr, "Ready.\n");
wait_for_interrupt(dsc, IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START,
10, 0);
if (!run)
return;
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
n = atspi_buf_read(dsc, buf, sizeof(buf));
if (n < 0)
exit(1);
if (n < 3) {
fprintf(stderr, "%d bytes received\n", n);
exit(1);
}
ed = atspi_reg_read(dsc, REG_PHY_ED_LEVEL);
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
ok = !!(atspi_reg_read(dsc, REG_PHY_RSSI) & RX_CRC_VALID);
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);
for (i = 0; i != n-3; i++)
putchar(buf[i] < ' ' || buf[i] > '~' ? '?' : buf[i]);
putchar('\n');
}
static void transmit(struct atspi_dsc *dsc, const char *msg, int times)
{
uint8_t buf[MAX_PSDU];
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
atspi_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);
/*
* We need to copy the message to append the CRC placeholders.
*/
strcpy((void *) buf, msg);
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
atspi_buf_write(dsc, buf, strlen(msg)+2);
while (run && times--) {
/* @@@ should wait for clear channel */
atspi_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);
}
}
static void die(int sig)
{
run = 0;
}
static void usage(const char *name)
{
fprintf(stderr,
"usage: %s [-c channel] [-p power] [-t trim] [message [repetitions]]\n"
" -c channel channel number, 11 to 26 (default %d)\n"
" -p power transmit power, -17.2 to 3.0 dBm (default %.1f)\n"
" -t trim trim capacitor, 0 to 15 (default 0)\n"
, name , DEFAULT_CHANNEL, DEFAULT_POWER);
exit(1);
}
int main(int argc, char *const *argv)
{
int channel = DEFAULT_CHANNEL;
double power = DEFAULT_POWER;
int trim = 0, times = 1;
char *end;
int c;
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
struct atspi_dsc *dsc;
while ((c = getopt(argc, argv, "c:p:t:")) != EOF)
switch (c) {
case 'c':
channel = strtoul(optarg, &end, 0);
if (*end)
usage(*argv);
if (channel < 11 || channel > 26)
usage(*argv);
break;
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;
default:
usage(*argv);
}
signal(SIGINT, die);
switch (argc-optind) {
case 0:
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
dsc = init_txrx(trim);
set_channel(dsc, channel);
receive(dsc);
break;
case 2:
times = strtoul(argv[optind+1], &end, 0);
if (*end)
usage(*argv);
/* fall through */
case 1:
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
dsc = init_txrx(trim);
set_channel(dsc, channel);
set_power(dsc, power);
transmit(dsc, argv[optind], times);
break;
default:
usage(*argv);
}
atspi_close(dsc);
return 0;
}