sysclk-lwla: Minor whitespace and consistency fixes.

This commit is contained in:
Uwe Hermann 2015-12-23 15:25:18 +01:00
parent 0cadb8a350
commit d64b5f43cc
6 changed files with 53 additions and 73 deletions

View File

@ -113,9 +113,8 @@ static struct sr_dev_inst *dev_inst_new_matching(GSList *conn_matches,
const struct model_info *model; const struct model_info *model;
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct libusb_device_descriptor des; struct libusb_device_descriptor des;
int bus, address; int bus, address, ret;
unsigned int vid, pid; unsigned int vid, pid;
int ret;
bus = libusb_get_bus_number(dev); bus = libusb_get_bus_number(dev);
address = libusb_get_device_address(dev); address = libusb_get_device_address(dev);
@ -217,11 +216,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
*/ */
static GSList *dev_list(const struct sr_dev_driver *di) static GSList *dev_list(const struct sr_dev_driver *di)
{ {
struct drv_context *drvc; return ((struct drv_context *)(di->context))->instances;
drvc = di->context;
return drvc->instances;
} }
/* Destroy the private device context. /* Destroy the private device context.
@ -234,7 +229,7 @@ static void clear_dev_context(void *priv)
if (devc->acquisition) { if (devc->acquisition) {
sr_err("Cannot clear device context during acquisition!"); sr_err("Cannot clear device context during acquisition!");
return; /* leak and pray */ return; /* Leak and pray. */
} }
sr_dbg("Device context cleared."); sr_dbg("Device context cleared.");
@ -254,10 +249,8 @@ static int dev_clear(const struct sr_dev_driver *di)
*/ */
static int drain_usb(struct sr_usb_dev_inst *usb, unsigned int endpoint) static int drain_usb(struct sr_usb_dev_inst *usb, unsigned int endpoint)
{ {
int drained, xfer_len; int drained, xfer_len, ret;
int ret;
unsigned char buf[512]; unsigned char buf[512];
const unsigned int drain_timeout_ms = 10; const unsigned int drain_timeout_ms = 10;
drained = 0; drained = 0;
@ -279,6 +272,7 @@ static int drain_usb(struct sr_usb_dev_inst *usb, unsigned int endpoint)
sr_warn("Drained %d bytes from USB endpoint %u.", sr_warn("Drained %d bytes from USB endpoint %u.",
drained, endpoint & (LIBUSB_ENDPOINT_IN - 1)); drained, endpoint & (LIBUSB_ENDPOINT_IN - 1));
} }
return SR_OK; return SR_OK;
} }
@ -289,8 +283,7 @@ static int dev_open(struct sr_dev_inst *sdi)
struct drv_context *drvc; struct drv_context *drvc;
struct dev_context *devc; struct dev_context *devc;
struct sr_usb_dev_inst *usb; struct sr_usb_dev_inst *usb;
int i; int i, ret;
int ret;
drvc = sdi->driver->context; drvc = sdi->driver->context;
devc = sdi->priv; devc = sdi->priv;
@ -411,6 +404,7 @@ static int has_devopt(const struct model_info *model, uint32_t key)
if ((model->devopts[i] & (SR_CONF_MASK | key)) == key) if ((model->devopts[i] & (SR_CONF_MASK | key)) == key)
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
@ -492,6 +486,7 @@ static int lookup_index(GVariant *value, const char *const *table, int len)
if (strcmp(entry, table[i]) == 0) if (strcmp(entry, table[i]) == 0)
return i; return i;
} }
return -1; return -1;
} }
@ -605,9 +600,7 @@ static int config_channel_set(const struct sr_dev_inst *sdi,
*/ */
static int prepare_trigger_masks(const struct sr_dev_inst *sdi) static int prepare_trigger_masks(const struct sr_dev_inst *sdi)
{ {
uint64_t trigger_mask; uint64_t trigger_mask, trigger_values, trigger_edge_mask;
uint64_t trigger_values;
uint64_t trigger_edge_mask;
uint64_t level_bit, type_bit; uint64_t level_bit, type_bit;
struct dev_context *devc; struct dev_context *devc;
struct sr_trigger *trigger; struct sr_trigger *trigger;
@ -637,14 +630,14 @@ static int prepare_trigger_masks(const struct sr_dev_inst *sdi)
match = node->data; match = node->data;
if (!match->channel->enabled) if (!match->channel->enabled)
continue; /* ignore disabled channel */ continue; /* Ignore disabled channel. */
idx = match->channel->index; idx = match->channel->index;
trg = match->match; trg = match->match;
if (idx < 0 || idx >= devc->model->num_channels) { if (idx < 0 || idx >= devc->model->num_channels) {
sr_err("Channel index %d out of range.", idx); 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 if (trg != SR_TRIGGER_ZERO
&& trg != SR_TRIGGER_ONE && trg != SR_TRIGGER_ONE
@ -713,8 +706,7 @@ static int config_list(uint32_t key, GVariant **data,
if (key == SR_CONF_SCAN_OPTIONS) { if (key == SR_CONF_SCAN_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
scanopts, ARRAY_SIZE(scanopts), scanopts, ARRAY_SIZE(scanopts), sizeof(scanopts[0]));
sizeof(scanopts[0]));
return SR_OK; return SR_OK;
} }
if (!sdi) { if (!sdi) {
@ -723,8 +715,7 @@ static int config_list(uint32_t key, GVariant **data,
/* List driver capabilities. */ /* List driver capabilities. */
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
drvopts, ARRAY_SIZE(drvopts), drvopts, ARRAY_SIZE(drvopts), sizeof(drvopts[0]));
sizeof(drvopts[0]));
return SR_OK; return SR_OK;
} }
@ -733,8 +724,7 @@ static int config_list(uint32_t key, GVariant **data,
/* List the model's device options. */ /* List the model's device options. */
if (key == SR_CONF_DEVICE_OPTIONS) { if (key == SR_CONF_DEVICE_OPTIONS) {
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
devc->model->devopts, devc->model->devopts, devc->model->num_devopts,
devc->model->num_devopts,
sizeof(devc->model->devopts[0])); sizeof(devc->model->devopts[0]));
return SR_OK; return SR_OK;
} }
@ -746,16 +736,14 @@ static int config_list(uint32_t key, GVariant **data,
case SR_CONF_SAMPLERATE: case SR_CONF_SAMPLERATE:
g_variant_builder_init(&gvb, G_VARIANT_TYPE_VARDICT); g_variant_builder_init(&gvb, G_VARIANT_TYPE_VARDICT);
gvar = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64, gvar = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT64,
devc->model->samplerates, devc->model->samplerates, devc->model->num_samplerates,
devc->model->num_samplerates,
sizeof(devc->model->samplerates[0])); sizeof(devc->model->samplerates[0]));
g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar); g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
*data = g_variant_builder_end(&gvb); *data = g_variant_builder_end(&gvb);
break; break;
case SR_CONF_TRIGGER_MATCH: case SR_CONF_TRIGGER_MATCH:
*data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
trigger_matches, trigger_matches, ARRAY_SIZE(trigger_matches),
ARRAY_SIZE(trigger_matches),
sizeof(trigger_matches[0])); sizeof(trigger_matches[0]));
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
@ -798,6 +786,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
struct dev_context *devc; struct dev_context *devc;
(void)cb_data; (void)cb_data;
devc = sdi->priv; devc = sdi->priv;
if (sdi->status != SR_ST_ACTIVE) if (sdi->status != SR_ST_ACTIVE)
@ -807,6 +796,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
devc->cancel_requested = TRUE; devc->cancel_requested = TRUE;
sr_dbg("Stopping acquisition."); sr_dbg("Stopping acquisition.");
} }
return SR_OK; return SR_OK;
} }

