mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2025-04-21 12:27:27 +03:00
Moved tools/ out of atrf, in preparation of merge with atusd.
- atrf/tools/: moved to tools/ - tools/Makefile: updated path to Makefile.recurse - tools/atspi-id/Makefile, tools/atspi-reset/Makefile, tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile, tools/atspi-txrx/Makefile, tools/lib/Makefile: updated paths to f32xbase and to atrf/fw/include
This commit is contained in:
17
tools/Makefile
Normal file
17
tools/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# tools/Makefile - Build the ATSPI-specific tools
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
DIRS=atspi-id atspi-reset atspi-rssi atspi-trim atspi-txrx
|
||||
TARGET_ONLY_DIRS=lib
|
||||
|
||||
include ../Makefile.recurse
|
||||
21
tools/atspi-id/Makefile
Normal file
21
tools/atspi-id/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# atspi-id/Makefile - Build the ATSPI identification utility
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
F32XBASE = ../../../f32xbase
|
||||
|
||||
MAIN = atspi-id
|
||||
|
||||
include $(F32XBASE)/lib/Makefile.common
|
||||
|
||||
CFLAGS += -I../../atrf/fw/include -I../include
|
||||
LDLIBS += -L../lib -latspi
|
||||
120
tools/atspi-id/atspi-id.c
Normal file
120
tools/atspi-id/atspi-id.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* atspi-id/atspi-id.c - Identify a ben-wpan AF86RF230 board
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <usb.h>
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "atspi/ep0.h"
|
||||
#include "atspi.h"
|
||||
|
||||
|
||||
#define FROM_DEV ATSPI_FROM_DEV(0)
|
||||
|
||||
#define BUF_SIZE 256
|
||||
|
||||
|
||||
|
||||
static int get_id(usb_dev_handle *dev, void *data, int size)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = usb_control_msg(dev, FROM_DEV, ATSPI_ID, 0, 0, data, size, 1000);
|
||||
if (res < 0)
|
||||
fprintf(stderr, "ATSPI_ID: %s\n", usb_strerror());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static int atspi_get_protocol(usb_dev_handle *dev,
|
||||
uint8_t *major, uint8_t *minor, uint8_t *target)
|
||||
{
|
||||
uint8_t ids[3];
|
||||
|
||||
if (get_id(dev, ids, 3) < 0)
|
||||
return -1;
|
||||
if (major)
|
||||
*major = ids[0];
|
||||
if (minor)
|
||||
*minor = ids[1];
|
||||
if (target)
|
||||
*target = ids[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int atspi_get_build(usb_dev_handle *dev, char *buf, size_t size)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = usb_control_msg(dev, FROM_DEV, ATSPI_BUILD, 0, 0, buf, size,
|
||||
1000);
|
||||
if (res < 0)
|
||||
fprintf(stderr, "ATSPI_BUILD: %s\n", usb_strerror());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void show_info(usb_dev_handle *dev)
|
||||
{
|
||||
const struct usb_device *device = usb_device(dev);
|
||||
uint8_t major, minor, target;
|
||||
char buf[BUF_SIZE+1]; /* +1 for terminating \0 */
|
||||
int len;
|
||||
uint8_t part, version, man_id_0, man_id_1;
|
||||
|
||||
printf("%04x:%04x ",
|
||||
device->descriptor.idVendor, device->descriptor.idProduct);
|
||||
|
||||
if (atspi_get_protocol(dev, &major, &minor, &target) < 0)
|
||||
exit(1);
|
||||
printf("protocol %u.%u hw %u\n", major, minor, target);
|
||||
|
||||
len = atspi_get_build(dev, buf, sizeof(buf)-1);
|
||||
if (len < 0)
|
||||
exit(1);
|
||||
buf[len] = 0;
|
||||
printf("%10s%s\n", "", buf);
|
||||
|
||||
part = atspi_reg_read(dev, REG_PART_NUM);
|
||||
version = atspi_reg_read(dev, REG_VERSION_NUM);
|
||||
man_id_0 = atspi_reg_read(dev, REG_MAN_ID_0);
|
||||
man_id_1 = atspi_reg_read(dev, REG_MAN_ID_1);
|
||||
printf("%10spart 0x%02x version %u manufacturer xxxx%02x%02x\n", "",
|
||||
part, version, man_id_1, man_id_0);
|
||||
}
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr, "%s\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
usb_dev_handle *dev;
|
||||
|
||||
if (argc != 1)
|
||||
usage(*argv);
|
||||
dev = atspi_open();
|
||||
if (!dev)
|
||||
return 1;
|
||||
|
||||
show_info(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
tools/atspi-reset/Makefile
Normal file
21
tools/atspi-reset/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# atspi-reset/Makefile - Reset the transceiver or the whole board
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
F32XBASE = ../../../f32xbase
|
||||
|
||||
MAIN = atspi-reset
|
||||
|
||||
include $(F32XBASE)/lib/Makefile.common
|
||||
|
||||
CFLAGS += -I../../atrf/fw/include -I../include
|
||||
LDLIBS += -L../lib -latspi
|
||||
62
tools/atspi-reset/atspi-reset.c
Normal file
62
tools/atspi-reset/atspi-reset.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* atspi-rssi/atspi-rssi.c - ben-wpan AF86RF230 spectrum scan
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <usb.h>
|
||||
|
||||
#include "atspi.h"
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s [-a|-t]\n\n"
|
||||
" -a reset the MCU and transceiver\n"
|
||||
" -t reset transceiver (default)\n"
|
||||
, name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
usb_dev_handle *dev;
|
||||
int txrx = 1;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
if (!strcmp(argv[1], "-t"))
|
||||
break;
|
||||
txrx = 0;
|
||||
if (!strcmp(argv[1], "-a"))
|
||||
break;
|
||||
/* fall through */
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
dev = atspi_open();
|
||||
if (!dev)
|
||||
return 1;
|
||||
|
||||
if (txrx)
|
||||
atspi_reset_rf(dev);
|
||||
else
|
||||
atspi_reset(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
21
tools/atspi-rssi/Makefile
Normal file
21
tools/atspi-rssi/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# atspi-rssi/Makefile - Build the spectrum scan utility
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
F32XBASE = ../../../f32xbase
|
||||
|
||||
MAIN = atspi-rssi
|
||||
|
||||
include $(F32XBASE)/lib/Makefile.common
|
||||
|
||||
CFLAGS += -I../../atrf/fw/include -I../include
|
||||
LDLIBS += -L../lib -latspi
|
||||
88
tools/atspi-rssi/atspi-rssi.c
Normal file
88
tools/atspi-rssi/atspi-rssi.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* atspi-rssi/atspi-rssi.c - ben-wpan AF86RF230 spectrum scan
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <usb.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "atspi/ep0.h"
|
||||
#include "atspi.h"
|
||||
|
||||
|
||||
static struct timeval t0;
|
||||
|
||||
|
||||
static void sweep(usb_dev_handle *dev)
|
||||
{
|
||||
int chan, rssi;
|
||||
struct timeval t;
|
||||
|
||||
for (chan = 11; chan <= 26; chan++) {
|
||||
atspi_reg_write(dev, REG_PHY_CC_CCA, chan);
|
||||
/*
|
||||
* No need to explicitly wait for the PPL lock - going USB-SPI
|
||||
* is pretty slow, leaving the transceiver plenty of time.
|
||||
*/
|
||||
gettimeofday(&t, NULL);
|
||||
rssi = atspi_reg_read(dev, REG_PHY_RSSI) & RSSI_MASK;
|
||||
t.tv_sec -= t0.tv_sec;
|
||||
t.tv_usec -= t0.tv_usec;
|
||||
printf("%d %f %d\n",
|
||||
2405+(chan-11)*5,
|
||||
(double) t.tv_sec+t.tv_usec/1000000.0,
|
||||
-91+3*(rssi-1));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr, "%s sweeps \n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
usb_dev_handle *dev;
|
||||
unsigned long sweeps, i;
|
||||
char *end;
|
||||
|
||||
if (argc != 2)
|
||||
usage(*argv);
|
||||
sweeps = strtoul(argv[1], &end, 0);
|
||||
if (*end)
|
||||
usage(*argv);
|
||||
|
||||
dev = atspi_open();
|
||||
if (!dev)
|
||||
return 1;
|
||||
|
||||
atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_TRX_OFF);
|
||||
/*
|
||||
* No need to explicitly wait for things to stabilize - going USB-SPI
|
||||
* is pretty slow, leaving the transceiver more than enough time.
|
||||
*/
|
||||
atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_RX_ON);
|
||||
|
||||
gettimeofday(&t0, NULL);
|
||||
for (i = 0; i != sweeps; i++)
|
||||
sweep(dev);
|
||||
|
||||
atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_TRX_OFF);
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
tools/atspi-trim/Makefile
Normal file
21
tools/atspi-trim/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# atspi-trim/Makefile - Build the oscillator trim utility
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
F32XBASE = ../../../f32xbase
|
||||
|
||||
MAIN = atspi-trim
|
||||
|
||||
include $(F32XBASE)/lib/Makefile.common
|
||||
|
||||
CFLAGS += -I../../atrf/fw/include -I../include
|
||||
LDLIBS += -L../lib -latspi
|
||||
62
tools/atspi-trim/atspi-trim.c
Normal file
62
tools/atspi-trim/atspi-trim.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* atspi-trim/atspi-trim.c - AF86RF230 oscillator trim utility
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <usb.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "atspi/ep0.h"
|
||||
#include "atspi.h"
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr, "%s [trim_value]\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
usb_dev_handle *dev;
|
||||
int trim = -1;
|
||||
char *end;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
trim = strtoul(argv[1], &end, 0);
|
||||
if (*end || trim > 15)
|
||||
usage(*argv);
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
dev = atspi_open();
|
||||
if (!dev)
|
||||
return 1;
|
||||
|
||||
if (trim == -1) {
|
||||
trim = atspi_reg_read(dev, REG_XOSC_CTRL) & XTAL_TRIM_MASK;
|
||||
printf("%d (%d.%d pF)\n", trim, trim*3/10, trim*3 % 10);
|
||||
} else {
|
||||
atspi_reg_write(dev, REG_XOSC_CTRL,
|
||||
(XTAL_MODE_INT << XTAL_MODE_SHIFT) | trim);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
tools/atspi-txrx/Makefile
Normal file
21
tools/atspi-txrx/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# atspi-txrx/Makefile - Build the TX/RX test utility
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
F32XBASE = ../../../f32xbase
|
||||
|
||||
MAIN = atspi-txrx
|
||||
|
||||
include $(F32XBASE)/lib/Makefile.common
|
||||
|
||||
CFLAGS += -I../../atrf/fw/include -I../include
|
||||
LDLIBS += -L../lib -latspi
|
||||
217
tools/atspi-txrx/atspi-txrx.c
Normal file
217
tools/atspi-txrx/atspi-txrx.c
Normal file
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* atspi-txrx/atspi-txrx.c - ben-wpan AF86RF230 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <usb.h>
|
||||
|
||||
#include "at86rf230.h"
|
||||
#include "atspi/ep0.h"
|
||||
#include "atspi.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 usb_dev_handle *init_txrx(int trim)
|
||||
{
|
||||
usb_dev_handle *dev;
|
||||
|
||||
dev = atspi_open();
|
||||
if (!dev)
|
||||
exit(1);
|
||||
|
||||
atspi_reset_rf(dev);
|
||||
atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_TRX_OFF);
|
||||
atspi_reg_write(dev, REG_XOSC_CTRL,
|
||||
(XTAL_MODE_INT << XTAL_MODE_SHIFT) | trim);
|
||||
atspi_reg_write(dev, REG_TRX_CTRL_0, 0); /* disable CLKM */
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
static void set_channel(usb_dev_handle *dev, int channel)
|
||||
{
|
||||
atspi_reg_write(dev, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
|
||||
}
|
||||
|
||||
|
||||
static void set_power(usb_dev_handle *dev, double power)
|
||||
{
|
||||
int n;
|
||||
|
||||
for (n = 0; n != sizeof(tx_pwr)/sizeof(*tx_pwr)-1; n++)
|
||||
if (tx_pwr[n] <= power)
|
||||
break;
|
||||
atspi_reg_write(dev, REG_PHY_TX_PWR, TX_AUTO_CRC_ON | n);
|
||||
}
|
||||
|
||||
|
||||
static void receive(usb_dev_handle *dev)
|
||||
{
|
||||
uint8_t irq;
|
||||
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
|
||||
int n, ok, i;
|
||||
uint8_t lq;
|
||||
|
||||
atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_RX_ON);
|
||||
|
||||
(void) atspi_reg_read(dev, REG_IRQ_STATUS);
|
||||
|
||||
fprintf(stderr, "Ready.\n");
|
||||
while (1) {
|
||||
irq = atspi_reg_read(dev, REG_IRQ_STATUS);
|
||||
if (atspi_error())
|
||||
exit(1);
|
||||
if (!irq)
|
||||
continue;
|
||||
if (irq == IRQ_TRX_END)
|
||||
break;
|
||||
fprintf(stderr, "IRQ (0x%02x):", irq);
|
||||
if (irq & IRQ_PLL_LOCK)
|
||||
fprintf(stderr, " PLL_LOCK");
|
||||
if (irq & IRQ_PLL_UNLOCK)
|
||||
fprintf(stderr, " PLL_UNLOCK");
|
||||
if (irq & IRQ_RX_START)
|
||||
fprintf(stderr, " RX_START");
|
||||
if (irq & IRQ_TRX_UR)
|
||||
fprintf(stderr, " TRX_UR");
|
||||
if (irq & IRQ_BAT_LOW)
|
||||
fprintf(stderr, " BAT_LOW");
|
||||
fprintf(stderr, "\n");
|
||||
if (irq & IRQ_TRX_END)
|
||||
break;
|
||||
}
|
||||
|
||||
n = atspi_buf_read(dev, buf, sizeof(buf));
|
||||
if (n < 0)
|
||||
exit(1);
|
||||
if (n < 3) {
|
||||
fprintf(stderr, "%d bytes received\n", n);
|
||||
exit(1);
|
||||
}
|
||||
ok = !!(atspi_reg_read(dev, REG_PHY_RSSI) & RX_CRC_VALID);
|
||||
lq = buf[n-1];
|
||||
fprintf(stderr, "%d bytes payload, CRC %s, LQI %u\n",
|
||||
n-3, ok ? "OK" : "BAD", lq);
|
||||
for (i = 0; i != n-3; i++)
|
||||
putchar(buf[i] < ' ' || buf[i] > '~' ? '?' : buf[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
static void transmit(usb_dev_handle *dev, const char *msg)
|
||||
{
|
||||
uint8_t buf[MAX_PSDU];
|
||||
|
||||
atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
||||
|
||||
/*
|
||||
* We need to copy the message to append the CRC placeholders.
|
||||
*/
|
||||
strcpy((void *) buf, msg);
|
||||
atspi_buf_write(dev, buf, strlen(msg)+2);
|
||||
|
||||
/* @@@ should wait for clear channel */
|
||||
atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_TX_START);
|
||||
/* @@@ should wait for TX done */
|
||||
}
|
||||
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s [-c channel] [-p power] [-t trim] [message]\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;
|
||||
char *end;
|
||||
int c;
|
||||
usb_dev_handle *dev;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
switch (argc-optind) {
|
||||
case 0:
|
||||
dev = init_txrx(trim);
|
||||
set_channel(dev, channel);
|
||||
receive(dev);
|
||||
break;
|
||||
case 1:
|
||||
dev = init_txrx(trim);
|
||||
set_channel(dev, channel);
|
||||
set_power(dev, power);
|
||||
transmit(dev, argv[optind]);
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
35
tools/include/atspi.h
Normal file
35
tools/include/atspi.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* include/atspi.h - ATSPI access functions library
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ATSPI_H
|
||||
#define ATSPI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <usb.h>
|
||||
|
||||
|
||||
int atspi_error(void);
|
||||
int atspi_clear_error(void);
|
||||
|
||||
usb_dev_handle *atspi_open(void);
|
||||
void atspi_close(usb_dev_handle *dev);
|
||||
|
||||
void atspi_reset(usb_dev_handle *dev);
|
||||
void atspi_reset_rf(usb_dev_handle *dev);
|
||||
|
||||
void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value);
|
||||
uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg);
|
||||
|
||||
void atspi_buf_write(usb_dev_handle *dev, const void *buf, int size);
|
||||
int atspi_buf_read(usb_dev_handle *dev, void *buf, int size);
|
||||
|
||||
#endif /* !ATSPI_H */
|
||||
32
tools/lib/Makefile
Normal file
32
tools/lib/Makefile
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# lib/Makefile - Build the ATSPI library
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
|
||||
F32XBASE = ../../../f32xbase
|
||||
|
||||
LIB = libatspi.a
|
||||
|
||||
CFLAGS = -Wall -I$(F32XBASE)/include -I../../atrf/fw/include -I../include
|
||||
OBJS = $(F32XBASE)/lib/usb.o atspi.o
|
||||
|
||||
.PHONY: all clean spotless
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
$(LIB): $(OBJS)
|
||||
$(AR) cr $@ $^
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS)
|
||||
|
||||
spotless: clean
|
||||
rm -f $(LIB)
|
||||
181
tools/lib/atspi.c
Normal file
181
tools/lib/atspi.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* lib/atspi.c - ATSPI access functions library
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <usb.h>
|
||||
|
||||
#include "f32xbase/usb.h"
|
||||
#include "atspi/ep0.h"
|
||||
#include "atspi/usb-ids.h"
|
||||
|
||||
#include "atspi.h"
|
||||
|
||||
|
||||
#define FROM_DEV ATSPI_FROM_DEV(0)
|
||||
#define TO_DEV ATSPI_TO_DEV(0)
|
||||
|
||||
|
||||
/* ----- error handling ---------------------------------------------------- */
|
||||
|
||||
|
||||
static int error;
|
||||
|
||||
|
||||
int atspi_error(void)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
int atspi_clear_error(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = error;
|
||||
error = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* ----- open/close -------------------------------------------------------- */
|
||||
|
||||
|
||||
usb_dev_handle *atspi_open(void)
|
||||
{
|
||||
usb_dev_handle *dev;
|
||||
|
||||
dev = open_usb(USB_VENDOR, USB_PRODUCT);
|
||||
if (dev) {
|
||||
error = 0;
|
||||
} else {
|
||||
fprintf(stderr, ":-(\n");
|
||||
error = 1;
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
void atspi_close(usb_dev_handle *dev)
|
||||
{
|
||||
/* to do */
|
||||
}
|
||||
|
||||
|
||||
/* ----- device mode ------------------------------------------------------- */
|
||||
|
||||
|
||||
void atspi_reset(usb_dev_handle *dev)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (error)
|
||||
return;
|
||||
|
||||
res =
|
||||
usb_control_msg(dev, TO_DEV, ATSPI_RESET, 0, 0, NULL, 0, 1000);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "ATSPI_RESET: %d\n", res);
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void atspi_reset_rf(usb_dev_handle *dev)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (error)
|
||||
return;
|
||||
|
||||
res =
|
||||
usb_control_msg(dev, TO_DEV, ATSPI_RF_RESET, 0, 0, NULL, 0, 1000);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "ATSPI_RF_RESET: %d\n", res);
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ----- register access --------------------------------------------------- */
|
||||
|
||||
|
||||
void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (error)
|
||||
return;
|
||||
|
||||
res = usb_control_msg(dev, TO_DEV, ATSPI_REG_WRITE, value, reg,
|
||||
NULL, 0, 1000);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "ATSPI_REG_WRITE: %d\n", res);
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg)
|
||||
{
|
||||
uint8_t value = 0;
|
||||
int res;
|
||||
|
||||
if (error)
|
||||
return 0;
|
||||
|
||||
res = usb_control_msg(dev, FROM_DEV, ATSPI_REG_READ, 0, reg,
|
||||
(void *) &value, 1, 1000);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "ATSPI_REG_READ: %d\n", res);
|
||||
error = 1;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/* ----- frame buffer access ----------------------------------------------- */
|
||||
|
||||
|
||||
void atspi_buf_write(usb_dev_handle *dev, const void *buf, int size)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (error)
|
||||
return;
|
||||
|
||||
res = usb_control_msg(dev, TO_DEV, ATSPI_BUF_WRITE, 0, 0,
|
||||
(void *) buf, size, 1000);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "ATSPI_BUF_WRITE: %d\n", res);
|
||||
error = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int atspi_buf_read(usb_dev_handle *dev, void *buf, int size)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (error)
|
||||
return -1;
|
||||
|
||||
res = usb_control_msg(dev, FROM_DEV, ATSPI_BUF_READ, 0, 0,
|
||||
buf, size, 1000);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "ATSPI_BUF_READ: %d\n", res);
|
||||
error = 1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user