From: Uwe Hermann Date: Sun, 22 Mar 2015 22:07:30 +0000 (+0100) Subject: Improve readability and clarity of some numbers. X-Git-Tag: libsigrok-0.4.0~565 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1a46cc62e2b528bcaeb1f8dc0c952a81b3bcba5c;p=libsigrok.git Improve readability and clarity of some numbers. --- diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index 23e388fc..957b1d1a 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -419,7 +419,7 @@ static int sigma_fpga_init_bitbang(struct dev_context *devc) 0x01, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, }; - int i, ret, timeout = 10000; + int i, ret, timeout = (10 * 1000); uint8_t data; /* Section 2. part 1), do the FPGA suicide. */ @@ -441,7 +441,7 @@ static int sigma_fpga_init_bitbang(struct dev_context *devc) if (data & (1 << 5)) return 0; /* The D6 was not asserted yet, wait a bit. */ - g_usleep(10000); + g_usleep(10 * 1000); } return SR_ERR_TIMEOUT; @@ -590,7 +590,7 @@ static int upload_firmware(int firmware_idx, struct dev_context *devc) } /* Four times the speed of sigmalogan - Works well. */ - ret = ftdi_set_baudrate(ftdic, 750000); + ret = ftdi_set_baudrate(ftdic, 750 * 1000); if (ret < 0) { sr_err("ftdi_set_baudrate failed: %s", ftdi_get_error_string(ftdic)); diff --git a/src/hardware/brymen-dmm/protocol.c b/src/hardware/brymen-dmm/protocol.c index 07ac1939..5fb5ec29 100644 --- a/src/hardware/brymen-dmm/protocol.c +++ b/src/hardware/brymen-dmm/protocol.c @@ -187,7 +187,7 @@ SR_PRIV int brymen_stream_detect(struct sr_serial_dev_inst *serial, "ms, baudrate = %d).", serial->port, timeout_ms, baudrate); /* Assume 8n1 transmission. That is 10 bits for every byte. */ - byte_delay_us = 10 * (1000000 / baudrate); + byte_delay_us = 10 * ((1000 * 1000) / baudrate); start = g_get_monotonic_time(); packet_len = i = ibuf = len = 0; diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index e58598f1..5ae4e37c 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -23,7 +23,7 @@ #define SERIALCOMM "9600/8n1" /* 23ms is the longest interval between tokens. */ -#define MAX_SCAN_TIME 25 * 1000 +#define MAX_SCAN_TIME_US (25 * 1000) static const uint32_t scanopts[] = { SR_CONF_CONN, @@ -104,7 +104,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; drvc = di->priv; start = g_get_monotonic_time(); - while (g_get_monotonic_time() - start < MAX_SCAN_TIME) { + while (g_get_monotonic_time() - start < MAX_SCAN_TIME_US) { if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) { /* Found one. */ sdi = g_malloc0(sizeof(struct sr_dev_inst)); diff --git a/src/hardware/cem-dt-885x/protocol.h b/src/hardware/cem-dt-885x/protocol.h index 233ef860..1f0e191b 100644 --- a/src/hardware/cem-dt-885x/protocol.h +++ b/src/hardware/cem-dt-885x/protocol.h @@ -32,11 +32,11 @@ #define SAMPLES_PER_PACKET 50 /* Various temporary storage, at least 8 bytes. */ -#define BUF_SIZE SAMPLES_PER_PACKET * 2 +#define BUF_SIZE (SAMPLES_PER_PACKET * 2) /* When in hold mode, force the last measurement out at this interval. * We're using 50ms, which duplicates the non-hold 20Hz update rate. */ -#define HOLD_REPEAT_INTERVAL 50 * 1000 +#define HOLD_REPEAT_INTERVAL (50 * 1000) enum { TOKEN_WEIGHT_TIME_FAST = 0x02, diff --git a/src/hardware/conrad-digi-35-cpu/protocol.c b/src/hardware/conrad-digi-35-cpu/protocol.c index caf1e85d..a414bd7b 100644 --- a/src/hardware/conrad-digi-35-cpu/protocol.c +++ b/src/hardware/conrad-digi-35-cpu/protocol.c @@ -57,7 +57,7 @@ SR_PRIV int send_msg1(const struct sr_dev_inst *sdi, char cmd, int param) * Wait 50ms to ensure that the device does not swallow any of the * following commands. */ - g_usleep(50000); + g_usleep(50 * 1000); return SR_OK; } diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index 63afcd10..7111097b 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -757,7 +757,7 @@ static int prepare_data(int fd, int revents, void *cb_data) /* How many samples should we have sent by now? */ time = g_get_monotonic_time(); elapsed = time - devc->starttime; - expected_samplenum = elapsed * devc->cur_samplerate / 1000000; + expected_samplenum = elapsed * devc->cur_samplerate / (1000 * 1000); /* But never more than the limit, if there is one. */ if (!devc->continuous) diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index 36142fd5..4c6e2c18 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -181,7 +181,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) break; /* The Scopemeter 199B, at least, requires this * after all the 115k/9.6k confusion. */ - g_usleep(5000); + g_usleep(5 * 1000); } } diff --git a/src/hardware/fx2lafw/dslogic.c b/src/hardware/fx2lafw/dslogic.c index 489671f5..f0b49c34 100644 --- a/src/hardware/fx2lafw/dslogic.c +++ b/src/hardware/fx2lafw/dslogic.c @@ -28,7 +28,8 @@ #include "protocol.h" #include "dslogic.h" -#define FW_BUFSIZE 4096 +#define FW_BUFSIZE (4 * 1024) + int dslogic_fpga_firmware_upload(const struct sr_dev_inst *sdi, const char *filename) { diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 302e6593..baa75738 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -108,7 +108,7 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) gint64 timeout_us; model = METRAHIT_NONE; - timeout_us = g_get_monotonic_time() + 1 * 1000 * 1000; + timeout_us = g_get_monotonic_time() + (1 * 1000 * 1000); /* * Try to find message consisting of device code and several @@ -296,7 +296,7 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) goto exit_err; /* Wait for reply from device(s) for up to 2s. */ - timeout_us = g_get_monotonic_time() + 2*1000*1000; + timeout_us = g_get_monotonic_time() + (2 * 1000 * 1000); while (timeout_us > g_get_monotonic_time()) { /* Receive reply (14 bytes) */ diff --git a/src/hardware/gmc-mh-1x-2x/protocol.c b/src/hardware/gmc-mh-1x-2x/protocol.c index 0c3b56f8..719a225f 100644 --- a/src/hardware/gmc-mh-1x-2x/protocol.c +++ b/src/hardware/gmc-mh-1x-2x/protocol.c @@ -1236,7 +1236,7 @@ SR_PRIV int gmc_mh_2x_receive_data(int fd, int revents, void *cb_data) if (sdi->status == SR_ST_ACTIVE) { if (devc->response_pending) { gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at; - if (elapsed_us > 1*1000*1000) /* Timeout! */ + if (elapsed_us > (1 * 1000 * 1000)) /* Timeout! */ devc->response_pending = FALSE; } if (!devc->response_pending) { @@ -1342,13 +1342,13 @@ int req_stat14(const struct sr_dev_inst *sdi, gboolean power_on) sr_info("Write some data and wait 3s to turn on powered off device..."); if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0) return SR_ERR; - g_usleep(1*1000*1000); + g_usleep(1 * 1000 * 1000); if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0) return SR_ERR; - g_usleep(1*1000*1000); + g_usleep(1 * 1000 * 1000); if (serial_write_blocking(serial, msg, sizeof(msg), 0) < 0) return SR_ERR; - g_usleep(1*1000*1000); + g_usleep(1 * 1000 * 1000); serial_flush(serial); } @@ -1534,7 +1534,7 @@ SR_PRIV int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *s if (serial_write_blocking(sdi->conn, msg, sizeof(msg), 0) < 0) return SR_ERR; else - g_usleep(2000000); /* Wait to ensure transfer before interface switched off. */ + g_usleep(2 * 1000 * 1000); /* Wait to ensure transfer before interface switched off. */ break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index c990a5c5..1676085e 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -72,13 +72,13 @@ static const char *channel_names[] = { }; static const uint64_t buffersizes_32k[] = { - 10240, 32768, + (10 * 1024), (32 * 1024), }; static const uint64_t buffersizes_512k[] = { - 10240, 524288, + (10 * 1024), (512 * 1024), }; static const uint64_t buffersizes_14k[] = { - 10240, 14336, + (10 * 1024), (14 * 1024), }; static const struct dso_profile dev_profiles[] = { diff --git a/src/hardware/hantek-dso/dso.h b/src/hardware/hantek-dso/dso.h index 3180a434..7938e9e5 100644 --- a/src/hardware/hantek-dso/dso.h +++ b/src/hardware/hantek-dso/dso.h @@ -49,7 +49,7 @@ #define EEPROM_CHANNEL_OFFSETS 0x08 /* All models have this for their "fast" mode. */ -#define FRAMESIZE_SMALL 10240 +#define FRAMESIZE_SMALL (10 * 1024) enum control_requests { CTRL_READ_EEPROM = 0xa2, diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 070357b3..31e1fb1f 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -225,11 +225,11 @@ static int dev_open(struct sr_dev_inst *sdi) libusb_fill_control_transfer(devc->xfer_in, usb->devhdl, devc->xfer_buf_in, sl2_receive_transfer_in, - sdi, USB_TIMEOUT); + sdi, USB_TIMEOUT_MS); libusb_fill_control_transfer(devc->xfer_out, usb->devhdl, devc->xfer_buf_out, sl2_receive_transfer_out, - sdi, USB_TIMEOUT); + sdi, USB_TIMEOUT_MS); memset(buffer, 0, sizeof(buffer)); diff --git a/src/hardware/ikalogic-scanalogic2/protocol.c b/src/hardware/ikalogic-scanalogic2/protocol.c index c26b32a6..f756b6e5 100644 --- a/src/hardware/ikalogic-scanalogic2/protocol.c +++ b/src/hardware/ikalogic-scanalogic2/protocol.c @@ -754,12 +754,12 @@ SR_PRIV int sl2_transfer_in(libusb_device_handle *dev_handle, uint8_t *data) { return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_IN, USB_HID_GET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, - (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT); + (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT_MS); } SR_PRIV int sl2_transfer_out(libusb_device_handle *dev_handle, uint8_t *data) { return libusb_control_transfer(dev_handle, USB_REQUEST_TYPE_OUT, USB_HID_SET_REPORT, USB_HID_REPORT_TYPE_FEATURE, USB_INTERFACE, - (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT); + (unsigned char *)data, PACKET_LENGTH, USB_TIMEOUT_MS); } diff --git a/src/hardware/ikalogic-scanalogic2/protocol.h b/src/hardware/ikalogic-scanalogic2/protocol.h index 5e7c7b3b..45f5917a 100644 --- a/src/hardware/ikalogic-scanalogic2/protocol.h +++ b/src/hardware/ikalogic-scanalogic2/protocol.h @@ -34,7 +34,7 @@ #define USB_VID_PID "20a0.4123" #define USB_INTERFACE 0 -#define USB_TIMEOUT 5000 +#define USB_TIMEOUT_MS (5 * 1000) #define USB_REQUEST_TYPE_IN (LIBUSB_REQUEST_TYPE_CLASS | \ LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_IN) diff --git a/src/hardware/ikalogic-scanaplus/protocol.h b/src/hardware/ikalogic-scanaplus/protocol.h index 1df0517e..deb76b15 100644 --- a/src/hardware/ikalogic-scanaplus/protocol.h +++ b/src/hardware/ikalogic-scanaplus/protocol.h @@ -30,7 +30,7 @@ #define LOG_PREFIX "ikalogic-scanaplus" -#define COMPRESSED_BUF_SIZE (64 * 1024) +#define COMPRESSED_BUF_SIZE (64 * 1024) /* Private, per-device-instance driver context. */ struct dev_context { diff --git a/src/hardware/kecheng-kc-330b/protocol.h b/src/hardware/kecheng-kc-330b/protocol.h index 09152b9f..a2536898 100644 --- a/src/hardware/kecheng-kc-330b/protocol.h +++ b/src/hardware/kecheng-kc-330b/protocol.h @@ -27,7 +27,7 @@ #define LOG_PREFIX "kecheng-kc-330b" -#define EP_IN 0x80 | 1 +#define EP_IN (0x80 | 1) #define EP_OUT 2 /* 500ms */ diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index 3fe2f57b..ce63bc67 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -390,7 +390,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) ; libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN, - resp, sizeof(resp), mark_xfer, 0, 10000); + resp, sizeof(resp), mark_xfer, 0, BULK_XFER_TIMEOUT); if (libusb_submit_transfer(xfer_in) != 0) { libusb_free_transfer(xfer_in); libusb_free_transfer(xfer_out); @@ -411,7 +411,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) tv.tv_sec = 0; tv.tv_usec = 0; while (!xfer_in->user_data || !xfer_out->user_data) { - g_usleep(5000); + g_usleep(SLEEP_US_LONG); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } if (xfer_in->user_data != GINT_TO_POINTER(1) || diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index 9e20edc6..7916f05d 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -111,7 +111,7 @@ SR_PRIV int lascar_get_config(libusb_device_handle *dev_hdl, /* Keep a read request waiting in the wings, ready to pounce * the moment the device sends something. */ libusb_fill_bulk_transfer(xfer_in, dev_hdl, LASCAR_EP_IN, - buf, 256, mark_xfer, 0, 10000); + buf, 256, mark_xfer, 0, BULK_XFER_TIMEOUT); if (libusb_submit_transfer(xfer_in) != 0) goto cleanup; @@ -132,7 +132,7 @@ SR_PRIV int lascar_get_config(libusb_device_handle *dev_hdl, start = 0; break; } - g_usleep(5000); + g_usleep(SLEEP_US_LONG); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } if (!start) { @@ -165,7 +165,7 @@ SR_PRIV int lascar_get_config(libusb_device_handle *dev_hdl, start = 0; break; } - g_usleep(5000); + g_usleep(SLEEP_US_LONG); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } if (!start) { @@ -189,9 +189,9 @@ cleanup: libusb_cancel_transfer(xfer_out); start = g_get_monotonic_time(); while (!xfer_in->user_data || !xfer_out->user_data) { - if (g_get_monotonic_time() - start > 10000) + if (g_get_monotonic_time() - start > EVENTS_TIMEOUT) break; - g_usleep(1000); + g_usleep(SLEEP_US_SHORT); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } } @@ -228,7 +228,7 @@ static int lascar_save_config(libusb_device_handle *dev_hdl, /* Keep a read request waiting in the wings, ready to pounce * the moment the device sends something. */ libusb_fill_bulk_transfer(xfer_in, dev_hdl, LASCAR_EP_IN, - buf, 256, mark_xfer, 0, 10000); + buf, 256, mark_xfer, 0, BULK_XFER_TIMEOUT); if (libusb_submit_transfer(xfer_in) != 0) { ret = SR_ERR; goto cleanup; @@ -247,7 +247,7 @@ static int lascar_save_config(libusb_device_handle *dev_hdl, tv.tv_sec = 0; tv.tv_usec = 0; while (!xfer_out->user_data) { - g_usleep(5000); + g_usleep(SLEEP_US_LONG); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } @@ -258,7 +258,7 @@ static int lascar_save_config(libusb_device_handle *dev_hdl, goto cleanup; } while (!xfer_in->user_data || !xfer_out->user_data) { - g_usleep(5000); + g_usleep(SLEEP_US_LONG); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } @@ -275,9 +275,9 @@ cleanup: libusb_cancel_transfer(xfer_out); start = g_get_monotonic_time(); while (!xfer_in->user_data || !xfer_out->user_data) { - if (g_get_monotonic_time() - start > 10000) + if (g_get_monotonic_time() - start > EVENTS_TIMEOUT) break; - g_usleep(1000); + g_usleep(SLEEP_US_SHORT); libusb_handle_events_timeout(drvc->sr_ctx->libusb_ctx, &tv); } } @@ -462,7 +462,7 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf, break; for (i = 0; i < samples; i++) { s = (buf[i * 2] << 8) | buf[i * 2 + 1]; - analog.data[i] = (s * devc->co_high + devc->co_low) / 1000000; + analog.data[i] = (s * devc->co_high + devc->co_low) / (1000 * 1000); if (analog.data[i] < 0.0) analog.data[i] = 0.0; } diff --git a/src/hardware/lascar-el-usb/protocol.h b/src/hardware/lascar-el-usb/protocol.h index a94bd8a5..82d39925 100644 --- a/src/hardware/lascar-el-usb/protocol.h +++ b/src/hardware/lascar-el-usb/protocol.h @@ -30,10 +30,15 @@ #define LASCAR_INTERFACE 0 #define LASCAR_EP_IN 0x82 #define LASCAR_EP_OUT 2 -/* Max 100ms for a device to positively identify. */ -#define SCAN_TIMEOUT 100000 #define MAX_CONFIGBLOCK_SIZE 256 +/* Max 100ms for a device to positively identify. */ +#define SCAN_TIMEOUT (100 * 1000) +#define BULK_XFER_TIMEOUT (10 * 1000) +#define EVENTS_TIMEOUT (10 * 1000) +#define SLEEP_US_LONG (5 * 1000) +#define SLEEP_US_SHORT (1 * 1000) + /** Private, per-device-instance driver context. */ struct dev_context { void *cb_data; diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index 4e776a54..c8ddc4be 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -83,6 +83,8 @@ static const uint64_t samplerates[] = { SR_HZ(1), }; +#define RESPONSE_DELAY_US (10 * 1000) + SR_PRIV struct sr_dev_driver ols_driver_info; static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) @@ -150,8 +152,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) } send_shortcommand(serial, CMD_ID); - /* Wait 10ms for a response. */ - g_usleep(10000); + g_usleep(RESPONSE_DELAY_US); if (sp_input_waiting(serial->data) == 0) { sr_dbg("Didn't get any reply."); @@ -175,8 +176,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) */ send_shortcommand(serial, CMD_METADATA); - /* Wait 10ms for a response. */ - g_usleep(10000); + g_usleep(RESPONSE_DELAY_US); if (sp_input_waiting(serial->data) != 0) { /* Got metadata. */ diff --git a/src/hardware/rigol-ds/protocol.c b/src/hardware/rigol-ds/protocol.c index f328d9a6..3fbf3d72 100644 --- a/src/hardware/rigol-ds/protocol.c +++ b/src/hardware/rigol-ds/protocol.c @@ -241,7 +241,7 @@ static int rigol_ds_check_stop(const struct sr_dev_inst *sdi) if (tmp & 0x10) { sr_warn("Single shot acquisition failed, retrying..."); /* Sleep a bit, otherwise the single shot will often fail */ - g_usleep(500000); + g_usleep(500 * 1000); rigol_ds_config_set(sdi, ":SING"); rigol_ds_set_wait_event(devc, WAIT_STOP); return SR_ERR; @@ -277,7 +277,7 @@ static int rigol_ds_block_wait(const struct sr_dev_inst *sdi) * it too much with SCPI requests but don't wait too * long for short sample frame sizes. */ - g_usleep(devc->analog_frame_size < 15000 ? 100000 : 1000000); + g_usleep(devc->analog_frame_size < (15 * 1000) ? (100 * 1000) : (1000 * 1000)); /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */ if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK) @@ -285,7 +285,7 @@ static int rigol_ds_block_wait(const struct sr_dev_inst *sdi) if (parse_int(buf + 5, &len) != SR_OK) return SR_ERR; - } while (buf[0] == 'R' && len < 1000000); + } while (buf[0] == 'R' && len < (1000 * 1000)); } rigol_ds_set_wait_event(devc, WAIT_NONE); @@ -310,7 +310,7 @@ SR_PRIV int rigol_ds_config_set(const struct sr_dev_inst *sdi, const char *forma if (devc->model->series->protocol == PROTOCOL_V2) { /* The DS1000 series needs this stupid delay, *OPC? doesn't work. */ sr_spew("delay %dms", 100); - g_usleep(100000); + g_usleep(100 * 1000); return SR_OK; } else { return sr_scpi_get_opc(sdi->conn); diff --git a/src/hardware/rigol-ds/protocol.h b/src/hardware/rigol-ds/protocol.h index 631c81db..62981856 100644 --- a/src/hardware/rigol-ds/protocol.h +++ b/src/hardware/rigol-ds/protocol.h @@ -29,10 +29,10 @@ #define LOG_PREFIX "rigol-ds" /* Size of acquisition buffers */ -#define ACQ_BUFFER_SIZE 32768 +#define ACQ_BUFFER_SIZE (32 * 1024) /* Maximum number of samples to retrieve at once. */ -#define ACQ_BLOCK_SIZE 30000 +#define ACQ_BLOCK_SIZE (30 * 1000) #define MAX_ANALOG_CHANNELS 4 #define MAX_DIGITAL_CHANNELS 16 diff --git a/src/hardware/sysclk-lwla/lwla.c b/src/hardware/sysclk-lwla/lwla.c index dcb7af77..2f55014e 100644 --- a/src/hardware/sysclk-lwla/lwla.c +++ b/src/hardware/sysclk-lwla/lwla.c @@ -23,8 +23,8 @@ #include #include -#define BITSTREAM_MAX_SIZE 262144 /* 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. @@ -110,7 +110,7 @@ SR_PRIV int lwla_send_bitstream(const struct sr_usb_dev_inst *usb, /* Transfer the entire bitstream in one URB. */ ret = libusb_bulk_transfer(usb->devhdl, EP_BITSTREAM, - stream, length, &xfer_len, USB_TIMEOUT); + stream, length, &xfer_len, USB_TIMEOUT_MS); g_free(stream); if (ret != 0) { @@ -126,7 +126,7 @@ SR_PRIV int lwla_send_bitstream(const struct sr_usb_dev_inst *usb, sr_info("FPGA bitstream download of %d bytes done.", xfer_len); /* This delay appears to be necessary for reliable operation. */ - g_usleep(30000); + g_usleep(30 * 1000); return SR_OK; } @@ -143,7 +143,7 @@ SR_PRIV int lwla_send_command(const struct sr_usb_dev_inst *usb, xfer_len = 0; ret = libusb_bulk_transfer(usb->devhdl, EP_COMMAND, (unsigned char *)command, cmd_len * 2, - &xfer_len, USB_TIMEOUT); + &xfer_len, USB_TIMEOUT_MS); if (ret != 0) { sr_dbg("Failed to send command %d: %s.", LWLA_TO_UINT16(command[0]), libusb_error_name(ret)); @@ -169,7 +169,7 @@ SR_PRIV int lwla_receive_reply(const struct sr_usb_dev_inst *usb, xfer_len = 0; ret = libusb_bulk_transfer(usb->devhdl, EP_REPLY, (unsigned char *)reply, reply_len * 4, - &xfer_len, USB_TIMEOUT); + &xfer_len, USB_TIMEOUT_MS); if (ret != 0) { sr_dbg("Failed to receive reply: %s.", libusb_error_name(ret)); return SR_ERR; diff --git a/src/hardware/sysclk-lwla/protocol.c b/src/hardware/sysclk-lwla/protocol.c index c8434049..2fd4dffa 100644 --- a/src/hardware/sysclk-lwla/protocol.c +++ b/src/hardware/sysclk-lwla/protocol.c @@ -65,7 +65,7 @@ static int capture_setup(const struct sr_dev_inst *sdi) uint64_t divider_count; uint64_t trigger_mask; uint64_t memory_limit; - uint16_t command[3 + 10*4]; + uint16_t command[3 + (10 * 4)]; devc = sdi->priv; acq = devc->acquisition; @@ -923,13 +923,13 @@ SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi) libusb_fill_bulk_transfer(acq->xfer_out, usb->devhdl, EP_COMMAND, (unsigned char *)acq->xfer_buf_out, 0, &receive_transfer_out, - (struct sr_dev_inst *)sdi, USB_TIMEOUT); + (struct sr_dev_inst *)sdi, USB_TIMEOUT_MS); libusb_fill_bulk_transfer(acq->xfer_in, usb->devhdl, EP_REPLY, (unsigned char *)acq->xfer_buf_in, sizeof acq->xfer_buf_in, &receive_transfer_in, - (struct sr_dev_inst *)sdi, USB_TIMEOUT); + (struct sr_dev_inst *)sdi, USB_TIMEOUT_MS); regvals = devc->reg_write_seq; diff --git a/src/hardware/sysclk-lwla/protocol.h b/src/hardware/sysclk-lwla/protocol.h index eb6cef3d..1c17b48d 100644 --- a/src/hardware/sysclk-lwla/protocol.h +++ b/src/hardware/sysclk-lwla/protocol.h @@ -35,7 +35,7 @@ #define USB_VID_PID "2961.6689" #define USB_INTERFACE 0 -#define USB_TIMEOUT 3000 /* ms */ +#define USB_TIMEOUT_MS 3000 #define NUM_CHANNELS 34 @@ -46,7 +46,7 @@ /** Unit and packet size for the sigrok logic datafeed. */ #define UNIT_SIZE ((NUM_CHANNELS + 7) / 8) -#define PACKET_LENGTH 10000 /* units */ +#define PACKET_LENGTH (10 * 1000) /* units */ /** Size of the acquisition buffer in device memory units. */ diff --git a/src/hardware/uni-t-ut32x/protocol.h b/src/hardware/uni-t-ut32x/protocol.h index 8513117c..e66b7920 100644 --- a/src/hardware/uni-t-ut32x/protocol.h +++ b/src/hardware/uni-t-ut32x/protocol.h @@ -34,7 +34,7 @@ #define USB_INTERFACE 0 #define USB_CONFIGURATION 1 -#define EP_IN 0x80 | 2 +#define EP_IN (0x80 | 2) #define EP_OUT 2 enum { diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 3b77407f..6548fb44 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -29,7 +29,7 @@ #define VICTOR_PID 0xd237 #define VICTOR_VENDOR "Victor" #define VICTOR_INTERFACE 0 -#define VICTOR_ENDPOINT LIBUSB_ENDPOINT_IN | 1 +#define VICTOR_ENDPOINT (LIBUSB_ENDPOINT_IN | 1) SR_PRIV struct sr_dev_driver victor_dmm_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); diff --git a/src/hardware/yokogawa-dlm/protocol.h b/src/hardware/yokogawa-dlm/protocol.h index 0bdb7f2f..4e80ea10 100644 --- a/src/hardware/yokogawa-dlm/protocol.h +++ b/src/hardware/yokogawa-dlm/protocol.h @@ -33,13 +33,13 @@ #define LOG_PREFIX "yokogawa-dlm" #define MAX_INSTRUMENT_VERSIONS 4 -#define RECEIVE_BUFFER_SIZE (4096) +#define RECEIVE_BUFFER_SIZE 4096 /* See Communication Interface User's Manual on p. 268 (:WAVeform:ALL:SEND?). */ -#define DLM_MAX_FRAME_LENGTH (12500) +#define DLM_MAX_FRAME_LENGTH 12500 /* See Communication Interface User's Manual on p. 269 (:WAVeform:SEND?). */ -#define DLM_DIVISION_FOR_WORD_FORMAT (3200) -#define DLM_DIVISION_FOR_BYTE_FORMAT (12.5) +#define DLM_DIVISION_FOR_WORD_FORMAT 3200 +#define DLM_DIVISION_FOR_BYTE_FORMAT 12.5 enum trigger_slopes { SLOPE_POSITIVE, @@ -121,18 +121,13 @@ struct dev_context { gboolean data_pending; }; -/*--- api.c -----------------------------------------------------------------*/ SR_PRIV int dlm_data_request(const struct sr_dev_inst *sdi); - -/*--- protocol.c ------------------------------------------------------------*/ SR_PRIV int dlm_model_get(char *model_id, char **model_name, int *model_index); SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index); SR_PRIV int dlm_data_receive(int fd, int revents, void *cb_data); - SR_PRIV void dlm_scope_state_destroy(struct scope_state *state); SR_PRIV int dlm_scope_state_query(struct sr_dev_inst *sdi); SR_PRIV int dlm_sample_rate_query(const struct sr_dev_inst *sdi); - SR_PRIV int dlm_channel_data_request(const struct sr_dev_inst *sdi); #endif diff --git a/src/hardware/zeroplus-logic-cube/gl_usb.c b/src/hardware/zeroplus-logic-cube/gl_usb.c index 20993286..2443f455 100644 --- a/src/hardware/zeroplus-logic-cube/gl_usb.c +++ b/src/hardware/zeroplus-logic-cube/gl_usb.c @@ -42,7 +42,7 @@ LIBUSB_RECIPIENT_INTERFACE) #define EP1_BULK_IN (LIBUSB_ENDPOINT_IN | 1) -#define TIMEOUT 5000 /* Timeout in ms */ +#define TIMEOUT_MS (5 * 1000) enum { REQ_READBULK = 0x82, @@ -57,7 +57,7 @@ static int gl_write_address(libusb_device_handle *devh, unsigned int address) int ret; ret = libusb_control_transfer(devh, CTRL_OUT, 0xc, REQ_WRITEADDR, - 0, packet, 1, TIMEOUT); + 0, packet, 1, TIMEOUT_MS); if (ret != 1) sr_err("%s: %s.", __func__, libusb_error_name(ret)); return ret; @@ -69,7 +69,7 @@ static int gl_write_data(libusb_device_handle *devh, unsigned int val) int ret; ret = libusb_control_transfer(devh, CTRL_OUT, 0xc, REQ_WRITEDATA, - 0, packet, 1, TIMEOUT); + 0, packet, 1, TIMEOUT_MS); if (ret != 1) sr_err("%s: %s.", __func__, libusb_error_name(ret)); return ret; @@ -81,7 +81,7 @@ static int gl_read_data(libusb_device_handle *devh) int ret; ret = libusb_control_transfer(devh, CTRL_IN, 0xc, REQ_READDATA, - 0, packet, 1, TIMEOUT); + 0, packet, 1, TIMEOUT_MS); if (ret != 1) sr_err("%s: %s, val=%hhx.", __func__, libusb_error_name(ret), packet[0]); @@ -97,13 +97,13 @@ SR_PRIV int gl_read_bulk(libusb_device_handle *devh, void *buffer, int ret, transferred = 0; ret = libusb_control_transfer(devh, CTRL_OUT, 0x4, REQ_READBULK, - 0, packet, 8, TIMEOUT); + 0, packet, 8, TIMEOUT_MS); if (ret != 8) sr_err("%s: libusb_control_transfer: %s.", __func__, libusb_error_name(ret)); ret = libusb_bulk_transfer(devh, EP1_BULK_IN, buffer, size, - &transferred, TIMEOUT); + &transferred, TIMEOUT_MS); if (ret < 0) sr_err("%s: libusb_bulk_transfer: %s.", __func__, libusb_error_name(ret)); diff --git a/src/hardware/zeroplus-logic-cube/protocol.c b/src/hardware/zeroplus-logic-cube/protocol.c index ce20ccf4..de488bf1 100644 --- a/src/hardware/zeroplus-logic-cube/protocol.c +++ b/src/hardware/zeroplus-logic-cube/protocol.c @@ -23,7 +23,7 @@ SR_PRIV unsigned int get_memory_size(int type) { if (type == MEMORY_SIZE_8K) - return 8 * 1024; + return (8 * 1024); else if (type <= MEMORY_SIZE_8M) return (32 * 1024) << type; else @@ -63,9 +63,9 @@ SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples) devc->limit_samples = samples; - if (samples <= 2 * 1024) + if (samples <= (2 * 1024)) devc->memory_size = MEMORY_SIZE_8K; - else if (samples <= 16 * 1024) + else if (samples <= (16 * 1024)) devc->memory_size = MEMORY_SIZE_64K; else devc->memory_size = 19 - clz(samples - 1); diff --git a/src/input/chronovu_la8.c b/src/input/chronovu_la8.c index 244abf19..e62d2c70 100644 --- a/src/input/chronovu_la8.c +++ b/src/input/chronovu_la8.c @@ -28,9 +28,9 @@ #define LOG_PREFIX "input/chronovu-la8" #define DEFAULT_NUM_CHANNELS 8 -#define DEFAULT_SAMPLERATE 100000000L -#define MAX_CHUNK_SIZE 4096 -#define CHRONOVU_LA8_FILESIZE 8 * 1024 * 1024 + 5 +#define DEFAULT_SAMPLERATE SR_MHZ(100) +#define MAX_CHUNK_SIZE (4 * 1024) +#define CHRONOVU_LA8_FILESIZE ((8 * 1024 * 1024) + 5) struct context { gboolean started; diff --git a/src/output/analog.c b/src/output/analog.c index 3b9a5812..406d8c6e 100644 --- a/src/output/analog.c +++ b/src/output/analog.c @@ -173,7 +173,7 @@ static void fancyprint(int unit, int mqflags, float value, GString *out) g_string_append(out, " %oA"); break; case SR_UNIT_CONCENTRATION: - g_string_append_printf(out, "%f ppm", value * 1000000); + g_string_append_printf(out, "%f ppm", value * (1000 * 1000)); break; case SR_UNIT_REVOLUTIONS_PER_MINUTE: si_printf(value, out, "RPM"); diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index ce3cb99d..0835c90b 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -26,7 +26,7 @@ #define LOG_PREFIX "scpi" #define SCPI_READ_RETRIES 100 -#define SCPI_READ_RETRY_TIMEOUT 10000 +#define SCPI_READ_RETRY_TIMEOUT_US (10 * 1000) /** * Parse a string representation of a boolean-like value into a gboolean. @@ -578,7 +578,7 @@ SR_PRIV int sr_scpi_get_opc(struct sr_scpi_dev_inst *scpi) sr_scpi_get_bool(scpi, SCPI_CMD_OPC, &opc); if (opc) return SR_OK; - g_usleep(SCPI_READ_RETRY_TIMEOUT); + g_usleep(SCPI_READ_RETRY_TIMEOUT_US); } return SR_ERR; diff --git a/src/scpi/scpi_vxi.c b/src/scpi/scpi_vxi.c index 62bf8c61..e4efbf1d 100644 --- a/src/scpi/scpi_vxi.c +++ b/src/scpi/scpi_vxi.c @@ -28,7 +28,7 @@ #include "libsigrok-internal.h" #define LOG_PREFIX "scpi_vxi" -#define VXI_DEFAULT_TIMEOUT 2000 /* in ms */ +#define VXI_DEFAULT_TIMEOUT_MS 2000 struct scpi_vxi { char *address; @@ -74,7 +74,7 @@ static int scpi_vxi_open(void *priv) /* Set link parameters */ link_parms.clientId = (long) vxi->client; link_parms.lockDevice = 0; - link_parms.lock_timeout = VXI_DEFAULT_TIMEOUT; + link_parms.lock_timeout = VXI_DEFAULT_TIMEOUT_MS; link_parms.device = "inst0"; if (!(link_resp = create_link_1(&link_parms, vxi->client))) { @@ -124,8 +124,8 @@ static int scpi_vxi_send(void *priv, const char *command) len = strlen(terminated_command); write_parms.lid = vxi->link; - write_parms.io_timeout = VXI_DEFAULT_TIMEOUT; - write_parms.lock_timeout = VXI_DEFAULT_TIMEOUT; + write_parms.io_timeout = VXI_DEFAULT_TIMEOUT_MS; + write_parms.lock_timeout = VXI_DEFAULT_TIMEOUT_MS; write_parms.flags = DF_END; write_parms.data.data_len = MIN(len, vxi->max_send_size); write_parms.data.data_val = terminated_command; @@ -169,8 +169,8 @@ static int scpi_vxi_read_data(void *priv, char *buf, int maxlen) Device_ReadResp *read_resp; read_parms.lid = vxi->link; - read_parms.io_timeout = VXI_DEFAULT_TIMEOUT; - read_parms.lock_timeout = VXI_DEFAULT_TIMEOUT; + read_parms.io_timeout = VXI_DEFAULT_TIMEOUT_MS; + read_parms.lock_timeout = VXI_DEFAULT_TIMEOUT_MS; read_parms.flags = 0; read_parms.termChar = 0; read_parms.requestSize = maxlen; diff --git a/src/serial.c b/src/serial.c index 6d33b3bf..959413b6 100644 --- a/src/serial.c +++ b/src/serial.c @@ -693,7 +693,7 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial, } /* Assume 8n1 transmission. That is 10 bits for every byte. */ - byte_delay_us = 10 * (1000000 / baudrate); + byte_delay_us = 10 * ((1000 * 1000) / baudrate); start = g_get_monotonic_time(); i = ibuf = len = 0; diff --git a/tests/input_binary.c b/tests/input_binary.c index 31ed69f3..403f7307 100644 --- a/tests/input_binary.c +++ b/tests/input_binary.c @@ -23,7 +23,7 @@ #include "../include/libsigrok/libsigrok.h" #include "lib.h" -#define BUFSIZE 1000000 +#define BUFSIZE (1000 * 1000) enum { CHECK_ALL_LOW,