View File

@ -24,8 +24,8 @@
#include "lwla.h" #include "lwla.h"
#include "protocol.h" #include "protocol.h"
#define BITSTREAM_MAX_SIZE (256 * 1024) /* bitstream size limit for safety */ #define BITSTREAM_MAX_SIZE (256 * 1024) /* Bitstream size limit for safety */
#define BITSTREAM_HEADER_SIZE 4 /* transfer header size in bytes */ #define BITSTREAM_HEADER_SIZE 4 /* Transfer header size in bytes */
/* Load a bitstream file into memory. Returns a newly allocated array /* Load a bitstream file into memory. Returns a newly allocated array
* consisting of a 32-bit length field followed by the bitstream data. * consisting of a 32-bit length field followed by the bitstream data.
@ -81,9 +81,7 @@ SR_PRIV int lwla_send_bitstream(struct sr_context *ctx,
const char *name) const char *name)
{ {
unsigned char *stream; unsigned char *stream;
int ret; int ret, length, xfer_len;
int length;
int xfer_len;
if (!ctx || !usb || !name) if (!ctx || !usb || !name)
return SR_ERR_BUG; return SR_ERR_BUG;
@ -120,8 +118,7 @@ SR_PRIV int lwla_send_bitstream(struct sr_context *ctx,
SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb, SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb,
const uint16_t *command, int cmd_len) const uint16_t *command, int cmd_len)
{ {
int ret; int ret, xfer_len;
int xfer_len;
if (!usb || !command || cmd_len <= 0) if (!usb || !command || cmd_len <= 0)
return SR_ERR_BUG; return SR_ERR_BUG;
@ -140,6 +137,7 @@ SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb,
LWLA_TO_UINT16(command[0]), xfer_len, cmd_len * 2); LWLA_TO_UINT16(command[0]), xfer_len, cmd_len * 2);
return SR_ERR; return SR_ERR;
} }
return SR_OK; return SR_OK;
} }
@ -157,16 +155,16 @@ SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb,
sr_dbg("Failed to receive reply: %s.", libusb_error_name(ret)); sr_dbg("Failed to receive reply: %s.", libusb_error_name(ret));
return SR_ERR; return SR_ERR;
} }
return SR_OK; return SR_OK;
} }
SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb, SR_PRIV int lwla_read_reg(const struct sr_usb_dev_inst *usb,
uint16_t reg, uint32_t *value) uint16_t reg, uint32_t *value)
{ {
int xfer_len; int xfer_len, ret;
int ret;
uint16_t command[2]; 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[0] = LWLA_WORD(CMD_READ_REG);
command[1] = LWLA_WORD(reg); command[1] = LWLA_WORD(reg);
@ -205,8 +203,7 @@ SR_PRIV int lwla_write_reg(const struct sr_usb_dev_inst *usb,
SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb, SR_PRIV int lwla_write_regs(const struct sr_usb_dev_inst *usb,
const struct regval *regvals, int count) const struct regval *regvals, int count)
{ {
int i; int i, ret;
int ret;
ret = SR_OK; ret = SR_OK;

View File

@ -142,9 +142,7 @@ static void read_response_rle(struct acquisition_state *acq)
{ {
uint32_t *in_p; uint32_t *in_p;
uint16_t *out_p; uint16_t *out_p;
unsigned int words_left; unsigned int words_left, max_samples, run_samples, wi, ri;
unsigned int max_samples, run_samples;
unsigned int wi, ri;
uint32_t word; uint32_t word;
uint16_t sample; uint16_t sample;
@ -170,14 +168,15 @@ static void read_response_rle(struct acquisition_state *acq)
acq->samples_done += run_samples; acq->samples_done += run_samples;
if (run_samples == max_samples) if (run_samples == max_samples)
break; /* packet full or sample limit reached */ break; /* Packet full or sample limit reached. */
if (wi >= words_left) if (wi >= words_left)
break; /* done with current transfer */ break; /* Done with current transfer. */
word = GUINT32_FROM_LE(in_p[wi]); word = GUINT32_FROM_LE(in_p[wi]);
acq->sample = word >> 16; acq->sample = word >> 16;
acq->run_len = (word & 0xFFFF) + 1; acq->run_len = (word & 0xFFFF) + 1;
} }
acq->in_index += wi; acq->in_index += wi;
acq->mem_addr_done += wi; acq->mem_addr_done += wi;
} }
@ -197,8 +196,7 @@ static int test_read_memory(const struct sr_dev_inst *sdi,
struct dev_context *devc; struct dev_context *devc;
struct sr_usb_dev_inst *usb; struct sr_usb_dev_inst *usb;
unsigned int i; unsigned int i;
int xfer_len; int xfer_len, ret;
int ret;
uint16_t command[5]; uint16_t command[5];
unsigned char reply[512]; unsigned char reply[512];
@ -231,6 +229,7 @@ static int test_read_memory(const struct sr_dev_inst *sdi,
xfer_len); xfer_len);
return SR_ERR; return SR_ERR;
} }
return SR_OK; return SR_OK;
} }
@ -240,19 +239,18 @@ static int apply_fpga_config(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct dev_context *devc;
struct drv_context *drvc; struct drv_context *drvc;
int config; int config, ret;
int ret;
devc = sdi->priv; devc = sdi->priv;
drvc = sdi->driver->context; drvc = sdi->driver->context;
if (sdi->status == SR_ST_INACTIVE) 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; config = (devc->cfg_rle) ? FPGA_100_TS : FPGA_100;
if (config == devc->active_fpga_config) 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, ret = lwla_send_bitstream(drvc->sr_ctx, sdi->conn,
bitstream_map[config]); bitstream_map[config]);
@ -271,7 +269,6 @@ static int device_init_check(const struct sr_dev_inst *sdi)
}; };
uint32_t value; uint32_t value;
int ret; int ret;
const unsigned int test_count = 24; const unsigned int test_count = 24;
lwla_read_reg(sdi->conn, REG_TEST_ID, &value); lwla_read_reg(sdi->conn, REG_TEST_ID, &value);
@ -293,6 +290,7 @@ static int device_init_check(const struct sr_dev_inst *sdi)
ret = test_read_memory(sdi, 0, test_count); ret = test_read_memory(sdi, 0, test_count);
if (ret != SR_OK) if (ret != SR_OK)
return ret; return ret;
/* /*
* Issue another read request or the device will stall, for whatever * Issue another read request or the device will stall, for whatever
* reason. This happens both with and without the short transfer quirk. * reason. This happens both with and without the short transfer quirk.

View File

@ -208,9 +208,7 @@ static void read_response(struct acquisition_state *acq)
uint64_t sample, high_nibbles, word; uint64_t sample, high_nibbles, word;
uint32_t *slice; uint32_t *slice;
uint8_t *out_p; uint8_t *out_p;
unsigned int words_left; unsigned int words_left, max_samples, run_samples, wi, ri, si;
unsigned int max_samples, run_samples;
unsigned int wi, ri, si;
/* Number of 36-bit words remaining in the transfer buffer. */ /* Number of 36-bit words remaining in the transfer buffer. */
words_left = MIN(acq->mem_addr_next, acq->mem_addr_stop) words_left = MIN(acq->mem_addr_next, acq->mem_addr_stop)
@ -239,13 +237,13 @@ static void read_response(struct acquisition_state *acq)
acq->samples_done += run_samples; acq->samples_done += run_samples;
if (run_samples == max_samples) if (run_samples == max_samples)
break; /* packet full or sample limit reached */ break; /* Packet full or sample limit reached. */
if (wi >= words_left) if (wi >= words_left)
break; /* done with current transfer */ break; /* Done with current transfer. */
/* Get the current slice of 8 packed 36-bit words. */ /* Get the current slice of 8 packed 36-bit words. */
slice = &acq->xfer_buf_in[(acq->in_index + wi) / 8 * 9]; 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. */ /* Extract the next 36-bit word. */
high_nibbles = LWLA_TO_UINT32(slice[8]); high_nibbles = LWLA_TO_UINT32(slice[8]);
@ -262,6 +260,7 @@ static void read_response(struct acquisition_state *acq)
acq->rle = RLE_STATE_DATA; acq->rle = RLE_STATE_DATA;
} }
} }
acq->in_index += wi; acq->in_index += wi;
acq->mem_addr_done += wi; acq->mem_addr_done += wi;
} }
@ -279,11 +278,9 @@ static int detect_short_transfer_quirk(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct dev_context *devc;
struct sr_usb_dev_inst *usb; struct sr_usb_dev_inst *usb;
int xfer_len; int xfer_len, ret;
int ret;
uint16_t command[3]; uint16_t command[3];
unsigned char buf[512]; unsigned char buf[512];
const int lreg_count = 10; const int lreg_count = 10;
devc = sdi->priv; devc = sdi->priv;
@ -326,8 +323,7 @@ static int apply_fpga_config(const struct sr_dev_inst *sdi)
{ {
struct dev_context *devc; struct dev_context *devc;
struct drv_context *drvc; struct drv_context *drvc;
int config; int config, ret;
int ret;
devc = sdi->priv; devc = sdi->priv;
drvc = sdi->driver->context; drvc = sdi->driver->context;
@ -342,7 +338,7 @@ static int apply_fpga_config(const struct sr_dev_inst *sdi)
config = FPGA_EXTNEG; config = FPGA_EXTNEG;
if (config == devc->active_fpga_config) 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, ret = lwla_send_bitstream(drvc->sr_ctx, sdi->conn,
bitstream_map[config]); bitstream_map[config]);
@ -386,8 +382,7 @@ static int setup_acquisition(const struct sr_dev_inst *sdi)
{REG_LONG_HIGH, 0}, {REG_LONG_HIGH, 0},
{REG_LONG_STROBE, 0}, {REG_LONG_STROBE, 0},
}; };
uint64_t divider_count; uint64_t divider_count, trigger_mask;
uint64_t trigger_mask;
struct dev_context *devc; struct dev_context *devc;
struct sr_usb_dev_inst *usb; struct sr_usb_dev_inst *usb;
struct acquisition_state *acq; struct acquisition_state *acq;

