mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-22 13:54:59 +02:00
tools/lib: cache chip ID in the descriptor
- atrf.c (struct atrf_dsc): added field "chip_id" to cache chip ID - atrf.c (identify, atrf_identify): moved identification logic to new function - atrf.c (atrf_open, atrf_identify): cache chip ID when opening the device and return ID from cache
This commit is contained in:
parent
f8fbb02bb0
commit
e73ca5fcd5
106
tools/lib/atrf.c
106
tools/lib/atrf.c
@ -27,6 +27,7 @@ extern struct atrf_driver atben_driver;
|
||||
struct atrf_dsc {
|
||||
struct atrf_driver *driver;
|
||||
void *handle;
|
||||
enum atrf_chip_id chip_id;
|
||||
};
|
||||
|
||||
|
||||
@ -53,55 +54,7 @@ int atrf_clear_error(struct atrf_dsc *dsc)
|
||||
}
|
||||
|
||||
|
||||
struct atrf_dsc *atrf_open(void)
|
||||
{
|
||||
struct atrf_dsc *dsc;
|
||||
struct atrf_driver *driver;
|
||||
void *handle;
|
||||
|
||||
#ifdef HAVE_USB
|
||||
driver = &atusb_driver;
|
||||
#elif HAVE_BEN
|
||||
driver = &atben_driver;
|
||||
#else
|
||||
#error Need either HAVE_USB or HAVE_BEN
|
||||
#endif
|
||||
handle = driver->open();
|
||||
if (!handle)
|
||||
return NULL;
|
||||
dsc = malloc(sizeof(*dsc));
|
||||
if (!dsc) {
|
||||
perror("malloc");
|
||||
exit(1);
|
||||
}
|
||||
dsc->driver = driver;
|
||||
dsc->handle = handle;
|
||||
return dsc;
|
||||
}
|
||||
|
||||
|
||||
void atrf_close(struct atrf_dsc *dsc)
|
||||
{
|
||||
if (dsc->driver->close)
|
||||
dsc->driver->close(dsc->handle);
|
||||
free(dsc);
|
||||
}
|
||||
|
||||
|
||||
void atrf_reset(struct atrf_dsc *dsc)
|
||||
{
|
||||
if (dsc->driver->reset)
|
||||
dsc->driver->reset(dsc->handle);
|
||||
}
|
||||
|
||||
|
||||
void atrf_reset_rf(struct atrf_dsc *dsc)
|
||||
{
|
||||
dsc->driver->reset_rf(dsc->handle);
|
||||
}
|
||||
|
||||
|
||||
enum atrf_chip_id atrf_identify(struct atrf_dsc *dsc)
|
||||
static enum atrf_chip_id identify(struct atrf_dsc *dsc)
|
||||
{
|
||||
uint8_t part, version;
|
||||
|
||||
@ -132,6 +85,61 @@ enum atrf_chip_id atrf_identify(struct atrf_dsc *dsc)
|
||||
}
|
||||
|
||||
|
||||
struct atrf_dsc *atrf_open(void)
|
||||
{
|
||||
struct atrf_dsc *dsc;
|
||||
struct atrf_driver *driver;
|
||||
void *handle;
|
||||
|
||||
#ifdef HAVE_USB
|
||||
driver = &atusb_driver;
|
||||
#elif HAVE_BEN
|
||||
driver = &atben_driver;
|
||||
#else
|
||||
#error Need either HAVE_USB or HAVE_BEN
|
||||
#endif
|
||||
handle = driver->open();
|
||||
if (!handle)
|
||||
return NULL;
|
||||
dsc = malloc(sizeof(*dsc));
|
||||
if (!dsc) {
|
||||
perror("malloc");
|
||||
exit(1);
|
||||
}
|
||||
dsc->driver = driver;
|
||||
dsc->handle = handle;
|
||||
dsc->chip_id = identify(dsc);
|
||||
return dsc;
|
||||
}
|
||||
|
||||
|
||||
void atrf_close(struct atrf_dsc *dsc)
|
||||
{
|
||||
if (dsc->driver->close)
|
||||
dsc->driver->close(dsc->handle);
|
||||
free(dsc);
|
||||
}
|
||||
|
||||
|
||||
void atrf_reset(struct atrf_dsc *dsc)
|
||||
{
|
||||
if (dsc->driver->reset)
|
||||
dsc->driver->reset(dsc->handle);
|
||||
}
|
||||
|
||||
|
||||
void atrf_reset_rf(struct atrf_dsc *dsc)
|
||||
{
|
||||
dsc->driver->reset_rf(dsc->handle);
|
||||
}
|
||||
|
||||
|
||||
enum atrf_chip_id atrf_identify(struct atrf_dsc *dsc)
|
||||
{
|
||||
return dsc->chip_id;
|
||||
}
|
||||
|
||||
|
||||
int atrf_test_mode(struct atrf_dsc *dsc)
|
||||
{
|
||||
if (!dsc->driver->test_mode)
|
||||
|
Loading…
Reference in New Issue
Block a user