X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Flink-mso19%2Flink-mso19.c;h=6fdf51c6032ba3781946cb88f93c00b01c4005bc;hb=d92faf6cacf7088bd241bb8f0b1adc48082e85fb;hp=cce8d87c01d9019b2d97077986720a6c185619ba;hpb=915f7cc87a8dce688ab99fc67005ef77e0d028a2;p=libsigrok.git diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index cce8d87c..6fdf51c6 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -28,8 +28,8 @@ #include #include #include -#include "sigrok.h" -#include "sigrok-internal.h" +#include "libsigrok.h" +#include "libsigrok-internal.h" #include "link-mso19.h" #define USB_VENDOR "3195" @@ -65,7 +65,7 @@ static const char *probe_names[NUM_PROBES + 1] = { NULL, }; -static uint64_t supported_samplerates[] = { +static const uint64_t supported_samplerates[] = { SR_HZ(100), SR_HZ(200), SR_HZ(500), @@ -89,7 +89,7 @@ static uint64_t supported_samplerates[] = { 0, }; -static struct sr_samplerates samplerates = { +static const struct sr_samplerates samplerates = { 0, 0, 0, @@ -111,7 +111,7 @@ static int mso_send_control_message(struct sr_dev_inst *sdi, goto ret; if (!(buf = g_try_malloc(s))) { - sr_err("mso19: %s: buf malloc failed", __func__); + sr_err("Failed to malloc message buffer."); ret = SR_ERR_MALLOC; goto ret; } @@ -151,7 +151,7 @@ static int mso_reset_adc(struct sr_dev_inst *sdi) ops[1] = mso_trans(REG_CTL1, ctx->ctlbase1); ctx->ctlbase1 |= BIT_CTL1_ADC_UNKNOWN4; - sr_dbg("mso19: Requesting ADC reset"); + sr_dbg("Requesting ADC reset."); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -163,7 +163,7 @@ static int mso_reset_fsm(struct sr_dev_inst *sdi) ctx->ctlbase1 |= BIT_CTL1_RESETFSM; ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1); - sr_dbg("mso19: Requesting ADC reset"); + sr_dbg("Requesting ADC reset."); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -177,7 +177,7 @@ static int mso_toggle_led(struct sr_dev_inst *sdi, int state) ctx->ctlbase1 |= BIT_CTL1_LED; ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1); - sr_dbg("mso19: Requesting LED toggle"); + sr_dbg("Requesting LED toggle."); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -187,7 +187,7 @@ static int mso_check_trigger(struct sr_dev_inst *sdi, uint8_t *info) char buf[1]; int ret; - sr_dbg("mso19: Requesting trigger state"); + sr_dbg("Requesting trigger state."); ret = mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); if (info == NULL || ret != SR_OK) return ret; @@ -197,7 +197,7 @@ static int mso_check_trigger(struct sr_dev_inst *sdi, uint8_t *info) ret = SR_ERR; *info = buf[0]; - sr_dbg("mso19: Trigger state is: 0x%x", *info); + sr_dbg("Trigger state is: 0x%x.", *info); return ret; } @@ -205,7 +205,7 @@ static int mso_read_buffer(struct sr_dev_inst *sdi) { uint16_t ops[] = { mso_trans(REG_BUFFER, 0) }; - sr_dbg("mso19: Requesting buffer dump"); + sr_dbg("Requesting buffer dump."); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -218,7 +218,7 @@ static int mso_arm(struct sr_dev_inst *sdi) mso_trans(REG_CTL1, ctx->ctlbase1), }; - sr_dbg("mso19: Requesting trigger arm"); + sr_dbg("Requesting trigger arm."); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -230,7 +230,7 @@ static int mso_force_capture(struct sr_dev_inst *sdi) mso_trans(REG_CTL1, ctx->ctlbase1), }; - sr_dbg("mso19: Requesting forced capture"); + sr_dbg("Requesting forced capture."); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -243,7 +243,7 @@ static int mso_dac_out(struct sr_dev_inst *sdi, uint16_t val) mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_RESETADC), }; - sr_dbg("mso19: Setting dac word to 0x%x", val); + sr_dbg("Setting dac word to 0x%x.", val); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -254,7 +254,7 @@ static int mso_clkrate_out(struct sr_dev_inst *sdi, uint16_t val) mso_trans(REG_CLKRATE2, val & 0xff), }; - sr_dbg("mso19: Setting clkrate word to 0x%x", val); + sr_dbg("Setting clkrate word to 0x%x.", val); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } @@ -401,7 +401,14 @@ static int mso_parse_serial(const char *iSerial, const char *iProduct, return SR_OK; } -static int hw_init(const char *devinfo) +static int hw_init(struct sr_context *sr_ctx) +{ + /* Nothing to do. */ + + return SR_OK; +} + +static int hw_scan(void) { struct sr_dev_inst *sdi; int devcnt = 0; @@ -410,8 +417,6 @@ static int hw_init(const char *devinfo) struct udev_list_entry *devs, *dev_list_entry; struct context *ctx; - devinfo = devinfo; - /* It's easier to map usb<->serial using udev */ /* * FIXME: On windows we can get the same information from the @@ -419,7 +424,7 @@ static int hw_init(const char *devinfo) */ udev = udev_new(); if (!udev) { - sr_err("mso19: Failed to initialize udev."); + sr_err("Failed to initialize udev."); goto ret; } enumerate = udev_enumerate_new(udev); @@ -439,7 +444,7 @@ static int hw_init(const char *devinfo) parent = udev_device_get_parent_with_subsystem_devtype( dev, "usb", "usb_device"); if (!parent) { - sr_err("mso19: Unable to find parent usb device for %s", + sr_err("Unable to find parent usb device for %s", sysname); continue; } @@ -458,7 +463,7 @@ static int hw_init(const char *devinfo) s = strcspn(iProduct, " "); if (s > sizeof(product) || strlen(iProduct) - s > sizeof(manufacturer)) { - sr_err("mso19: Could not parse iProduct: %s", iProduct); + sr_err("Could not parse iProduct: %s.", iProduct); continue; } strncpy(product, iProduct, s); @@ -466,12 +471,12 @@ static int hw_init(const char *devinfo) strcpy(manufacturer, iProduct + s); if (!(ctx = g_try_malloc0(sizeof(struct context)))) { - sr_err("mso19: %s: ctx malloc failed", __func__); + sr_err("Context malloc failed."); continue; /* TODO: Errors handled correctly? */ } if (mso_parse_serial(iSerial, iProduct, ctx) != SR_OK) { - sr_err("mso19: Invalid iSerial: %s", iSerial); + sr_err("Invalid iSerial: %s.", iSerial); goto err_free_ctx; } sprintf(hwrev, "r%d", ctx->hwrev); @@ -491,7 +496,7 @@ static int hw_init(const char *devinfo) sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING, manufacturer, product, hwrev); if (!sdi) { - sr_err("mso19: Unable to create device instance for %s", + sr_err("Unable to create device instance for %s", sysname); goto err_free_ctx; } @@ -531,7 +536,7 @@ static int hw_cleanup(void) for (l = dev_insts; l; l = l->next) { if (!(sdi = l->data)) { /* Log error, but continue cleaning up the rest. */ - sr_err("mso19: %s: sdi was NULL, continuing", __func__); + sr_err("%s: sdi was NULL, continuing", __func__); ret = SR_ERR_BUG; continue; } @@ -555,7 +560,7 @@ static int hw_dev_open(int dev_index) return ret; ctx = sdi->priv; - sdi->serial->fd = serial_open(sdi->serial->port, O_RDWR); + sdi->serial->fd = serial_open(sdi->serial->port, SERIAL_RDWR); if (sdi->serial->fd == -1) return ret; @@ -568,21 +573,19 @@ static int hw_dev_open(int dev_index) /* FIXME: discard serial buffer */ mso_check_trigger(sdi, &ctx->trigger_state); - sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state); + sr_dbg("Trigger state: 0x%x.", ctx->trigger_state); ret = mso_reset_adc(sdi); if (ret != SR_OK) return ret; mso_check_trigger(sdi, &ctx->trigger_state); - sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state); + sr_dbg("Trigger state: 0x%x.", ctx->trigger_state); // ret = mso_reset_fsm(sdi); // if (ret != SR_OK) // return ret; - sr_dbg("mso19: Finished %s", __func__); - // return SR_ERR; return SR_OK; } @@ -592,7 +595,7 @@ static int hw_dev_close(int dev_index) struct sr_dev_inst *sdi; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { - sr_err("mso19: %s: sdi was NULL", __func__); + sr_err("%s: sdi was NULL", __func__); return SR_ERR_BUG; } @@ -603,15 +606,14 @@ static int hw_dev_close(int dev_index) sdi->status = SR_ST_INACTIVE; } - sr_dbg("mso19: finished %s", __func__); return SR_OK; } -static void *hw_dev_info_get(int dev_index, int dev_info_id) +static const void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; struct context *ctx; - void *info = NULL; + const void *info = NULL; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return NULL; @@ -655,7 +657,7 @@ static const int *hw_hwcap_get_all(void) return hwcaps; } -static int hw_dev_config_set(int dev_index, int hwcap, void *value) +static int hw_dev_config_set(int dev_index, int hwcap, const void *value) { struct sr_dev_inst *sdi; @@ -664,7 +666,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) switch (hwcap) { case SR_HWCAP_SAMPLERATE: - return mso_configure_rate(sdi, *(uint64_t *) value); + return mso_configure_rate(sdi, *(const uint64_t *) value); case SR_HWCAP_PROBECONFIG: case SR_HWCAP_LIMIT_SAMPLES: default: @@ -691,7 +693,6 @@ static int receive_data(int fd, int revents, void *cb_data) double analog_out[1024]; size_t i, s; - /* Avoid compiler warnings. */ (void)revents; s = serial_read(fd, in, sizeof(in)); @@ -827,7 +828,6 @@ static int hw_dev_acquisition_stop(int dev_index, void *cb_data) { struct sr_datafeed_packet packet; - /* Avoid compiler warnings. */ (void)dev_index; packet.type = SR_DF_END; @@ -842,6 +842,7 @@ SR_PRIV struct sr_dev_driver link_mso19_driver_info = { .api_version = 1, .init = hw_init, .cleanup = hw_cleanup, + .scan = hw_scan, .dev_open = hw_dev_open, .dev_close = hw_dev_close, .dev_info_get = hw_dev_info_get,