sr: add new driver API call: scan()

This changes the semantics of the init() call as well. That now only
initializes the driver -- an administrative affair, no hardware gets
touched during this call. It returns a standard SR_OK or SR_ERR* code.

The scan() call does a discovery run for devices it knows, and returns
the number found. It can be called at any time.
This commit is contained in:
Bert Vermeulen 2012-07-05 11:27:48 +02:00
parent 40dda2c3a5
commit 61136ea603
11 changed files with 97 additions and 21 deletions

View File

@ -406,6 +406,14 @@ static int bin2bitbang(const char *filename,
} }
static int hw_init(void) static int hw_init(void)
{
/* Nothing to do. */
return SR_OK;
}
static int hw_scan(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct context *ctx; struct context *ctx;
@ -1437,6 +1445,7 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -40,6 +40,14 @@ static const uint16_t usb_pids[] = {
static int hw_dev_acquisition_stop(int dev_index, void *cb_data); static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
static int hw_init(void) static int hw_init(void)
{
/* Nothing to do. */
return SR_OK;
}
static int hw_scan(void)
{ {
int ret; int ret;
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
@ -542,6 +550,7 @@ SR_PRIV struct sr_dev_driver chronovu_la8_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -141,6 +141,14 @@ static int thread_running;
static int hw_dev_acquisition_stop(int dev_index, void *cb_data); static int hw_dev_acquisition_stop(int dev_index, void *cb_data);
static int hw_init(void) static int hw_init(void)
{
/* Nothing to do. */
return SR_OK;
}
static int hw_scan(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
@ -510,6 +518,7 @@ SR_PRIV struct sr_dev_driver demo_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -383,22 +383,27 @@ static struct context *fx2lafw_dev_new(void)
*/ */
static int hw_init(void) static int hw_init(void)
{
if (libusb_init(&usb_context) != 0) {
sr_warn("fx2lafw: Failed to initialize libusb.");
return SR_ERR;
}
return SR_OK;
}
static int hw_scan(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct libusb_device_descriptor des; struct libusb_device_descriptor des;
const struct fx2lafw_profile *prof; const struct fx2lafw_profile *prof;
struct context *ctx; struct context *ctx;
libusb_device **devlist; libusb_device **devlist;
int ret; int devcnt, ret, i, j;
int devcnt = 0;
int i, j;
if (libusb_init(&usb_context) != 0) {
sr_warn("fx2lafw: Failed to initialize libusb.");
return 0;
}
/* Find all fx2lafw compatible devices and upload firmware to them. */ /* Find all fx2lafw compatible devices and upload firmware to them. */
devcnt = 0;
libusb_get_device_list(usb_context, &devlist); libusb_get_device_list(usb_context, &devlist);
for (i = 0; devlist[i]; i++) { for (i = 0; devlist[i]; i++) {
@ -1009,6 +1014,7 @@ SR_PRIV struct sr_dev_driver fx2lafw_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -58,15 +58,22 @@ SR_PRIV libusb_context *genericdmm_usb_context = NULL;
static int hw_init(void) static int hw_init(void)
{ {
struct sr_dev_inst *sdi;
struct context *ctx;
int devcnt = 0;
if (libusb_init(&genericdmm_usb_context) != 0) { if (libusb_init(&genericdmm_usb_context) != 0) {
sr_err("genericdmm: Failed to initialize USB."); sr_err("genericdmm: Failed to initialize USB.");
return 0; return SR_ERR;
} }
return SR_OK;
}
static int hw_scan(void)
{
struct sr_dev_inst *sdi;
struct context *ctx;
int devcnt = 0;
if (!(ctx = g_try_malloc0(sizeof(struct context)))) { if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
sr_err("genericdmm: ctx malloc failed."); sr_err("genericdmm: ctx malloc failed.");
return 0; return 0;
@ -610,6 +617,7 @@ SR_PRIV struct sr_dev_driver genericdmm_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -201,25 +201,31 @@ static int configure_probes(struct context *ctx, const GSList *probes)
} }
static int hw_init(void) static int hw_init(void)
{
if (libusb_init(&usb_context) != 0) {
sr_err("hantek-dso: Failed to initialize USB.");
return SR_ERR;
}
return SR_OK;
}
static int hw_scan(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct libusb_device_descriptor des; struct libusb_device_descriptor des;
const struct dso_profile *prof; const struct dso_profile *prof;
struct context *ctx; struct context *ctx;
libusb_device **devlist; libusb_device **devlist;
int err, devcnt, i, j; int devcnt, ret, i, j;
if (libusb_init(&usb_context) != 0) {
sr_err("hantek-dso: Failed to initialize USB.");
return 0;
}
/* Find all Hantek DSO devices and upload firmware to all of them. */ /* Find all Hantek DSO devices and upload firmware to all of them. */
devcnt = 0; devcnt = 0;
libusb_get_device_list(usb_context, &devlist); libusb_get_device_list(usb_context, &devlist);
for (i = 0; devlist[i]; i++) { for (i = 0; devlist[i]; i++) {
if ((err = libusb_get_device_descriptor(devlist[i], &des))) { if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
sr_err("hantek-dso: failed to get device descriptor: %d", err); sr_err("hantek-dso: failed to get device descriptor: %d", ret);
continue; continue;
} }
@ -856,6 +862,7 @@ SR_PRIV struct sr_dev_driver hantek_dso_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -402,6 +402,14 @@ static int mso_parse_serial(const char *iSerial, const char *iProduct,
} }
static int hw_init(void) static int hw_init(void)
{
/* Nothing to do. */
return SR_OK;
}
static int hw_scan(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
int devcnt = 0; int devcnt = 0;
@ -840,6 +848,7 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -349,6 +349,14 @@ static struct sr_dev_inst *get_metadata(int fd)
} }
static int hw_init(void) static int hw_init(void)
{
/* Nothing to do. */
return SR_OK;
}
static int hw_scan(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct context *ctx; struct context *ctx;
@ -1047,6 +1055,7 @@ SR_PRIV struct sr_dev_driver ols_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -328,6 +328,14 @@ static int configure_probes(struct sr_dev_inst *sdi, const GSList *probes)
*/ */
static int hw_init(void) static int hw_init(void)
{
/* Nothing to do. */
return SR_OK;
}
static int hw_scan(void)
{ {
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct libusb_device_descriptor des; struct libusb_device_descriptor des;
@ -737,6 +745,7 @@ SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
.api_version = 1, .api_version = 1,
.init = hw_init, .init = hw_init,
.cleanup = hw_cleanup, .cleanup = hw_cleanup,
.scan = hw_scan,
.dev_open = hw_dev_open, .dev_open = hw_dev_open,
.dev_close = hw_dev_close, .dev_close = hw_dev_close,
.dev_info_get = hw_dev_info_get, .dev_info_get = hw_dev_info_get,

View File

@ -472,6 +472,7 @@ struct sr_dev_driver {
int api_version; int api_version;
int (*init) (void); int (*init) (void);
int (*cleanup) (void); int (*cleanup) (void);
int (*scan) (void);
/* Device-specific */ /* Device-specific */
int (*dev_open) (int dev_index); int (*dev_open) (int dev_index);

View File

@ -151,7 +151,7 @@ static int hw_cleanup(void);
static int hw_init(void) static int hw_init(void)
{ {
return 0; return SR_OK;
} }
/** /**