ols->probe_mask = 0xffffffff;
ols->cur_samplerate = SR_KHZ(200);
ols->period_ps = 5000000;
+ ols->serial = NULL;
return ols;
}
ols->num_probes = 32;
sdi->priv = ols;
}
- sdi->serial = sr_serial_device_instance_new(device_names[i], -1);
+ ols->serial = sr_serial_device_instance_new(device_names[i], -1);
device_instances = g_slist_append(device_instances, sdi);
final_devcnt++;
serial_close(fds[i].fd);
static int hw_opendev(int device_index)
{
struct sr_device_instance *sdi;
+ struct ols_device *ols;
if (!(sdi = sr_get_device_instance(device_instances, device_index)))
return SR_ERR;
- sdi->serial->fd = serial_open(sdi->serial->port, O_RDWR);
- if (sdi->serial->fd == -1)
+ ols = sdi->priv;
+
+ ols->serial->fd = serial_open(ols->serial->port, O_RDWR);
+ if (ols->serial->fd == -1)
return SR_ERR;
sdi->status = SR_ST_ACTIVE;
static int hw_closedev(int device_index)
{
struct sr_device_instance *sdi;
+ struct ols_device *ols;
if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
sr_err("ols: %s: sdi was NULL", __func__);
return SR_ERR; /* TODO: SR_ERR_ARG? */
}
+ ols = sdi->priv;
+
/* TODO */
- if (sdi->serial->fd != -1) {
- serial_close(sdi->serial->fd);
- sdi->serial->fd = -1;
+ if (ols->serial->fd != -1) {
+ serial_close(ols->serial->fd);
+ ols->serial->fd = -1;
sdi->status = SR_ST_INACTIVE;
}
{
GSList *l;
struct sr_device_instance *sdi;
+ struct ols_device *ols;
/* Properly close and free all devices. */
for (l = device_instances; l; l = l->next) {
sdi = l->data;
- if (sdi->serial->fd != -1)
- serial_close(sdi->serial->fd);
+ ols = sdi->priv;
+ if (ols->serial->fd != -1)
+ serial_close(ols->serial->fd);
+ sr_serial_device_instance_free(ols->serial);
sr_device_instance_free(sdi);
}
g_slist_free(device_instances);
ols = NULL;
for (l = device_instances; l; l = l->next) {
sdi = l->data;
- if (sdi->serial->fd == fd) {
+ if (ols->serial->fd == fd) {
ols = sdi->priv;
break;
}
delaycount = readcount * (1 - ols->capture_ratio / 100.0);
ols->trigger_at = (readcount - delaycount) * 4 - ols->num_stages;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_0,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_0,
reverse32(ols->trigger_mask[0])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_0,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_0,
reverse32(ols->trigger_value[0])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
trigger_config[0]) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_1,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_1,
reverse32(ols->trigger_mask[1])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_1,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_1,
reverse32(ols->trigger_value[1])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_1,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_1,
trigger_config[1]) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_2,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_2,
reverse32(ols->trigger_mask[2])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_2,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_2,
reverse32(ols->trigger_value[2])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_2,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_2,
trigger_config[2]) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_3,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_3,
reverse32(ols->trigger_mask[3])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_3,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_3,
reverse32(ols->trigger_value[3])) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_3,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_3,
trigger_config[3]) != SR_OK)
return SR_ERR;
} else {
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_0,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_0,
ols->trigger_mask[0]) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_0,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_0,
ols->trigger_value[0]) != SR_OK)
return SR_ERR;
- if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
+ if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
0x00000008) != SR_OK)
return SR_ERR;
delaycount = readcount;
sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
"demux %s)", ols->cur_samplerate, ols->cur_samplerate_divider,
ols->flag_reg & FLAG_DEMUX ? "on" : "off");
- if (send_longcommand(sdi->serial->fd, CMD_SET_DIVIDER,
+ if (send_longcommand(ols->serial->fd, CMD_SET_DIVIDER,
reverse32(ols->cur_samplerate_divider)) != SR_OK)
return SR_ERR;
/* Send sample limit and pre/post-trigger capture ratio. */
data = ((readcount - 1) & 0xffff) << 16;
data |= (delaycount - 1) & 0xffff;
- if (send_longcommand(sdi->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
+ if (send_longcommand(ols->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
return SR_ERR;
/* The flag register wants them here, and 1 means "disable channel". */
ols->flag_reg |= FLAG_FILTER;
ols->rle_count = 0;
data = (ols->flag_reg << 24) | ((ols->flag_reg << 8) & 0xff0000);
- if (send_longcommand(sdi->serial->fd, CMD_SET_FLAGS, data) != SR_OK)
+ if (send_longcommand(ols->serial->fd, CMD_SET_FLAGS, data) != SR_OK)
return SR_ERR;
/* Start acquisition on the device. */
- if (send_shortcommand(sdi->serial->fd, CMD_RUN) != SR_OK)
+ if (send_shortcommand(ols->serial->fd, CMD_RUN) != SR_OK)
return SR_ERR;
- sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data,
+ sr_source_add(ols->serial->fd, G_IO_IN, -1, receive_data,
session_data);
if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
unsigned char sample[4];
unsigned char tmp_sample[4];
unsigned char *raw_sample_buf;
+
+ struct sr_serial_device_instance *serial;
};
#endif /* OLS_H_ */
* This device is fully enumerated, so we need to find this
* device by vendor, product, bus and address.
*/
- if (libusb_get_bus_number(devlist[i]) != sdi->usb->bus
- || libusb_get_device_address(devlist[i]) != sdi->usb->address)
+ if (libusb_get_bus_number(devlist[i]) != fx2->usb->bus
+ || libusb_get_device_address(devlist[i]) != fx2->usb->address)
/* this is not the one */
continue;
}
- if (!(err = libusb_open(devlist[i], &sdi->usb->devhdl))) {
- if (sdi->usb->address == 0xff)
+ if (!(err = libusb_open(devlist[i], &fx2->usb->devhdl))) {
+ if (fx2->usb->address == 0xff)
/*
* first time we touch this device after firmware upload,
* so we don't know the address yet.
*/
- sdi->usb->address = libusb_get_device_address(devlist[i]);
+ fx2->usb->address = libusb_get_device_address(devlist[i]);
sdi->status = SR_ST_ACTIVE;
sr_info("saleae: opened device %d on %d.%d interface %d",
- sdi->index, sdi->usb->bus,
- sdi->usb->address, USB_INTERFACE);
+ sdi->index, fx2->usb->bus,
+ fx2->usb->address, USB_INTERFACE);
} else {
sr_warn("failed to open device: %d", err);
}
static void close_device(struct sr_device_instance *sdi)
{
- if (sdi->usb->devhdl == NULL)
+ struct fx2_device *fx2;
+
+ fx2 = sdi->priv;
+
+ if (fx2->usb->devhdl == NULL)
return;
sr_info("saleae: closing device %d on %d.%d interface %d", sdi->index,
- sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
- libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
- libusb_close(sdi->usb->devhdl);
- sdi->usb->devhdl = NULL;
+ fx2->usb->bus, fx2->usb->address, USB_INTERFACE);
+ libusb_release_interface(fx2->usb->devhdl, USB_INTERFACE);
+ libusb_close(fx2->usb->devhdl);
+ fx2->usb->devhdl = NULL;
sdi->status = SR_ST_INACTIVE;
}
struct fx2_device *fx2;
if (!(fx2 = g_try_malloc0(sizeof(struct fx2_device)))) {
- sr_err("saleae: %s: saleae malloc failed", __func__);
+ sr_err("saleae: %s: fx2 malloc failed", __func__);
return NULL;
}
fx2->trigger_stage = TRIGGER_FIRED;
+ fx2->usb = NULL;
return fx2;
}
if (check_conf_profile(devlist[i])) {
/* Already has the firmware, so fix the new address. */
sdi->status = SR_ST_INACTIVE;
- sdi->usb = sr_usb_device_instance_new
+ fx2->usb = sr_usb_device_instance_new
(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
} else {
g_get_current_time(&fx2->fw_updated);
else
sr_warn("firmware upload failed for device %d", devcnt);
- sdi->usb = sr_usb_device_instance_new
+ fx2->usb = sr_usb_device_instance_new
(libusb_get_bus_number(devlist[i]), 0xff, NULL);
}
devcnt++;
}
fx2 = sdi->priv;
- err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
+ err = libusb_claim_interface(fx2->usb->devhdl, USB_INTERFACE);
if (err != 0) {
sr_warn("Unable to claim interface: %d", err);
return SR_ERR;
static void hw_cleanup(void)
{
GSList *l;
+ struct sr_device_instance *sdi;
+ struct fx2_device *fx2;
- /* Properly close all devices... */
- for (l = device_instances; l; l = l->next)
- close_device((struct sr_device_instance *)l->data);
+ /* Properly close and free all devices. */
+ for (l = device_instances; l; l = l->next) {
+ sdi = l->data;
+ fx2 = sdi->priv;
+ close_device(sdi);
+ sr_usb_device_instance_free(fx2->usb);
+ sr_device_instance_free(sdi);
+ }
- /* ...and free all their memory. */
- for (l = device_instances; l; l = l->next)
- g_free(l->data);
g_slist_free(device_instances);
device_instances = NULL;
samplerate, divider);
buf[0] = 0x01;
buf[1] = divider;
- ret = libusb_bulk_transfer(sdi->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT,
+ ret = libusb_bulk_transfer(fx2->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT,
buf, 2, &result, 500);
if (ret != 0) {
sr_warn("failed to set samplerate: %d", ret);
return SR_ERR_MALLOC;
}
transfer = libusb_alloc_transfer(0);
- libusb_fill_bulk_transfer(transfer, sdi->usb->devhdl,
+ libusb_fill_bulk_transfer(transfer, fx2->usb->devhdl,
2 | LIBUSB_ENDPOINT_IN, buf, size,
receive_transfer, fx2, 40);
if (libusb_submit_transfer(transfer) != 0) {
* on the session bus along with samples.
*/
void *session_data;
+
+ struct sr_usb_device_instance *usb;
};
#endif /* SALEAE_LOGIC_H_ */
uint8_t trigger_mask[NUM_TRIGGER_STAGES];
uint8_t trigger_value[NUM_TRIGGER_STAGES];
// uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
+
+ struct sr_usb_device_instance *usb;
};
static int hw_set_configuration(int device_index, int capability, void *value);
if (des->idVendor != USB_VENDOR)
return 0;
- if (libusb_get_bus_number(dev) == (*sdi)->usb->bus
- && libusb_get_device_address(dev) == (*sdi)->usb->address) {
+ if (libusb_get_bus_number(dev) == zp->usb->bus
+ && libusb_get_device_address(dev) == zp->usb->address) {
for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) {
if (!(des->idProduct == zeroplus_models[i].pid))
}
/* Found it. */
- if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
+ if (!(err = libusb_open(dev, &(zp->usb->devhdl)))) {
(*sdi)->status = SR_ST_ACTIVE;
sr_info("opened device %d on %d.%d interface %d",
- (*sdi)->index, (*sdi)->usb->bus,
- (*sdi)->usb->address, USB_INTERFACE);
+ (*sdi)->index, zp->usb->bus,
+ zp->usb->address, USB_INTERFACE);
} else {
sr_warn("failed to open device: %d", err);
*sdi = NULL;
static void close_device(struct sr_device_instance *sdi)
{
- if (!sdi->usb->devhdl)
+ struct zp *zp;
+
+ if (!(zp = sdi->priv)) {
+ sr_err("zp: %s: sdi->priv was NULL", __func__);
+ return; /* FIXME */
+ }
+
+ if (!zp->usb->devhdl)
return;
sr_info("closing device %d on %d.%d interface %d", sdi->index,
- sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
- libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
- libusb_close(sdi->usb->devhdl);
- sdi->usb->devhdl = NULL;
+ zp->usb->bus, zp->usb->address, USB_INTERFACE);
+ libusb_release_interface(zp->usb->devhdl, USB_INTERFACE);
+ libusb_close(zp->usb->devhdl);
+ zp->usb->devhdl = NULL;
sdi->status = SR_ST_INACTIVE;
}
device_instances =
g_slist_append(device_instances, sdi);
- sdi->usb = sr_usb_device_instance_new(
+ zp->usb = sr_usb_device_instance_new(
libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
devcnt++;
return SR_ERR_ARG;
}
- err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
+ err = libusb_claim_interface(zp->usb->devhdl, USB_INTERFACE);
if (err != 0) {
sr_warn("Unable to claim interface: %d", err);
return SR_ERR;
}
- analyzer_reset(sdi->usb->devhdl);
- analyzer_initialize(sdi->usb->devhdl);
+ analyzer_reset(zp->usb->devhdl);
+ analyzer_initialize(zp->usb->devhdl);
analyzer_set_memory_size(MEMORY_SIZE_512K);
// analyzer_set_freq(g_freq, g_freq_scale);
}
/* push configured settings to device */
- analyzer_configure(sdi->usb->devhdl);
+ analyzer_configure(zp->usb->devhdl);
- analyzer_start(sdi->usb->devhdl);
+ analyzer_start(zp->usb->devhdl);
sr_info("Waiting for data");
- analyzer_wait_data(sdi->usb->devhdl);
+ analyzer_wait_data(zp->usb->devhdl);
- sr_info("Stop address = 0x%x", analyzer_get_stop_address(sdi->usb->devhdl));
- sr_info("Now address = 0x%x", analyzer_get_now_address(sdi->usb->devhdl));
- sr_info("Trigger address = 0x%x", analyzer_get_trigger_address(sdi->usb->devhdl));
+ sr_info("Stop address = 0x%x", analyzer_get_stop_address(zp->usb->devhdl));
+ sr_info("Now address = 0x%x", analyzer_get_now_address(zp->usb->devhdl));
+ sr_info("Trigger address = 0x%x", analyzer_get_trigger_address(zp->usb->devhdl));
packet.type = SR_DF_HEADER;
packet.payload = &header;
}
samples_read = 0;
- analyzer_read_start(sdi->usb->devhdl);
+ analyzer_read_start(zp->usb->devhdl);
/* Send the incoming transfer to the session bus. */
for (packet_num = 0; packet_num < (zp->memory_size * 4 / PACKET_SIZE);
packet_num++) {
- res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE);
+ res = analyzer_read_data(zp->usb->devhdl, buf, PACKET_SIZE);
sr_info("Tried to read %llx bytes, actually read %x bytes",
PACKET_SIZE, res);
sr_session_bus(session_data, &packet);
samples_read += res / 4;
}
- analyzer_read_stop(sdi->usb->devhdl);
+ analyzer_read_stop(zp->usb->devhdl);
g_free(buf);
packet.type = SR_DF_END;
{
struct sr_datafeed_packet packet;
struct sr_device_instance *sdi;
+ struct zp *zp;
packet.type = SR_DF_END;
sr_session_bus(session_device_id, &packet);
- if (!(sdi = sr_get_device_instance(device_instances, device_index)))
- return; /* TODO: Cry? */
+ if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+ sr_err("zp: %s: sdi was NULL", __func__);
+ return; /* FIXME */
+ }
+
+ if (!(zp = sdi->priv)) {
+ sr_err("zp: %s: sdi->priv was NULL", __func__);
+ return; /* FIXME */
+ }
- analyzer_reset(sdi->usb->devhdl);
+ analyzer_reset(zp->usb->devhdl);
/* TODO: Need to cancel and free any queued up transfers. */
}
sdi->model = model ? g_strdup(model) : NULL;
sdi->version = version ? g_strdup(version) : NULL;
sdi->priv = NULL;
- sdi->usb = NULL;
return sdi;
}
void sr_device_instance_free(struct sr_device_instance *sdi)
{
- switch (sdi->instance_type) {
-#ifdef HAVE_LIBUSB_1_0
- case SR_USB_INSTANCE:
- sr_usb_device_instance_free(sdi->usb);
- break;
-#endif
- case SR_SERIAL_INSTANCE:
- sr_serial_device_instance_free(sdi->serial);
- break;
- default:
- /* No specific type, nothing extra to free. */
- break;
- }
-
g_free(sdi->priv);
g_free(sdi->vendor);
g_free(sdi->model);
#include <stdarg.h>
#include <glib.h>
+#ifdef HAVE_LIBUSB_1_0
+#include <libusb.h>
+#endif
/*--- Macros ----------------------------------------------------------------*/
int load_hwplugins(void);
+#ifdef HAVE_LIBUSB_1_0
+struct sr_usb_device_instance {
+ uint8_t bus;
+ uint8_t address;
+ struct libusb_device_handle *devhdl;
+};
+#endif
+
+struct sr_serial_device_instance {
+ char *port;
+ int fd;
+};
+
+#ifdef HAVE_LIBUSB_1_0
+/* USB-specific instances */
+struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
+ uint8_t address, struct libusb_device_handle *hdl);
+void sr_usb_device_instance_free(struct sr_usb_device_instance *usb);
+#endif
+
+/* Serial-specific instances */
+struct sr_serial_device_instance *sr_serial_device_instance_new(
+ const char *port, int fd);
+void sr_serial_device_instance_free(struct sr_serial_device_instance *serial);
+
/*--- log.c -----------------------------------------------------------------*/
int sr_log(int loglevel, const char *format, ...);
int device_index);
void sr_device_instance_free(struct sr_device_instance *sdi);
-/* USB-specific instances */
-#ifdef HAVE_LIBUSB_1_0
-struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
- uint8_t address, struct libusb_device_handle *hdl);
-void sr_usb_device_instance_free(struct sr_usb_device_instance *usb);
-#endif
-
-/* Serial-specific instances */
-struct sr_serial_device_instance *sr_serial_device_instance_new(
- const char *port, int fd);
-void sr_serial_device_instance_free(struct sr_serial_device_instance *serial);
-
int sr_find_hwcap(int *capabilities, int hwcap);
struct sr_hwcap_option *sr_find_hwcap_option(int hwcap);
void sr_source_remove(int fd);
#include <stdint.h>
#include <inttypes.h>
#include <glib.h>
-#ifdef HAVE_LIBUSB_1_0
-#include <libusb.h>
-#endif
#ifdef __cplusplus
extern "C" {
char *model;
char *version;
void *priv;
- union {
- struct sr_usb_device_instance *usb;
- struct sr_serial_device_instance *serial;
- };
};
/* sr_device_instance types */
SR_SERIAL_INSTANCE,
};
-#ifdef HAVE_LIBUSB_1_0
-struct sr_usb_device_instance {
- uint8_t bus;
- uint8_t address;
- struct libusb_device_handle *devhdl;
-};
-#endif
-
-struct sr_serial_device_instance {
- char *port;
- int fd;
-};
-
/* Device instance status */
enum {
SR_ST_NOT_FOUND,