#define BS 4096 /* Block size */
#define NUM_BLOCKS 2048 /* Number of blocks */
-static GSList *device_instances = NULL;
+static GSList *dev_insts = NULL;
static const char *probe_names[NUM_PROBES + 1] = {
"0",
uint8_t divcount;
};
-/* This will be initialized via hw_get_device_info()/SR_DI_SAMPLERATES. */
+/* This will be initialized via hw_dev_info_get()/SR_DI_SAMPLERATES. */
static uint64_t supported_samplerates[255 + 1] = { 0 };
/*
};
/* Note: Continuous sampling is not supported by the hardware. */
-static int capabilities[] = {
+static int hwcaps[] = {
SR_HWCAP_LOGIC_ANALYZER,
SR_HWCAP_SAMPLERATE,
SR_HWCAP_LIMIT_MSEC, /* TODO: Not yet implemented. */
/* Function prototypes. */
static int la8_close_usb_reset_sequencer(struct la8 *la8);
-static void hw_stop_acquisition(int device_index, gpointer session_data);
+static int hw_stop_acquisition(int dev_index, gpointer session_data);
static int la8_reset(struct la8 *la8);
static void fill_supported_samplerates_if_needed(void)
uint8_t buf[8] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
int ret;
- sr_spew("la8: entering %s", __func__);
-
if (!la8) {
sr_err("la8: %s: la8 was NULL", __func__);
return SR_ERR_ARG;
if ((ret = ftdi_usb_close(la8->ftdic)) < 0)
sr_err("la8: %s: ftdi_usb_close: (%d) %s", __func__,
ret, ftdi_get_error_string(la8->ftdic));
- } else {
- sr_spew("la8: %s: usb_dev was NULL, nothing to do", __func__);
}
ftdi_free(la8->ftdic); /* Returns void. */
return SR_OK;
}
-static int hw_init(const char *deviceinfo)
+static int hw_init(const char *devinfo)
{
int ret;
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
- sr_spew("la8: entering %s", __func__);
-
/* Avoid compiler errors. */
- (void)deviceinfo;
+ (void)devinfo;
/* Allocate memory for our private driver context. */
if (!(la8 = g_try_malloc(sizeof(struct la8)))) {
/* Check for the device and temporarily open it. */
if ((ret = ftdi_usb_open_desc(la8->ftdic, USB_VENDOR_ID,
USB_PRODUCT_ID, USB_DESCRIPTION, NULL)) < 0) {
- sr_dbg("la8: %s: ftdi_usb_open_desc: (%d) %s",
- __func__, ret, ftdi_get_error_string(la8->ftdic));
(void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */
goto err_free_ftdic;
}
sr_dbg("la8: found device");
/* Register the device with libsigrok. */
- sdi = sr_device_instance_new(0, SR_ST_INITIALIZING,
+ sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING,
USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION);
if (!sdi) {
- sr_err("la8: %s: sr_device_instance_new failed", __func__);
+ sr_err("la8: %s: sr_dev_inst_new failed", __func__);
goto err_close_ftdic;
}
sdi->priv = la8;
- device_instances = g_slist_append(device_instances, sdi);
+ dev_insts = g_slist_append(dev_insts, sdi);
sr_spew("la8: %s finished successfully", __func__);
return 0;
}
-static int hw_opendev(int device_index)
+static int hw_opendev(int dev_index)
{
int ret;
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
- if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
return SR_ERR;
}
-static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate)
+static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate)
{
struct la8 *la8;
return SR_OK;
}
-static int hw_closedev(int device_index)
+static int hw_closedev(int dev_index)
{
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
- if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
return SR_OK;
}
-static void hw_cleanup(void)
+static int hw_cleanup(void)
{
GSList *l;
- struct sr_device_instance *sdi;
-
- sr_spew("la8: entering %s", __func__);
+ struct sr_dev_inst *sdi;
+ int ret = SR_OK;
/* Properly close all devices. */
- for (l = device_instances; l; l = l->next) {
- if ((sdi = l->data) == NULL) {
+ for (l = dev_insts; l; l = l->next) {
+ if (!(sdi = l->data)) {
+ /* Log error, but continue cleaning up the rest. */
sr_err("la8: %s: sdi was NULL, continuing", __func__);
+ ret = SR_ERR_BUG;
continue;
}
-#if 0
- /*
- * Fixes a segfault as it's free()d elsewhere already.
- * TODO: Document who is supposed to free this, and when.
- */
- if (sdi->priv != NULL)
- g_free(sdi->priv);
- else
- sr_err("la8: %s: sdi->priv was NULL, nothing "
- "to do", __func__);
-#endif
- sr_device_instance_free(sdi); /* Returns void. */
- }
- g_slist_free(device_instances); /* Returns void. */
- device_instances = NULL;
+ sr_dev_inst_free(sdi); /* Returns void. */
+ }
+ g_slist_free(dev_insts); /* Returns void. */
+ dev_insts = NULL;
+
+ return ret;
}
-static void *hw_get_device_info(int device_index, int device_info_id)
+static void *hw_dev_info_get(int dev_index, int dev_info_id)
{
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
void *info;
sr_spew("la8: entering %s", __func__);
- if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__);
return NULL;
}
return NULL;
}
- switch (device_info_id) {
- case SR_DI_INSTANCE:
+ switch (dev_info_id) {
+ case SR_DI_INST:
info = sdi;
break;
case SR_DI_NUM_PROBES:
return info;
}
-static int hw_get_status(int device_index)
+static int hw_get_status(int dev_index)
{
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
- if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
sr_err("la8: %s: sdi was NULL, device not found", __func__);
return SR_ST_NOT_FOUND;
}
return sdi->status;
}
-static int *hw_get_capabilities(void)
+static int *hw_hwcap_get_all(void)
{
sr_spew("la8: entering %s", __func__);
- return capabilities;
+ return hwcaps;
}
-static int hw_set_configuration(int device_index, int capability, void *value)
+static int hw_config_set(int dev_index, int hwcap, void *value)
{
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
sr_spew("la8: entering %s", __func__);
- if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
- switch (capability) {
+ switch (hwcap) {
case SR_HWCAP_SAMPLERATE:
if (set_samplerate(sdi, *(uint64_t *)value) == SR_ERR)
return SR_ERR;
static int receive_data(int fd, int revents, void *session_data)
{
int i, ret;
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
/* Avoid compiler errors. */
return TRUE;
}
-static int hw_start_acquisition(int device_index, gpointer session_data)
+static int hw_start_acquisition(int dev_index, gpointer session_data)
{
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
struct sr_datafeed_packet packet;
struct sr_datafeed_header header;
sr_spew("la8: entering %s", __func__);
- if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
return SR_OK;
}
-static void hw_stop_acquisition(int device_index, gpointer session_data)
+static int hw_stop_acquisition(int dev_index, gpointer session_data)
{
- struct sr_device_instance *sdi;
+ struct sr_dev_inst *sdi;
struct la8 *la8;
struct sr_datafeed_packet packet;
sr_dbg("la8: stopping acquisition");
- if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) {
sr_err("la8: %s: sdi was NULL", __func__);
- return;
+ return SR_ERR_BUG;
}
if (!(la8 = sdi->priv)) {
sr_err("la8: %s: sdi->priv was NULL", __func__);
- return;
+ return SR_ERR_BUG;
}
/* Send end packet to the session bus. */
sr_dbg("la8: %s: sending SR_DF_END", __func__);
packet.type = SR_DF_END;
sr_session_bus(session_data, &packet);
+
+ return SR_OK;
}
-SR_PRIV struct sr_device_plugin chronovu_la8_plugin_info = {
+SR_PRIV struct sr_dev_plugin chronovu_la8_plugin_info = {
.name = "chronovu-la8",
.longname = "ChronoVu LA8",
.api_version = 1,
.cleanup = hw_cleanup,
.opendev = hw_opendev,
.closedev = hw_closedev,
- .get_device_info = hw_get_device_info,
+ .dev_info_get = hw_dev_info_get,
.get_status = hw_get_status,
- .get_capabilities = hw_get_capabilities,
- .set_configuration = hw_set_configuration,
+ .hwcap_get_all = hw_hwcap_get_all,
+ .config_set = hw_config_set,
.start_acquisition = hw_start_acquisition,
.stop_acquisition = hw_stop_acquisition,
};