const struct model_info *model;
struct sr_dev_inst *sdi;
struct libusb_device_descriptor des;
- int bus, address;
+ int bus, address, ret;
unsigned int vid, pid;
- int ret;
bus = libusb_get_bus_number(dev);
address = libusb_get_device_address(dev);
*/
static GSList *dev_list(const struct sr_dev_driver *di)
{
- struct drv_context *drvc;
-
- drvc = di->context;
-
- return drvc->instances;
+ return ((struct drv_context *)(di->context))->instances;
}
/* Destroy the private device context.
if (devc->acquisition) {
sr_err("Cannot clear device context during acquisition!");
- return; /* leak and pray */
+ return; /* Leak and pray. */
}
sr_dbg("Device context cleared.");
*/
static int drain_usb(struct sr_usb_dev_inst *usb, unsigned int endpoint)
{
- int drained, xfer_len;
- int ret;
+ int drained, xfer_len, ret;
unsigned char buf[512];
-
const unsigned int drain_timeout_ms = 10;
drained = 0;
sr_warn("Drained %d bytes from USB endpoint %u.",
drained, endpoint & (LIBUSB_ENDPOINT_IN - 1));
}
+
return SR_OK;
}
struct drv_context *drvc;
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
- int i;
- int ret;
+ int i, ret;
drvc = sdi->driver->context;
devc = sdi->priv;
if ((model->devopts[i] & (SR_CONF_MASK | key)) == key)
return TRUE;
}
+
return FALSE;
}
if (strcmp(entry, table[i]) == 0)
return i;
}
+
return -1;
}
*/
static int prepare_trigger_masks(const struct sr_dev_inst *sdi)
{
- uint64_t trigger_mask;
- uint64_t trigger_values;
- uint64_t trigger_edge_mask;
+ uint64_t trigger_mask, trigger_values, trigger_edge_mask;
uint64_t level_bit, type_bit;
struct dev_context *devc;
struct sr_trigger *trigger;
match = node->data;
if (!match->channel->enabled)
- continue; /* ignore disabled channel */
+ continue; /* Ignore disabled channel. */
idx = match->channel->index;
trg = match->match;
if (idx < 0 || idx >= devc->model->num_channels) {
sr_err("Channel index %d out of range.", idx);
- return SR_ERR_BUG; /* should not happen */
+ return SR_ERR_BUG; /* Should not happen. */
}
if (trg != SR_TRIGGER_ZERO
&& trg != SR_TRIGGER_ONE
if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- scanopts, ARRAY_SIZE(scanopts),
- sizeof(scanopts[0]));
+ scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0]));
return SR_OK;
}
if (!sdi) {
/* List driver capabilities. */
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- drvopts, ARRAY_SIZE(drvopts),
- sizeof(drvopts[0]));
+ drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0]));
return SR_OK;
}
/* List the model's device options. */
if (key == SR_CONF_DEVICE_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
- devc->model->devopts,
- devc->model->num_devopts,
- sizeof(devc->model->devopts[0]));
+ devc->model->devopts, devc->model->num_devopts,
+ sizeof(devc->model->devopts[0]));
return SR_OK;
}
case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_VARDICT);
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
- devc->model->samplerates,
- devc->model->num_samplerates,
- sizeof(devc->model->samplerates[0]));
+ devc->model->samplerates, devc->model->num_samplerates,
+ sizeof(devc->model->samplerates[0]));
g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
*data = g_variant_builder_end(&gvb);
break;
case SR_CONF_TRIGGER_MATCH:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
- trigger_matches,
- ARRAY_SIZE(trigger_matches),
- sizeof(trigger_matches[0]));
+ trigger_matches, ARRAY_SIZE(trigger_matches),
+ sizeof(trigger_matches[0]));
break;
case SR_CONF_TRIGGER_SOURCE:
*data = g_variant_new_strv(trigger_source_names,
- ARRAY_SIZE(trigger_source_names));
+ ARRAY_SIZE(trigger_source_names));
break;
case SR_CONF_TRIGGER_SLOPE:
case SR_CONF_CLOCK_EDGE:
*data = g_variant_new_strv(signal_edge_names,
- ARRAY_SIZE(signal_edge_names));
+ ARRAY_SIZE(signal_edge_names));
break;
default:
/* Must not happen for a key listed in devopts. */
struct dev_context *devc;
(void)cb_data;
+
devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE)
devc->cancel_requested = TRUE;
sr_dbg("Stopping acquisition.");
}
+
return SR_OK;
}
#include "lwla.h"
#include "protocol.h"
-#define BITSTREAM_MAX_SIZE (256 * 1024) /* bitstream size limit for safety */
-#define BITSTREAM_HEADER_SIZE 4 /* transfer header size in bytes */
+#define BITSTREAM_MAX_SIZE (256 * 1024) /* Bitstream size limit for safety */
+#define BITSTREAM_HEADER_SIZE 4 /* Transfer header size in bytes */
/* Load a bitstream file into memory. Returns a newly allocated array
* consisting of a 32-bit length field followed by the bitstream data.
const char *name)
{
unsigned char *stream;
- int ret;
- int length;
- int xfer_len;
+ int ret, length, xfer_len;
if (!ctx || !usb || !name)
return SR_ERR_BUG;
SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb,
const uint16_t *command, int cmd_len)
{
- int ret;
- int xfer_len;
+ int ret, xfer_len;
if (!usb || !command || cmd_len <= 0)
return SR_ERR_BUG;
LWLA_TO_UINT16(command[0]), xfer_len, cmd_len * 2);
return SR_ERR;
}
+
return SR_OK;
}
sr_dbg("Failed to receive reply: %s.", libusb_error_name(ret));
return SR_ERR;
}
+
return SR_OK;
}
SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb,
uint16_t reg, uint32_t *value)
{
- int xfer_len;
- int ret;
+ int xfer_len, ret;
uint16_t command[2];
- uint32_t reply[128]; /* full EP buffer to avoid overflows */
+ uint32_t reply[128]; /* Full EP buffer to avoid overflows. */
command[0] = LWLA_WORD(CMD_READ_REG);
command[1] = LWLA_WORD(reg);
SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb,
const struct regval *regvals, int count)
{
- int i;
- int ret;
+ int i, ret;
ret = SR_OK;
{
uint32_t *in_p;
uint16_t *out_p;
- unsigned int words_left;
- unsigned int max_samples, run_samples;
- unsigned int wi, ri;
+ unsigned int words_left, max_samples, run_samples, wi, ri;
uint32_t word;
uint16_t sample;
acq->samples_done += run_samples;
if (run_samples == max_samples)
- break; /* packet full or sample limit reached */
+ break; /* Packet full or sample limit reached. */
if (wi >= words_left)
- break; /* done with current transfer */
+ break; /* Done with current transfer. */
word = GUINT32_FROM_LE(in_p[wi]);
acq->sample = word >> 16;
acq->run_len = (word & 0xFFFF) + 1;
}
+
acq->in_index += wi;
acq->mem_addr_done += wi;
}
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
unsigned int i;
- int xfer_len;
- int ret;
+ int xfer_len, ret;
uint16_t command[5];
unsigned char reply[512];
xfer_len);
return SR_ERR;
}
+
return SR_OK;
}
{
struct dev_context *devc;
struct drv_context *drvc;
- int config;
- int ret;
+ int config, ret;
devc = sdi->priv;
drvc = sdi->driver->context;
if (sdi->status == SR_ST_INACTIVE)
- return SR_OK; /* the LWLA1016 has no off state */
+ return SR_OK; /* The LWLA1016 has no off state. */
config = (devc->cfg_rle) ? FPGA_100_TS : FPGA_100;
if (config == devc->active_fpga_config)
- return SR_OK; /* no change */
+ return SR_OK; /* No change. */
ret = lwla_send_bitstream(drvc->sr_ctx, sdi->conn,
bitstream_map[config]);
};
uint32_t value;
int ret;
-
const unsigned int test_count = 24;
lwla_read_reg(sdi->conn, REG_TEST_ID, &value);
ret = test_read_memory(sdi, 0, test_count);
if (ret != SR_OK)
return ret;
+
/*
* Issue another read request or the device will stall, for whatever
* reason. This happens both with and without the short transfer quirk.
uint64_t sample, high_nibbles, word;
uint32_t *slice;
uint8_t *out_p;
- unsigned int words_left;
- unsigned int max_samples, run_samples;
- unsigned int wi, ri, si;
+ unsigned int words_left, max_samples, run_samples, wi, ri, si;
/* Number of 36-bit words remaining in the transfer buffer. */
words_left = MIN(acq->mem_addr_next, acq->mem_addr_stop)
acq->samples_done += run_samples;
if (run_samples == max_samples)
- break; /* packet full or sample limit reached */
+ break; /* Packet full or sample limit reached. */
if (wi >= words_left)
- break; /* done with current transfer */
+ break; /* Done with current transfer. */
/* Get the current slice of 8 packed 36-bit words. */
slice = &acq->xfer_buf_in[(acq->in_index + wi) / 8 * 9];
- si = (acq->in_index + wi) % 8; /* word index within slice */
+ si = (acq->in_index + wi) % 8; /* Word index within slice. */
/* Extract the next 36-bit word. */
high_nibbles = LWLA_TO_UINT32(slice[8]);
acq->rle = RLE_STATE_DATA;
}
}
+
acq->in_index += wi;
acq->mem_addr_done += wi;
}
{
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
- int xfer_len;
- int ret;
+ int xfer_len, ret;
uint16_t command[3];
unsigned char buf[512];
-
const int lreg_count = 10;
devc = sdi->priv;
{
struct dev_context *devc;
struct drv_context *drvc;
- int config;
- int ret;
+ int config, ret;
devc = sdi->priv;
drvc = sdi->driver->context;
config = FPGA_EXTNEG;
if (config == devc->active_fpga_config)
- return SR_OK; /* no change */
+ return SR_OK; /* No change. */
ret = lwla_send_bitstream(drvc->sr_ctx, sdi->conn,
bitstream_map[config]);
{REG_LONG_HIGH, 0},
{REG_LONG_STROBE, 0},
};
- uint64_t divider_count;
- uint64_t trigger_mask;
+ uint64_t divider_count, trigger_mask;
struct dev_context *devc;
struct sr_usb_dev_inst *usb;
struct acquisition_state *acq;
end_addr = MIN(acq->mem_addr_next, acq->mem_addr_stop);
acq->in_index = 0;
+
/*
* Repeatedly call the model-specific read response handler until
* all data received in the transfer has been accounted for.
struct drv_context *drvc;
struct dev_context *devc;
int ret;
-
const int poll_interval_ms = 100;
drvc = sdi->driver->context;
usb_source_remove(sdi->session, drvc->sr_ctx);
clear_acquisition_state(sdi);
}
+
return ret;
}
enum signal_edge cfg_clock_edge; /* ext clock edge setting */
enum trigger_source cfg_trigger_source; /* trigger source setting */
enum signal_edge cfg_trigger_slope; /* ext trigger slope setting */
-
};
/** LWLA model descriptor.