View File

@ -212,6 +212,7 @@ static void handle_read_response(const struct sr_dev_inst *sdi)
end_addr = MIN(acq->mem_addr_next, acq->mem_addr_stop); end_addr = MIN(acq->mem_addr_next, acq->mem_addr_stop);
acq->in_index = 0; acq->in_index = 0;
/* /*
* Repeatedly call the model-specific read response handler until * Repeatedly call the model-specific read response handler until
* all data received in the transfer has been accounted for. * all data received in the transfer has been accounted for.
@ -545,7 +546,6 @@ SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi)
struct drv_context *drvc; struct drv_context *drvc;
struct dev_context *devc; struct dev_context *devc;
int ret; int ret;
const int poll_interval_ms = 100; const int poll_interval_ms = 100;
drvc = sdi->driver->context; drvc = sdi->driver->context;
@ -585,5 +585,6 @@ SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi)
usb_source_remove(sdi->session, drvc->sr_ctx); usb_source_remove(sdi->session, drvc->sr_ctx);
clear_acquisition_state(sdi); clear_acquisition_state(sdi);
} }
return ret; return ret;
} }

View File

@ -140,7 +140,6 @@ struct dev_context {
enum signal_edge cfg_clock_edge; /* ext clock edge setting */ enum signal_edge cfg_clock_edge; /* ext clock edge setting */
enum trigger_source cfg_trigger_source; /* trigger source setting */ enum trigger_source cfg_trigger_source; /* trigger source setting */
enum signal_edge cfg_trigger_slope; /* ext trigger slope setting */ enum signal_edge cfg_trigger_slope; /* ext trigger slope setting */
}; };
/** LWLA model descriptor. /** LWLA model descriptor.