]> sigrok.org Git - libsigrok.git/commitdiff
saleae-logic16: Whitespace fixes, cosmetics.
authorUwe Hermann <redacted>
Wed, 21 Aug 2013 00:02:41 +0000 (02:02 +0200)
committerUwe Hermann <redacted>
Wed, 21 Aug 2013 09:33:37 +0000 (11:33 +0200)
hardware/saleae-logic16/api.c
hardware/saleae-logic16/protocol.c
hardware/saleae-logic16/protocol.h

index c3fbd072971a68429f888b905a2c4333aff9d305..baaf0e487b33313ae0d2ca2bbc7e79d50c770a1f 100644 (file)
@@ -28,9 +28,9 @@
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
-#define LOGIC16_VID 0x21a9
-#define LOGIC16_PID 0x1001
-#define NUM_PROBES  16
+#define LOGIC16_VID            0x21a9
+#define LOGIC16_PID            0x1001
+#define NUM_PROBES             16
 
 #define USB_INTERFACE          0
 #define USB_CONFIGURATION      1
@@ -39,7 +39,6 @@
 #define MAX_RENUM_DELAY_MS     3000
 #define NUM_SIMUL_TRANSFERS    32
 
-
 SR_PRIV struct sr_dev_driver saleae_logic16_driver_info;
 static struct sr_dev_driver *di = &saleae_logic16_driver_info;
 
@@ -118,7 +117,7 @@ static gboolean check_conf_profile(libusb_device *dev)
                        break;
 
                if (libusb_get_string_descriptor_ascii(hdl,
-                               des.iProduct, strdesc, sizeof(strdesc)) < 0)
+                   des.iProduct, strdesc, sizeof(strdesc)) < 0)
                        break;
                if (strcmp((const char *)strdesc, "Logic S/16"))
                        break;
@@ -180,7 +179,7 @@ static GSList *scan(GSList *options)
                                continue;
                }
 
-               if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) {
+               if ((ret = libusb_get_device_descriptor(devlist[i], &des)) != 0) {
                        sr_warn("Failed to get device descriptor: %s.",
                                libusb_error_name(ret));
                        continue;
@@ -215,8 +214,9 @@ static GSList *scan(GSList *options)
                        sr_dbg("Found a Logic16 device.");
                        sdi->status = SR_ST_INACTIVE;
                        sdi->inst_type = SR_INST_USB;
-                       sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
-                                                       libusb_get_device_address(devlist[i]), NULL);
+                       sdi->conn = sr_usb_dev_inst_new(
+                               libusb_get_bus_number(devlist[i]),
+                               libusb_get_device_address(devlist[i]), NULL);
                } else {
                        if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
                                                  FX2_FIRMWARE) == SR_OK)
@@ -226,8 +226,8 @@ static GSList *scan(GSList *options)
                                sr_err("Firmware upload failed for "
                                       "device %d.", devcnt);
                        sdi->inst_type = SR_INST_USB;
-                       sdi->conn = sr_usb_dev_inst_new (libusb_get_bus_number(devlist[i]),
-                                                        0xff, NULL);
+                       sdi->conn = sr_usb_dev_inst_new(
+                               libusb_get_bus_number(devlist[i]), 0xff, NULL);
                }
        }
        libusb_free_device_list(devlist, 1);
@@ -280,8 +280,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                        continue;
                }
 
-               if (des.idVendor != LOGIC16_VID
-                   || des.idProduct != LOGIC16_PID)
+               if (des.idVendor != LOGIC16_VID || des.idProduct != LOGIC16_PID)
                        continue;
 
                if (sdi->status == SR_ST_INITIALIZING) {
@@ -296,7 +295,7 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                         * this device by vendor, product, bus and address.
                         */
                        if (libusb_get_bus_number(devlist[i]) != usb->bus
-                               || libusb_get_device_address(devlist[i]) != usb->address)
+                           || libusb_get_device_address(devlist[i]) != usb->address)
                                /* This is not the one. */
                                continue;
                }
@@ -314,16 +313,14 @@ static int logic16_dev_open(struct sr_dev_inst *sdi)
                        break;
                }
 
