]> sigrok.org Git - libsigrok.git/commitdiff
sysclk-lwla: Minor whitespace and consistency fixes.
authorUwe Hermann <redacted>
Wed, 23 Dec 2015 14:25:18 +0000 (15:25 +0100)
committerUwe Hermann <redacted>
Thu, 7 Jan 2016 22:50:17 +0000 (23:50 +0100)
src/hardware/sysclk-lwla/api.c
src/hardware/sysclk-lwla/lwla.c
src/hardware/sysclk-lwla/lwla1016.c
src/hardware/sysclk-lwla/lwla1034.c
src/hardware/sysclk-lwla/protocol.c
src/hardware/sysclk-lwla/protocol.h

index d9a6661798aedc6ddfe07bff40332741afb454d9..7e6190378b2063dfab166a9608cb066716798c63 100644 (file)
@@ -113,9 +113,8 @@ static struct sr_dev_inst *dev_inst_new_matching(GSList *conn_matches,
        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);
@@ -217,11 +216,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
  */
 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.
@@ -234,7 +229,7 @@ static void clear_dev_context(void *priv)
 
        if (devc->acquisition) {
                sr_err("Cannot clear device context during acquisition!");
-               return; /* leak and pray */
+               return; /* Leak and pray. */
        }
        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)
 {
-       int drained, xfer_len;
-       int ret;
+       int drained, xfer_len, ret;
        unsigned char buf[512];
-
        const unsigned int drain_timeout_ms = 10;
 
        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.",
                        drained, endpoint & (LIBUSB_ENDPOINT_IN - 1));
        }
+
        return SR_OK;
 }
 
@@ -289,8 +283,7 @@ static int dev_open(struct sr_dev_inst *sdi)
        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;
@@ -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)
                        return TRUE;
        }
+
        return FALSE;
 }
 
@@ -492,6 +486,7 @@ static int lookup_index(GVariant *value, const char *const *table, int len)
                if (strcmp(entry, table[i]) == 0)
                        return i;
        }
+
        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)
 {
-       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;
@@ -637,14 +630,14 @@ static int prepare_trigger_masks(const struct sr_dev_inst *sdi)
                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
@@ -713,8 +706,7 @@ static int config_list(uint32_t key, GVariant **data,
 
        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) {
@@ -723,8 +715,7 @@ static int config_list(uint32_t key, GVariant **data,
 
                /* 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;
        }
 
@@ -733,9 +724,8 @@ static int config_list(uint32_t key, GVariant **data,
        /* 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;
        }
 
@@ -746,26 +736,24 @@ static int config_list(uint32_t key, GVariant **data,
        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. */
@@ -798,6 +786,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        struct dev_context *devc;
 
        (void)cb_data;
+
        devc = sdi->priv;
 
        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;
                sr_dbg("Stopping acquisition.");
        }
+
        return SR_OK;
 }
 
index b7a7bbe17e5d33a63151a3310a6f33487796f5ab..6e6413fb9c87babcaa138c33814cd6bbde43e436 100644 (file)
@@ -24,8 +24,8 @@
 #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.
@@ -81,9 +81,7 @@ SR_PRIV int lwla_send_bitstream(struct sr_context *ctx,
                                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;
@@ -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,
                              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;
@@ -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);
                return SR_ERR;
        }
+
        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));
                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);
@@ -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,
                            const struct regval *regvals, int count)
 {
-       int i;
-       int ret;
+       int i, ret;
 
        ret = SR_OK;
 
index 61435553951ccf9285712df6c76672da5dcc72b6..b280b7a2790d26708abe1b8ffa17c976c1380431 100644 (file)
@@ -142,9 +142,7 @@ static void read_response_rle(struct acquisition_state *acq)
 {
        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;
 
@@ -170,14 +168,15 @@ static void read_response_rle(struct acquisition_state *acq)
                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;
 }
@@ -197,8 +196,7 @@ static int test_read_memory(const struct sr_dev_inst *sdi,
        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];
 
@@ -231,6 +229,7 @@ static int test_read_memory(const struct sr_dev_inst *sdi,
                       xfer_len);
                return SR_ERR;
        }
+
        return SR_OK;
 }
 
@@ -240,19 +239,18 @@ static int apply_fpga_config(const struct sr_dev_inst *sdi)
 {
        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]);
@@ -271,7 +269,6 @@ static int device_init_check(const struct sr_dev_inst *sdi)
        };
        uint32_t value;
        int ret;
-
        const unsigned int test_count = 24;
 
        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);
        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.
index d29a9df2ed869449d224df8a3b7c02b13f910b99..14692c38c618a58bac0f08b779cee3c2d5a93557 100644 (file)
@@ -208,9 +208,7 @@ static void read_response(struct acquisition_state *acq)
        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)
@@ -239,13 +237,13 @@ static void read_response(struct acquisition_state *acq)
                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]);
@@ -262,6 +260,7 @@ static void read_response(struct acquisition_state *acq)
                        acq->rle = RLE_STATE_DATA;
                }
        }
+
        acq->in_index += 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 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;
@@ -326,8 +323,7 @@ static int apply_fpga_config(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct drv_context *drvc;
-       int config;
-       int ret;
+       int config, ret;
 
        devc = sdi->priv;
        drvc = sdi->driver->context;
@@ -342,7 +338,7 @@ static int apply_fpga_config(const struct sr_dev_inst *sdi)
                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]);
@@ -386,8 +382,7 @@ static int setup_acquisition(const struct sr_dev_inst *sdi)
                {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;
index a8d71b799c9cae57b9458a917425c1f637530cfd..20cf10f9c5fabc81b2cf9329e8babc778ae3a6e4 100644 (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);
        acq->in_index = 0;
+
        /*
         * Repeatedly call the model-specific read response handler until
         * 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 dev_context *devc;
        int ret;
-
        const int poll_interval_ms = 100;
 
        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);
                clear_acquisition_state(sdi);
        }
+
        return ret;
 }
index 5bdc71feff3a5d93595c242b229600b02d70b2bc..ebfc704a97417b7737f8cd1c7fb11ac0fba93639 100644 (file)
@@ -140,7 +140,6 @@ struct dev_context {
        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.