uint8_t trigger_value[NUM_TRIGGER_STAGES];
// uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
+ /* TODO: this belongs in the device instance */
struct sr_usb_dev_inst *usb;
};
return SR_OK;
}
+static void clear_instances(void)
+{
+ GSList *l;
+ struct sr_dev_inst *sdi;
+
+ for (l = zdi->instances; l; l = l->next) {
+ sdi = l->data;
+ /* Properly close all devices... */
+ close_dev(sdi);
+ /* ...and free all their memory. */
+ sr_dev_inst_free(sdi);
+ }
+ g_slist_free(zdi->instances);
+ zdi->instances = NULL;
+
+}
+
/*
* API callbacks
*/
static int hw_init(void)
{
- /* Nothing to do. */
+ if (libusb_init(&usb_context) != 0) {
+ sr_err("zp: Failed to initialize USB.");
+ return 0;
+ }
return SR_OK;
}
(void)options;
devices = NULL;
+ clear_instances();
+
/* Allocate memory for our private driver context. */
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
sr_err("zp: %s: ctx malloc failed", __func__);
memset(ctx->trigger_value, 0, NUM_TRIGGER_STAGES);
// memset(ctx->trigger_buffer, 0, NUM_TRIGGER_STAGES);
- if (libusb_init(&usb_context) != 0) {
- sr_err("zp: Failed to initialize USB.");
- return 0;
- }
-
/* Find all ZEROPLUS analyzers and add them to device list. */
devcnt = 0;
libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */
static int hw_cleanup(void)
{
- GSList *l;
- struct sr_dev_inst *sdi;
- for (l = zdi->instances; l; l = l->next) {
- sdi = l->data;
- /* Properly close all devices... */
- close_dev(sdi);
- /* ...and free all their memory. */
- sr_dev_inst_free(sdi);
- }
- g_slist_free(zdi->instances);
- zdi->instances = NULL;
+ clear_instances();
if (usb_context)
libusb_exit(usb_context);