-               if ((ret = saleae_logic16_init_device(sdi)) != SR_OK) {
+               if ((ret = logic16_init_device(sdi)) != SR_OK) {
                        sr_err("Failed to init device.");
                        break;
                }
 
                sdi->status = SR_ST_ACTIVE;
-               sr_info("Opened device %d on %d.%d, "
-                       "interface %d.",
-                       sdi->index, usb->bus, usb->address,
-                       USB_INTERFACE);
+               sr_info("Opened device %d on %d.%d, interface %d.",
+                       sdi->index, usb->bus, usb->address, USB_INTERFACE);
 
                break;
        }
@@ -381,7 +378,7 @@ static int dev_open(struct sr_dev_inst *sdi)
 
        ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
        if (ret != 0) {
-               switch(ret) {
+               switch (ret) {
                case LIBUSB_ERROR_BUSY:
                        sr_err("Unable to claim USB interface. Another "
                               "program or driver has already claimed it.");
@@ -447,7 +444,7 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
        GVariant *range[2];
        char str[128];
        int ret;
-       unsigned i;
+       unsigned int i;
 
        ret = SR_OK;
        switch (key) {
@@ -473,15 +470,16 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
                        return SR_ERR;
                devc = sdi->priv;
                ret = SR_ERR;
-               for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++)
-                       if (devc->selected_voltage_range ==
-                           volt_thresholds[i].range) {
-                               range[0] = g_variant_new_double(volt_thresholds[i].low);
-                               range[1] = g_variant_new_double(volt_thresholds[i].high);
-                               *data = g_variant_new_tuple(range, 2);
-                               ret = SR_OK;
-                               break;
-                       }
+               for (i = 0; i < ARRAY_SIZE(volt_thresholds); i++) {
+                       if (devc->selected_voltage_range !=
+                           volt_thresholds[i].range)
+                               continue;
+                       range[0] = g_variant_new_double(volt_thresholds[i].low);
+                       range[1] = g_variant_new_double(volt_thresholds[i].high);
+                       *data = g_variant_new_tuple(range, 2);
+                       ret = SR_OK;
+                       break;
+               }
                break;
        default:
                return SR_ERR_NA;
@@ -495,7 +493,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        gdouble low, high;
        int ret;
-       unsigned i;
+       unsigned int i;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
@@ -535,7 +533,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
        GVariant *gvar, *range[2];
        GVariantBuilder gvb;
        int ret;
-       unsigned i;
+       unsigned int i;
 
        (void)sdi;
 
@@ -551,8 +549,8 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
                break;
        case SR_CONF_SAMPLERATE:
                g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
-               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"), samplerates,
-                               ARRAY_SIZE(samplerates), sizeof(uint64_t));
+               gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
+                       samplerates, ARRAY_SIZE(samplerates), sizeof(uint64_t));
                g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
                *data = g_variant_builder_end(&gvb);
                break;
@@ -646,14 +644,15 @@ static int configure_probes(const struct sr_dev_inst *sdi)
                devc->cur_channels |= probe_bit;
 
 #ifdef WORDS_BIGENDIAN
-               /* Output logic data should be stored in little endian
-                  format.  To speed things up during conversion, do the
-                  switcharoo here instead. */
-
+               /*
+                * Output logic data should be stored in little endian format.
+                * To speed things up during conversion, do the switcharoo
+                * here instead.
+                */
                probe_bit = 1 << (probe->index ^ 8);
 #endif
 
-               devc->channel_masks[devc->num_channels ++] = probe_bit;
+               devc->channel_masks[devc->num_channels++] = probe_bit;
        }
 
        return SR_OK;
@@ -677,15 +676,14 @@ static int receive_data(int fd, int revents, void *cb_data)
        libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv);
 
        if (devc->num_samples == -2) {
-               saleae_logic16_abort_acquisition(sdi);
+               logic16_abort_acquisition(sdi);
                abort_acquisition(devc);
        }
 
        return TRUE;
 }
 
-static int dev_acquisition_start(const struct sr_dev_inst *sdi,
-                                void *cb_data)
+static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc;
        struct drv_context *drvc;
@@ -704,7 +702,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        devc = sdi->priv;
        usb = sdi->conn;
 
-       /* Configures devc->cur_channels */
+       /* Configures devc->cur_channels. */
        if (configure_probes(sdi) != SR_OK) {
                sr_err("Failed to configure probes.");
                return SR_ERR;
@@ -736,8 +734,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR_MALLOC;
        }
 
