1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-22 12:59:21 +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
This commit is contained in:
Werner Almesberger 2010-11-11 10:10:13 -03:00
parent 688df9771d
commit bcd3691c8a
11 changed files with 101 additions and 101 deletions

View File

@ -71,7 +71,7 @@ static int get_build(usb_dev_handle *dev, char *buf, size_t size)
}
static void show_usb_info(struct atspi_dsc *dsc)
static void show_usb_info(struct atrf_dsc *dsc)
{
usb_dev_handle *dev;
const struct usb_device *device;
@ -79,7 +79,7 @@ static void show_usb_info(struct atspi_dsc *dsc)
char buf[BUF_SIZE+1]; /* +1 for terminating \0 */
int len;
dev = atspi_usb_handle(dsc);
dev = atrf_usb_handle(dsc);
if (!dev)
return;
device = usb_device(dev);
@ -102,7 +102,7 @@ static void show_usb_info(struct atspi_dsc *dsc)
#else /* HAVE_USB */
static void show_usb_info(struct atspi_dsc *dsc)
static void show_usb_info(struct atrf_dsc *dsc)
{
}
@ -110,16 +110,16 @@ static void show_usb_info(struct atspi_dsc *dsc)
#endif /* !HAVE_USB */
static void show_info(struct atspi_dsc *dsc)
static void show_info(struct atrf_dsc *dsc)
{
uint8_t part, version, man_id_0, man_id_1;
show_usb_info(dsc);
part = atspi_reg_read(dsc, REG_PART_NUM);
version = atspi_reg_read(dsc, REG_VERSION_NUM);
man_id_0 = atspi_reg_read(dsc, REG_MAN_ID_0);
man_id_1 = atspi_reg_read(dsc, REG_MAN_ID_1);
part = atrf_reg_read(dsc, REG_PART_NUM);
version = atrf_reg_read(dsc, REG_VERSION_NUM);
man_id_0 = atrf_reg_read(dsc, REG_MAN_ID_0);
man_id_1 = atrf_reg_read(dsc, REG_MAN_ID_1);
printf("%10spart 0x%02x version %u manufacturer xxxx%02x%02x\n", "",
part, version, man_id_1, man_id_0);
}
@ -134,17 +134,17 @@ static void usage(const char *name)
int main(int argc, const char **argv)
{
struct atspi_dsc *dsc;
struct atrf_dsc *dsc;
if (argc != 1)
usage(*argv);
dsc = atspi_open();
dsc = atrf_open();
if (!dsc)
return 1;
show_info(dsc);
atspi_close(dsc);
atrf_close(dsc);
return 0;
}

View File

@ -31,7 +31,7 @@ static void usage(const char *name)
int main(int argc, const char **argv)
{
struct atspi_dsc *dsc;
struct atrf_dsc *dsc;
int txrx = 1;
switch (argc) {
@ -48,14 +48,14 @@ int main(int argc, const char **argv)
usage(*argv);
}
dsc = atspi_open();
dsc = atrf_open();
if (!dsc)
return 1;
if (txrx)
atspi_reset_rf(dsc);
atrf_reset_rf(dsc);
else
atspi_reset(dsc);
atrf_reset(dsc);
return 0;
}

View File

@ -32,18 +32,18 @@ static struct timeval t0;
static volatile int run = 1;
static void sweep(struct atspi_dsc *dsc)
static void sweep(struct atrf_dsc *dsc)
{
int chan, rssi;
struct timeval t;
for (chan = 11; chan <= 26; chan++) {
atspi_reg_write(dsc, REG_PHY_CC_CCA, chan);
atrf_reg_write(dsc, REG_PHY_CC_CCA, chan);
/* 150 us, according to AVR2001 section 3.5 */
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
gettimeofday(&t, NULL);
rssi = atspi_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
rssi = atrf_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
t.tv_sec -= t0.tv_sec;
t.tv_usec -= t0.tv_usec;
printf("%d %f %d\n",
@ -77,7 +77,7 @@ static void usage(const char *name)
int main(int argc, char **argv)
{
struct atspi_dsc *dsc;
struct atrf_dsc *dsc;
unsigned long arg = 0, i;
char *end;
int c;
@ -115,12 +115,12 @@ int main(int argc, char **argv)
signal(SIGINT, die);
dsc = atspi_open();
dsc = atrf_open();
if (!dsc)
return 1;
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
/*
* We'll wait for the PLL lock after selecting the channel.
*/
@ -133,9 +133,9 @@ int main(int argc, char **argv)
sweep(dsc);
}
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
atspi_close(dsc);
atrf_close(dsc);
return 0;
}

View File

@ -67,16 +67,16 @@ static void shift_grid(int *z, int nx, int ny)
}
static void sweep(struct atspi_dsc *dsc, int *z)
static void sweep(struct atrf_dsc *dsc, int *z)
{
int chan;
for (chan = 11; chan <= 26; chan++) {
atspi_reg_write(dsc, REG_PHY_CC_CCA, chan);
atrf_reg_write(dsc, REG_PHY_CC_CCA, chan);
/* 150 us, according to AVR2001 section 3.5 */
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
*z++ = Z_STEP*atspi_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
*z++ = Z_STEP*atrf_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
#if 0
if (chan >= 13 && chan <= 19 )
z[-1] = 3*28-(chan-16)*(chan-16)*(chan-16)*(chan-16);
@ -121,7 +121,7 @@ static void label_channels(SDL_Surface *s, int sx, int x0, int y0)
}
void gui(struct atspi_dsc *dsc)
void gui(struct atrf_dsc *dsc)
{
SDL_Surface *surf;
int z[N_CHAN*N_TIME];

View File

@ -16,6 +16,6 @@
#include "atrf.h"
void gui(struct atspi_dsc *dsc);
void gui(struct atrf_dsc *dsc);
#endif /* !GUI_H */

View File

@ -28,7 +28,7 @@ static void usage(const char *name)
int main(int argc, const char **argv)
{
struct atspi_dsc *dsc;
struct atrf_dsc *dsc;
int trim = -1;
char *end;
@ -44,15 +44,15 @@ int main(int argc, const char **argv)
usage(*argv);
}
dsc = atspi_open();
dsc = atrf_open();
if (!dsc)
return 1;
if (trim == -1) {
trim = atspi_reg_read(dsc, REG_XOSC_CTRL) & XTAL_TRIM_MASK;
trim = atrf_reg_read(dsc, REG_XOSC_CTRL) & XTAL_TRIM_MASK;
printf("%d (%d.%d pF)\n", trim, trim*3/10, trim*3 % 10);
} else {
atspi_reg_write(dsc, REG_XOSC_CTRL,
atrf_reg_write(dsc, REG_XOSC_CTRL,
(XTAL_MODE_INT << XTAL_MODE_SHIFT) | trim);
}

View File

@ -51,37 +51,37 @@ static double tx_pwr[] = {
static volatile int run = 1;
static struct atspi_dsc *init_txrx(int trim)
static struct atrf_dsc *init_txrx(int trim)
{
struct atspi_dsc *dsc;
struct atrf_dsc *dsc;
dsc = atspi_open();
dsc = atrf_open();
if (!dsc)
exit(1);
atspi_reset_rf(dsc);
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
atrf_reset_rf(dsc);
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
#ifdef HAVE_USB /* @@@ yeah, ugly */
atspi_reg_write(dsc, REG_XOSC_CTRL,
atrf_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);
atrf_reg_write(dsc, REG_XOSC_CTRL, XTAL_MODE_EXT << XTAL_MODE_SHIFT);
#endif
atspi_reg_write(dsc, REG_TRX_CTRL_0, 0); /* disable CLKM */
atrf_reg_write(dsc, REG_TRX_CTRL_0, 0); /* disable CLKM */
(void) atspi_reg_read(dsc, REG_IRQ_STATUS);
(void) atrf_reg_read(dsc, REG_IRQ_STATUS);
return dsc;
}
static void set_channel(struct atspi_dsc *dsc, int channel)
static void set_channel(struct atrf_dsc *dsc, int channel)
{
atspi_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
atrf_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
}
static void set_power(struct atspi_dsc *dsc, double power, int crc)
static void set_power(struct atrf_dsc *dsc, double power, int crc)
{
int n;
@ -90,17 +90,17 @@ static void set_power(struct atspi_dsc *dsc, double power, int crc)
break;
if (fabs(tx_pwr[n]-power) > 0.01)
fprintf(stderr, "TX power %.1f dBm\n", tx_pwr[n]);
atspi_reg_write(dsc, REG_PHY_TX_PWR, (crc ? TX_AUTO_CRC_ON : 0) | n);
atrf_reg_write(dsc, REG_PHY_TX_PWR, (crc ? TX_AUTO_CRC_ON : 0) | n);
}
static void receive(struct atspi_dsc *dsc)
static void receive(struct atrf_dsc *dsc)
{
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
int n, ok, i;
uint8_t ed, lqi;
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
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.
@ -113,15 +113,15 @@ static void receive(struct atspi_dsc *dsc)
if (!run)
return;
n = atspi_buf_read(dsc, buf, sizeof(buf));
n = atrf_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);
ok = !!(atspi_reg_read(dsc, REG_PHY_RSSI) & RX_CRC_VALID);
ed = atrf_reg_read(dsc, REG_PHY_ED_LEVEL);
ok = !!(atrf_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);
@ -131,11 +131,11 @@ static void receive(struct atspi_dsc *dsc)
}
static void transmit(struct atspi_dsc *dsc, const char *msg, int times)
static void transmit(struct atrf_dsc *dsc, const char *msg, int times)
{
uint8_t buf[MAX_PSDU];
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
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.
@ -146,11 +146,11 @@ static void transmit(struct atspi_dsc *dsc, const char *msg, int times)
* We need to copy the message to append the CRC placeholders.
*/
strcpy((void *) buf, msg);
atspi_buf_write(dsc, buf, strlen(msg)+2);
atrf_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);
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
/* wait up to 10 ms (nominally) */
wait_for_interrupt(dsc, IRQ_TRX_END,
@ -159,26 +159,26 @@ static void transmit(struct atspi_dsc *dsc, const char *msg, int times)
}
static void test_mode(struct atspi_dsc *dsc, uint8_t cont_tx)
static void test_mode(struct atrf_dsc *dsc, uint8_t cont_tx)
{
atspi_buf_write(dsc, "", 1);
atspi_reg_write(dsc, REG_CONT_TX_0, CONT_TX_MAGIC);
atspi_reg_write(dsc, REG_CONT_TX_1, cont_tx);
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);
if (!atspi_test_mode(dsc)) {
atspi_reset_rf(dsc);
if (!atrf_test_mode(dsc)) {
atrf_reset_rf(dsc);
fprintf(stderr, "device does not support test mode\n");
exit(1);
}
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
while (run)
sleep(1);
atspi_reset_rf(dsc);
atrf_reset_rf(dsc);
}
@ -214,7 +214,7 @@ int main(int argc, char *const *argv)
uint8_t cont_tx = 0;
char *end;
int c, freq;
struct atspi_dsc *dsc;
struct atrf_dsc *dsc;
while ((c = getopt(argc, argv, "c:f:p:t:T:")) != EOF)
switch (c) {
@ -291,7 +291,7 @@ int main(int argc, char *const *argv)
usage(*argv);
}
atspi_close(dsc);
atrf_close(dsc);
return 0;
}

View File

@ -16,27 +16,27 @@
#include <stdint.h>
struct atspi_dsc;
struct atrf_dsc;
void *atspi_usb_handle(struct atspi_dsc *dsc); /* hack for atspi-id */
void *atrf_usb_handle(struct atrf_dsc *dsc); /* hack for atspi-id */
struct atspi_dsc *atspi_open(void);
void atspi_close(struct atspi_dsc *dsc);
struct atrf_dsc *atrf_open(void);
void atrf_close(struct atrf_dsc *dsc);
int atspi_error(struct atspi_dsc *dsc);
int atspi_clear_error(struct atspi_dsc *dsc);
int atrf_error(struct atrf_dsc *dsc);
int atrf_clear_error(struct atrf_dsc *dsc);
void atspi_reset(struct atspi_dsc *dsc);
void atspi_reset_rf(struct atspi_dsc *dsc);
int atspi_test_mode(struct atspi_dsc *dsc);
void atrf_reset(struct atrf_dsc *dsc);
void atrf_reset_rf(struct atrf_dsc *dsc);
int atrf_test_mode(struct atrf_dsc *dsc);
void atspi_reg_write(struct atspi_dsc *dsc, uint8_t reg, uint8_t value);
uint8_t atspi_reg_read(struct atspi_dsc *dsc, uint8_t reg);
void atrf_reg_write(struct atrf_dsc *dsc, uint8_t reg, uint8_t value);
uint8_t atrf_reg_read(struct atrf_dsc *dsc, uint8_t reg);
void atspi_buf_write(struct atspi_dsc *dsc, const void *buf, int size);
int atspi_buf_read(struct atspi_dsc *dsc, void *buf, int size);
void atrf_buf_write(struct atrf_dsc *dsc, const void *buf, int size);
int atrf_buf_read(struct atrf_dsc *dsc, void *buf, int size);
int atspi_interrupt(struct atspi_dsc *dsc);
int atrf_interrupt(struct atrf_dsc *dsc);
#endif /* !ATRF_H */

View File

@ -18,7 +18,7 @@
#include "atrf.h"
uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
uint8_t ignore, int sleep_us, int timeout);
#endif /* !MISCTXRX_H */

View File

@ -1,5 +1,5 @@
/*
* lib/atspi.c - ATSPI access functions library
* lib/atrf.c - ATSPI access functions library
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
@ -22,13 +22,13 @@ extern struct atrf_driver atusb_driver;
extern struct atrf_driver atusd_driver;
struct atspi_dsc {
struct atrf_dsc {
struct atrf_driver *driver;
void *handle;
};
void *atspi_usb_handle(struct atspi_dsc *dsc)
void *atrf_usb_handle(struct atrf_dsc *dsc)
{
#ifdef HAVE_USB
return dsc->handle;
@ -38,22 +38,22 @@ void *atspi_usb_handle(struct atspi_dsc *dsc)
}
int atspi_error(struct atspi_dsc *dsc)
int atrf_error(struct atrf_dsc *dsc)
{
return dsc->driver->error ? dsc->driver->error(dsc->handle) : 0;
}
int atspi_clear_error(struct atspi_dsc *dsc)
int atrf_clear_error(struct atrf_dsc *dsc)
{
return dsc->driver->clear_error ?
dsc->driver->clear_error(dsc->handle) : 0;
}
struct atspi_dsc *atspi_open(void)
struct atrf_dsc *atrf_open(void)
{
struct atspi_dsc *dsc;
struct atrf_dsc *dsc;
struct atrf_driver *driver;
void *handle;
@ -78,7 +78,7 @@ struct atspi_dsc *atspi_open(void)
}
void atspi_close(struct atspi_dsc *dsc)
void atrf_close(struct atrf_dsc *dsc)
{
if (dsc->driver->close)
dsc->driver->close(dsc->handle);
@ -86,20 +86,20 @@ void atspi_close(struct atspi_dsc *dsc)
}
void atspi_reset(struct atspi_dsc *dsc)
void atrf_reset(struct atrf_dsc *dsc)
{
if (dsc->driver->reset)
dsc->driver->reset(dsc->handle);
}
void atspi_reset_rf(struct atspi_dsc *dsc)
void atrf_reset_rf(struct atrf_dsc *dsc)
{
dsc->driver->reset_rf(dsc->handle);
}
int atspi_test_mode(struct atspi_dsc *dsc)
int atrf_test_mode(struct atrf_dsc *dsc)
{
if (!dsc->driver->test_mode)
return 0;
@ -108,31 +108,31 @@ int atspi_test_mode(struct atspi_dsc *dsc)
}
void atspi_reg_write(struct atspi_dsc *dsc, uint8_t reg, uint8_t value)
void atrf_reg_write(struct atrf_dsc *dsc, uint8_t reg, uint8_t value)
{
dsc->driver->reg_write(dsc->handle, reg, value);
}
uint8_t atspi_reg_read(struct atspi_dsc *dsc, uint8_t reg)
uint8_t atrf_reg_read(struct atrf_dsc *dsc, uint8_t reg)
{
return dsc->driver->reg_read(dsc->handle, reg);
}
void atspi_buf_write(struct atspi_dsc *dsc, const void *buf, int size)
void atrf_buf_write(struct atrf_dsc *dsc, const void *buf, int size)
{
dsc->driver->buf_write(dsc->handle, buf, size);
}
int atspi_buf_read(struct atspi_dsc *dsc, void *buf, int size)
int atrf_buf_read(struct atrf_dsc *dsc, void *buf, int size)
{
return dsc->driver->buf_read(dsc->handle, buf, size);
}
int atspi_interrupt(struct atspi_dsc *dsc)
int atrf_interrupt(struct atrf_dsc *dsc)
{
return
dsc->driver->interrupt ? dsc->driver->interrupt(dsc->handle) : 1;

View File

@ -31,7 +31,7 @@ static void die(int sig)
}
uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
uint8_t wait_for_interrupt(struct atrf_dsc *dsc, uint8_t wait_for,
uint8_t ignore, int sleep_us, int timeout)
{
uint8_t irq = 0, show;
@ -40,13 +40,13 @@ uint8_t wait_for_interrupt(struct atspi_dsc *dsc, uint8_t wait_for,
run = 1;
old_sig = signal(SIGINT, die);
while (run) {
while (run && !atspi_interrupt(dsc)) {
while (run && !atrf_interrupt(dsc)) {
usleep(sleep_us);
if (timeout && !--timeout)
return 0;
}
irq = atspi_reg_read(dsc, REG_IRQ_STATUS);
if (atspi_error(dsc))
irq = atrf_reg_read(dsc, REG_IRQ_STATUS);
if (atrf_error(dsc))
exit(1);
if (!irq)
continue;