2010-08-20 22:27:24 +03:00
|
|
|
/*
|
2010-11-11 15:30:37 +02:00
|
|
|
* lib/atrf.c - ATRF access functions library
|
2010-08-20 22:27:24 +03:00
|
|
|
*
|
2011-01-07 17:35:51 +02:00
|
|
|
* Written 2010-2011 by Werner Almesberger
|
|
|
|
* Copyright 2010-2011 Werner Almesberger
|
2010-08-20 22:27:24 +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-06 00:59:42 +03:00
|
|
|
#include <stdlib.h>
|
2010-08-20 22:27:24 +03:00
|
|
|
#include <stdio.h>
|
2011-04-10 03:00:48 +03:00
|
|
|
#include <string.h>
|
2010-08-20 22:27:24 +03:00
|
|
|
|
2011-01-07 17:35:51 +02:00
|
|
|
#include "at86rf230.h"
|
|
|
|
|
2010-09-06 00:59:42 +03:00
|
|
|
#include "driver.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-08-20 22:27:24 +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 {
|
2011-04-10 03:00:48 +03:00
|
|
|
const struct atrf_driver *driver;
|
2010-09-06 00:59:42 +03:00
|
|
|
void *handle;
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
char *spec;
|
2011-02-11 02:15:05 +02:00
|
|
|
enum atrf_chip_id chip_id;
|
2010-09-06 00:59:42 +03:00
|
|
|
};
|
2010-08-20 22:27:24 +03:00
|
|
|
|
|
|
|
|
2011-04-10 23:45:19 +03:00
|
|
|
static const struct atrf_driver *drivers[] = {
|
|
|
|
#ifdef HAVE_BEN
|
|
|
|
&atben_driver,
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB
|
|
|
|
&atusb_driver,
|
|
|
|
#endif
|
|
|
|
&atnet_driver,
|
|
|
|
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
|
|
|
void *atrf_usb_handle(struct atrf_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
|
|
|
{
|
|
|
|
#ifdef HAVE_USB
|
2011-04-10 23:34:46 +03:00
|
|
|
if (dsc->driver == &atusb_driver)
|
2011-04-12 15:22:40 +03:00
|
|
|
return atusb_dev_handle(dsc->handle);
|
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
|
|
|
#endif
|
2011-04-10 23:34:46 +03:00
|
|
|
return NULL;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-10 13:25:11 +03:00
|
|
|
void *atrf_ben_regs(struct atrf_dsc *dsc)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_BEN
|
2011-04-10 23:34:46 +03:00
|
|
|
if (dsc->driver == &atben_driver)
|
|
|
|
return atben_regs(dsc->handle);
|
2011-04-10 13:25:11 +03:00
|
|
|
#endif
|
2011-04-10 23:34:46 +03:00
|
|
|
return NULL;
|
2011-04-10 13:25:11 +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
|
|
|
int atrf_error(struct atrf_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
|
|
|
{
|
|
|
|
return dsc->driver->error ? dsc->driver->error(dsc->handle) : 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
|
|
|
int atrf_clear_error(struct atrf_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
|
|
|
{
|
|
|
|
return dsc->driver->clear_error ?
|
|
|
|
dsc->driver->clear_error(dsc->handle) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-11 02:15:05 +02:00
|
|
|
static enum atrf_chip_id identify(struct atrf_dsc *dsc)
|
|
|
|
{
|
|
|
|
uint8_t part, version;
|
|
|
|
|
|
|
|
part = atrf_reg_read(dsc, REG_PART_NUM);
|
|
|
|
version = atrf_reg_read(dsc, REG_VERSION_NUM);
|
|
|
|
switch (part) {
|
|
|
|
case 2: /* AT86RF230 */
|
|
|
|
switch (version) {
|
|
|
|
case 1: /* rev A */
|
|
|
|
case 2: /* rev B */
|
|
|
|
return artf_at86rf230;
|
|
|
|
default:
|
|
|
|
return atrf_unknown_chip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: /* AT86RF231 */
|
|
|
|
switch (version) {
|
|
|
|
case 2: /* rev A */
|
|
|
|
return artf_at86rf231;
|
|
|
|
default:
|
|
|
|
return atrf_unknown_chip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return atrf_unknown_chip;
|
|
|
|
}
|
|
|
|
return atrf_unknown_chip;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-10 04:35:29 +03:00
|
|
|
const char *atrf_default_driver_name(void)
|
|
|
|
{
|
|
|
|
return drivers[0] ? drivers[0]->name : "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 14:15:19 +03:00
|
|
|
static const struct atrf_driver *select_driver(const char *spec,
|
2011-04-10 03:00:48 +03:00
|
|
|
const char **opt)
|
|
|
|
{
|
|
|
|
const struct atrf_driver **drv;
|
|
|
|
const char *end;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!*drivers) {
|
|
|
|
fprintf(stderr, "no drivers defined\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*opt = NULL;
|
2011-04-20 14:15:19 +03:00
|
|
|
if (!spec || !strcmp(spec, "default"))
|
2011-04-10 03:00:48 +03:00
|
|
|
return *drivers;
|
|
|
|
|
2011-04-20 14:15:19 +03:00
|
|
|
end = strchr(spec, ':');
|
2011-04-10 03:00:48 +03:00
|
|
|
if (!end)
|
2011-04-20 14:15:19 +03:00
|
|
|
end = strchr(spec, 0);
|
|
|
|
len = end-spec;
|
2011-04-10 03:00:48 +03:00
|
|
|
for (drv = drivers; *drv; drv++)
|
2011-04-20 14:15:19 +03:00
|
|
|
if (!strncmp((*drv)->name, spec, len) &&
|
2011-04-10 03:00:48 +03:00
|
|
|
strlen((*drv)->name) == len)
|
|
|
|
break;
|
|
|
|
if (!*drv) {
|
2011-04-20 14:15:19 +03:00
|
|
|
fprintf(stderr, "no driver \"%.*s\" found\n", (int) len, spec);
|
2011-04-10 03:00:48 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (*end)
|
|
|
|
*opt = end+1;
|
|
|
|
return *drv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 14:15:19 +03:00
|
|
|
struct atrf_dsc *atrf_open(const char *spec)
|
2010-08-20 22:27:24 +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;
|
2011-04-10 03:00:48 +03:00
|
|
|
const struct atrf_driver *driver;
|
|
|
|
const char *opt;
|
2010-09-06 00:59:42 +03:00
|
|
|
void *handle;
|
|
|
|
|
2011-04-20 14:15:19 +03:00
|
|
|
driver = select_driver(spec, &opt);
|
2011-04-10 03:00:48 +03:00
|
|
|
if (!driver)
|
|
|
|
return NULL;
|
|
|
|
handle = driver->open(opt);
|
2010-09-06 00:59:42 +03:00
|
|
|
if (!handle)
|
|
|
|
return NULL;
|
|
|
|
dsc = malloc(sizeof(*dsc));
|
|
|
|
if (!dsc) {
|
|
|
|
perror("malloc");
|
|
|
|
exit(1);
|
2010-08-20 22:27:24 +03:00
|
|
|
}
|
2010-09-06 00:59:42 +03:00
|
|
|
dsc->driver = driver;
|
|
|
|
dsc->handle = handle;
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
if (spec) {
|
|
|
|
dsc->spec = strdup(spec);
|
|
|
|
if (!dsc->spec) {
|
|
|
|
perror("strdup");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dsc->spec= NULL;
|
|
|
|
}
|
2011-02-11 02:15:05 +02:00
|
|
|
dsc->chip_id = identify(dsc);
|
2010-09-06 00:59:42 +03:00
|
|
|
return dsc;
|
2010-08-20 22:27:24 +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
|
|
|
void atrf_close(struct atrf_dsc *dsc)
|
2010-08-20 22:27:24 +03:00
|
|
|
{
|
2010-09-06 00:59:42 +03:00
|
|
|
if (dsc->driver->close)
|
|
|
|
dsc->driver->close(dsc->handle);
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
free(dsc->spec);
|
2010-09-06 00:59:42 +03:00
|
|
|
free(dsc);
|
2010-08-20 22:27:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
tools: atrf-id option -s to retrieve driver spec, with necessary infrastructure
- include/atrf.h (atrf_driver_spec), lib/atrf.c (atrf_driver_spec):
new function to retrieve the local or remote/final driver spec
- lib/atrf.c (struct atrf_dsc, atrf_open, atrf_close): record the local
driver spec
- lib/driver.h (struct atrf_driver): new driver function "driver_spec"
to retrieve the driver spec
- lib/atnet.c (struct atnet_dsc, atnet_open, atnet_close): maintain a
cache for the driver spec
- lib/atnet.c (atnet_driver_spec, atnet_driver): added support for the
"driver_spec" function
- atrf-proxy/PROTOCOL, atrf-proxy/atrf-proxy.c (cmd_zero): added command
SPEC to retrieve the (final) driver spec
- atrf-id/atrf-id.c (usage, main): added option -s to retrieve the
driver spec. One -s retrieves the local spec, -s -s the remote/final.
2011-04-20 14:58:17 +03:00
|
|
|
const char *atrf_driver_spec(struct atrf_dsc *dsc, int last)
|
|
|
|
{
|
|
|
|
if (!dsc->spec)
|
|
|
|
return dsc->driver->name;
|
|
|
|
if (!last || !dsc->driver->driver_spec)
|
|
|
|
return dsc->spec;
|
|
|
|
return dsc->driver->driver_spec(dsc->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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_reset(struct atrf_dsc *dsc)
|
2010-08-22 12:24:52 +03:00
|
|
|
{
|
2010-09-06 00:59:42 +03:00
|
|
|
if (dsc->driver->reset)
|
|
|
|
dsc->driver->reset(dsc->handle);
|
2010-08-22 12:24:52 +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
|
|
|
void atrf_reset_rf(struct atrf_dsc *dsc)
|
2010-08-22 12:24:52 +03:00
|
|
|
{
|
2010-09-06 00:59:42 +03:00
|
|
|
dsc->driver->reset_rf(dsc->handle);
|
2010-08-22 12:24:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-07 17:35:51 +02:00
|
|
|
enum atrf_chip_id atrf_identify(struct atrf_dsc *dsc)
|
|
|
|
{
|
2011-02-11 02:15:05 +02:00
|
|
|
return dsc->chip_id;
|
2011-01-07 17:35:51 +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
|
|
|
int atrf_test_mode(struct atrf_dsc *dsc)
|
2010-11-11 07:29:07 +02:00
|
|
|
{
|
|
|
|
if (!dsc->driver->test_mode)
|
|
|
|
return 0;
|
|
|
|
dsc->driver->test_mode(dsc->handle);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-04 02:13:38 +03:00
|
|
|
int atrf_slp_tr(struct atrf_dsc *dsc, int on)
|
|
|
|
{
|
|
|
|
if (!dsc->driver->slp_tr)
|
|
|
|
return 0;
|
|
|
|
dsc->driver->slp_tr(dsc->handle, on);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-11 04:11:34 +02:00
|
|
|
int atrf_set_clkm_generic(
|
|
|
|
void (*reg_write)(void *dsc, uint8_t reg, uint8_t value),
|
|
|
|
void *handle, int mhz)
|
|
|
|
{
|
|
|
|
uint8_t clkm;
|
|
|
|
|
|
|
|
if (!mhz) {
|
|
|
|
reg_write(handle, REG_TRX_CTRL_0, 0); /* disable CLKM */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (mhz) {
|
|
|
|
case 1:
|
|
|
|
clkm = CLKM_CTRL_1MHz;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
clkm = CLKM_CTRL_2MHz;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
clkm = CLKM_CTRL_4MHz;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
clkm = CLKM_CTRL_8MHz;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
clkm = CLKM_CTRL_16MHz;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "unsupported CLKM frequency %d MHz\n", mhz);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
reg_write(handle, REG_TRX_CTRL_0,
|
|
|
|
(PAD_IO_8mA << PAD_IO_CLKM_SHIFT) | clkm);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int atrf_set_clkm(struct atrf_dsc *dsc, int mhz)
|
|
|
|
{
|
|
|
|
if (dsc->driver->set_clkm)
|
|
|
|
return dsc->driver->set_clkm(dsc->handle, mhz);
|
|
|
|
else
|
|
|
|
return atrf_set_clkm_generic(dsc->driver->reg_write,
|
|
|
|
dsc->handle, mhz);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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_write(struct atrf_dsc *dsc, uint8_t reg, uint8_t value)
|
2010-08-20 22:27:24 +03:00
|
|
|
{
|
2010-09-06 00:59:42 +03:00
|
|
|
dsc->driver->reg_write(dsc->handle, reg, value);
|
2010-08-20 22:27:24 +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
|
|
|
uint8_t atrf_reg_read(struct atrf_dsc *dsc, uint8_t reg)
|
2010-08-20 22:27:24 +03:00
|
|
|
{
|
2010-09-06 00:59:42 +03:00
|
|
|
return dsc->driver->reg_read(dsc->handle, reg);
|
2010-08-20 22:27:24 +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
|
|
|
void atrf_buf_write(struct atrf_dsc *dsc, const void *buf, int size)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
2010-09-06 00:59:42 +03:00
|
|
|
dsc->driver->buf_write(dsc->handle, buf, size);
|
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
|
|
|
int atrf_buf_read(struct atrf_dsc *dsc, void *buf, int size)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
2010-09-06 00:59:42 +03:00
|
|
|
return dsc->driver->buf_read(dsc->handle, buf, size);
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2011-06-03 19:52:13 +03:00
|
|
|
void atrf_sram_write(struct atrf_dsc *dsc, uint8_t addr, uint8_t value)
|
|
|
|
{
|
|
|
|
dsc->driver->sram_write(dsc->handle, addr, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t atrf_sram_read(struct atrf_dsc *dsc, uint8_t addr)
|
|
|
|
{
|
|
|
|
return dsc->driver->sram_read(dsc->handle, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
int atrf_interrupt(struct atrf_dsc *dsc)
|
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
|
|
|
{
|
|
|
|
return
|
|
|
|
dsc->driver->interrupt ? dsc->driver->interrupt(dsc->handle) : 1;
|
|
|
|
}
|