-       if ((ret = saleae_logic16_setup_acquisition(sdi, devc->cur_samplerate,
-                                                   devc->cur_channels)) != SR_OK) {
+       if ((ret = logic16_setup_acquisition(sdi, devc->cur_samplerate,
+                                            devc->cur_channels)) != SR_OK) {
                g_free(devc->transfers);
                g_free(devc->convbuffer);
                return ret;
@@ -758,7 +756,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                transfer = libusb_alloc_transfer(0);
                libusb_fill_bulk_transfer(transfer, usb->devhdl,
                                2 | LIBUSB_ENDPOINT_IN, buf, size,
-                               saleae_logic16_receive_transfer, devc, timeout);
+                               logic16_receive_transfer, devc, timeout);
                if ((ret = libusb_submit_transfer(transfer)) != 0) {
                        sr_err("Failed to submit transfer: %s.",
                               libusb_error_name(ret));
@@ -773,7 +771,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
        for (i = 0; lupfd[i]; i++);
-       if (!(devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1)))) {
+       devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1));
+       if (!devc->usbfd) {
                abort_acquisition(devc);
                free(lupfd);
                return SR_ERR;
@@ -789,7 +788,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
-       if ((ret = saleae_logic16_start_acquisition(sdi)) != SR_OK) {
+       if ((ret = logic16_start_acquisition(sdi)) != SR_OK) {
                abort_acquisition(devc);
                return ret;
        }
@@ -806,7 +805,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       ret = saleae_logic16_abort_acquisition(sdi);
+       ret = logic16_abort_acquisition(sdi);
 
        abort_acquisition(sdi->priv);
 
index 5dbda1428737b73fefa2d7d8c5be79e5bb586833..4cea180f50f660a0af69e33c531efea578d0997f 100644 (file)
 
 #define MAX_EMPTY_TRANSFERS            64
 
-
 static void encrypt(uint8_t *dest, const uint8_t *src, uint8_t cnt)
 {
        uint8_t state1 = 0x9b, state2 = 0x54;
+       uint8_t t, v;
        int i;
 
-       for (i=0; i<cnt; i++) {
-               uint8_t t, v = src[i];
+       for (i = 0; i < cnt; i++) {
+               v = src[i];
                t = (((v ^ state2 ^ 0x2b) - 0x05) ^ 0x35) - 0x39;
                t = (((t ^ state1 ^ 0x5a) - 0xb0) ^ 0x38) - 0x45;
                dest[i] = state2 = t;
@@ -84,9 +84,11 @@ static void encrypt(uint8_t *dest, const uint8_t *src, uint8_t cnt)
 static void decrypt(uint8_t *dest, const uint8_t *src, uint8_t cnt)
 {
        uint8_t state1 = 0x9b, state2 = 0x54;
+       uint8_t t, v;
        int i;
-       for (i=0; i<cnt; i++) {
-               uint8_t t, v = src[i];
+
+       for (i = 0; i < cnt; i++) {
+               v = src[i];
                t = (((v + 0x45) ^ 0x38) + 0xb0) ^ 0x5a ^ state1;
                t = (((t + 0x39) ^ 0x35) + 0x05) ^ 0x2b ^ state2;
                dest[i] = state1 = t;
@@ -112,28 +114,29 @@ static int do_ep1_command(const struct sr_dev_inst *sdi,
 
        ret = libusb_bulk_transfer(usb->devhdl, 1, buf, cmd_len, &xfer, 1000);
        if (ret != 0) {
-               sr_dbg("Failed to send EP1 command 0x%02x: %s",
+               sr_dbg("Failed to send EP1 command 0x%02x: %s.",
                       command[0], libusb_error_name(ret));
                return SR_ERR;
        }
        if (xfer != cmd_len) {
-               sr_dbg("Failed to send EP1 command 0x%02x: incorrect length %d != %d",
-                      xfer, cmd_len);
+               sr_dbg("Failed to send EP1 command 0x%02x: incorrect length "
+                      "%d != %d.", xfer, cmd_len);
                return SR_ERR;
        }
 
        if (reply_len == 0)
                return SR_OK;
 
-       ret = libusb_bulk_transfer(usb->devhdl, 0x80 | 1, buf, reply_len, &xfer, 1000);
+       ret = libusb_bulk_transfer(usb->devhdl, 0x80 | 1, buf, reply_len,
+                                  &xfer, 1000);
        if (ret != 0) {
-               sr_dbg("Failed to receive reply to EP1 command 0x%02x: %s",
+               sr_dbg("Failed to receive reply to EP1 command 0x%02x: %s.",
                       command[0], libusb_error_name(ret));
                return SR_ERR;
        }
        if (xfer != reply_len) {
-               sr_dbg("Failed to receive reply to EP1 command 0x%02x: incorrect length %d != %d",
-                      xfer, reply_len);
+               sr_dbg("Failed to receive reply to EP1 command 0x%02x: "
+                      "incorrect length %d != %d.", xfer, reply_len);
                return SR_ERR;
        }
 
@@ -159,21 +162,22 @@ static int read_eeprom(const struct sr_dev_inst *sdi,
 static int upload_led_table(const struct sr_dev_inst *sdi,
                            const uint8_t *table, uint8_t offset, uint8_t cnt)
 {
-       uint8_t command[64];
+       uint8_t chunk, command[64];
        int ret;
 
-       if (cnt < 1 || cnt+offset > 64 || table == NULL)
+       if (cnt < 1 || cnt + offset > 64 || table == NULL)
                return SR_ERR_ARG;
 
        while (cnt > 0) {
-               uint8_t chunk = (cnt > 32? 32 : cnt);
+               chunk = (cnt > 32 ? 32 : cnt);
 
                command[0] = COMMAND_WRITE_LED_TABLE;
                command[1] = offset;
                command[2] = chunk;
-               memcpy(command+3, table, chunk);
+               memcpy(command + 3, table, chunk);
 
-               if ((ret = do_ep1_command(sdi, command, 3+chunk, NULL, 0)) != SR_OK)
+               ret = do_ep1_command(sdi, command, 3 + chunk, NULL, 0);
+               if (ret != SR_OK)
                        return ret;
 
                table += chunk;
@@ -191,8 +195,8 @@ static int set_led_mode(const struct sr_dev_inst *sdi,
        uint8_t command[6] = {
                COMMAND_SET_LED_MODE,
                animate,
-               t2reload&0xff,
-               t2reload>>8,
+               t2reload & 0xff,
+               t2reload >> 8,
                div,
                repeat,
        };
@@ -223,22 +227,22 @@ static int write_fpga_registers(const struct sr_dev_inst *sdi,
 
        command[0] = COMMAND_FPGA_WRITE_REGISTER;
        command[1] = cnt;
-       for (i=0; i<cnt; i++) {
-               command[2+2*i] = regs[i][0];
-               command[3+2*i] = regs[i][1];
+       for (i = 0; i < cnt; i++) {
+               command[2 + 2 * i] = regs[i][0];
+               command[3 + 2 * i] = regs[i][1];
        }
 
-       return do_ep1_command(sdi, command, 2*(cnt+1), NULL, 0);
+       return do_ep1_command(sdi, command, 2 * (cnt + 1), NULL, 0);
 }
 
 static int write_fpga_register(const struct sr_dev_inst *sdi,
                               uint8_t address, uint8_t value)
 {
        uint8_t regs[2] = { address, value };
+
        return write_fpga_registers(sdi, &regs, 1);
 }
 
-
 static uint8_t map_eeprom_data(uint8_t v)
 {
        return (((v ^ 0x80) + 0x44) ^ 0xd5) + 0x69;
@@ -254,9 +258,9 @@ static int prime_fpga(const struct sr_dev_inst *sdi)
                {12, 0},
                {10, 0xc0},
                {10, 0x40},
-               { 6, 0},
-               { 7, 1},
-               { 7, 0}
+               {6, 0},
+               {7, 1},
+               {7, 0}
        };
        int i, ret;
 
@@ -271,7 +275,7 @@ static int prime_fpga(const struct sr_dev_inst *sdi)
        regs[3][1] |= old_reg_10;
        regs[4][1] |= old_reg_10;
 
-       for (i=0; i<16; i++) {
+       for (i = 0; i < 16; i++) {
                regs[2][1] = eeprom_data[i];
                regs[5][1] = map_eeprom_data(eeprom_data[i]);
                if (i)
@@ -289,7 +293,7 @@ static int prime_fpga(const struct sr_dev_inst *sdi)
                return ret;
 
        if (version != 0x10) {
-               sr_err("Invalid FPGA bitstream version: 0x%02x != 0x10", version);
+               sr_err("Invalid FPGA bitstream version: 0x%02x != 0x10.", version);
                return SR_ERR;
        }
 
@@ -302,9 +306,9 @@ static void make_heartbeat(uint8_t *table, int len)
 
        memset(table, 0, len);
        len >>= 3;
-       for (i=0; i<2; i++)
-               for (j=0; j<len; j++)
-                       *table++ = sin(j*M_PI/len)*255;
+       for (i = 0; i < 2; i++)
+               for (j = 0; j < len; j++)
+                       *table++ = sin(j * M_PI / len) * 255;
 }
 
 static int configure_led(const struct sr_dev_inst *sdi)
@@ -325,8 +329,8 @@ static int upload_fpga_bitstream(const struct sr_dev_inst *sdi,
        struct dev_context *devc;
        int offset, chunksize, ret;
        const char *filename;
+       uint8_t len, buf[256 * 62], command[64];
        FILE *fw;
-       unsigned char buf[256*62];
 
        devc = sdi->priv;
 
@@ -341,13 +345,13 @@ static int upload_fpga_bitstream(const struct sr_dev_inst *sdi,
                filename = FPGA_FIRMWARE_33;
                break;
        default:
-               sr_err("Unsupported voltage range");
+               sr_err("Unsupported voltage range.");
                return SR_ERR;
        }
 
-       sr_info("Uploading FPGA bitstream at %s", filename);
+       sr_info("Uploading FPGA bitstream at %s.", filename);
        if ((fw = g_fopen(filename, "rb")) == NULL) {
-               sr_err("Unable to open bitstream file %s for reading: %s",
+               sr_err("Unable to open bitstream file %s for reading: %s.",
                       filename, strerror(errno));
                return SR_ERR;
        }
@@ -364,22 +368,22 @@ static int upload_fpga_bitstream(const struct sr_dev_inst *sdi,
                        break;
 
                for (offset = 0; offset < chunksize; offset += 62) {
-                       uint8_t command[64];
-                       uint8_t len = (offset + 62 > chunksize?
-                                      chunksize - offset : 62);
+                       len = (offset + 62 > chunksize ?
+                               chunksize - offset : 62);
                        command[0] = COMMAND_FPGA_UPLOAD_SEND_DATA;
                        command[1] = len;
-                       memcpy(command+2, buf+offset, len);
-                       if ((ret = do_ep1_command(sdi, command, len+2, NULL, 0)) != SR_OK) {
+                       memcpy(command + 2, buf + offset, len);
+                       ret = do_ep1_command(sdi, command, len + 2, NULL, 0);
+                       if (ret != SR_OK) {
                                fclose(fw);
                                return ret;
                        }
                }
 
-               sr_info("Uploaded %d bytes", chunksize);
+               sr_info("Uploaded %d bytes.", chunksize);
        }
        fclose(fw);
-       sr_info("FPGA bitstream upload done");
+       sr_info("FPGA bitstream upload done.");
 
        if ((ret = prime_fpga(sdi)) != SR_OK)
                return ret;
@@ -406,16 +410,15 @@ static int abort_acquisition_sync(const struct sr_dev_inst *sdi)
        expected_reply = ~command[1];
        if (reply != expected_reply) {
                sr_err("Invalid response for abort acquisition command: "
-                      "0x%02x != 0x%02x", reply, expected_reply);
+                      "0x%02x != 0x%02x.", reply, expected_reply);
                return SR_ERR;
        }
 
        return SR_OK;
 }
 
-SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
-                                            uint64_t samplerate,
-                                            uint16_t channels)
+SR_PRIV int logic16_setup_acquisition(const struct sr_dev_inst *sdi,
+                            uint64_t samplerate, uint16_t channels)
 {
        uint8_t clock_select, reg1, reg10;
        uint64_t div;
@@ -440,8 +443,8 @@ SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       for (i=0; i<16; i++)
-               if (channels & (1U<<i))
+       for (i = 0; i < 16; i++)
+               if (channels & (1U << i))
                        nchan++;
 
        if ((nchan >= 13 && samplerate > MAX_13CH_SAMPLE_RATE) ||
@@ -454,14 +457,15 @@ SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       if ((ret = upload_fpga_bitstream(sdi, devc->selected_voltage_range)) != SR_OK)
+       ret = upload_fpga_bitstream(sdi, devc->selected_voltage_range);
+       if (ret != SR_OK)
                return ret;
 
        if ((ret = read_fpga_register(sdi, 1, &reg1)) != SR_OK)
                return ret;
 
        if (reg1 != 0x08) {
-               sr_dbg("Invalid state at acquisition setup: 0x%02x != 0x08", reg1);
+               sr_dbg("Invalid state at acquisition setup: 0x%02x != 0x08.", reg1);
                return SR_ERR;
        }
 
@@ -471,7 +475,7 @@ SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
        if ((ret = write_fpga_register(sdi, 10, clock_select)) != SR_OK)
                return ret;
 
-       if ((ret = write_fpga_register(sdi, 4, (uint8_t)(div-1))) != SR_OK)
+       if ((ret = write_fpga_register(sdi, 4, (uint8_t)(div - 1))) != SR_OK)
                return ret;
 
        if ((ret = write_fpga_register(sdi, 2, (uint8_t)(channels & 0xff))) != SR_OK)
@@ -490,7 +494,7 @@ SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
                return ret;
 
        if (reg1 != 0x48) {
-               sr_dbg("Invalid state at acquisition setup: 0x%02x != 0x48", reg1);
+               sr_dbg("Invalid state at acquisition setup: 0x%02x != 0x48.", reg1);
                return SR_ERR;
        }
 
@@ -498,15 +502,15 @@ SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
                return ret;
 
        if (reg10 != clock_select) {
-               sr_dbg("Invalid state at acquisition setup: 0x%02x != 0x%02x",
-                      reg10, (unsigned)clock_select);
+               sr_dbg("Invalid state at acquisition setup: 0x%02x != 0x%02x.",
+                      reg10, clock_select);
                return SR_ERR;
        }
 
        return SR_OK;
 }
 
-SR_PRIV int saleae_logic16_start_acquisition(const struct sr_dev_inst *sdi)
+SR_PRIV int logic16_start_acquisition(const struct sr_dev_inst *sdi)
 {
        static const uint8_t command[1] = {
                COMMAND_START_ACQUISITION,
@@ -519,7 +523,7 @@ SR_PRIV int saleae_logic16_start_acquisition(const struct sr_dev_inst *sdi)
        return write_fpga_register(sdi, 1, 0x41);
 }
 
-SR_PRIV int saleae_logic16_abort_acquisition(const struct sr_dev_inst *sdi)
+SR_PRIV int logic16_abort_acquisition(const struct sr_dev_inst *sdi)
 {
        static const uint8_t command[1] = {
                COMMAND_ABORT_ACQUISITION_ASYNC,
@@ -537,7 +541,7 @@ SR_PRIV int saleae_logic16_abort_acquisition(const struct sr_dev_inst *sdi)
                return ret;
 
        if (reg1 != 0x08) {
-               sr_dbg("Invalid state at acquisition stop: 0x%02x != 0x08", reg1);
+               sr_dbg("Invalid state at acquisition stop: 0x%02x != 0x08.", reg1);
                return SR_ERR;
        }
 
@@ -550,7 +554,7 @@ SR_PRIV int saleae_logic16_abort_acquisition(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-SR_PRIV int saleae_logic16_init_device(const struct sr_dev_inst *sdi)
+SR_PRIV int logic16_init_device(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        int ret;
@@ -565,7 +569,8 @@ SR_PRIV int saleae_logic16_init_device(const struct sr_dev_inst *sdi)
        if ((ret = read_eeprom(sdi, 8, 8, devc->eeprom_data)) != SR_OK)
                return ret;
 
-       if ((ret = upload_fpga_bitstream(sdi, devc->selected_voltage_range)) != SR_OK)
+       ret = upload_fpga_bitstream(sdi, devc->selected_voltage_range);
+       if (ret != SR_OK)
                return ret;
 
        return SR_OK;
@@ -635,35 +640,34 @@ static size_t convert_sample_data(struct dev_context *devc,
        uint16_t *channel_data;
        int i, cur_channel;
        size_t ret = 0;
+       uint16_t sample, channel_mask;
 
        srccnt /= 2;
 
        channel_data = devc->channel_data;
        cur_channel = devc->cur_channel;
 
-       while(srccnt--) {
-               uint16_t sample, channel_mask;
-
+       while (srccnt--) {
                sample = src[0] | (src[1] << 8);
                src += 2;
 
                channel_mask = devc->channel_masks[cur_channel];
 
-               for (i=15; i>=0; --i, sample >>= 1)
+               for (i = 15; i >= 0; --i, sample >>= 1)
                        if (sample & 1)
                                channel_data[i] |= channel_mask;
 
                if (++cur_channel == devc->num_channels) {
                        cur_channel = 0;
-                       if (destcnt < 16*2) {
+                       if (destcnt < 16 * 2) {
                                sr_err("Conversion buffer too small!");
                                break;
                        }
-                       memcpy(dest, channel_data, 16*2);
-                       memset(channel_data, 0, 16*2);
-                       dest += 16*2;
-                       ret += 16*2;
-                       destcnt -= 16*2;
+                       memcpy(dest, channel_data, 16 * 2);
+                       memset(channel_data, 0, 16 * 2);
+                       dest += 16 * 2;
+                       ret += 16 * 2;
+                       destcnt -= 16 * 2;
                }
        }
 
@@ -672,7 +676,7 @@ static size_t convert_sample_data(struct dev_context *devc,
        return ret;
 }
 
-SR_PRIV void saleae_logic16_receive_transfer(struct libusb_transfer *transfer)
+SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
 {
        gboolean packet_has_error = FALSE;
        struct sr_datafeed_packet packet;
@@ -708,8 +712,9 @@ SR_PRIV void saleae_logic16_receive_transfer(struct libusb_transfer *transfer)
        }
 
        if (transfer->actual_length & 1) {
-               sr_err("Got an odd number of bytes from the device.  This should not happen.");
-               /* Bail out right away */
+               sr_err("Got an odd number of bytes from the device. "
+                      "This should not happen.");
+               /* Bail out right away. */
                packet_has_error = TRUE;
                devc->empty_transfer_count = MAX_EMPTY_TRANSFERS;
        }
@@ -731,10 +736,9 @@ SR_PRIV void saleae_logic16_receive_transfer(struct libusb_transfer *transfer)
                devc->empty_transfer_count = 0;
        }
 
-       converted_length =
-               convert_sample_data(devc,
-                                   devc->convbuffer, devc->convbuffer_size,
-                                   transfer->buffer, transfer->actual_length);
+       converted_length = convert_sample_data(devc, devc->convbuffer,
+                               devc->convbuffer_size, transfer->buffer,
+                               transfer->actual_length);
 
        if (converted_length > 0) {
                /* Send the incoming transfer to the session bus. */
index 84788313de865fab531e16802afac6174dab7ceb..cd8380e3d1d7d399a50be0b87fcd42aca8bf2280 100644 (file)
@@ -55,21 +55,19 @@ struct dev_context {
        /** The currently configured samplerate of the device. */
        uint64_t cur_samplerate;
 
-       /** Maximum number of samples to capture, if nonzero */
+       /** Maximum number of samples to capture, if nonzero. */
        uint64_t limit_samples;
 
-       /** The currently configured input voltage of the device */
+       /** The currently configured input voltage of the device. */
        enum voltage_range cur_voltage_range;
 
-       /** The input voltage selected by the user */
+       /** The input voltage selected by the user. */
        enum voltage_range selected_voltage_range;
 
-       /** Channels to use */
+       /** Channels to use. */
        uint16_t cur_channels;
 
-       /*
-        * EEPROM data from address 8
-        */
+       /* EEPROM data from address 8. */
        uint8_t eeprom_data[8];
 
        int64_t num_samples;
@@ -87,12 +85,11 @@ struct dev_context {
        int *usbfd;
 };
 
-SR_PRIV int saleae_logic16_setup_acquisition(const struct sr_dev_inst *sdi,
-                                            uint64_t samplerate,
-                                            uint16_t channels);
-SR_PRIV int saleae_logic16_start_acquisition(const struct sr_dev_inst *sdi);
-SR_PRIV int saleae_logic16_abort_acquisition(const struct sr_dev_inst *sdi);
-SR_PRIV int saleae_logic16_init_device(const struct sr_dev_inst *sdi);
-SR_PRIV void saleae_logic16_receive_transfer(struct libusb_transfer *transfer);
+SR_PRIV int logic16_setup_acquisition(const struct sr_dev_inst *sdi,
+                       uint64_t samplerate, uint16_t channels);
+SR_PRIV int logic16_start_acquisition(const struct sr_dev_inst *sdi);
+SR_PRIV int logic16_abort_acquisition(const struct sr_dev_inst *sdi);
+SR_PRIV int logic16_init_device(const struct sr_dev_inst *sdi);
+SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer);
 
 #endif