From: Uwe Hermann Date: Sat, 18 Feb 2012 17:07:42 +0000 (+0100) Subject: sr: Consistent ctx name for per-dev-inst context. X-Git-Tag: libsigrok-0.1.0~104 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=ea9cfed7a55260ab97f57150b57c42a28c3a85a7;p=libsigrok.git sr: Consistent ctx name for per-dev-inst context. --- diff --git a/hardware/alsa/alsa.c b/hardware/alsa/alsa.c index 9e33d430..80c0e11d 100644 --- a/hardware/alsa/alsa.c +++ b/hardware/alsa/alsa.c @@ -56,7 +56,8 @@ static const char *probe_names[NUM_PROBES + 1] = { static GSList *dev_insts = NULL; -struct alsa { +/* Private, per-device-instance driver context. */ +struct context { uint64_t cur_rate; uint64_t limit_samples; snd_pcm_t *capture_handle; @@ -67,57 +68,58 @@ struct alsa { static int hw_init(const char *devinfo) { struct sr_dev_inst *sdi; - struct alsa *alsa; + struct context *ctx; /* Avoid compiler warnings. */ - devinfo = devinfo; + (void)devinfo; - if (!(alsa = g_try_malloc0(sizeof(struct alsa)))) { - sr_err("alsa: %s: alsa malloc failed", __func__); + if (!(ctx = g_try_malloc0(sizeof(struct context)))) { + sr_err("alsa: %s: ctx malloc failed", __func__); return 0; } - sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, "alsa", NULL, NULL); - if (!sdi) - goto free_alsa; + if (!(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, "alsa", NULL, NULL))) { + sr_err("alsa: %s: sdi was NULL", __func__); + goto free_ctx; + } - sdi->priv = alsa; + sdi->priv = ctx; dev_insts = g_slist_append(dev_insts, sdi); return 1; -free_alsa: - g_free(alsa); +free_ctx: + g_free(ctx); return 0; } static int hw_dev_open(int dev_index) { struct sr_dev_inst *sdi; - struct alsa *alsa; + struct context *ctx; int err; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - alsa = sdi->priv; + ctx = sdi->priv; - err = snd_pcm_open(&alsa->capture_handle, AUDIO_DEV, - SND_PCM_STREAM_CAPTURE, 0); + err = snd_pcm_open(&ctx->capture_handle, AUDIO_DEV, + SND_PCM_STREAM_CAPTURE, 0); if (err < 0) { sr_err("alsa: can't open audio device %s (%s)", AUDIO_DEV, snd_strerror(err)); return SR_ERR; } - err = snd_pcm_hw_params_malloc(&alsa->hw_params); + err = snd_pcm_hw_params_malloc(&ctx->hw_params); if (err < 0) { sr_err("alsa: can't allocate hardware parameter structure (%s)", snd_strerror(err)); return SR_ERR; } - err = snd_pcm_hw_params_any(alsa->capture_handle, alsa->hw_params); + err = snd_pcm_hw_params_any(ctx->capture_handle, ctx->hw_params); if (err < 0) { sr_err("alsa: can't initialize hardware parameter structure " "(%s)", snd_strerror(err)); @@ -130,23 +132,23 @@ static int hw_dev_open(int dev_index) static int hw_dev_close(int dev_index) { struct sr_dev_inst *sdi; - struct alsa *alsa; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("alsa: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } - if (!(alsa = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("alsa: %s: sdi->priv was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } // TODO: Return values of snd_*? - if (alsa->hw_params) - snd_pcm_hw_params_free(alsa->hw_params); - if (alsa->capture_handle) - snd_pcm_close(alsa->capture_handle); + if (ctx->hw_params) + snd_pcm_hw_params_free(ctx->hw_params); + if (ctx->capture_handle) + snd_pcm_close(ctx->capture_handle); return SR_OK; } @@ -168,12 +170,12 @@ static int hw_cleanup(void) static void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; - struct alsa *alsa; + struct context *ctx; void *info = NULL; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return NULL; - alsa = sdi->priv; + ctx = sdi->priv; switch (dev_info_id) { case SR_DI_INST: @@ -186,7 +188,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = probe_names; break; case SR_DI_CUR_SAMPLERATE: - info = &alsa->cur_rate; + info = &ctx->cur_rate; break; // case SR_DI_PROBE_TYPE: // info = GINT_TO_POINTER(SR_PROBE_TYPE_ANALOG); @@ -212,20 +214,20 @@ static int *hw_hwcap_get_all(void) static int hw_dev_config_set(int dev_index, int hwcap, void *value) { struct sr_dev_inst *sdi; - struct alsa *alsa; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - alsa = sdi->priv; + ctx = sdi->priv; switch (hwcap) { case SR_HWCAP_PROBECONFIG: return SR_OK; case SR_HWCAP_SAMPLERATE: - alsa->cur_rate = *(uint64_t *) value; + ctx->cur_rate = *(uint64_t *)value; return SR_OK; case SR_HWCAP_LIMIT_SAMPLES: - alsa->limit_samples = *(uint64_t *) value; + ctx->limit_samples = *(uint64_t *)value; return SR_OK; default: return SR_ERR; @@ -235,7 +237,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) static int receive_data(int fd, int revents, void *user_data) { struct sr_dev_inst *sdi = user_data; - struct alsa *alsa = sdi->priv; + struct context *ctx = sdi->priv; struct sr_datafeed_packet packet; struct sr_analog_sample *sample; unsigned int sample_size = sizeof(struct sr_analog_sample) + @@ -249,8 +251,8 @@ static int receive_data(int fd, int revents, void *user_data) do { memset(inb, 0, sizeof(inb)); - count = snd_pcm_readi(alsa->capture_handle, inb, - MIN(4096/4, alsa->limit_samples)); + count = snd_pcm_readi(ctx->capture_handle, inb, + MIN(4096 / 4, ctx->limit_samples)); if (count < 1) { sr_err("alsa: Failed to read samples"); return FALSE; @@ -268,7 +270,7 @@ static int receive_data(int fd, int revents, void *user_data) for (x = 0; x < NUM_PROBES; x++) { sample->probes[x].val = - *(uint16_t *) (inb + (i * 4) + (x * 2)); + *(uint16_t *)(inb + (i * 4) + (x * 2)); sample->probes[x].val &= ((1 << 16) - 1); sample->probes[x].res = 16; } @@ -280,9 +282,9 @@ static int receive_data(int fd, int revents, void *user_data) packet.payload = outb; sr_session_bus(user_data, &packet); g_free(outb); - alsa->limit_samples -= count; + ctx->limit_samples -= count; - } while (alsa->limit_samples > 0); + } while (ctx->limit_samples > 0); packet.type = SR_DF_END; sr_session_bus(user_data, &packet); @@ -293,7 +295,7 @@ static int receive_data(int fd, int revents, void *user_data) static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id) { struct sr_dev_inst *sdi; - struct alsa *alsa; + struct context *ctx; struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct pollfd *ufds; @@ -302,51 +304,51 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - alsa = sdi->priv; + ctx = sdi->priv; - err = snd_pcm_hw_params_set_access(alsa->capture_handle, - alsa->hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); + err = snd_pcm_hw_params_set_access(ctx->capture_handle, + ctx->hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { sr_err("alsa: can't set access type (%s)", snd_strerror(err)); return SR_ERR; } /* FIXME: Hardcoded for 16bits */ - err = snd_pcm_hw_params_set_format(alsa->capture_handle, - alsa->hw_params, SND_PCM_FORMAT_S16_LE); + err = snd_pcm_hw_params_set_format(ctx->capture_handle, + ctx->hw_params, SND_PCM_FORMAT_S16_LE); if (err < 0) { sr_err("alsa: can't set sample format (%s)", snd_strerror(err)); return SR_ERR; } - err = snd_pcm_hw_params_set_rate_near(alsa->capture_handle, - alsa->hw_params, (unsigned int *) &alsa->cur_rate, 0); + err = snd_pcm_hw_params_set_rate_near(ctx->capture_handle, + ctx->hw_params, (unsigned int *)&ctx->cur_rate, 0); if (err < 0) { sr_err("alsa: can't set sample rate (%s)", snd_strerror(err)); return SR_ERR; } - err = snd_pcm_hw_params_set_channels(alsa->capture_handle, - alsa->hw_params, NUM_PROBES); + err = snd_pcm_hw_params_set_channels(ctx->capture_handle, + ctx->hw_params, NUM_PROBES); if (err < 0) { sr_err("alsa: can't set channel count (%s)", snd_strerror(err)); return SR_ERR; } - err = snd_pcm_hw_params(alsa->capture_handle, alsa->hw_params); + err = snd_pcm_hw_params(ctx->capture_handle, ctx->hw_params); if (err < 0) { sr_err("alsa: can't set parameters (%s)", snd_strerror(err)); return SR_ERR; } - err = snd_pcm_prepare(alsa->capture_handle); + err = snd_pcm_prepare(ctx->capture_handle); if (err < 0) { sr_err("alsa: can't prepare audio interface for use (%s)", snd_strerror(err)); return SR_ERR; } - count = snd_pcm_poll_descriptors_count(alsa->capture_handle); + count = snd_pcm_poll_descriptors_count(ctx->capture_handle); if (count < 1) { sr_err("alsa: Unable to obtain poll descriptors count"); return SR_ERR; @@ -357,7 +359,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id) return SR_ERR_MALLOC; } - err = snd_pcm_poll_descriptors(alsa->capture_handle, ufds, count); + err = snd_pcm_poll_descriptors(ctx->capture_handle, ufds, count); if (err < 0) { sr_err("alsa: Unable to obtain poll descriptors (%s)", snd_strerror(err)); @@ -365,15 +367,15 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id) return SR_ERR; } - alsa->session_id = session_dev_id; + ctx->session_id = session_dev_id; sr_source_add(ufds[0].fd, ufds[0].events, 10, receive_data, sdi); packet.type = SR_DF_HEADER; packet.length = sizeof(struct sr_datafeed_header); - packet.payload = (unsigned char *) &header; + packet.payload = (unsigned char *)&header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); - header.samplerate = alsa->cur_rate; + header.samplerate = ctx->cur_rate; header.num_analog_probes = NUM_PROBES; header.num_logic_probes = 0; header.protocol_id = SR_PROTO_RAW; diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index d0427498..bb90b41a 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -120,27 +120,27 @@ static const char *firmware_files[] = { static int hw_dev_acquisition_stop(int dev_index, gpointer session_data); -static int sigma_read(void *buf, size_t size, struct sigma *sigma) +static int sigma_read(void *buf, size_t size, struct context *ctx) { int ret; - ret = ftdi_read_data(&sigma->ftdic, (unsigned char *)buf, size); + ret = ftdi_read_data(&ctx->ftdic, (unsigned char *)buf, size); if (ret < 0) { sr_err("sigma: ftdi_read_data failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + ftdi_get_error_string(&ctx->ftdic)); } return ret; } -static int sigma_write(void *buf, size_t size, struct sigma *sigma) +static int sigma_write(void *buf, size_t size, struct context *ctx) { int ret; - ret = ftdi_write_data(&sigma->ftdic, (unsigned char *)buf, size); + ret = ftdi_write_data(&ctx->ftdic, (unsigned char *)buf, size); if (ret < 0) { sr_err("sigma: ftdi_write_data failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + ftdi_get_error_string(&ctx->ftdic)); } else if ((size_t) ret != size) { sr_err("sigma: ftdi_write_data did not complete write\n"); } @@ -149,7 +149,7 @@ static int sigma_write(void *buf, size_t size, struct sigma *sigma) } static int sigma_write_register(uint8_t reg, uint8_t *data, size_t len, - struct sigma *sigma) + struct context *ctx) { size_t i; uint8_t buf[len + 2]; @@ -163,16 +163,16 @@ static int sigma_write_register(uint8_t reg, uint8_t *data, size_t len, buf[idx++] = REG_DATA_HIGH_WRITE | (data[i] >> 4); } - return sigma_write(buf, idx, sigma); + return sigma_write(buf, idx, ctx); } -static int sigma_set_register(uint8_t reg, uint8_t value, struct sigma *sigma) +static int sigma_set_register(uint8_t reg, uint8_t value, struct context *ctx) { - return sigma_write_register(reg, &value, 1, sigma); + return sigma_write_register(reg, &value, 1, ctx); } static int sigma_read_register(uint8_t reg, uint8_t *data, size_t len, - struct sigma *sigma) + struct context *ctx) { uint8_t buf[3]; @@ -180,16 +180,16 @@ static int sigma_read_register(uint8_t reg, uint8_t *data, size_t len, buf[1] = REG_ADDR_HIGH | (reg >> 4); buf[2] = REG_READ_ADDR; - sigma_write(buf, sizeof(buf), sigma); + sigma_write(buf, sizeof(buf), ctx); - return sigma_read(data, len, sigma); + return sigma_read(data, len, ctx); } -static uint8_t sigma_get_register(uint8_t reg, struct sigma *sigma) +static uint8_t sigma_get_register(uint8_t reg, struct context *ctx) { uint8_t value; - if (1 != sigma_read_register(reg, &value, 1, sigma)) { + if (1 != sigma_read_register(reg, &value, 1, ctx)) { sr_err("sigma: sigma_get_register: 1 byte expected"); return 0; } @@ -198,7 +198,7 @@ static uint8_t sigma_get_register(uint8_t reg, struct sigma *sigma) } static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos, - struct sigma *sigma) + struct context *ctx) { uint8_t buf[] = { REG_ADDR_LOW | READ_TRIGGER_POS_LOW, @@ -212,9 +212,9 @@ static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos, }; uint8_t result[6]; - sigma_write(buf, sizeof(buf), sigma); + sigma_write(buf, sizeof(buf), ctx); - sigma_read(result, sizeof(result), sigma); + sigma_read(result, sizeof(result), ctx); *triggerpos = result[0] | (result[1] << 8) | (result[2] << 16); *stoppos = result[3] | (result[4] << 8) | (result[5] << 16); @@ -230,7 +230,7 @@ static int sigma_read_pos(uint32_t *stoppos, uint32_t *triggerpos, } static int sigma_read_dram(uint16_t startchunk, size_t numchunks, - uint8_t *data, struct sigma *sigma) + uint8_t *data, struct context *ctx) { size_t i; uint8_t buf[4096]; @@ -239,7 +239,7 @@ static int sigma_read_dram(uint16_t startchunk, size_t numchunks, /* Send the startchunk. Index start with 1. */ buf[0] = startchunk >> 8; buf[1] = startchunk & 0xff; - sigma_write_register(WRITE_MEMROW, buf, 2, sigma); + sigma_write_register(WRITE_MEMROW, buf, 2, ctx); /* Read the DRAM. */ buf[idx++] = REG_DRAM_BLOCK; @@ -256,13 +256,13 @@ static int sigma_read_dram(uint16_t startchunk, size_t numchunks, buf[idx++] = REG_DRAM_WAIT_ACK; } - sigma_write(buf, idx, sigma); + sigma_write(buf, idx, ctx); - return sigma_read(data, numchunks * CHUNK_SIZE, sigma); + return sigma_read(data, numchunks * CHUNK_SIZE, ctx); } /* Upload trigger look-up tables to Sigma. */ -static int sigma_write_trigger_lut(struct triggerlut *lut, struct sigma *sigma) +static int sigma_write_trigger_lut(struct triggerlut *lut, struct context *ctx) { int i; uint8_t tmp[2]; @@ -309,13 +309,13 @@ static int sigma_write_trigger_lut(struct triggerlut *lut, struct sigma *sigma) tmp[1] |= 0x80; sigma_write_register(WRITE_TRIGGER_SELECT0, tmp, sizeof(tmp), - sigma); - sigma_set_register(WRITE_TRIGGER_SELECT1, 0x30 | i, sigma); + ctx); + sigma_set_register(WRITE_TRIGGER_SELECT1, 0x30 | i, ctx); } /* Send the parameters */ sigma_write_register(WRITE_TRIGGER_SELECT0, (uint8_t *) &lut->params, - sizeof(lut->params), sigma); + sizeof(lut->params), ctx); return SR_OK; } @@ -418,31 +418,31 @@ static int bin2bitbang(const char *filename, static int hw_init(const char *devinfo) { struct sr_dev_inst *sdi; - struct sigma *sigma; + struct context *ctx; /* Avoid compiler warnings. */ (void)devinfo; - if (!(sigma = g_try_malloc(sizeof(struct sigma)))) { - sr_err("sigma: %s: sigma malloc failed", __func__); + if (!(ctx = g_try_malloc(sizeof(struct context)))) { + sr_err("sigma: %s: ctx malloc failed", __func__); return 0; /* FIXME: Should be SR_ERR_MALLOC. */ } - ftdi_init(&sigma->ftdic); + ftdi_init(&ctx->ftdic); /* Look for SIGMAs. */ - if (ftdi_usb_open_desc(&sigma->ftdic, USB_VENDOR, USB_PRODUCT, + if (ftdi_usb_open_desc(&ctx->ftdic, USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL) < 0) goto free; - sigma->cur_samplerate = 0; - sigma->period_ps = 0; - sigma->limit_msec = 0; - sigma->cur_firmware = -1; - sigma->num_probes = 0; - sigma->samples_per_event = 0; - sigma->capture_ratio = 50; - sigma->use_triggers = 0; + ctx->cur_samplerate = 0; + ctx->period_ps = 0; + ctx->limit_msec = 0; + ctx->cur_firmware = -1; + ctx->num_probes = 0; + ctx->samples_per_event = 0; + ctx->capture_ratio = 50; + ctx->use_triggers = 0; /* Register SIGMA device. */ if (!(sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING, USB_VENDOR_NAME, @@ -451,20 +451,21 @@ static int hw_init(const char *devinfo) goto free; } - sdi->priv = sigma; + sdi->priv = ctx; dev_insts = g_slist_append(dev_insts, sdi); /* We will open the device again when we need it. */ - ftdi_usb_close(&sigma->ftdic); + ftdi_usb_close(&ctx->ftdic); return 1; + free: - g_free(sigma); + g_free(ctx); return 0; } -static int upload_firmware(int firmware_idx, struct sigma *sigma) +static int upload_firmware(int firmware_idx, struct context *ctx) { int ret; unsigned char *buf; @@ -474,40 +475,40 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) char firmware_path[128]; /* Make sure it's an ASIX SIGMA. */ - if ((ret = ftdi_usb_open_desc(&sigma->ftdic, + if ((ret = ftdi_usb_open_desc(&ctx->ftdic, USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) { sr_err("sigma: ftdi_usb_open failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + ftdi_get_error_string(&ctx->ftdic)); return 0; } - if ((ret = ftdi_set_bitmode(&sigma->ftdic, 0xdf, BITMODE_BITBANG)) < 0) { + if ((ret = ftdi_set_bitmode(&ctx->ftdic, 0xdf, BITMODE_BITBANG)) < 0) { sr_err("sigma: ftdi_set_bitmode failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + ftdi_get_error_string(&ctx->ftdic)); return 0; } /* Four times the speed of sigmalogan - Works well. */ - if ((ret = ftdi_set_baudrate(&sigma->ftdic, 750000)) < 0) { + if ((ret = ftdi_set_baudrate(&ctx->ftdic, 750000)) < 0) { sr_err("sigma: ftdi_set_baudrate failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + ftdi_get_error_string(&ctx->ftdic)); return 0; } /* Force the FPGA to reboot. */ - sigma_write(suicide, sizeof(suicide), sigma); - sigma_write(suicide, sizeof(suicide), sigma); - sigma_write(suicide, sizeof(suicide), sigma); - sigma_write(suicide, sizeof(suicide), sigma); + sigma_write(suicide, sizeof(suicide), ctx); + sigma_write(suicide, sizeof(suicide), ctx); + sigma_write(suicide, sizeof(suicide), ctx); + sigma_write(suicide, sizeof(suicide), ctx); /* Prepare to upload firmware (FPGA specific). */ - sigma_write(init, sizeof(init), sigma); + sigma_write(init, sizeof(init), ctx); - ftdi_usb_purge_buffers(&sigma->ftdic); + ftdi_usb_purge_buffers(&ctx->ftdic); /* Wait until the FPGA asserts INIT_B. */ while (1) { - ret = sigma_read(result, 1, sigma); + ret = sigma_read(result, 1, ctx); if (result[0] & 0x20) break; } @@ -523,34 +524,34 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) } /* Upload firmare. */ - sigma_write(buf, buf_size, sigma); + sigma_write(buf, buf_size, ctx); g_free(buf); - if ((ret = ftdi_set_bitmode(&sigma->ftdic, 0x00, BITMODE_RESET)) < 0) { + if ((ret = ftdi_set_bitmode(&ctx->ftdic, 0x00, BITMODE_RESET)) < 0) { sr_err("sigma: ftdi_set_bitmode failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + ftdi_get_error_string(&ctx->ftdic)); return SR_ERR; } - ftdi_usb_purge_buffers(&sigma->ftdic); + ftdi_usb_purge_buffers(&ctx->ftdic); /* Discard garbage. */ - while (1 == sigma_read(&pins, 1, sigma)) + while (1 == sigma_read(&pins, 1, ctx)) ; /* Initialize the logic analyzer mode. */ - sigma_write(logic_mode_start, sizeof(logic_mode_start), sigma); + sigma_write(logic_mode_start, sizeof(logic_mode_start), ctx); /* Expect a 3 byte reply. */ - ret = sigma_read(result, 3, sigma); + ret = sigma_read(result, 3, ctx); if (ret != 3 || result[0] != 0xa6 || result[1] != 0x55 || result[2] != 0xaa) { sr_err("sigma: Configuration failed. Invalid reply received."); return SR_ERR; } - sigma->cur_firmware = firmware_idx; + ctx->cur_firmware = firmware_idx; return SR_OK; } @@ -558,20 +559,20 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) static int hw_dev_open(int dev_index) { struct sr_dev_inst *sdi; - struct sigma *sigma; + struct context *ctx; int ret; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - sigma = sdi->priv; + ctx = sdi->priv; /* Make sure it's an ASIX SIGMA. */ - if ((ret = ftdi_usb_open_desc(&sigma->ftdic, + if ((ret = ftdi_usb_open_desc(&ctx->ftdic, USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) { sr_err("sigma: ftdi_usb_open failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + ftdi_get_error_string(&ctx->ftdic)); return 0; } @@ -584,7 +585,7 @@ static int hw_dev_open(int dev_index) static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { int i, ret; - struct sigma *sigma = sdi->priv; + struct context *ctx = sdi->priv; for (i = 0; supported_samplerates[i]; i++) { if (supported_samplerates[i] == samplerate) @@ -594,22 +595,22 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) return SR_ERR_SAMPLERATE; if (samplerate <= SR_MHZ(50)) { - ret = upload_firmware(0, sigma); - sigma->num_probes = 16; + ret = upload_firmware(0, ctx); + ctx->num_probes = 16; } if (samplerate == SR_MHZ(100)) { - ret = upload_firmware(1, sigma); - sigma->num_probes = 8; + ret = upload_firmware(1, ctx); + ctx->num_probes = 8; } else if (samplerate == SR_MHZ(200)) { - ret = upload_firmware(2, sigma); - sigma->num_probes = 4; + ret = upload_firmware(2, ctx); + ctx->num_probes = 4; } - sigma->cur_samplerate = samplerate; - sigma->period_ps = 1000000000000 / samplerate; - sigma->samples_per_event = 16 / sigma->num_probes; - sigma->state.state = SIGMA_IDLE; + ctx->cur_samplerate = samplerate; + ctx->period_ps = 1000000000000 / samplerate; + ctx->samples_per_event = 16 / ctx->num_probes; + ctx->state.state = SIGMA_IDLE; sr_info("sigma: Firmware uploaded"); @@ -626,13 +627,13 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) */ static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) { - struct sigma *sigma = sdi->priv; + struct context *ctx = sdi->priv; struct sr_probe *probe; GSList *l; int trigger_set = 0; int probebit; - memset(&sigma->trigger, 0, sizeof(struct sigma_trigger)); + memset(&ctx->trigger, 0, sizeof(struct sigma_trigger)); for (l = probes; l; l = l->next) { probe = (struct sr_probe *)l->data; @@ -641,7 +642,7 @@ static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) if (!probe->enabled || !probe->trigger) continue; - if (sigma->cur_samplerate >= SR_MHZ(100)) { + if (ctx->cur_samplerate >= SR_MHZ(100)) { /* Fast trigger support. */ if (trigger_set) { sr_err("sigma: ASIX SIGMA only supports a single " @@ -649,9 +650,9 @@ static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) return SR_ERR; } if (probe->trigger[0] == 'f') - sigma->trigger.fallingmask |= probebit; + ctx->trigger.fallingmask |= probebit; else if (probe->trigger[0] == 'r') - sigma->trigger.risingmask |= probebit; + ctx->trigger.risingmask |= probebit; else { sr_err("sigma: ASIX SIGMA only supports " "rising/falling trigger in 100 " @@ -663,27 +664,27 @@ static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) } else { /* Simple trigger support (event). */ if (probe->trigger[0] == '1') { - sigma->trigger.simplevalue |= probebit; - sigma->trigger.simplemask |= probebit; + ctx->trigger.simplevalue |= probebit; + ctx->trigger.simplemask |= probebit; } else if (probe->trigger[0] == '0') { - sigma->trigger.simplevalue &= ~probebit; - sigma->trigger.simplemask |= probebit; + ctx->trigger.simplevalue &= ~probebit; + ctx->trigger.simplemask |= probebit; } else if (probe->trigger[0] == 'f') { - sigma->trigger.fallingmask |= probebit; + ctx->trigger.fallingmask |= probebit; ++trigger_set; } else if (probe->trigger[0] == 'r') { - sigma->trigger.risingmask |= probebit; + ctx->trigger.risingmask |= probebit; ++trigger_set; } - /* - * Actually, Sigma supports 2 rising/falling triggers, - * but they are ORed and the current trigger syntax - * does not permit ORed triggers. - */ + /* + * Actually, Sigma supports 2 rising/falling triggers, + * but they are ORed and the current trigger syntax + * does not permit ORed triggers. + */ if (trigger_set > 1) { sr_err("sigma: ASIX SIGMA only supports 1 " "rising/falling triggers."); @@ -692,7 +693,7 @@ static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) } if (trigger_set) - sigma->use_triggers = 1; + ctx->use_triggers = 1; } return SR_OK; @@ -701,21 +702,21 @@ static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) static int hw_dev_close(int dev_index) { struct sr_dev_inst *sdi; - struct sigma *sigma; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("sigma: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } - if (!(sigma = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("sigma: %s: sdi->priv was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } /* TODO */ if (sdi->status == SR_ST_ACTIVE) - ftdi_usb_close(&sigma->ftdic); + ftdi_usb_close(&ctx->ftdic); sdi->status = SR_ST_INACTIVE; @@ -747,7 +748,7 @@ static int hw_cleanup(void) static void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; - struct sigma *sigma; + struct context *ctx; void *info = NULL; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { @@ -755,7 +756,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) return NULL; } - sigma = sdi->priv; + ctx = sdi->priv; switch (dev_info_id) { case SR_DI_INST: @@ -774,7 +775,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = (char *)TRIGGER_TYPES; break; case SR_DI_CUR_SAMPLERATE: - info = &sigma->cur_samplerate; + info = &ctx->cur_samplerate; break; } @@ -800,27 +801,27 @@ static int *hw_hwcap_get_all(void) static int hw_dev_config_set(int dev_index, int hwcap, void *value) { struct sr_dev_inst *sdi; - struct sigma *sigma; + struct context *ctx; int ret; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - sigma = sdi->priv; + ctx = sdi->priv; if (hwcap == SR_HWCAP_SAMPLERATE) { - ret = set_samplerate(sdi, *(uint64_t*) value); + ret = set_samplerate(sdi, *(uint64_t *)value); } else if (hwcap == SR_HWCAP_PROBECONFIG) { ret = configure_probes(sdi, value); } else if (hwcap == SR_HWCAP_LIMIT_MSEC) { - sigma->limit_msec = *(uint64_t*) value; - if (sigma->limit_msec > 0) + ctx->limit_msec = *(uint64_t *)value; + if (ctx->limit_msec > 0) ret = SR_OK; else ret = SR_ERR; } else if (hwcap == SR_HWCAP_CAPTURE_RATIO) { - sigma->capture_ratio = *(uint64_t*) value; - if (sigma->capture_ratio < 0 || sigma->capture_ratio > 100) + ctx->capture_ratio = *(uint64_t *)value; + if (ctx->capture_ratio < 0 || ctx->capture_ratio > 100) ret = SR_ERR; else ret = SR_OK; @@ -876,21 +877,21 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, uint16_t limit_chunk, void *session_data) { struct sr_dev_inst *sdi = session_data; - struct sigma *sigma = sdi->priv; + struct context *ctx = sdi->priv; uint16_t tsdiff, ts; - uint16_t samples[65536 * sigma->samples_per_event]; + uint16_t samples[65536 * ctx->samples_per_event]; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; int i, j, k, l, numpad, tosend; size_t n = 0, sent = 0; - int clustersize = EVENTS_PER_CLUSTER * sigma->samples_per_event; + int clustersize = EVENTS_PER_CLUSTER * ctx->samples_per_event; uint16_t *event; uint16_t cur_sample; int triggerts = -1; /* Check if trigger is in this chunk. */ if (triggerpos != -1) { - if (sigma->cur_samplerate <= SR_MHZ(50)) + if (ctx->cur_samplerate <= SR_MHZ(50)) triggerpos -= EVENTS_PER_CLUSTER - 1; if (triggerpos < 0) @@ -911,7 +912,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, return SR_OK; /* Pad last sample up to current point. */ - numpad = tsdiff * sigma->samples_per_event - clustersize; + numpad = tsdiff * ctx->samples_per_event - clustersize; if (numpad > 0) { for (j = 0; j < numpad; ++j) samples[j] = *lastsample; @@ -929,7 +930,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, logic.length = tosend * sizeof(uint16_t); logic.unitsize = 2; logic.data = samples + sent; - sr_session_bus(sigma->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); sent += tosend; } @@ -942,15 +943,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, for (j = 0; j < 7; ++j) { /* For each sample in event. */ - for (k = 0; k < sigma->samples_per_event; ++k) { + for (k = 0; k < ctx->samples_per_event; ++k) { cur_sample = 0; /* For each probe. */ - for (l = 0; l < sigma->num_probes; ++l) + for (l = 0; l < ctx->num_probes; ++l) cur_sample |= (!!(event[j] & (1 << (l * - sigma->samples_per_event - + k)))) - << l; + ctx->samples_per_event + k)))) << l; samples[n++] = cur_sample; } @@ -966,7 +965,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, * samples to pinpoint the exact position of the trigger. */ tosend = get_trigger_offset(samples, *lastsample, - &sigma->trigger); + &ctx->trigger); if (tosend > 0) { packet.type = SR_DF_LOGIC; @@ -974,15 +973,15 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, logic.length = tosend * sizeof(uint16_t); logic.unitsize = 2; logic.data = samples; - sr_session_bus(sigma->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); sent += tosend; } /* Only send trigger if explicitly enabled. */ - if (sigma->use_triggers) { + if (ctx->use_triggers) { packet.type = SR_DF_TRIGGER; - sr_session_bus(sigma->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); } } @@ -995,7 +994,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, logic.length = tosend * sizeof(uint16_t); logic.unitsize = 2; logic.data = samples + sent; - sr_session_bus(sigma->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); } *lastsample = samples[n - 1]; @@ -1007,7 +1006,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, static int receive_data(int fd, int revents, void *session_data) { struct sr_dev_inst *sdi = session_data; - struct sigma *sigma = sdi->priv; + struct context *ctx = sdi->priv; struct sr_datafeed_packet packet; const int chunks_per_read = 32; unsigned char buf[chunks_per_read * CHUNK_SIZE]; @@ -1019,51 +1018,49 @@ static int receive_data(int fd, int revents, void *session_data) (void)fd; (void)revents; - numchunks = (sigma->state.stoppos + 511) / 512; + numchunks = (ctx->state.stoppos + 511) / 512; - if (sigma->state.state == SIGMA_IDLE) + if (ctx->state.state == SIGMA_IDLE) return FALSE; - if (sigma->state.state == SIGMA_CAPTURE) { - + if (ctx->state.state == SIGMA_CAPTURE) { /* Check if the timer has expired, or memory is full. */ gettimeofday(&tv, 0); - running_msec = (tv.tv_sec - sigma->start_tv.tv_sec) * 1000 + - (tv.tv_usec - sigma->start_tv.tv_usec) / 1000; + running_msec = (tv.tv_sec - ctx->start_tv.tv_sec) * 1000 + + (tv.tv_usec - ctx->start_tv.tv_usec) / 1000; - if (running_msec < sigma->limit_msec && numchunks < 32767) + if (running_msec < ctx->limit_msec && numchunks < 32767) return FALSE; hw_dev_acquisition_stop(sdi->index, session_data); return FALSE; - - } else if (sigma->state.state == SIGMA_DOWNLOAD) { - if (sigma->state.chunks_downloaded >= numchunks) { + } else if (ctx->state.state == SIGMA_DOWNLOAD) { + if (ctx->state.chunks_downloaded >= numchunks) { /* End of samples. */ packet.type = SR_DF_END; - sr_session_bus(sigma->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); - sigma->state.state = SIGMA_IDLE; + ctx->state.state = SIGMA_IDLE; return TRUE; } newchunks = MIN(chunks_per_read, - numchunks - sigma->state.chunks_downloaded); + numchunks - ctx->state.chunks_downloaded); sr_info("sigma: Downloading sample data: %.0f %%", - 100.0 * sigma->state.chunks_downloaded / numchunks); + 100.0 * ctx->state.chunks_downloaded / numchunks); - bufsz = sigma_read_dram(sigma->state.chunks_downloaded, - newchunks, buf, sigma); + bufsz = sigma_read_dram(ctx->state.chunks_downloaded, + newchunks, buf, ctx); /* TODO: Check bufsz. For now, just avoid compiler warnings. */ (void)bufsz; /* Find first ts. */ - if (sigma->state.chunks_downloaded == 0) { - sigma->state.lastts = *(uint16_t *) buf - 1; - sigma->state.lastsample = 0; + if (ctx->state.chunks_downloaded == 0) { + ctx->state.lastts = *(uint16_t *) buf - 1; + ctx->state.lastsample = 0; } /* Decode chunks and send them to sigrok. */ @@ -1071,25 +1068,24 @@ static int receive_data(int fd, int revents, void *session_data) int limit_chunk = 0; /* The last chunk may potentially be only in part. */ - if (sigma->state.chunks_downloaded == numchunks - 1) - { + if (ctx->state.chunks_downloaded == numchunks - 1) { /* Find the last valid timestamp */ - limit_chunk = sigma->state.stoppos % 512 + sigma->state.lastts; + limit_chunk = ctx->state.stoppos % 512 + ctx->state.lastts; } - if (sigma->state.chunks_downloaded + i == sigma->state.triggerchunk) + if (ctx->state.chunks_downloaded + i == ctx->state.triggerchunk) decode_chunk_ts(buf + (i * CHUNK_SIZE), - &sigma->state.lastts, - &sigma->state.lastsample, - sigma->state.triggerpos & 0x1ff, + &ctx->state.lastts, + &ctx->state.lastsample, + ctx->state.triggerpos & 0x1ff, limit_chunk, session_data); else decode_chunk_ts(buf + (i * CHUNK_SIZE), - &sigma->state.lastts, - &sigma->state.lastsample, + &ctx->state.lastts, + &ctx->state.lastsample, -1, limit_chunk, session_data); - ++sigma->state.chunks_downloaded; + ++ctx->state.chunks_downloaded; } } @@ -1168,12 +1164,13 @@ static void add_trigger_function(enum triggerop oper, enum triggerfunc func, /* Transpose if neg is set. */ if (neg) { - for (i = 0; i < 2; ++i) + for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { tmp = x[i][j]; x[i][j] = x[1-i][1-j]; x[1-i][1-j] = tmp; } + } } /* Update mask with function. */ @@ -1206,7 +1203,7 @@ static void add_trigger_function(enum triggerop oper, enum triggerfunc func, * simple pin change and state triggers. Only two transitions (rise/fall) can be * set at any time, but a full mask and value can be set (0/1). */ -static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma) +static int build_basic_trigger(struct triggerlut *lut, struct context *ctx) { int i,j; uint16_t masks[2] = { 0, 0 }; @@ -1217,13 +1214,13 @@ static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma) lut->m4 = 0xa000; /* Value/mask trigger support. */ - build_lut_entry(sigma->trigger.simplevalue, sigma->trigger.simplemask, + build_lut_entry(ctx->trigger.simplevalue, ctx->trigger.simplemask, lut->m2d); /* Rise/fall trigger support. */ for (i = 0, j = 0; i < 16; ++i) { - if (sigma->trigger.risingmask & (1 << i) || - sigma->trigger.fallingmask & (1 << i)) + if (ctx->trigger.risingmask & (1 << i) || + ctx->trigger.fallingmask & (1 << i)) masks[j++] = 1 << i; } @@ -1233,13 +1230,13 @@ static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma) /* Add glue logic */ if (masks[0] || masks[1]) { /* Transition trigger. */ - if (masks[0] & sigma->trigger.risingmask) + if (masks[0] & ctx->trigger.risingmask) add_trigger_function(OP_RISE, FUNC_OR, 0, 0, &lut->m3); - if (masks[0] & sigma->trigger.fallingmask) + if (masks[0] & ctx->trigger.fallingmask) add_trigger_function(OP_FALL, FUNC_OR, 0, 0, &lut->m3); - if (masks[1] & sigma->trigger.risingmask) + if (masks[1] & ctx->trigger.risingmask) add_trigger_function(OP_RISE, FUNC_OR, 1, 0, &lut->m3); - if (masks[1] & sigma->trigger.fallingmask) + if (masks[1] & ctx->trigger.fallingmask) add_trigger_function(OP_FALL, FUNC_OR, 1, 0, &lut->m3); } else { /* Only value/mask trigger. */ @@ -1255,7 +1252,7 @@ static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma) static int hw_dev_acquisition_start(int dev_index, gpointer session_data) { struct sr_dev_inst *sdi; - struct sigma *sigma; + struct context *ctx; struct sr_datafeed_packet packet; struct sr_datafeed_header header; struct clockselect_50 clockselect; @@ -1270,24 +1267,24 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - sigma = sdi->priv; + ctx = sdi->priv; - /* If the samplerate has not been set, default to 200 KHz. */ - if (sigma->cur_firmware == -1) { + /* If the samplerate has not been set, default to 200 kHz. */ + if (ctx->cur_firmware == -1) { if ((ret = set_samplerate(sdi, SR_KHZ(200))) != SR_OK) return ret; } /* Enter trigger programming mode. */ - sigma_set_register(WRITE_TRIGGER_SELECT1, 0x20, sigma); + sigma_set_register(WRITE_TRIGGER_SELECT1, 0x20, ctx); /* 100 and 200 MHz mode. */ - if (sigma->cur_samplerate >= SR_MHZ(100)) { - sigma_set_register(WRITE_TRIGGER_SELECT1, 0x81, sigma); + if (ctx->cur_samplerate >= SR_MHZ(100)) { + sigma_set_register(WRITE_TRIGGER_SELECT1, 0x81, ctx); /* Find which pin to trigger on from mask. */ for (triggerpin = 0; triggerpin < 8; ++triggerpin) - if ((sigma->trigger.risingmask | sigma->trigger.fallingmask) & + if ((ctx->trigger.risingmask | ctx->trigger.fallingmask) & (1 << triggerpin)) break; @@ -1295,14 +1292,14 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) triggerselect = (1 << LEDSEL1) | (triggerpin & 0x7); /* Default rising edge. */ - if (sigma->trigger.fallingmask) + if (ctx->trigger.fallingmask) triggerselect |= 1 << 3; /* All other modes. */ - } else if (sigma->cur_samplerate <= SR_MHZ(50)) { - build_basic_trigger(&lut, sigma); + } else if (ctx->cur_samplerate <= SR_MHZ(50)) { + build_basic_trigger(&lut, ctx); - sigma_write_trigger_lut(&lut, sigma); + sigma_write_trigger_lut(&lut, ctx); triggerselect = (1 << LEDSEL1) | (1 << LEDSEL0); } @@ -1314,24 +1311,24 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) sigma_write_register(WRITE_TRIGGER_OPTION, (uint8_t *) &triggerinout_conf, - sizeof(struct triggerinout), sigma); + sizeof(struct triggerinout), ctx); /* Go back to normal mode. */ - sigma_set_register(WRITE_TRIGGER_SELECT1, triggerselect, sigma); + sigma_set_register(WRITE_TRIGGER_SELECT1, triggerselect, ctx); /* Set clock select register. */ - if (sigma->cur_samplerate == SR_MHZ(200)) + if (ctx->cur_samplerate == SR_MHZ(200)) /* Enable 4 probes. */ - sigma_set_register(WRITE_CLOCK_SELECT, 0xf0, sigma); - else if (sigma->cur_samplerate == SR_MHZ(100)) + sigma_set_register(WRITE_CLOCK_SELECT, 0xf0, ctx); + else if (ctx->cur_samplerate == SR_MHZ(100)) /* Enable 8 probes. */ - sigma_set_register(WRITE_CLOCK_SELECT, 0x00, sigma); + sigma_set_register(WRITE_CLOCK_SELECT, 0x00, ctx); else { /* * 50 MHz mode (or fraction thereof). Any fraction down to * 50 MHz / 256 can be used, but is not supported by sigrok API. */ - frac = SR_MHZ(50) / sigma->cur_samplerate - 1; + frac = SR_MHZ(50) / ctx->cur_samplerate - 1; clockselect.async = 0; clockselect.fraction = frac; @@ -1339,32 +1336,32 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) sigma_write_register(WRITE_CLOCK_SELECT, (uint8_t *) &clockselect, - sizeof(clockselect), sigma); + sizeof(clockselect), ctx); } /* Setup maximum post trigger time. */ sigma_set_register(WRITE_POST_TRIGGER, - (sigma->capture_ratio * 255) / 100, sigma); + (ctx->capture_ratio * 255) / 100, ctx); /* Start acqusition. */ - gettimeofday(&sigma->start_tv, 0); - sigma_set_register(WRITE_MODE, 0x0d, sigma); + gettimeofday(&ctx->start_tv, 0); + sigma_set_register(WRITE_MODE, 0x0d, ctx); - sigma->session_id = session_data; + ctx->session_id = session_data; /* Send header packet to the session bus. */ packet.type = SR_DF_HEADER; packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); - header.samplerate = sigma->cur_samplerate; - header.num_logic_probes = sigma->num_probes; + header.samplerate = ctx->cur_samplerate; + header.num_logic_probes = ctx->num_probes; sr_session_bus(session_data, &packet); /* Add capture source. */ sr_source_add(0, G_IO_IN, 10, receive_data, sdi); - sigma->state.state = SIGMA_CAPTURE; + ctx->state.state = SIGMA_CAPTURE; return SR_OK; } @@ -1372,7 +1369,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) static int hw_dev_acquisition_stop(int dev_index, gpointer session_data) { struct sr_dev_inst *sdi; - struct sigma *sigma; + struct context *ctx; uint8_t modestatus; /* Avoid compiler warnings. */ @@ -1383,30 +1380,30 @@ static int hw_dev_acquisition_stop(int dev_index, gpointer session_data) return SR_ERR_BUG; } - if (!(sigma = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("sigma: %s: sdi->priv was NULL", __func__); return SR_ERR_BUG; } /* Stop acquisition. */ - sigma_set_register(WRITE_MODE, 0x11, sigma); + sigma_set_register(WRITE_MODE, 0x11, ctx); /* Set SDRAM Read Enable. */ - sigma_set_register(WRITE_MODE, 0x02, sigma); + sigma_set_register(WRITE_MODE, 0x02, ctx); /* Get the current position. */ - sigma_read_pos(&sigma->state.stoppos, &sigma->state.triggerpos, sigma); + sigma_read_pos(&ctx->state.stoppos, &ctx->state.triggerpos, ctx); /* Check if trigger has fired. */ - modestatus = sigma_get_register(READ_MODE, sigma); + modestatus = sigma_get_register(READ_MODE, ctx); if (modestatus & 0x20) - sigma->state.triggerchunk = sigma->state.triggerpos / 512; + ctx->state.triggerchunk = ctx->state.triggerpos / 512; else - sigma->state.triggerchunk = -1; + ctx->state.triggerchunk = -1; - sigma->state.chunks_downloaded = 0; + ctx->state.chunks_downloaded = 0; - sigma->state.state = SIGMA_DOWNLOAD; + ctx->state.state = SIGMA_DOWNLOAD; return SR_OK; } diff --git a/hardware/asix-sigma/asix-sigma.h b/hardware/asix-sigma/asix-sigma.h index fbecb80f..c65a8eb0 100644 --- a/hardware/asix-sigma/asix-sigma.h +++ b/hardware/asix-sigma/asix-sigma.h @@ -173,7 +173,8 @@ struct sigma_state { int chunks_downloaded; }; -struct sigma { +/* Private, per-device-instance driver context. */ +struct context { struct ftdi_context ftdic; uint64_t cur_samplerate; uint64_t period_ps; diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index 6de27a49..fea43db8 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -54,7 +54,8 @@ static const char *probe_names[NUM_PROBES + 1] = { NULL, }; -struct la8 { +/* Private, per-device-instance driver context. */ +struct context { /** FTDI device context (used by libftdi). */ struct ftdi_context *ftdic; @@ -135,9 +136,9 @@ static int hwcaps[] = { }; /* Function prototypes. */ -static int la8_close_usb_reset_sequencer(struct la8 *la8); +static int la8_close_usb_reset_sequencer(struct context *ctx); static int hw_dev_acquisition_stop(int dev_index, gpointer session_data); -static int la8_reset(struct la8 *la8); +static int la8_reset(struct context *ctx); static void fill_supported_samplerates_if_needed(void) { @@ -205,22 +206,22 @@ static uint8_t samplerate_to_divcount(uint64_t samplerate) /** * Write data of a certain length to the LA8's FTDI device. * - * @param la8 The LA8 struct containing private per-device-instance data. + * @param ctx The struct containing private per-device-instance data. * @param buf The buffer containing the data to write. * @param size The number of bytes to write. * @return The number of bytes written, or a negative value upon errors. */ -static int la8_write(struct la8 *la8, uint8_t *buf, int size) +static int la8_write(struct context *ctx, uint8_t *buf, int size) { int bytes_written; - if (!la8) { - sr_err("la8: %s: la8 was NULL", __func__); + if (!ctx) { + sr_err("la8: %s: ctx was NULL", __func__); return SR_ERR_ARG; } - if (!la8->ftdic) { - sr_err("la8: %s: la8->ftdic was NULL", __func__); + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); return SR_ERR_ARG; } @@ -234,16 +235,16 @@ static int la8_write(struct la8 *la8, uint8_t *buf, int size) return SR_ERR_ARG; } - bytes_written = ftdi_write_data(la8->ftdic, buf, size); + bytes_written = ftdi_write_data(ctx->ftdic, buf, size); if (bytes_written < 0) { sr_err("la8: %s: ftdi_write_data: (%d) %s", __func__, - bytes_written, ftdi_get_error_string(la8->ftdic)); - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + bytes_written, ftdi_get_error_string(ctx->ftdic)); + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ } else if (bytes_written != size) { sr_err("la8: %s: bytes to write: %d, bytes written: %d", __func__, size, bytes_written); - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ } return bytes_written; @@ -252,22 +253,22 @@ static int la8_write(struct la8 *la8, uint8_t *buf, int size) /** * Read a certain amount of bytes from the LA8's FTDI device. * - * @param la8 The LA8 struct containing private per-device-instance data. + * @param ctx The struct containing private per-device-instance data. * @param buf The buffer where the received data will be stored. * @param size The number of bytes to read. * @return The number of bytes read, or a negative value upon errors. */ -static int la8_read(struct la8 *la8, uint8_t *buf, int size) +static int la8_read(struct context *ctx, uint8_t *buf, int size) { int bytes_read; - if (!la8) { - sr_err("la8: %s: la8 was NULL", __func__); + if (!ctx) { + sr_err("la8: %s: ctx was NULL", __func__); return SR_ERR_ARG; } - if (!la8->ftdic) { - sr_err("la8: %s: la8->ftdic was NULL", __func__); + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); return SR_ERR_ARG; } @@ -281,11 +282,11 @@ static int la8_read(struct la8 *la8, uint8_t *buf, int size) return SR_ERR_ARG; } - bytes_read = ftdi_read_data(la8->ftdic, buf, size); + bytes_read = ftdi_read_data(ctx->ftdic, buf, size); if (bytes_read < 0) { sr_err("la8: %s: ftdi_read_data: (%d) %s", __func__, - bytes_read, ftdi_get_error_string(la8->ftdic)); + bytes_read, ftdi_get_error_string(ctx->ftdic)); } else if (bytes_read != size) { // sr_err("la8: %s: bytes to read: %d, bytes read: %d", // __func__, size, bytes_read); @@ -294,23 +295,23 @@ static int la8_read(struct la8 *la8, uint8_t *buf, int size) return bytes_read; } -static int la8_close(struct la8 *la8) +static int la8_close(struct context *ctx) { int ret; - if (!la8) { - sr_err("la8: %s: la8 was NULL", __func__); + if (!ctx) { + sr_err("la8: %s: ctx was NULL", __func__); return SR_ERR_ARG; } - if (!la8->ftdic) { - sr_err("la8: %s: la8->ftdic was NULL", __func__); + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); return SR_ERR_ARG; } - if ((ret = ftdi_usb_close(la8->ftdic)) < 0) { + if ((ret = ftdi_usb_close(ctx->ftdic)) < 0) { sr_err("la8: %s: ftdi_usb_close: (%d) %s", - __func__, ret, ftdi_get_error_string(la8->ftdic)); + __func__, ret, ftdi_get_error_string(ctx->ftdic)); } return ret; @@ -319,48 +320,48 @@ static int la8_close(struct la8 *la8) /** * Close the ChronoVu LA8 USB port and reset the LA8 sequencer logic. * - * @param la8 The LA8 struct containing private per-device-instance data. + * @param ctx The struct containing private per-device-instance data. * @return SR_OK upon success, SR_ERR upon failure. */ -static int la8_close_usb_reset_sequencer(struct la8 *la8) +static int la8_close_usb_reset_sequencer(struct context *ctx) { /* Magic sequence of bytes for resetting the LA8 sequencer logic. */ uint8_t buf[8] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; int ret; - if (!la8) { - sr_err("la8: %s: la8 was NULL", __func__); + if (!ctx) { + sr_err("la8: %s: ctx was NULL", __func__); return SR_ERR_ARG; } - if (!la8->ftdic) { - sr_err("la8: %s: la8->ftdic was NULL", __func__); + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); return SR_ERR_ARG; } - if (la8->ftdic->usb_dev) { + if (ctx->ftdic->usb_dev) { /* Reset the LA8 sequencer logic, then wait 100ms. */ sr_dbg("la8: resetting sequencer logic"); - (void) la8_write(la8, buf, 8); /* Ignore errors. */ + (void) la8_write(ctx, buf, 8); /* Ignore errors. */ g_usleep(100 * 1000); /* Purge FTDI buffers, then reset and close the FTDI device. */ sr_dbg("la8: purging buffers, resetting+closing FTDI device"); /* Log errors, but ignore them (i.e., don't abort). */ - if ((ret = ftdi_usb_purge_buffers(la8->ftdic)) < 0) + if ((ret = ftdi_usb_purge_buffers(ctx->ftdic)) < 0) sr_err("la8: %s: ftdi_usb_purge_buffers: (%d) %s", - __func__, ret, ftdi_get_error_string(la8->ftdic)); - if ((ret = ftdi_usb_reset(la8->ftdic)) < 0) + __func__, ret, ftdi_get_error_string(ctx->ftdic)); + if ((ret = ftdi_usb_reset(ctx->ftdic)) < 0) sr_err("la8: %s: ftdi_usb_reset: (%d) %s", __func__, - ret, ftdi_get_error_string(la8->ftdic)); - if ((ret = ftdi_usb_close(la8->ftdic)) < 0) + ret, ftdi_get_error_string(ctx->ftdic)); + if ((ret = ftdi_usb_close(ctx->ftdic)) < 0) sr_err("la8: %s: ftdi_usb_close: (%d) %s", __func__, - ret, ftdi_get_error_string(la8->ftdic)); + ret, ftdi_get_error_string(ctx->ftdic)); } - ftdi_free(la8->ftdic); /* Returns void. */ - la8->ftdic = NULL; + ftdi_free(ctx->ftdic); /* Returns void. */ + ctx->ftdic = NULL; return SR_OK; } @@ -370,22 +371,22 @@ static int la8_close_usb_reset_sequencer(struct la8 *la8) * * The LA8 must be reset after a failed read/write operation or upon timeouts. * - * @param la8 The LA8 struct containing private per-device-instance data. + * @param ctx The struct containing private per-device-instance data. * @return SR_OK upon success, SR_ERR upon failure. */ -static int la8_reset(struct la8 *la8) +static int la8_reset(struct context *ctx) { uint8_t buf[BS]; time_t done, now; int bytes_read; - if (!la8) { - sr_err("la8: %s: la8 was NULL", __func__); + if (!ctx) { + sr_err("la8: %s: ctx was NULL", __func__); return SR_ERR_ARG; } - if (!la8->ftdic) { - sr_err("la8: %s: la8->ftdic was NULL", __func__); + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); return SR_ERR_ARG; } @@ -398,27 +399,27 @@ static int la8_reset(struct la8 *la8) done = 20 + time(NULL); do { /* TODO: Ignore errors? Check for < 0 at least! */ - bytes_read = la8_read(la8, (uint8_t *)&buf, BS); + bytes_read = la8_read(ctx, (uint8_t *)&buf, BS); now = time(NULL); } while ((done > now) && (bytes_read > 0)); /* Reset the LA8 sequencer logic and close the USB port. */ - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ sr_dbg("la8: device reset finished"); return SR_OK; } -static int configure_probes(struct la8 *la8, GSList *probes) +static int configure_probes(struct context *ctx, GSList *probes) { struct sr_probe *probe; GSList *l; uint8_t probe_bit; char *tc; - la8->trigger_pattern = 0; - la8->trigger_mask = 0; /* Default to "don't care" for all probes. */ + ctx->trigger_pattern = 0; + ctx->trigger_mask = 0; /* Default to "don't care" for all probes. */ for (l = probes; l; l = l->next) { probe = (struct sr_probe *)l->data; @@ -447,7 +448,7 @@ static int configure_probes(struct la8 *la8, GSList *probes) /* Configure the probe's trigger mask and trigger pattern. */ for (tc = probe->trigger; tc && *tc; tc++) { - la8->trigger_mask |= probe_bit; + ctx->trigger_mask |= probe_bit; /* Sanity check, LA8 only supports low/high trigger. */ if (*tc != '0' && *tc != '1') { @@ -457,12 +458,12 @@ static int configure_probes(struct la8 *la8, GSList *probes) } if (*tc == '1') - la8->trigger_pattern |= probe_bit; + ctx->trigger_pattern |= probe_bit; } } sr_dbg("la8: %s: trigger_mask = 0x%x, trigger_pattern = 0x%x", - __func__, la8->trigger_mask, la8->trigger_pattern); + __func__, ctx->trigger_mask, ctx->trigger_pattern); return SR_OK; } @@ -471,49 +472,49 @@ static int hw_init(const char *devinfo) { int ret; struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; /* Avoid compiler errors. */ (void)devinfo; /* Allocate memory for our private driver context. */ - if (!(la8 = g_try_malloc(sizeof(struct la8)))) { - sr_err("la8: %s: struct la8 malloc failed", __func__); + if (!(ctx = g_try_malloc(sizeof(struct context)))) { + sr_err("la8: %s: struct context malloc failed", __func__); goto err_free_nothing; } /* Set some sane defaults. */ - la8->ftdic = NULL; - la8->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */ - la8->limit_msec = 0; - la8->limit_samples = 0; - la8->session_id = NULL; - memset(la8->mangled_buf, 0, BS); - la8->final_buf = NULL; - la8->trigger_pattern = 0x00; /* Value irrelevant, see trigger_mask. */ - la8->trigger_mask = 0x00; /* All probes are "don't care". */ - la8->trigger_timeout = 10; /* Default to 10s trigger timeout. */ - la8->trigger_found = 0; - la8->done = 0; - la8->block_counter = 0; - la8->divcount = 0; /* 10ns sample period == 100MHz samplerate */ + ctx->ftdic = NULL; + ctx->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */ + ctx->limit_msec = 0; + ctx->limit_samples = 0; + ctx->session_id = NULL; + memset(ctx->mangled_buf, 0, BS); + ctx->final_buf = NULL; + ctx->trigger_pattern = 0x00; /* Value irrelevant, see trigger_mask. */ + ctx->trigger_mask = 0x00; /* All probes are "don't care". */ + ctx->trigger_timeout = 10; /* Default to 10s trigger timeout. */ + ctx->trigger_found = 0; + ctx->done = 0; + ctx->block_counter = 0; + ctx->divcount = 0; /* 10ns sample period == 100MHz samplerate */ /* Allocate memory where we'll store the de-mangled data. */ - if (!(la8->final_buf = g_try_malloc(SDRAM_SIZE))) { + if (!(ctx->final_buf = g_try_malloc(SDRAM_SIZE))) { sr_err("la8: %s: final_buf malloc failed", __func__); - goto err_free_la8; + goto err_free_ctx; } /* Allocate memory for the FTDI context (ftdic) and initialize it. */ - if (!(la8->ftdic = ftdi_new())) { + if (!(ctx->ftdic = ftdi_new())) { sr_err("la8: %s: ftdi_new failed", __func__); goto err_free_final_buf; } /* Check for the device and temporarily open it. */ - if ((ret = ftdi_usb_open_desc(la8->ftdic, USB_VENDOR_ID, + if ((ret = ftdi_usb_open_desc(ctx->ftdic, USB_VENDOR_ID, USB_PRODUCT_ID, USB_DESCRIPTION, NULL)) < 0) { - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ goto err_free_ftdic; } sr_dbg("la8: found device"); @@ -526,25 +527,25 @@ static int hw_init(const char *devinfo) goto err_close_ftdic; } - sdi->priv = la8; + sdi->priv = ctx; dev_insts = g_slist_append(dev_insts, sdi); sr_spew("la8: %s finished successfully", __func__); /* Close device. We'll reopen it again when we need it. */ - (void) la8_close(la8); /* Log, but ignore errors. */ + (void) la8_close(ctx); /* Log, but ignore errors. */ return 1; err_close_ftdic: - (void) la8_close(la8); /* Log, but ignore errors. */ + (void) la8_close(ctx); /* Log, but ignore errors. */ err_free_ftdic: - free(la8->ftdic); /* NOT g_free()! */ + free(ctx->ftdic); /* NOT g_free()! */ err_free_final_buf: - g_free(la8->final_buf); -err_free_la8: - g_free(la8); + g_free(ctx->final_buf); +err_free_ctx: + g_free(ctx); err_free_nothing: return 0; @@ -554,14 +555,14 @@ static int hw_dev_open(int dev_index) { int ret; struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } @@ -569,29 +570,29 @@ static int hw_dev_open(int dev_index) sr_dbg("la8: opening device"); /* Open the device. */ - if ((ret = ftdi_usb_open_desc(la8->ftdic, USB_VENDOR_ID, + if ((ret = ftdi_usb_open_desc(ctx->ftdic, USB_VENDOR_ID, USB_PRODUCT_ID, USB_DESCRIPTION, NULL)) < 0) { sr_err("la8: %s: ftdi_usb_open_desc: (%d) %s", - __func__, ret, ftdi_get_error_string(la8->ftdic)); - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + __func__, ret, ftdi_get_error_string(ctx->ftdic)); + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ return SR_ERR; } sr_dbg("la8: device opened successfully"); /* Purge RX/TX buffers in the FTDI chip. */ - if ((ret = ftdi_usb_purge_buffers(la8->ftdic)) < 0) { + if ((ret = ftdi_usb_purge_buffers(ctx->ftdic)) < 0) { sr_err("la8: %s: ftdi_usb_purge_buffers: (%d) %s", - __func__, ret, ftdi_get_error_string(la8->ftdic)); - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + __func__, ret, ftdi_get_error_string(ctx->ftdic)); + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ goto err_dev_open_close_ftdic; } sr_dbg("la8: FTDI buffers purged successfully"); /* Enable flow control in the FTDI chip. */ - if ((ret = ftdi_setflowctrl(la8->ftdic, SIO_RTS_CTS_HS)) < 0) { + if ((ret = ftdi_setflowctrl(ctx->ftdic, SIO_RTS_CTS_HS)) < 0) { sr_err("la8: %s: ftdi_setflowcontrol: (%d) %s", - __func__, ret, ftdi_get_error_string(la8->ftdic)); - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + __func__, ret, ftdi_get_error_string(ctx->ftdic)); + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ goto err_dev_open_close_ftdic; } sr_dbg("la8: FTDI flow control enabled successfully"); @@ -604,20 +605,20 @@ static int hw_dev_open(int dev_index) return SR_OK; err_dev_open_close_ftdic: - (void) la8_close(la8); /* Log, but ignore errors. */ + (void) la8_close(ctx); /* Log, but ignore errors. */ return SR_ERR; } static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { - struct la8 *la8; + struct context *ctx; if (!sdi) { sr_err("la8: %s: sdi was NULL", __func__); return SR_ERR_ARG; } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; } @@ -631,9 +632,9 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) return SR_ERR; /* Set the new samplerate. */ - la8->cur_samplerate = samplerate; + ctx->cur_samplerate = samplerate; - sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate); + sr_dbg("la8: samplerate set to %" PRIu64 "Hz", ctx->cur_samplerate); return SR_OK; } @@ -641,14 +642,14 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) static int hw_dev_close(int dev_index) { struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } @@ -658,7 +659,7 @@ static int hw_dev_close(int dev_index) if (sdi->status == SR_ST_ACTIVE) { sr_dbg("la8: %s: status ACTIVE, closing device", __func__); /* TODO: Really ignore errors here, or return SR_ERR? */ - (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ + (void) la8_close_usb_reset_sequencer(ctx); /* Ignore errors. */ } else { sr_spew("la8: %s: status not ACTIVE, nothing to do", __func__); } @@ -666,7 +667,7 @@ static int hw_dev_close(int dev_index) sdi->status = SR_ST_INACTIVE; sr_dbg("la8: %s: freeing sample buffers", __func__); - g_free(la8->final_buf); + g_free(ctx->final_buf); return SR_OK; } @@ -696,7 +697,7 @@ static int hw_cleanup(void) static void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; void *info; sr_spew("la8: entering %s", __func__); @@ -706,7 +707,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) return NULL; } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return NULL; } @@ -729,7 +730,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = (char *)TRIGGER_TYPES; break; case SR_DI_CUR_SAMPLERATE: - info = &la8->cur_samplerate; + info = &ctx->cur_samplerate; break; default: /* Unknown device info ID, return NULL. */ @@ -765,7 +766,7 @@ static int *hw_hwcap_get_all(void) static int hw_dev_config_set(int dev_index, int hwcap, void *value) { struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; sr_spew("la8: entering %s", __func__); @@ -774,7 +775,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) return SR_ERR; /* TODO: SR_ERR_ARG? */ } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } @@ -783,10 +784,10 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) case SR_HWCAP_SAMPLERATE: if (set_samplerate(sdi, *(uint64_t *)value) == SR_ERR) return SR_ERR; - sr_dbg("la8: SAMPLERATE = %" PRIu64, la8->cur_samplerate); + sr_dbg("la8: SAMPLERATE = %" PRIu64, ctx->cur_samplerate); break; case SR_HWCAP_PROBECONFIG: - if (configure_probes(la8, (GSList *)value) != SR_OK) { + if (configure_probes(ctx, (GSList *)value) != SR_OK) { sr_err("la8: %s: probe config failed", __func__); return SR_ERR; } @@ -796,16 +797,16 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) sr_err("la8: %s: LIMIT_MSEC can't be 0", __func__); return SR_ERR; } - la8->limit_msec = *(uint64_t *)value; - sr_dbg("la8: LIMIT_MSEC = %" PRIu64, la8->limit_msec); + ctx->limit_msec = *(uint64_t *)value; + sr_dbg("la8: LIMIT_MSEC = %" PRIu64, ctx->limit_msec); break; case SR_HWCAP_LIMIT_SAMPLES: if (*(uint64_t *)value < MIN_NUM_SAMPLES) { sr_err("la8: %s: LIMIT_SAMPLES too small", __func__); return SR_ERR; } - la8->limit_samples = *(uint64_t *)value; - sr_dbg("la8: LIMIT_SAMPLES = %" PRIu64, la8->limit_samples); + ctx->limit_samples = *(uint64_t *)value; + sr_dbg("la8: LIMIT_SAMPLES = %" PRIu64, ctx->limit_samples); break; default: /* Unknown capability, return SR_ERR. */ @@ -820,61 +821,61 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) /** * Get a block of data from the LA8. * - * @param la8 The LA8 struct containing private per-device-instance data. + * @param ctx The struct containing private per-device-instance data. * @return SR_OK upon success, or SR_ERR upon errors. */ -static int la8_read_block(struct la8 *la8) +static int la8_read_block(struct context *ctx) { int i, byte_offset, m, mi, p, index, bytes_read; time_t now; - if (!la8) { - sr_err("la8: %s: la8 was NULL", __func__); + if (!ctx) { + sr_err("la8: %s: ctx was NULL", __func__); return SR_ERR_ARG; } - if (!la8->ftdic) { - sr_err("la8: %s: la8->ftdic was NULL", __func__); + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); return SR_ERR_ARG; } - sr_spew("la8: %s: reading block %d", __func__, la8->block_counter); + sr_spew("la8: %s: reading block %d", __func__, ctx->block_counter); - bytes_read = la8_read(la8, la8->mangled_buf, BS); + bytes_read = la8_read(ctx, ctx->mangled_buf, BS); /* If first block read got 0 bytes, retry until success or timeout. */ - if ((bytes_read == 0) && (la8->block_counter == 0)) { + if ((bytes_read == 0) && (ctx->block_counter == 0)) { do { sr_spew("la8: %s: reading block 0 again", __func__); - bytes_read = la8_read(la8, la8->mangled_buf, BS); + bytes_read = la8_read(ctx, ctx->mangled_buf, BS); /* TODO: How to handle read errors here? */ now = time(NULL); - } while ((la8->done > now) && (bytes_read == 0)); + } while ((ctx->done > now) && (bytes_read == 0)); } /* Check if block read was successful or a timeout occured. */ if (bytes_read != BS) { sr_err("la8: %s: trigger timed out", __func__); - (void) la8_reset(la8); /* Ignore errors. */ + (void) la8_reset(ctx); /* Ignore errors. */ return SR_ERR; } /* De-mangle the data. */ - sr_spew("la8: de-mangling samples of block %d", la8->block_counter); - byte_offset = la8->block_counter * BS; + sr_spew("la8: de-mangling samples of block %d", ctx->block_counter); + byte_offset = ctx->block_counter * BS; m = byte_offset / (1024 * 1024); mi = m * (1024 * 1024); for (i = 0; i < BS; i++) { p = i & (1 << 0); index = m * 2 + (((byte_offset + i) - mi) / 2) * 16; - index += (la8->divcount == 0) ? p : (1 - p); - la8->final_buf[index] = la8->mangled_buf[i]; + index += (ctx->divcount == 0) ? p : (1 - p); + ctx->final_buf[index] = ctx->mangled_buf[i]; } return SR_OK; } -static void send_block_to_session_bus(struct la8 *la8, int block) +static void send_block_to_session_bus(struct context *ctx, int block) { int i; uint8_t sample, expected_sample; @@ -882,14 +883,14 @@ static void send_block_to_session_bus(struct la8 *la8, int block) struct sr_datafeed_logic logic; int trigger_point; /* Relative trigger point (in this block). */ - /* Note: No sanity checks on la8/block, caller is responsible. */ + /* Note: No sanity checks on ctx/block, caller is responsible. */ /* Check if we can find the trigger condition in this block. */ trigger_point = -1; - expected_sample = la8->trigger_pattern & la8->trigger_mask; + expected_sample = ctx->trigger_pattern & ctx->trigger_mask; for (i = 0; i < BS; i++) { /* Don't continue if the trigger was found previously. */ - if (la8->trigger_found) + if (ctx->trigger_found) break; /* @@ -897,14 +898,14 @@ static void send_block_to_session_bus(struct la8 *la8, int block) * no trigger conditions were specified by the user. In that * case we don't want to send an SR_DF_TRIGGER packet at all. */ - if (la8->trigger_mask == 0x00) + if (ctx->trigger_mask == 0x00) break; - sample = *(la8->final_buf + (block * BS) + i); + sample = *(ctx->final_buf + (block * BS) + i); - if ((sample & la8->trigger_mask) == expected_sample) { + if ((sample & ctx->trigger_mask) == expected_sample) { trigger_point = i; - la8->trigger_found = 1; + ctx->trigger_found = 1; break; } } @@ -918,8 +919,8 @@ static void send_block_to_session_bus(struct la8 *la8, int block) packet.payload = &logic; logic.length = BS; logic.unitsize = 1; - logic.data = la8->final_buf + (block * BS); - sr_session_bus(la8->session_id, &packet); + logic.data = ctx->final_buf + (block * BS); + sr_session_bus(ctx->session_id, &packet); return; } @@ -941,8 +942,8 @@ static void send_block_to_session_bus(struct la8 *la8, int block) packet.payload = &logic; logic.length = trigger_point; logic.unitsize = 1; - logic.data = la8->final_buf + (block * BS); - sr_session_bus(la8->session_id, &packet); + logic.data = ctx->final_buf + (block * BS); + sr_session_bus(ctx->session_id, &packet); } /* Send the SR_DF_TRIGGER packet to the session bus. */ @@ -950,7 +951,7 @@ static void send_block_to_session_bus(struct la8 *la8, int block) (block * BS) + trigger_point); packet.type = SR_DF_TRIGGER; packet.payload = NULL; - sr_session_bus(la8->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); /* If at least one sample is located after the trigger... */ if (trigger_point < (BS - 1)) { @@ -962,8 +963,8 @@ static void send_block_to_session_bus(struct la8 *la8, int block) packet.payload = &logic; logic.length = BS - trigger_point; logic.unitsize = 1; - logic.data = la8->final_buf + (block * BS) + trigger_point; - sr_session_bus(la8->session_id, &packet); + logic.data = ctx->final_buf + (block * BS) + trigger_point; + sr_session_bus(ctx->session_id, &packet); } } @@ -971,7 +972,7 @@ static int receive_data(int fd, int revents, void *session_data) { int i, ret; struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; /* Avoid compiler errors. */ (void)fd; @@ -982,21 +983,21 @@ static int receive_data(int fd, int revents, void *session_data) return FALSE; } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return FALSE; } /* Get one block of data. */ - if ((ret = la8_read_block(la8)) < 0) { + if ((ret = la8_read_block(ctx)) < 0) { sr_err("la8: %s: la8_read_block error: %d", __func__, ret); hw_dev_acquisition_stop(sdi->index, session_data); return FALSE; } /* We need to get exactly NUM_BLOCKS blocks (i.e. 8MB) of data. */ - if (la8->block_counter != (NUM_BLOCKS - 1)) { - la8->block_counter++; + if (ctx->block_counter != (NUM_BLOCKS - 1)) { + ctx->block_counter++; return TRUE; } @@ -1004,7 +1005,7 @@ static int receive_data(int fd, int revents, void *session_data) /* All data was received and demangled, send it to the session bus. */ for (i = 0; i < NUM_BLOCKS; i++) - send_block_to_session_bus(la8, i); + send_block_to_session_bus(ctx, i); hw_dev_acquisition_stop(sdi->index, session_data); @@ -1015,7 +1016,7 @@ static int receive_data(int fd, int revents, void *session_data) static int hw_dev_acquisition_start(int dev_index, gpointer session_data) { struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; struct sr_datafeed_packet packet; struct sr_datafeed_header header; uint8_t buf[4]; @@ -1028,30 +1029,30 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) return SR_ERR; /* TODO: SR_ERR_ARG? */ } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } - if (!la8->ftdic) { - sr_err("la8: %s: la8->ftdic was NULL", __func__); + if (!ctx->ftdic) { + sr_err("la8: %s: ctx->ftdic was NULL", __func__); return SR_ERR_ARG; } - la8->divcount = samplerate_to_divcount(la8->cur_samplerate); - if (la8->divcount == 0xff) { + ctx->divcount = samplerate_to_divcount(ctx->cur_samplerate); + if (ctx->divcount == 0xff) { sr_err("la8: %s: invalid divcount/samplerate", __func__); return SR_ERR; } /* Fill acquisition parameters into buf[]. */ - buf[0] = la8->divcount; + buf[0] = ctx->divcount; buf[1] = 0xff; /* This byte must always be 0xff. */ - buf[2] = la8->trigger_pattern; - buf[3] = la8->trigger_mask; + buf[2] = ctx->trigger_pattern; + buf[3] = ctx->trigger_mask; /* Start acquisition. */ - bytes_written = la8_write(la8, buf, 4); + bytes_written = la8_write(ctx, buf, 4); if (bytes_written < 0) { sr_err("la8: acquisition failed to start"); @@ -1063,7 +1064,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) sr_dbg("la8: acquisition started successfully"); - la8->session_id = session_data; + ctx->session_id = session_data; /* Send header packet to the session bus. */ sr_dbg("la8: %s: sending SR_DF_HEADER", __func__); @@ -1071,15 +1072,15 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); - header.samplerate = la8->cur_samplerate; + header.samplerate = ctx->cur_samplerate; header.num_logic_probes = NUM_PROBES; sr_session_bus(session_data, &packet); /* Time when we should be done (for detecting trigger timeouts). */ - la8->done = (la8->divcount + 1) * 0.08388608 + time(NULL) - + la8->trigger_timeout; - la8->block_counter = 0; - la8->trigger_found = 0; + ctx->done = (ctx->divcount + 1) * 0.08388608 + time(NULL) + + ctx->trigger_timeout; + ctx->block_counter = 0; + ctx->trigger_found = 0; /* Hook up a dummy handler to receive data from the LA8. */ sr_source_add(-1, G_IO_IN, 0, receive_data, sdi); @@ -1090,7 +1091,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) static int hw_dev_acquisition_stop(int dev_index, gpointer session_data) { struct sr_dev_inst *sdi; - struct la8 *la8; + struct context *ctx; struct sr_datafeed_packet packet; sr_dbg("la8: stopping acquisition"); @@ -1100,7 +1101,7 @@ static int hw_dev_acquisition_stop(int dev_index, gpointer session_data) return SR_ERR_BUG; } - if (!(la8 = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); return SR_ERR_BUG; } diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index 6ae0d80d..aa3f57d4 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -125,6 +125,9 @@ static uint8_t pattern_sigrok[] = { 0xbe, 0xbe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; +/* Private, per-device-instance driver context. */ +/* TODO: struct context as with the other drivers. */ + /* List of struct sr_dev_inst, maintained by dev_open()/dev_close(). */ static GSList *dev_insts = NULL; static uint64_t cur_samplerate = SR_KHZ(200); diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 37f0a96b..c3dc19bd 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -139,12 +139,12 @@ ret: static int mso_reset_adc(struct sr_dev_inst *sdi) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; uint16_t ops[2]; - ops[0] = mso_trans(REG_CTL1, (mso->ctlbase1 | BIT_CTL1_RESETADC)); - ops[1] = mso_trans(REG_CTL1, mso->ctlbase1); - mso->ctlbase1 |= BIT_CTL1_ADC_UNKNOWN4; + ops[0] = mso_trans(REG_CTL1, (ctx->ctlbase1 | BIT_CTL1_RESETADC)); + ops[1] = mso_trans(REG_CTL1, ctx->ctlbase1); + ctx->ctlbase1 |= BIT_CTL1_ADC_UNKNOWN4; sr_dbg("mso19: Requesting ADC reset"); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); @@ -152,11 +152,11 @@ static int mso_reset_adc(struct sr_dev_inst *sdi) static int mso_reset_fsm(struct sr_dev_inst *sdi) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; uint16_t ops[1]; - mso->ctlbase1 |= BIT_CTL1_RESETFSM; - ops[0] = mso_trans(REG_CTL1, mso->ctlbase1); + ctx->ctlbase1 |= BIT_CTL1_RESETFSM; + ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1); sr_dbg("mso19: Requesting ADC reset"); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); @@ -164,13 +164,13 @@ static int mso_reset_fsm(struct sr_dev_inst *sdi) static int mso_toggle_led(struct sr_dev_inst *sdi, int state) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; uint16_t ops[1]; - mso->ctlbase1 &= ~BIT_CTL1_LED; + ctx->ctlbase1 &= ~BIT_CTL1_LED; if (state) - mso->ctlbase1 |= BIT_CTL1_LED; - ops[0] = mso_trans(REG_CTL1, mso->ctlbase1); + ctx->ctlbase1 |= BIT_CTL1_LED; + ops[0] = mso_trans(REG_CTL1, ctx->ctlbase1); sr_dbg("mso19: Requesting LED toggle"); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); @@ -206,11 +206,11 @@ static int mso_read_buffer(struct sr_dev_inst *sdi) static int mso_arm(struct sr_dev_inst *sdi) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; uint16_t ops[] = { - mso_trans(REG_CTL1, mso->ctlbase1 | BIT_CTL1_RESETFSM), - mso_trans(REG_CTL1, mso->ctlbase1 | BIT_CTL1_ARM), - mso_trans(REG_CTL1, mso->ctlbase1), + mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_RESETFSM), + mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_ARM), + mso_trans(REG_CTL1, ctx->ctlbase1), }; sr_dbg("mso19: Requesting trigger arm"); @@ -219,10 +219,10 @@ static int mso_arm(struct sr_dev_inst *sdi) static int mso_force_capture(struct sr_dev_inst *sdi) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; uint16_t ops[] = { - mso_trans(REG_CTL1, mso->ctlbase1 | 8), - mso_trans(REG_CTL1, mso->ctlbase1), + mso_trans(REG_CTL1, ctx->ctlbase1 | 8), + mso_trans(REG_CTL1, ctx->ctlbase1), }; sr_dbg("mso19: Requesting forced capture"); @@ -231,11 +231,11 @@ static int mso_force_capture(struct sr_dev_inst *sdi) static int mso_dac_out(struct sr_dev_inst *sdi, uint16_t val) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; uint16_t ops[] = { mso_trans(REG_DAC1, (val >> 8) & 0xff), mso_trans(REG_DAC2, val & 0xff), - mso_trans(REG_CTL1, mso->ctlbase1 | BIT_CTL1_RESETADC), + mso_trans(REG_CTL1, ctx->ctlbase1 | BIT_CTL1_RESETADC), }; sr_dbg("mso19: Setting dac word to 0x%x", val); @@ -255,44 +255,44 @@ static int mso_clkrate_out(struct sr_dev_inst *sdi, uint16_t val) static int mso_configure_rate(struct sr_dev_inst *sdi, uint32_t rate) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; unsigned int i; int ret = SR_ERR; for (i = 0; i < ARRAY_SIZE(rate_map); i++) { if (rate_map[i].rate == rate) { - mso->ctlbase2 = rate_map[i].slowmode; + ctx->ctlbase2 = rate_map[i].slowmode; ret = mso_clkrate_out(sdi, rate_map[i].val); if (ret == SR_OK) - mso->cur_rate = rate; + ctx->cur_rate = rate; return ret; } } return ret; } -static inline uint16_t mso_calc_raw_from_mv(struct mso *mso) +static inline uint16_t mso_calc_raw_from_mv(struct context *ctx) { return (uint16_t) (0x200 - - ((mso->dso_trigger_voltage / mso->dso_probe_attn) / - mso->vbit)); + ((ctx->dso_trigger_voltage / ctx->dso_probe_attn) / + ctx->vbit)); } static int mso_configure_trigger(struct sr_dev_inst *sdi) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; uint16_t ops[16]; - uint16_t dso_trigger = mso_calc_raw_from_mv(mso); + uint16_t dso_trigger = mso_calc_raw_from_mv(ctx); dso_trigger &= 0x3ff; - if ((!mso->trigger_slope && mso->trigger_chan == 1) || - (mso->trigger_slope && - (mso->trigger_chan == 0 || - mso->trigger_chan == 2 || - mso->trigger_chan == 3))) + if ((!ctx->trigger_slope && ctx->trigger_chan == 1) || + (ctx->trigger_slope && + (ctx->trigger_chan == 0 || + ctx->trigger_chan == 2 || + ctx->trigger_chan == 3))) dso_trigger |= 0x400; - switch (mso->trigger_chan) { + switch (ctx->trigger_chan) { case 1: dso_trigger |= 0xe000; case 2: @@ -312,7 +312,7 @@ static int mso_configure_trigger(struct sr_dev_inst *sdi) break; } - switch (mso->trigger_outsrc) { + switch (ctx->trigger_outsrc) { case 1: dso_trigger |= 0x800; break; @@ -325,40 +325,40 @@ static int mso_configure_trigger(struct sr_dev_inst *sdi) } - ops[0] = mso_trans(5, mso->la_trigger); - ops[1] = mso_trans(6, mso->la_trigger_mask); + ops[0] = mso_trans(5, ctx->la_trigger); + ops[1] = mso_trans(6, ctx->la_trigger_mask); ops[2] = mso_trans(3, dso_trigger & 0xff); ops[3] = mso_trans(4, (dso_trigger >> 8) & 0xff); ops[4] = mso_trans(11, - mso->dso_trigger_width / SR_HZ_TO_NS(mso->cur_rate)); + ctx->dso_trigger_width / SR_HZ_TO_NS(ctx->cur_rate)); /* Select the SPI/I2C trigger config bank */ - ops[5] = mso_trans(REG_CTL2, (mso->ctlbase2 | BITS_CTL2_BANK(2))); + ops[5] = mso_trans(REG_CTL2, (ctx->ctlbase2 | BITS_CTL2_BANK(2))); /* Configure the SPI/I2C protocol trigger */ - ops[6] = mso_trans(REG_PT_WORD(0), mso->protocol_trigger.word[0]); - ops[7] = mso_trans(REG_PT_WORD(1), mso->protocol_trigger.word[1]); - ops[8] = mso_trans(REG_PT_WORD(2), mso->protocol_trigger.word[2]); - ops[9] = mso_trans(REG_PT_WORD(3), mso->protocol_trigger.word[3]); - ops[10] = mso_trans(REG_PT_MASK(0), mso->protocol_trigger.mask[0]); - ops[11] = mso_trans(REG_PT_MASK(1), mso->protocol_trigger.mask[1]); - ops[12] = mso_trans(REG_PT_MASK(2), mso->protocol_trigger.mask[2]); - ops[13] = mso_trans(REG_PT_MASK(3), mso->protocol_trigger.mask[3]); - ops[14] = mso_trans(REG_PT_SPIMODE, mso->protocol_trigger.spimode); + ops[6] = mso_trans(REG_PT_WORD(0), ctx->protocol_trigger.word[0]); + ops[7] = mso_trans(REG_PT_WORD(1), ctx->protocol_trigger.word[1]); + ops[8] = mso_trans(REG_PT_WORD(2), ctx->protocol_trigger.word[2]); + ops[9] = mso_trans(REG_PT_WORD(3), ctx->protocol_trigger.word[3]); + ops[10] = mso_trans(REG_PT_MASK(0), ctx->protocol_trigger.mask[0]); + ops[11] = mso_trans(REG_PT_MASK(1), ctx->protocol_trigger.mask[1]); + ops[12] = mso_trans(REG_PT_MASK(2), ctx->protocol_trigger.mask[2]); + ops[13] = mso_trans(REG_PT_MASK(3), ctx->protocol_trigger.mask[3]); + ops[14] = mso_trans(REG_PT_SPIMODE, ctx->protocol_trigger.spimode); /* Select the default config bank */ - ops[15] = mso_trans(REG_CTL2, mso->ctlbase2); + ops[15] = mso_trans(REG_CTL2, ctx->ctlbase2); return mso_send_control_message(sdi, ARRAY_AND_SIZE(ops)); } static int mso_configure_threshold_level(struct sr_dev_inst *sdi) { - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; - return mso_dac_out(sdi, la_threshold_map[mso->la_threshold]); + return mso_dac_out(sdi, la_threshold_map[ctx->la_threshold]); } static int mso_parse_serial(const char *iSerial, const char *iProduct, - struct mso *mso) + struct context *ctx) { unsigned int u1, u2, u3, u4, u5, u6; @@ -366,26 +366,26 @@ static int mso_parse_serial(const char *iSerial, const char *iProduct, /* FIXME: This code is in the original app, but I think its * used only for the GUI */ /* if (strstr(iProduct, "REV_02") || strstr(iProduct, "REV_03")) - mso->num_sample_rates = 0x16; + ctx->num_sample_rates = 0x16; else - mso->num_sample_rates = 0x10; */ + ctx->num_sample_rates = 0x10; */ /* parse iSerial */ if (iSerial[0] != '4' || sscanf(iSerial, "%5u%3u%3u%1u%1u%6u", &u1, &u2, &u3, &u4, &u5, &u6) != 6) return SR_ERR; - mso->hwmodel = u4; - mso->hwrev = u5; - mso->serial = u6; - mso->vbit = u1 / 10000; - if (mso->vbit == 0) - mso->vbit = 4.19195; - mso->dac_offset = u2; - if (mso->dac_offset == 0) - mso->dac_offset = 0x1ff; - mso->offset_range = u3; - if (mso->offset_range == 0) - mso->offset_range = 0x17d; + ctx->hwmodel = u4; + ctx->hwrev = u5; + ctx->serial = u6; + ctx->vbit = u1 / 10000; + if (ctx->vbit == 0) + ctx->vbit = 4.19195; + ctx->dac_offset = u2; + if (ctx->dac_offset == 0) + ctx->dac_offset = 0x1ff; + ctx->offset_range = u3; + if (ctx->offset_range == 0) + ctx->offset_range = 0x17d; /* * FIXME: There is more code on the original software to handle @@ -403,7 +403,7 @@ static int hw_init(const char *devinfo) struct udev *udev; struct udev_enumerate *enumerate; struct udev_list_entry *devs, *dev_list_entry; - struct mso *mso; + struct context *ctx; devinfo = devinfo; @@ -460,27 +460,27 @@ static int hw_init(const char *devinfo) product[s] = 0; strcpy(manufacturer, iProduct + s); - if (!(mso = g_try_malloc0(sizeof(struct mso)))) { - sr_err("mso19: %s: mso malloc failed", __func__); + if (!(ctx = g_try_malloc0(sizeof(struct context)))) { + sr_err("mso19: %s: ctx malloc failed", __func__); continue; /* TODO: Errors handled correctly? */ } - if (mso_parse_serial(iSerial, iProduct, mso) != SR_OK) { + if (mso_parse_serial(iSerial, iProduct, ctx) != SR_OK) { sr_err("mso19: Invalid iSerial: %s", iSerial); - goto err_free_mso; + goto err_free_ctx; } - sprintf(hwrev, "r%d", mso->hwrev); + sprintf(hwrev, "r%d", ctx->hwrev); /* hardware initial state */ - mso->ctlbase1 = 0; + ctx->ctlbase1 = 0; { /* Initialize the protocol trigger configuration */ int i; for (i = 0; i < 4; i++) { - mso->protocol_trigger.word[i] = 0; - mso->protocol_trigger.mask[i] = 0xff; + ctx->protocol_trigger.word[i] = 0; + ctx->protocol_trigger.mask[i] = 0xff; } - mso->protocol_trigger.spimode = 0; + ctx->protocol_trigger.spimode = 0; } sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING, @@ -488,11 +488,11 @@ static int hw_init(const char *devinfo) if (!sdi) { sr_err("mso19: Unable to create device instance for %s", sysname); - goto err_free_mso; + goto err_free_ctx; } /* save a pointer to our private instance data */ - sdi->priv = mso; + sdi->priv = ctx; sdi->serial = sr_serial_dev_inst_new(path, -1); if (!sdi->serial) @@ -504,8 +504,8 @@ static int hw_init(const char *devinfo) err_dev_inst_free: sr_dev_inst_free(sdi); -err_free_mso: - g_free(mso); +err_free_ctx: + g_free(ctx); } udev_enumerate_unref(enumerate); @@ -543,13 +543,13 @@ static int hw_cleanup(void) static int hw_dev_open(int dev_index) { struct sr_dev_inst *sdi; - struct mso *mso; + struct context *ctx; int ret = SR_ERR; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return ret; - mso = sdi->priv; + ctx = sdi->priv; sdi->serial->fd = serial_open(sdi->serial->port, O_RDWR); if (sdi->serial->fd == -1) return ret; @@ -562,15 +562,15 @@ static int hw_dev_open(int dev_index) /* FIXME: discard serial buffer */ - mso_check_trigger(sdi, &mso->trigger_state); - sr_dbg("mso19: trigger state: 0x%x", mso->trigger_state); + mso_check_trigger(sdi, &ctx->trigger_state); + sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state); ret = mso_reset_adc(sdi); if (ret != SR_OK) return ret; - mso_check_trigger(sdi, &mso->trigger_state); - sr_dbg("mso19: trigger state: 0x%x", mso->trigger_state); + mso_check_trigger(sdi, &ctx->trigger_state); + sr_dbg("mso19: trigger state: 0x%x", ctx->trigger_state); // ret = mso_reset_fsm(sdi); // if (ret != SR_OK) @@ -605,12 +605,12 @@ static int hw_dev_close(int dev_index) static void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; - struct mso *mso; + struct context *ctx; void *info = NULL; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return NULL; - mso = sdi->priv; + ctx = sdi->priv; switch (dev_info_id) { case SR_DI_INST: @@ -629,7 +629,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = "01"; /* FIXME */ break; case SR_DI_CUR_SAMPLERATE: - info = &mso->cur_rate; + info = &ctx->cur_rate; break; } return info; @@ -679,7 +679,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) static int receive_data(int fd, int revents, void *user_data) { struct sr_dev_inst *sdi = user_data; - struct mso *mso = sdi->priv; + struct context *ctx = sdi->priv; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; uint8_t in[1024], logic_out[1024]; @@ -693,11 +693,11 @@ static int receive_data(int fd, int revents, void *user_data) return FALSE; /* No samples */ - if (mso->trigger_state != MSO_TRIGGER_DATAREADY) { - mso->trigger_state = in[0]; - if (mso->trigger_state == MSO_TRIGGER_DATAREADY) { + if (ctx->trigger_state != MSO_TRIGGER_DATAREADY) { + ctx->trigger_state = in[0]; + if (ctx->trigger_state == MSO_TRIGGER_DATAREADY) { mso_read_buffer(sdi); - mso->buffer_n = 0; + ctx->buffer_n = 0; } else { mso_check_trigger(sdi, NULL); } @@ -705,20 +705,20 @@ static int receive_data(int fd, int revents, void *user_data) } /* the hardware always dumps 1024 samples, 24bits each */ - if (mso->buffer_n < 3072) { - memcpy(mso->buffer + mso->buffer_n, in, s); - mso->buffer_n += s; + if (ctx->buffer_n < 3072) { + memcpy(ctx->buffer + ctx->buffer_n, in, s); + ctx->buffer_n += s; } - if (mso->buffer_n < 3072) + if (ctx->buffer_n < 3072) return FALSE; /* do the conversion */ for (i = 0; i < 1024; i++) { /* FIXME: Need to do conversion to mV */ - analog_out[i] = (mso->buffer[i * 3] & 0x3f) | - ((mso->buffer[i * 3 + 1] & 0xf) << 6); - logic_out[i] = ((mso->buffer[i * 3 + 1] & 0x30) >> 4) | - ((mso->buffer[i * 3 + 2] & 0x3f) << 2); + analog_out[i] = (ctx->buffer[i * 3] & 0x3f) | + ((ctx->buffer[i * 3 + 1] & 0xf) << 6); + logic_out[i] = ((ctx->buffer[i * 3 + 1] & 0x30) >> 4) | + ((ctx->buffer[i * 3 + 2] & 0x3f) << 2); } packet.type = SR_DF_LOGIC; @@ -726,7 +726,7 @@ static int receive_data(int fd, int revents, void *user_data) logic.length = 1024; logic.unitsize = 1; logic.data = logic_out; - sr_session_bus(mso->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); // Dont bother fixing this yet, keep it "old style" /* @@ -734,11 +734,11 @@ static int receive_data(int fd, int revents, void *user_data) packet.length = 1024; packet.unitsize = sizeof(double); packet.payload = analog_out; - sr_session_bus(mso->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); */ packet.type = SR_DF_END; - sr_session_bus(mso->session_id, &packet); + sr_session_bus(ctx->session_id, &packet); return TRUE; } @@ -746,14 +746,14 @@ static int receive_data(int fd, int revents, void *user_data) static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id) { struct sr_dev_inst *sdi; - struct mso *mso; + struct context *ctx; struct sr_datafeed_packet packet; struct sr_datafeed_header header; int ret = SR_ERR; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return ret; - mso = sdi->priv; + ctx = sdi->priv; /* FIXME: No need to do full reconfigure every time */ // ret = mso_reset_fsm(sdi); @@ -761,15 +761,15 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id) // return ret; /* FIXME: ACDC Mode */ - mso->ctlbase1 &= 0x7f; -// mso->ctlbase1 |= mso->acdcmode; + ctx->ctlbase1 &= 0x7f; +// ctx->ctlbase1 |= ctx->acdcmode; - ret = mso_configure_rate(sdi, mso->cur_rate); + ret = mso_configure_rate(sdi, ctx->cur_rate); if (ret != SR_OK) return ret; /* set dac offset */ - ret = mso_dac_out(sdi, mso->dac_offset); + ret = mso_dac_out(sdi, ctx->dac_offset); if (ret != SR_OK) return ret; @@ -796,19 +796,19 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_dev_id) // if (ret != SR_OK) // return ret; - mso_check_trigger(sdi, &mso->trigger_state); + mso_check_trigger(sdi, &ctx->trigger_state); ret = mso_check_trigger(sdi, NULL); if (ret != SR_OK) return ret; - mso->session_id = session_dev_id; + ctx->session_id = session_dev_id; sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data, sdi); packet.type = SR_DF_HEADER; packet.payload = (unsigned char *) &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); - header.samplerate = mso->cur_rate; + header.samplerate = ctx->cur_rate; // header.num_analog_probes = 1; header.num_logic_probes = 8; sr_session_bus(session_dev_id, &packet); diff --git a/hardware/link-mso19/link-mso19.h b/hardware/link-mso19/link-mso19.h index 02a42e52..13215f66 100644 --- a/hardware/link-mso19/link-mso19.h +++ b/hardware/link-mso19/link-mso19.h @@ -51,7 +51,7 @@ struct mso_prototrig { uint8_t spimode; }; -/* our private per-instance data */ +/* Private, per-device-instance driver context. */ struct mso { /* info */ uint8_t hwmodel; diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index a4013826..4e38f56b 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -130,20 +130,20 @@ static int send_longcommand(int fd, uint8_t command, uint32_t data) return SR_OK; } -static int configure_probes(struct ols_dev *ols, GSList *probes) +static int configure_probes(struct context *ctx, GSList *probes) { struct sr_probe *probe; GSList *l; int probe_bit, stage, i; char *tc; - ols->probe_mask = 0; + ctx->probe_mask = 0; for (i = 0; i < NUM_TRIGGER_STAGES; i++) { - ols->trigger_mask[i] = 0; - ols->trigger_value[i] = 0; + ctx->trigger_mask[i] = 0; + ctx->trigger_value[i] = 0; } - ols->num_stages = 0; + ctx->num_stages = 0; for (l = probes; l; l = l->next) { probe = (struct sr_probe *)l->data; if (!probe->enabled) @@ -154,7 +154,7 @@ static int configure_probes(struct ols_dev *ols, GSList *probes) * flag register. */ probe_bit = 1 << (probe->index - 1); - ols->probe_mask |= probe_bit; + ctx->probe_mask |= probe_bit; if (!probe->trigger) continue; @@ -162,9 +162,9 @@ static int configure_probes(struct ols_dev *ols, GSList *probes) /* Configure trigger mask and value. */ stage = 0; for (tc = probe->trigger; tc && *tc; tc++) { - ols->trigger_mask[stage] |= probe_bit; + ctx->trigger_mask[stage] |= probe_bit; if (*tc == '1') - ols->trigger_value[stage] |= probe_bit; + ctx->trigger_value[stage] |= probe_bit; stage++; if (stage > 3) /* @@ -173,8 +173,8 @@ static int configure_probes(struct ols_dev *ols, GSList *probes) */ return SR_ERR; } - if (stage > ols->num_stages) - ols->num_stages = stage; + if (stage > ctx->num_stages) + ctx->num_stages = stage; } return SR_OK; @@ -204,36 +204,36 @@ static uint32_t reverse32(uint32_t in) return out; } -static struct ols_dev *ols_dev_new(void) +static struct context *ols_dev_new(void) { - struct ols_dev *ols; + struct context *ctx; - /* TODO: Is 'ols' ever g_free()'d? */ - if (!(ols = g_try_malloc0(sizeof(struct ols_dev)))) { - sr_err("ols: %s: ols malloc failed", __func__); + /* TODO: Is 'ctx' ever g_free()'d? */ + if (!(ctx = g_try_malloc0(sizeof(struct context)))) { + sr_err("ols: %s: ctx malloc failed", __func__); return NULL; } - ols->trigger_at = -1; - ols->probe_mask = 0xffffffff; - ols->cur_samplerate = SR_KHZ(200); - ols->serial = NULL; + ctx->trigger_at = -1; + ctx->probe_mask = 0xffffffff; + ctx->cur_samplerate = SR_KHZ(200); + ctx->serial = NULL; - return ols; + return ctx; } static struct sr_dev_inst *get_metadata(int fd) { struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; uint32_t tmp_int; uint8_t key, type, token; GString *tmp_str, *devname, *version; gchar tmp_c; sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, NULL, NULL, NULL); - ols = ols_dev_new(); - sdi->priv = ols; + ctx = ols_dev_new(); + sdi->priv = ctx; devname = g_string_new(""); version = g_string_new(""); @@ -288,11 +288,11 @@ static struct sr_dev_inst *get_metadata(int fd) switch (token) { case 0x00: /* Number of usable probes */ - ols->num_probes = tmp_int; + ctx->num_probes = tmp_int; break; case 0x01: /* Amount of sample memory available (bytes) */ - ols->max_samples = tmp_int; + ctx->max_samples = tmp_int; break; case 0x02: /* Amount of dynamic memory available (bytes) */ @@ -300,11 +300,11 @@ static struct sr_dev_inst *get_metadata(int fd) break; case 0x03: /* Maximum sample rate (hz) */ - ols->max_samplerate = tmp_int; + ctx->max_samplerate = tmp_int; break; case 0x04: /* protocol version */ - ols->protocol_version = tmp_int; + ctx->protocol_version = tmp_int; break; default: sr_info("ols: unknown token 0x%.2x: 0x%.8x", @@ -321,11 +321,11 @@ static struct sr_dev_inst *get_metadata(int fd) switch (token) { case 0x00: /* Number of usable probes */ - ols->num_probes = tmp_c; + ctx->num_probes = tmp_c; break; case 0x01: /* protocol version */ - ols->protocol_version = tmp_c; + ctx->protocol_version = tmp_c; break; default: sr_info("ols: unknown token 0x%.2x: 0x%.2x", @@ -350,7 +350,7 @@ static struct sr_dev_inst *get_metadata(int fd) static int hw_init(const char *devinfo) { struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; GSList *ports, *l; GPollFD *fds, probefd; int devcnt, final_devcnt, num_ports, fd, ret, i; @@ -448,11 +448,11 @@ static int hw_init(const char *devinfo) /* not an OLS -- some other board that uses the sump protocol */ sdi = sr_dev_inst_new(final_devcnt, SR_ST_INACTIVE, "Sump", "Logic Analyzer", "v1.0"); - ols = ols_dev_new(); - ols->num_probes = 32; - sdi->priv = ols; + ctx = ols_dev_new(); + ctx->num_probes = 32; + sdi->priv = ctx; } - ols->serial = sr_serial_dev_inst_new(dev_names[i], -1); + ctx->serial = sr_serial_dev_inst_new(dev_names[i], -1); dev_insts = g_slist_append(dev_insts, sdi); final_devcnt++; serial_close(fds[i].fd); @@ -483,15 +483,15 @@ hw_init_free_ports: static int hw_dev_open(int dev_index) { struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - ols = sdi->priv; + ctx = sdi->priv; - ols->serial->fd = serial_open(ols->serial->port, O_RDWR); - if (ols->serial->fd == -1) + ctx->serial->fd = serial_open(ctx->serial->port, O_RDWR); + if (ctx->serial->fd == -1) return SR_ERR; sdi->status = SR_ST_ACTIVE; @@ -502,19 +502,19 @@ static int hw_dev_open(int dev_index) static int hw_dev_close(int dev_index) { struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("ols: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } - ols = sdi->priv; + ctx = sdi->priv; /* TODO */ - if (ols->serial->fd != -1) { - serial_close(ols->serial->fd); - ols->serial->fd = -1; + if (ctx->serial->fd != -1) { + serial_close(ctx->serial->fd); + ctx->serial->fd = -1; sdi->status = SR_ST_INACTIVE; } @@ -525,7 +525,7 @@ static int hw_cleanup(void) { GSList *l; struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; int ret = SR_OK; /* Properly close and free all devices. */ @@ -536,7 +536,7 @@ static int hw_cleanup(void) ret = SR_ERR_BUG; continue; } - if (!(ols = sdi->priv)) { + if (!(ctx = sdi->priv)) { /* Log error, but continue cleaning up the rest. */ sr_err("ols: %s: sdi->priv was NULL, continuing", __func__); @@ -544,9 +544,9 @@ static int hw_cleanup(void) continue; } /* TODO: Check for serial != NULL. */ - if (ols->serial->fd != -1) - serial_close(ols->serial->fd); - sr_serial_dev_inst_free(ols->serial); + if (ctx->serial->fd != -1) + serial_close(ctx->serial->fd); + sr_serial_dev_inst_free(ctx->serial); sr_dev_inst_free(sdi); } g_slist_free(dev_insts); @@ -558,12 +558,12 @@ static int hw_cleanup(void) static void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; void *info; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return NULL; - ols = sdi->priv; + ctx = sdi->priv; info = NULL; switch (dev_info_id) { @@ -583,7 +583,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = (char *)TRIGGER_TYPES; break; case SR_DI_CUR_SAMPLERATE: - info = &ols->cur_samplerate; + info = &ctx->cur_samplerate; break; } @@ -607,32 +607,32 @@ static int *hw_hwcap_get_all(void) static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { - struct ols_dev *ols; + struct context *ctx; - ols = sdi->priv; - if (ols->max_samplerate) { - if (samplerate > ols->max_samplerate) + ctx = sdi->priv; + if (ctx->max_samplerate) { + if (samplerate > ctx->max_samplerate) return SR_ERR_SAMPLERATE; } else if (samplerate < samplerates.low || samplerate > samplerates.high) return SR_ERR_SAMPLERATE; if (samplerate > CLOCK_RATE) { - ols->flag_reg |= FLAG_DEMUX; - ols->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1; + ctx->flag_reg |= FLAG_DEMUX; + ctx->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1; } else { - ols->flag_reg &= ~FLAG_DEMUX; - ols->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1; + ctx->flag_reg &= ~FLAG_DEMUX; + ctx->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1; } /* Calculate actual samplerate used and complain if it is different * from the requested. */ - ols->cur_samplerate = CLOCK_RATE / (ols->cur_samplerate_divider + 1); - if (ols->flag_reg & FLAG_DEMUX) - ols->cur_samplerate *= 2; - if (ols->cur_samplerate != samplerate) + ctx->cur_samplerate = CLOCK_RATE / (ctx->cur_samplerate_divider + 1); + if (ctx->flag_reg & FLAG_DEMUX) + ctx->cur_samplerate *= 2; + if (ctx->cur_samplerate != samplerate) sr_err("ols: can't match samplerate %" PRIu64 ", using %" - PRIu64, samplerate, ols->cur_samplerate); + PRIu64, samplerate, ctx->cur_samplerate); return SR_OK; } @@ -640,13 +640,13 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) static int hw_dev_config_set(int dev_index, int hwcap, void *value) { struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; int ret; uint64_t *tmp_u64; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - ols = sdi->priv; + ctx = sdi->priv; if (sdi->status != SR_ST_ACTIVE) return SR_ERR; @@ -656,22 +656,22 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) ret = set_samplerate(sdi, *(uint64_t *)value); break; case SR_HWCAP_PROBECONFIG: - ret = configure_probes(ols, (GSList *)value); + ret = configure_probes(ctx, (GSList *)value); break; case SR_HWCAP_LIMIT_SAMPLES: tmp_u64 = value; if (*tmp_u64 < MIN_NUM_SAMPLES) return SR_ERR; - if (*tmp_u64 > ols->max_samples) + if (*tmp_u64 > ctx->max_samples) sr_err("ols: sample limit exceeds hw max"); - ols->limit_samples = *tmp_u64; - sr_info("ols: sample limit %" PRIu64, ols->limit_samples); + ctx->limit_samples = *tmp_u64; + sr_info("ols: sample limit %" PRIu64, ctx->limit_samples); ret = SR_OK; break; case SR_HWCAP_CAPTURE_RATIO: - ols->capture_ratio = *(uint64_t *)value; - if (ols->capture_ratio < 0 || ols->capture_ratio > 100) { - ols->capture_ratio = 0; + ctx->capture_ratio = *(uint64_t *)value; + if (ctx->capture_ratio < 0 || ctx->capture_ratio > 100) { + ctx->capture_ratio = 0; ret = SR_ERR; } else ret = SR_OK; @@ -679,7 +679,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) case SR_HWCAP_RLE: if (GPOINTER_TO_INT(value)) { sr_info("ols: enabling RLE"); - ols->flag_reg |= FLAG_RLE; + ctx->flag_reg |= FLAG_RLE; } ret = SR_OK; break; @@ -695,25 +695,25 @@ static int receive_data(int fd, int revents, void *session_data) struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; GSList *l; int num_channels, offset, i, j; unsigned char byte; - /* find this device's ols_dev struct by its fd */ - ols = NULL; + /* Find this device's ctx struct by its fd. */ + ctx = NULL; for (l = dev_insts; l; l = l->next) { sdi = l->data; - if (ols->serial->fd == fd) { - ols = sdi->priv; + if (ctx->serial->fd == fd) { + ctx = sdi->priv; break; } } - if (!ols) - /* shouldn't happen */ + if (!ctx) + /* Shouldn't happen. */ return TRUE; - if (ols->num_transfers++ == 0) { + if (ctx->num_transfers++ == 0) { /* * First time round, means the device started sending data, * and will not stop until done. If it stops sending for @@ -722,19 +722,19 @@ static int receive_data(int fd, int revents, void *session_data) */ sr_source_remove(fd); sr_source_add(fd, G_IO_IN, 30, receive_data, session_data); - ols->raw_sample_buf = g_try_malloc(ols->limit_samples * 4); - if (!ols->raw_sample_buf) { - sr_err("ols: %s: ols->raw_sample_buf malloc failed", + ctx->raw_sample_buf = g_try_malloc(ctx->limit_samples * 4); + if (!ctx->raw_sample_buf) { + sr_err("ols: %s: ctx->raw_sample_buf malloc failed", __func__); return FALSE; } /* fill with 1010... for debugging */ - memset(ols->raw_sample_buf, 0x82, ols->limit_samples * 4); + memset(ctx->raw_sample_buf, 0x82, ctx->limit_samples * 4); } num_channels = 0; for (i = 0x20; i > 0x02; i /= 2) { - if ((ols->flag_reg & i) == 0) + if ((ctx->flag_reg & i) == 0) num_channels++; } @@ -743,37 +743,37 @@ static int receive_data(int fd, int revents, void *session_data) return FALSE; /* Ignore it if we've read enough. */ - if (ols->num_samples >= ols->limit_samples) + if (ctx->num_samples >= ctx->limit_samples) return TRUE; - ols->sample[ols->num_bytes++] = byte; + ctx->sample[ctx->num_bytes++] = byte; sr_dbg("ols: received byte 0x%.2x", byte); - if (ols->num_bytes == num_channels) { + if (ctx->num_bytes == num_channels) { /* Got a full sample. */ sr_dbg("ols: received sample 0x%.*x", - ols->num_bytes * 2, *(int *)ols->sample); - if (ols->flag_reg & FLAG_RLE) { + ctx->num_bytes * 2, *(int *)ctx->sample); + if (ctx->flag_reg & FLAG_RLE) { /* * In RLE mode -1 should never come in as a * sample, because bit 31 is the "count" flag. */ - if (ols->sample[ols->num_bytes - 1] & 0x80) { - ols->sample[ols->num_bytes - 1] &= 0x7f; + if (ctx->sample[ctx->num_bytes - 1] & 0x80) { + ctx->sample[ctx->num_bytes - 1] &= 0x7f; /* * FIXME: This will only work on * little-endian systems. */ - ols->rle_count = *(int *)(ols->sample); - sr_dbg("ols: RLE count = %d", ols->rle_count); - ols->num_bytes = 0; + ctx->rle_count = *(int *)(ctx->sample); + sr_dbg("ols: RLE count = %d", ctx->rle_count); + ctx->num_bytes = 0; return TRUE; } } - ols->num_samples += ols->rle_count + 1; - if (ols->num_samples > ols->limit_samples) { + ctx->num_samples += ctx->rle_count + 1; + if (ctx->num_samples > ctx->limit_samples) { /* Save us from overrunning the buffer. */ - ols->rle_count -= ols->num_samples - ols->limit_samples; - ols->num_samples = ols->limit_samples; + ctx->rle_count -= ctx->num_samples - ctx->limit_samples; + ctx->num_samples = ctx->limit_samples; } if (num_channels < 4) { @@ -787,33 +787,33 @@ static int receive_data(int fd, int revents, void *session_data) * the number of probes. */ j = 0; - memset(ols->tmp_sample, 0, 4); + memset(ctx->tmp_sample, 0, 4); for (i = 0; i < 4; i++) { - if (((ols->flag_reg >> 2) & (1 << i)) == 0) { + if (((ctx->flag_reg >> 2) & (1 << i)) == 0) { /* * This channel group was * enabled, copy from received * sample. */ - ols->tmp_sample[i] = ols->sample[j++]; + ctx->tmp_sample[i] = ctx->sample[j++]; } } - memcpy(ols->sample, ols->tmp_sample, 4); - sr_dbg("ols: full sample 0x%.8x", *(int *)ols->sample); + memcpy(ctx->sample, ctx->tmp_sample, 4); + sr_dbg("ols: full sample 0x%.8x", *(int *)ctx->sample); } /* the OLS sends its sample buffer backwards. * store it in reverse order here, so we can dump * this on the session bus later. */ - offset = (ols->limit_samples - ols->num_samples) * 4; - for (i = 0; i <= ols->rle_count; i++) { - memcpy(ols->raw_sample_buf + offset + (i * 4), - ols->sample, 4); + offset = (ctx->limit_samples - ctx->num_samples) * 4; + for (i = 0; i <= ctx->rle_count; i++) { + memcpy(ctx->raw_sample_buf + offset + (i * 4), + ctx->sample, 4); } - memset(ols->sample, 0, 4); - ols->num_bytes = 0; - ols->rle_count = 0; + memset(ctx->sample, 0, 4); + ctx->num_bytes = 0; + ctx->rle_count = 0; } } else { /* @@ -821,18 +821,18 @@ static int receive_data(int fd, int revents, void *session_data) * we've acquired all the samples we asked for -- we're done. * Send the (properly-ordered) buffer to the frontend. */ - if (ols->trigger_at != -1) { + if (ctx->trigger_at != -1) { /* a trigger was set up, so we need to tell the frontend * about it. */ - if (ols->trigger_at > 0) { + if (ctx->trigger_at > 0) { /* there are pre-trigger samples, send those first */ packet.type = SR_DF_LOGIC; packet.payload = &logic; - logic.length = ols->trigger_at * 4; + logic.length = ctx->trigger_at * 4; logic.unitsize = 4; - logic.data = ols->raw_sample_buf + - (ols->limit_samples - ols->num_samples) * 4; + logic.data = ctx->raw_sample_buf + + (ctx->limit_samples - ctx->num_samples) * 4; sr_session_bus(session_data, &packet); } @@ -843,22 +843,22 @@ static int receive_data(int fd, int revents, void *session_data) /* send post-trigger samples */ packet.type = SR_DF_LOGIC; packet.payload = &logic; - logic.length = (ols->num_samples * 4) - (ols->trigger_at * 4); + logic.length = (ctx->num_samples * 4) - (ctx->trigger_at * 4); logic.unitsize = 4; - logic.data = ols->raw_sample_buf + ols->trigger_at * 4 + - (ols->limit_samples - ols->num_samples) * 4; + logic.data = ctx->raw_sample_buf + ctx->trigger_at * 4 + + (ctx->limit_samples - ctx->num_samples) * 4; sr_session_bus(session_data, &packet); } else { /* no trigger was used */ packet.type = SR_DF_LOGIC; packet.payload = &logic; - logic.length = ols->num_samples * 4; + logic.length = ctx->num_samples * 4; logic.unitsize = 4; - logic.data = ols->raw_sample_buf + - (ols->limit_samples - ols->num_samples) * 4; + logic.data = ctx->raw_sample_buf + + (ctx->limit_samples - ctx->num_samples) * 4; sr_session_bus(session_data, &packet); } - g_free(ols->raw_sample_buf); + g_free(ctx->raw_sample_buf); serial_flush(fd); serial_close(fd); @@ -874,7 +874,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) struct sr_datafeed_packet *packet; struct sr_datafeed_header *header; struct sr_dev_inst *sdi; - struct ols_dev *ols; + struct context *ctx; uint32_t trigger_config[4]; uint32_t data; uint16_t readcount, delaycount; @@ -885,7 +885,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - ols = sdi->priv; + ctx = sdi->priv; if (sdi->status != SR_ST_ACTIVE) return SR_ERR; @@ -898,7 +898,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) changrp_mask = 0; num_channels = 0; for (i = 0; i < 4; i++) { - if (ols->probe_mask & (0xff << (i * 8))) { + if (ctx->probe_mask & (0xff << (i * 8))) { changrp_mask |= (1 << i); num_channels++; } @@ -908,92 +908,92 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) * Limit readcount to prevent reading past the end of the hardware * buffer. */ - readcount = MIN(ols->max_samples / num_channels, ols->limit_samples) / 4; + readcount = MIN(ctx->max_samples / num_channels, ctx->limit_samples) / 4; memset(trigger_config, 0, 16); - trigger_config[ols->num_stages - 1] |= 0x08; - if (ols->trigger_mask[0]) { - delaycount = readcount * (1 - ols->capture_ratio / 100.0); - ols->trigger_at = (readcount - delaycount) * 4 - ols->num_stages; + trigger_config[ctx->num_stages - 1] |= 0x08; + if (ctx->trigger_mask[0]) { + delaycount = readcount * (1 - ctx->capture_ratio / 100.0); + ctx->trigger_at = (readcount - delaycount) * 4 - ctx->num_stages; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_0, - reverse32(ols->trigger_mask[0])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_MASK_0, + reverse32(ctx->trigger_mask[0])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_0, - reverse32(ols->trigger_value[0])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_VALUE_0, + reverse32(ctx->trigger_value[0])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_0, + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_CONFIG_0, trigger_config[0]) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_1, - reverse32(ols->trigger_mask[1])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_MASK_1, + reverse32(ctx->trigger_mask[1])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_1, - reverse32(ols->trigger_value[1])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_VALUE_1, + reverse32(ctx->trigger_value[1])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_1, + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_CONFIG_1, trigger_config[1]) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_2, - reverse32(ols->trigger_mask[2])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_MASK_2, + reverse32(ctx->trigger_mask[2])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_2, - reverse32(ols->trigger_value[2])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_VALUE_2, + reverse32(ctx->trigger_value[2])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_2, + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_CONFIG_2, trigger_config[2]) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_3, - reverse32(ols->trigger_mask[3])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_MASK_3, + reverse32(ctx->trigger_mask[3])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_3, - reverse32(ols->trigger_value[3])) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_VALUE_3, + reverse32(ctx->trigger_value[3])) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_3, + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_CONFIG_3, trigger_config[3]) != SR_OK) return SR_ERR; } else { - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_0, - ols->trigger_mask[0]) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_MASK_0, + ctx->trigger_mask[0]) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_0, - ols->trigger_value[0]) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_VALUE_0, + ctx->trigger_value[0]) != SR_OK) return SR_ERR; - if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_0, + if (send_longcommand(ctx->serial->fd, CMD_SET_TRIGGER_CONFIG_0, 0x00000008) != SR_OK) return SR_ERR; delaycount = readcount; } sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, " - "demux %s)", ols->cur_samplerate, ols->cur_samplerate_divider, - ols->flag_reg & FLAG_DEMUX ? "on" : "off"); - if (send_longcommand(ols->serial->fd, CMD_SET_DIVIDER, - reverse32(ols->cur_samplerate_divider)) != SR_OK) + "demux %s)", ctx->cur_samplerate, ctx->cur_samplerate_divider, + ctx->flag_reg & FLAG_DEMUX ? "on" : "off"); + if (send_longcommand(ctx->serial->fd, CMD_SET_DIVIDER, + reverse32(ctx->cur_samplerate_divider)) != SR_OK) return SR_ERR; /* Send sample limit and pre/post-trigger capture ratio. */ data = ((readcount - 1) & 0xffff) << 16; data |= (delaycount - 1) & 0xffff; - if (send_longcommand(ols->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK) + if (send_longcommand(ctx->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK) return SR_ERR; /* The flag register wants them here, and 1 means "disable channel". */ - ols->flag_reg |= ~(changrp_mask << 2) & 0x3c; - ols->flag_reg |= FLAG_FILTER; - ols->rle_count = 0; - data = (ols->flag_reg << 24) | ((ols->flag_reg << 8) & 0xff0000); - if (send_longcommand(ols->serial->fd, CMD_SET_FLAGS, data) != SR_OK) + ctx->flag_reg |= ~(changrp_mask << 2) & 0x3c; + ctx->flag_reg |= FLAG_FILTER; + ctx->rle_count = 0; + data = (ctx->flag_reg << 24) | ((ctx->flag_reg << 8) & 0xff0000); + if (send_longcommand(ctx->serial->fd, CMD_SET_FLAGS, data) != SR_OK) return SR_ERR; /* Start acquisition on the device. */ - if (send_shortcommand(ols->serial->fd, CMD_RUN) != SR_OK) + if (send_shortcommand(ctx->serial->fd, CMD_RUN) != SR_OK) return SR_ERR; - sr_source_add(ols->serial->fd, G_IO_IN, -1, receive_data, + sr_source_add(ctx->serial->fd, G_IO_IN, -1, receive_data, session_data); if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) { @@ -1012,7 +1012,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) packet->payload = (unsigned char *)header; header->feed_version = 1; gettimeofday(&header->starttime, NULL); - header->samplerate = ols->cur_samplerate; + header->samplerate = ctx->cur_samplerate; header->num_logic_probes = NUM_PROBES; sr_session_bus(session_data, packet); diff --git a/hardware/openbench-logic-sniffer/ols.h b/hardware/openbench-logic-sniffer/ols.h index 832413fd..f452c748 100644 --- a/hardware/openbench-logic-sniffer/ols.h +++ b/hardware/openbench-logic-sniffer/ols.h @@ -59,7 +59,8 @@ #define FLAG_CLOCK_INVERTED 0x80 #define FLAG_RLE 0x0100 -struct ols_dev { +/* Private, per-device-instance driver context. */ +struct context { uint32_t max_samplerate; uint32_t max_samples; uint32_t protocol_version; diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index cf4b600d..295582a9 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -170,12 +170,12 @@ static int sl_open_dev(int dev_index) libusb_device **devlist; struct libusb_device_descriptor des; struct sr_dev_inst *sdi; - struct fx2_dev *fx2; + struct context *ctx; int err, skip, i; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - fx2 = sdi->priv; + ctx = sdi->priv; if (sdi->status == SR_ST_ACTIVE) /* already in use */ @@ -189,8 +189,8 @@ static int sl_open_dev(int dev_index) continue; } - if (des.idVendor != fx2->profile->fw_vid - || des.idProduct != fx2->profile->fw_pid) + if (des.idVendor != ctx->profile->fw_vid + || des.idProduct != ctx->profile->fw_pid) continue; if (sdi->status == SR_ST_INITIALIZING) { @@ -204,24 +204,24 @@ static int sl_open_dev(int dev_index) * This device is fully enumerated, so we need to find * this device by vendor, product, bus and address. */ - if (libusb_get_bus_number(devlist[i]) != fx2->usb->bus - || libusb_get_device_address(devlist[i]) != fx2->usb->address) + if (libusb_get_bus_number(devlist[i]) != ctx->usb->bus + || libusb_get_device_address(devlist[i]) != ctx->usb->address) /* this is not the one */ continue; } - if (!(err = libusb_open(devlist[i], &fx2->usb->devhdl))) { - if (fx2->usb->address == 0xff) + if (!(err = libusb_open(devlist[i], &ctx->usb->devhdl))) { + if (ctx->usb->address == 0xff) /* * first time we touch this device after firmware upload, * so we don't know the address yet. */ - fx2->usb->address = libusb_get_device_address(devlist[i]); + ctx->usb->address = libusb_get_device_address(devlist[i]); sdi->status = SR_ST_ACTIVE; sr_info("logic: opened device %d on %d.%d interface %d", - sdi->index, fx2->usb->bus, - fx2->usb->address, USB_INTERFACE); + sdi->index, ctx->usb->bus, + ctx->usb->address, USB_INTERFACE); } else { sr_err("logic: failed to open device: %d", err); } @@ -239,32 +239,32 @@ static int sl_open_dev(int dev_index) static void close_dev(struct sr_dev_inst *sdi) { - struct fx2_dev *fx2; + struct context *ctx; - fx2 = sdi->priv; + ctx = sdi->priv; - if (fx2->usb->devhdl == NULL) + if (ctx->usb->devhdl == NULL) return; sr_info("logic: closing device %d on %d.%d interface %d", sdi->index, - fx2->usb->bus, fx2->usb->address, USB_INTERFACE); - libusb_release_interface(fx2->usb->devhdl, USB_INTERFACE); - libusb_close(fx2->usb->devhdl); - fx2->usb->devhdl = NULL; + ctx->usb->bus, ctx->usb->address, USB_INTERFACE); + libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE); + libusb_close(ctx->usb->devhdl); + ctx->usb->devhdl = NULL; sdi->status = SR_ST_INACTIVE; } -static int configure_probes(struct fx2_dev *fx2, GSList *probes) +static int configure_probes(struct context *ctx, GSList *probes) { struct sr_probe *probe; GSList *l; int probe_bit, stage, i; char *tc; - fx2->probe_mask = 0; + ctx->probe_mask = 0; for (i = 0; i < NUM_TRIGGER_STAGES; i++) { - fx2->trigger_mask[i] = 0; - fx2->trigger_value[i] = 0; + ctx->trigger_mask[i] = 0; + ctx->trigger_value[i] = 0; } stage = -1; @@ -273,15 +273,15 @@ static int configure_probes(struct fx2_dev *fx2, GSList *probes) if (probe->enabled == FALSE) continue; probe_bit = 1 << (probe->index - 1); - fx2->probe_mask |= probe_bit; + ctx->probe_mask |= probe_bit; if (!(probe->trigger)) continue; stage = 0; for (tc = probe->trigger; *tc; tc++) { - fx2->trigger_mask[stage] |= probe_bit; + ctx->trigger_mask[stage] |= probe_bit; if (*tc == '1') - fx2->trigger_value[stage] |= probe_bit; + ctx->trigger_value[stage] |= probe_bit; stage++; if (stage > NUM_TRIGGER_STAGES) return SR_ERR; @@ -293,25 +293,25 @@ static int configure_probes(struct fx2_dev *fx2, GSList *probes) * We didn't configure any triggers, make sure acquisition * doesn't wait for any. */ - fx2->trigger_stage = TRIGGER_FIRED; + ctx->trigger_stage = TRIGGER_FIRED; else - fx2->trigger_stage = 0; + ctx->trigger_stage = 0; return SR_OK; } -static struct fx2_dev *fx2_dev_new(void) +static struct context *fx2_dev_new(void) { - struct fx2_dev *fx2; + struct context *ctx; - if (!(fx2 = g_try_malloc0(sizeof(struct fx2_dev)))) { - sr_err("logic: %s: fx2 malloc failed", __func__); + if (!(ctx = g_try_malloc0(sizeof(struct context)))) { + sr_err("logic: %s: ctx malloc failed", __func__); return NULL; } - fx2->trigger_stage = TRIGGER_FIRED; - fx2->usb = NULL; + ctx->trigger_stage = TRIGGER_FIRED; + ctx->usb = NULL; - return fx2; + return ctx; } @@ -324,7 +324,7 @@ static int hw_init(const char *devinfo) struct sr_dev_inst *sdi; struct libusb_device_descriptor des; struct fx2_profile *fx2_prof; - struct fx2_dev *fx2; + struct context *ctx; libusb_device **devlist; int err, devcnt, i, j; @@ -363,9 +363,9 @@ static int hw_init(const char *devinfo) fx2_prof->vendor, fx2_prof->model, fx2_prof->model_version); if (!sdi) return 0; - fx2 = fx2_dev_new(); - fx2->profile = fx2_prof; - sdi->priv = fx2; + ctx = fx2_dev_new(); + ctx->profile = fx2_prof; + sdi->priv = ctx; dev_insts = g_slist_append(dev_insts, sdi); if (check_conf_profile(devlist[i])) { @@ -373,17 +373,17 @@ static int hw_init(const char *devinfo) sr_dbg("logic: Found a Saleae Logic with %s firmware.", new_saleae_logic_firmware ? "new" : "old"); sdi->status = SR_ST_INACTIVE; - fx2->usb = sr_usb_dev_inst_new + ctx->usb = 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, FIRMWARE) == SR_OK) /* Remember when the firmware on this device was updated */ - g_get_current_time(&fx2->fw_updated); + g_get_current_time(&ctx->fw_updated); else sr_err("logic: firmware upload failed for " "device %d", devcnt); - fx2->usb = sr_usb_dev_inst_new + ctx->usb = sr_usb_dev_inst_new (libusb_get_bus_number(devlist[i]), 0xff, NULL); } devcnt++; @@ -397,19 +397,19 @@ static int hw_dev_open(int dev_index) { GTimeVal cur_time; struct sr_dev_inst *sdi; - struct fx2_dev *fx2; + struct context *ctx; int timediff, err; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - fx2 = sdi->priv; + ctx = sdi->priv; /* * if the firmware was recently uploaded, wait up to MAX_RENUM_DELAY ms * for the FX2 to renumerate */ err = 0; - if (GTV_TO_MSEC(fx2->fw_updated) > 0) { + if (GTV_TO_MSEC(ctx->fw_updated) > 0) { sr_info("logic: waiting for device to reset"); /* takes at least 300ms for the FX2 to be gone from the USB bus */ g_usleep(300 * 1000); @@ -419,7 +419,7 @@ static int hw_dev_open(int dev_index) break; g_usleep(100 * 1000); g_get_current_time(&cur_time); - timediff = GTV_TO_MSEC(cur_time) - GTV_TO_MSEC(fx2->fw_updated); + timediff = GTV_TO_MSEC(cur_time) - GTV_TO_MSEC(ctx->fw_updated); } sr_info("logic: device came back after %d ms", timediff); } else { @@ -430,15 +430,15 @@ static int hw_dev_open(int dev_index) sr_err("logic: unable to open device"); return SR_ERR; } - fx2 = sdi->priv; + ctx = sdi->priv; - err = libusb_claim_interface(fx2->usb->devhdl, USB_INTERFACE); + err = libusb_claim_interface(ctx->usb->devhdl, USB_INTERFACE); if (err != 0) { sr_err("logic: Unable to claim interface: %d", err); return SR_ERR; } - if (fx2->cur_samplerate == 0) { + if (ctx->cur_samplerate == 0) { /* Samplerate hasn't been set; default to the slowest one. */ if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE, &supported_samplerates[0]) == SR_ERR) @@ -467,7 +467,7 @@ static int hw_cleanup(void) { GSList *l; struct sr_dev_inst *sdi; - struct fx2_dev *fx2; + struct context *ctx; int ret = SR_OK; /* Properly close and free all devices. */ @@ -478,7 +478,7 @@ static int hw_cleanup(void) ret = SR_ERR_BUG; continue; } - if (!(fx2 = sdi->priv)) { + if (!(ctx = sdi->priv)) { /* Log error, but continue cleaning up the rest. */ sr_err("logic: %s: sdi->priv was NULL, continuing", __func__); @@ -486,7 +486,7 @@ static int hw_cleanup(void) continue; } close_dev(sdi); - sr_usb_dev_inst_free(fx2->usb); + sr_usb_dev_inst_free(ctx->usb); sr_dev_inst_free(sdi); } @@ -503,19 +503,19 @@ static int hw_cleanup(void) static void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; - struct fx2_dev *fx2; + struct context *ctx; void *info = NULL; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return NULL; - fx2 = sdi->priv; + ctx = sdi->priv; switch (dev_info_id) { case SR_DI_INST: info = sdi; break; case SR_DI_NUM_PROBES: - info = GINT_TO_POINTER(fx2->profile->num_probes); + info = GINT_TO_POINTER(ctx->profile->num_probes); break; case SR_DI_PROBE_NAMES: info = probe_names; @@ -527,7 +527,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = TRIGGER_TYPES; break; case SR_DI_CUR_SAMPLERATE: - info = &fx2->cur_samplerate; + info = &ctx->cur_samplerate; break; } @@ -593,12 +593,12 @@ static uint8_t new_firmware_divider_value(uint64_t samplerate) static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { - struct fx2_dev *fx2; + struct context *ctx; uint8_t divider; int ret, result, i; unsigned char buf[2]; - fx2 = sdi->priv; + ctx = sdi->priv; for (i = 0; supported_samplerates[i]; i++) { if (supported_samplerates[i] == samplerate) break; @@ -616,13 +616,13 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) buf[0] = (new_saleae_logic_firmware) ? 0xd5 : 0x01; buf[1] = divider; - ret = libusb_bulk_transfer(fx2->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT, + ret = libusb_bulk_transfer(ctx->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT, buf, 2, &result, 500); if (ret != 0) { sr_err("logic: failed to set samplerate: %d", ret); return SR_ERR; } - fx2->cur_samplerate = samplerate; + ctx->cur_samplerate = samplerate; return SR_OK; } @@ -630,19 +630,19 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) static int hw_dev_config_set(int dev_index, int hwcap, void *value) { struct sr_dev_inst *sdi; - struct fx2_dev *fx2; + struct context *ctx; int ret; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - fx2 = sdi->priv; + ctx = sdi->priv; if (hwcap == SR_HWCAP_SAMPLERATE) { ret = set_samplerate(sdi, *(uint64_t *)value); } else if (hwcap == SR_HWCAP_PROBECONFIG) { - ret = configure_probes(fx2, (GSList *) value); + ret = configure_probes(ctx, (GSList *) value); } else if (hwcap == SR_HWCAP_LIMIT_SAMPLES) { - fx2->limit_samples = *(uint64_t *)value; + ctx->limit_samples = *(uint64_t *)value; ret = SR_OK; } else { ret = SR_ERR; @@ -668,12 +668,12 @@ static int receive_data(int fd, int revents, void *user_data) static void receive_transfer(struct libusb_transfer *transfer) { - /* TODO: these statics have to move to fx2_dev struct */ + /* TODO: These statics have to move to the ctx struct. */ static int num_samples = 0; static int empty_transfer_count = 0; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; - struct fx2_dev *fx2; + struct context *ctx; int cur_buflen, trigger_offset, i; unsigned char *cur_buf, *new_buf; @@ -697,7 +697,7 @@ static void receive_transfer(struct libusb_transfer *transfer) /* Save incoming transfer before reusing the transfer struct. */ cur_buf = transfer->buffer; cur_buflen = transfer->actual_length; - fx2 = transfer->user_data; + ctx = transfer->user_data; /* Fire off a new request. */ if (!(new_buf = g_try_malloc(4096))) { @@ -720,7 +720,7 @@ static void receive_transfer(struct libusb_transfer *transfer) * The FX2 gave up. End the acquisition, the frontend * will work out that the samplecount is short. */ - hw_dev_acquisition_stop(-1, fx2->session_data); + hw_dev_acquisition_stop(-1, ctx->session_data); } return; } else { @@ -728,15 +728,15 @@ static void receive_transfer(struct libusb_transfer *transfer) } trigger_offset = 0; - if (fx2->trigger_stage >= 0) { + if (ctx->trigger_stage >= 0) { for (i = 0; i < cur_buflen; i++) { - if ((cur_buf[i] & fx2->trigger_mask[fx2->trigger_stage]) == fx2->trigger_value[fx2->trigger_stage]) { + if ((cur_buf[i] & ctx->trigger_mask[ctx->trigger_stage]) == ctx->trigger_value[ctx->trigger_stage]) { /* Match on this trigger stage. */ - fx2->trigger_buffer[fx2->trigger_stage] = cur_buf[i]; - fx2->trigger_stage++; + ctx->trigger_buffer[ctx->trigger_stage] = cur_buf[i]; + ctx->trigger_stage++; - if (fx2->trigger_stage == NUM_TRIGGER_STAGES || fx2->trigger_mask[fx2->trigger_stage] == 0) { + if (ctx->trigger_stage == NUM_TRIGGER_STAGES || ctx->trigger_mask[ctx->trigger_stage] == 0) { /* Match on all trigger stages, we're done. */ trigger_offset = i + 1; @@ -746,7 +746,7 @@ static void receive_transfer(struct libusb_transfer *transfer) */ packet.type = SR_DF_TRIGGER; packet.payload = NULL; - sr_session_bus(fx2->session_data, &packet); + sr_session_bus(ctx->session_data, &packet); /* * Send the samples that triggered it, since we're @@ -754,12 +754,12 @@ static void receive_transfer(struct libusb_transfer *transfer) */ packet.type = SR_DF_LOGIC; packet.payload = &logic; - logic.length = fx2->trigger_stage; + logic.length = ctx->trigger_stage; logic.unitsize = 1; - logic.data = fx2->trigger_buffer; - sr_session_bus(fx2->session_data, &packet); + logic.data = ctx->trigger_buffer; + sr_session_bus(ctx->session_data, &packet); - fx2->trigger_stage = TRIGGER_FIRED; + ctx->trigger_stage = TRIGGER_FIRED; break; } return; @@ -772,29 +772,29 @@ static void receive_transfer(struct libusb_transfer *transfer) * the next sample from the one that matched originally, which the * counter increment at the end of the loop takes care of. */ - if (fx2->trigger_stage > 0) { - i -= fx2->trigger_stage; + if (ctx->trigger_stage > 0) { + i -= ctx->trigger_stage; if (i < -1) i = -1; /* Oops, went back past this buffer. */ /* Reset trigger stage. */ - fx2->trigger_stage = 0; + ctx->trigger_stage = 0; } } } - if (fx2->trigger_stage == TRIGGER_FIRED) { + if (ctx->trigger_stage == TRIGGER_FIRED) { /* Send the incoming transfer to the session bus. */ packet.type = SR_DF_LOGIC; packet.payload = &logic; logic.length = cur_buflen - trigger_offset; logic.unitsize = 1; logic.data = cur_buf + trigger_offset; - sr_session_bus(fx2->session_data, &packet); + sr_session_bus(ctx->session_data, &packet); g_free(cur_buf); num_samples += cur_buflen; - if (fx2->limit_samples && (unsigned int) num_samples > fx2->limit_samples) { - hw_dev_acquisition_stop(-1, fx2->session_data); + if (ctx->limit_samples && (unsigned int) num_samples > ctx->limit_samples) { + hw_dev_acquisition_stop(-1, ctx->session_data); } } else { /* @@ -809,7 +809,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) struct sr_dev_inst *sdi; struct sr_datafeed_packet *packet; struct sr_datafeed_header *header; - struct fx2_dev *fx2; + struct context *ctx; struct libusb_transfer *transfer; const struct libusb_pollfd **lupfd; int size, i; @@ -817,8 +817,8 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; - fx2 = sdi->priv; - fx2->session_data = session_data; + ctx = sdi->priv; + ctx->session_data = session_data; if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) { sr_err("logic: %s: packet malloc failed", __func__); @@ -838,9 +838,9 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) return SR_ERR_MALLOC; } transfer = libusb_alloc_transfer(0); - libusb_fill_bulk_transfer(transfer, fx2->usb->devhdl, + libusb_fill_bulk_transfer(transfer, ctx->usb->devhdl, 2 | LIBUSB_ENDPOINT_IN, buf, size, - receive_transfer, fx2, 40); + receive_transfer, ctx, 40); if (libusb_submit_transfer(transfer) != 0) { /* TODO: Free them all. */ libusb_free_transfer(transfer); @@ -860,8 +860,8 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) packet->payload = header; header->feed_version = 1; gettimeofday(&header->starttime, NULL); - header->samplerate = fx2->cur_samplerate; - header->num_logic_probes = fx2->profile->num_probes; + header->samplerate = ctx->cur_samplerate; + header->num_logic_probes = ctx->profile->num_probes; sr_session_bus(session_data, packet); g_free(header); g_free(packet); diff --git a/hardware/saleae-logic/saleae-logic.h b/hardware/saleae-logic/saleae-logic.h index 5b8f489c..7cd28c48 100644 --- a/hardware/saleae-logic/saleae-logic.h +++ b/hardware/saleae-logic/saleae-logic.h @@ -48,7 +48,8 @@ struct fx2_profile { int num_probes; }; -struct fx2_dev { +/* Private, per-device-instance driver context. */ +struct context { struct fx2_profile *profile; /* * Since we can't keep track of a Saleae Logic device after upgrading diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 4accf20c..c3a1f922 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -153,7 +153,8 @@ static struct sr_samplerates samplerates = { supported_samplerates, }; -struct zp { +/* Private, per-device-instance driver context. */ +struct context { uint64_t cur_samplerate; uint64_t limit_samples; int num_channels; /* TODO: This isn't initialized before it's needed :( */ @@ -185,13 +186,13 @@ static unsigned int get_memory_size(int type) static int opendev4(struct sr_dev_inst **sdi, libusb_device *dev, struct libusb_device_descriptor *des) { - struct zp *zp; + struct context *ctx; unsigned int i; int err; /* Note: sdi is non-NULL, the caller already checked this. */ - if (!(zp = (*sdi)->priv)) { + if (!(ctx = (*sdi)->priv)) { sr_err("zp: %s: (*sdi)->priv was NULL", __func__); return -1; } @@ -204,8 +205,8 @@ static int opendev4(struct sr_dev_inst **sdi, libusb_device *dev, if (des->idVendor != USB_VENDOR) return 0; - if (libusb_get_bus_number(dev) == zp->usb->bus - && libusb_get_device_address(dev) == zp->usb->address) { + if (libusb_get_bus_number(dev) == ctx->usb->bus + && libusb_get_device_address(dev) == ctx->usb->address) { for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) { if (!(des->idProduct == zeroplus_models[i].pid)) @@ -213,23 +214,23 @@ static int opendev4(struct sr_dev_inst **sdi, libusb_device *dev, sr_info("zp: Found ZeroPlus device 0x%04x (%s)", des->idProduct, zeroplus_models[i].model_name); - zp->num_channels = zeroplus_models[i].channels; - zp->memory_size = zeroplus_models[i].sample_depth * 1024; + ctx->num_channels = zeroplus_models[i].channels; + ctx->memory_size = zeroplus_models[i].sample_depth * 1024; break; } - if (zp->num_channels == 0) { + if (ctx->num_channels == 0) { sr_err("zp: Unknown ZeroPlus device 0x%04x", des->idProduct); return -2; } /* Found it. */ - if (!(err = libusb_open(dev, &(zp->usb->devhdl)))) { + if (!(err = libusb_open(dev, &(ctx->usb->devhdl)))) { (*sdi)->status = SR_ST_ACTIVE; sr_info("zp: opened device %d on %d.%d interface %d", - (*sdi)->index, zp->usb->bus, - zp->usb->address, USB_INTERFACE); + (*sdi)->index, ctx->usb->bus, + ctx->usb->address, USB_INTERFACE); } else { sr_err("zp: failed to open device: %d", err); *sdi = NULL; @@ -271,41 +272,41 @@ static struct sr_dev_inst *zp_open_dev(int dev_index) static void close_dev(struct sr_dev_inst *sdi) { - struct zp *zp; + struct context *ctx; - if (!(zp = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return; /* FIXME */ } - if (!zp->usb->devhdl) + if (!ctx->usb->devhdl) return; sr_info("zp: closing device %d on %d.%d interface %d", sdi->index, - zp->usb->bus, zp->usb->address, USB_INTERFACE); - libusb_release_interface(zp->usb->devhdl, USB_INTERFACE); - libusb_reset_device(zp->usb->devhdl); - libusb_close(zp->usb->devhdl); - zp->usb->devhdl = NULL; + ctx->usb->bus, ctx->usb->address, USB_INTERFACE); + libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE); + libusb_reset_device(ctx->usb->devhdl); + libusb_close(ctx->usb->devhdl); + ctx->usb->devhdl = NULL; /* TODO: Call libusb_exit() here or only in hw_cleanup()? */ sdi->status = SR_ST_INACTIVE; } static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) { - struct zp *zp; + struct context *ctx; struct sr_probe *probe; GSList *l; int probe_bit, stage, i; char *tc; /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */ - zp = sdi->priv; + ctx = sdi->priv; - zp->probe_mask = 0; + ctx->probe_mask = 0; for (i = 0; i < NUM_TRIGGER_STAGES; i++) { - zp->trigger_mask[i] = 0; - zp->trigger_value[i] = 0; + ctx->trigger_mask[i] = 0; + ctx->trigger_value[i] = 0; } stage = -1; @@ -314,14 +315,14 @@ static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) if (probe->enabled == FALSE) continue; probe_bit = 1 << (probe->index - 1); - zp->probe_mask |= probe_bit; + ctx->probe_mask |= probe_bit; if (probe->trigger) { stage = 0; for (tc = probe->trigger; *tc; tc++) { - zp->trigger_mask[stage] |= probe_bit; + ctx->trigger_mask[stage] |= probe_bit; if (*tc == '1') - zp->trigger_value[stage] |= probe_bit; + ctx->trigger_value[stage] |= probe_bit; stage++; if (stage > NUM_TRIGGER_STAGES) return SR_ERR; @@ -342,26 +343,26 @@ static int hw_init(const char *devinfo) struct libusb_device_descriptor des; libusb_device **devlist; int err, devcnt, i; - struct zp *zp; + struct context *ctx; /* Avoid compiler warnings. */ (void)devinfo; /* Allocate memory for our private driver context. */ - if (!(zp = g_try_malloc(sizeof(struct zp)))) { - sr_err("zp: %s: struct zp malloc failed", __func__); + if (!(ctx = g_try_malloc(sizeof(struct context)))) { + sr_err("zp: %s: ctx malloc failed", __func__); return 0; } /* Set some sane defaults. */ - zp->cur_samplerate = 0; - zp->limit_samples = 0; - zp->num_channels = 32; /* TODO: This isn't initialized before it's needed :( */ - zp->memory_size = 0; - zp->probe_mask = 0; - memset(zp->trigger_mask, 0, NUM_TRIGGER_STAGES); - memset(zp->trigger_value, 0, NUM_TRIGGER_STAGES); - // memset(zp->trigger_buffer, 0, NUM_TRIGGER_STAGES); + ctx->cur_samplerate = 0; + ctx->limit_samples = 0; + ctx->num_channels = 32; /* TODO: This isn't initialized before it's needed :( */ + ctx->memory_size = 0; + ctx->probe_mask = 0; + memset(ctx->trigger_mask, 0, NUM_TRIGGER_STAGES); + memset(ctx->trigger_value, 0, NUM_TRIGGER_STAGES); + // memset(ctx->trigger_buffer, 0, NUM_TRIGGER_STAGES); if (libusb_init(&usb_context) != 0) { sr_err("zp: Failed to initialize USB."); @@ -394,11 +395,11 @@ static int hw_init(const char *devinfo) return 0; } - sdi->priv = zp; + sdi->priv = ctx; dev_insts = g_slist_append(dev_insts, sdi); - zp->usb = sr_usb_dev_inst_new( + ctx->usb = sr_usb_dev_inst_new( libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); devcnt++; @@ -412,7 +413,7 @@ static int hw_init(const char *devinfo) static int hw_dev_open(int dev_index) { struct sr_dev_inst *sdi; - struct zp *zp; + struct context *ctx; int err; if (!(sdi = zp_open_dev(dev_index))) { @@ -422,26 +423,26 @@ static int hw_dev_open(int dev_index) /* TODO: Note: sdi is retrieved in zp_open_dev(). */ - if (!(zp = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; } - err = libusb_set_configuration(zp->usb->devhdl, USB_CONFIGURATION); + err = libusb_set_configuration(ctx->usb->devhdl, USB_CONFIGURATION); if (err < 0) { sr_err("zp: Unable to set USB configuration %d: %d", USB_CONFIGURATION, err); return SR_ERR; } - err = libusb_claim_interface(zp->usb->devhdl, USB_INTERFACE); + err = libusb_claim_interface(ctx->usb->devhdl, USB_INTERFACE); if (err != 0) { sr_err("zp: Unable to claim interface: %d", err); return SR_ERR; } - analyzer_reset(zp->usb->devhdl); - analyzer_initialize(zp->usb->devhdl); + analyzer_reset(ctx->usb->devhdl); + analyzer_initialize(ctx->usb->devhdl); analyzer_set_memory_size(MEMORY_SIZE_512K); // analyzer_set_freq(g_freq, g_freq_scale); @@ -460,7 +461,7 @@ static int hw_dev_open(int dev_index) #endif analyzer_set_compression(COMPRESSION_NONE); - if (zp->cur_samplerate == 0) { + if (ctx->cur_samplerate == 0) { /* Samplerate hasn't been set. Default to the slowest one. */ if (hw_dev_config_set(dev_index, SR_HWCAP_SAMPLERATE, &samplerates.list[0]) == SR_ERR) @@ -510,7 +511,7 @@ static int hw_cleanup(void) static void *hw_dev_info_get(int dev_index, int dev_info_id) { struct sr_dev_inst *sdi; - struct zp *zp; + struct context *ctx; void *info; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { @@ -518,7 +519,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) return NULL; } - if (!(zp = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return NULL; } @@ -528,7 +529,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = sdi; break; case SR_DI_NUM_PROBES: - info = GINT_TO_POINTER(zp->num_channels); + info = GINT_TO_POINTER(ctx->num_channels); break; case SR_DI_PROBE_NAMES: info = probe_names; @@ -540,7 +541,7 @@ static void *hw_dev_info_get(int dev_index, int dev_info_id) info = TRIGGER_TYPES; break; case SR_DI_CUR_SAMPLERATE: - info = &zp->cur_samplerate; + info = &ctx->cur_samplerate; break; default: /* Unknown device info ID, return NULL. */ @@ -570,14 +571,14 @@ static int *hw_hwcap_get_all(void) static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { - struct zp *zp; + struct context *ctx; if (!sdi) { sr_err("zp: %s: sdi was NULL", __func__); return SR_ERR_ARG; } - if (!(zp = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; } @@ -591,7 +592,7 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) else analyzer_set_freq(samplerate, FREQ_SCALE_HZ); - zp->cur_samplerate = samplerate; + ctx->cur_samplerate = samplerate; return SR_OK; } @@ -599,14 +600,14 @@ static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) static int hw_dev_config_set(int dev_index, int hwcap, void *value) { struct sr_dev_inst *sdi; - struct zp *zp; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("zp: %s: sdi was NULL", __func__); return SR_ERR; } - if (!(zp = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; } @@ -617,7 +618,7 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value) case SR_HWCAP_PROBECONFIG: return configure_probes(sdi, (GSList *)value); case SR_HWCAP_LIMIT_SAMPLES: - zp->limit_samples = *(uint64_t *)value; + ctx->limit_samples = *(uint64_t *)value; return SR_OK; default: return SR_ERR; @@ -634,38 +635,38 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) int res; unsigned int packet_num; unsigned char *buf; - struct zp *zp; + struct context *ctx; if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("zp: %s: sdi was NULL", __func__); return SR_ERR; } - if (!(zp = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_ARG; } /* push configured settings to device */ - analyzer_configure(zp->usb->devhdl); + analyzer_configure(ctx->usb->devhdl); - analyzer_start(zp->usb->devhdl); + analyzer_start(ctx->usb->devhdl); sr_info("zp: Waiting for data"); - analyzer_wait_data(zp->usb->devhdl); + analyzer_wait_data(ctx->usb->devhdl); sr_info("zp: Stop address = 0x%x", - analyzer_get_stop_address(zp->usb->devhdl)); + analyzer_get_stop_address(ctx->usb->devhdl)); sr_info("zp: Now address = 0x%x", - analyzer_get_now_address(zp->usb->devhdl)); + analyzer_get_now_address(ctx->usb->devhdl)); sr_info("zp: Trigger address = 0x%x", - analyzer_get_trigger_address(zp->usb->devhdl)); + analyzer_get_trigger_address(ctx->usb->devhdl)); packet.type = SR_DF_HEADER; packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); - header.samplerate = zp->cur_samplerate; - header.num_logic_probes = zp->num_channels; + header.samplerate = ctx->cur_samplerate; + header.num_logic_probes = ctx->num_channels; sr_session_bus(session_data, &packet); if (!(buf = g_try_malloc(PACKET_SIZE))) { @@ -674,11 +675,11 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) } samples_read = 0; - analyzer_read_start(zp->usb->devhdl); + analyzer_read_start(ctx->usb->devhdl); /* Send the incoming transfer to the session bus. */ - for (packet_num = 0; packet_num < (zp->memory_size * 4 / PACKET_SIZE); + for (packet_num = 0; packet_num < (ctx->memory_size * 4 / PACKET_SIZE); packet_num++) { - res = analyzer_read_data(zp->usb->devhdl, buf, PACKET_SIZE); + res = analyzer_read_data(ctx->usb->devhdl, buf, PACKET_SIZE); sr_info("zp: Tried to read %llx bytes, actually read %x bytes", PACKET_SIZE, res); @@ -690,7 +691,7 @@ static int hw_dev_acquisition_start(int dev_index, gpointer session_data) sr_session_bus(session_data, &packet); samples_read += res / 4; } - analyzer_read_stop(zp->usb->devhdl); + analyzer_read_stop(ctx->usb->devhdl); g_free(buf); packet.type = SR_DF_END; @@ -704,7 +705,7 @@ static int hw_dev_acquisition_stop(int dev_index, gpointer session_dev_id) { struct sr_datafeed_packet packet; struct sr_dev_inst *sdi; - struct zp *zp; + struct context *ctx; packet.type = SR_DF_END; sr_session_bus(session_dev_id, &packet); @@ -714,12 +715,12 @@ static int hw_dev_acquisition_stop(int dev_index, gpointer session_dev_id) return SR_ERR_BUG; } - if (!(zp = sdi->priv)) { + if (!(ctx = sdi->priv)) { sr_err("zp: %s: sdi->priv was NULL", __func__); return SR_ERR_BUG; } - analyzer_reset(zp->usb->devhdl); + analyzer_reset(ctx->usb->devhdl); /* TODO: Need to cancel and free any queued up transfers. */ return SR_OK;