X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fasix-sigma%2Fasix-sigma.c;h=77f3e3507787a2797caab5821ee680bfd1632d49;hb=5097b0d0912165429aceddb5febbf68467b623f5;hp=50bb932db26030405a611ebd684c916a8ff02521;hpb=86f5e3d826fc9059e110f07221cb1a30652ceac2;p=libsigrok.git diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 50bb932d..77f3e350 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -23,14 +23,13 @@ * ASIX SIGMA Logic Analyzer Driver */ -#include "config.h" #include #include #include #include #include -#include -#include +#include "sigrok.h" +#include "sigrok-internal.h" #include "asix-sigma.h" #define USB_VENDOR 0xa600 @@ -40,8 +39,9 @@ #define USB_MODEL_NAME "SIGMA" #define USB_MODEL_VERSION "" #define TRIGGER_TYPES "rf10" +#define NUM_PROBES 16 -static GSList *device_instances = NULL; +static GSList *dev_insts = NULL; static uint64_t supported_samplerates[] = { SR_KHZ(200), @@ -57,6 +57,26 @@ static uint64_t supported_samplerates[] = { 0, }; +static const char *probe_names[NUM_PROBES + 1] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "15", + NULL, +}; + static struct sr_samplerates samplerates = { SR_KHZ(200), SR_MHZ(200), @@ -64,7 +84,7 @@ static struct sr_samplerates samplerates = { supported_samplerates, }; -static int capabilities[] = { +static int hwcaps[] = { SR_HWCAP_LOGIC_ANALYZER, SR_HWCAP_SAMPLERATE, SR_HWCAP_CAPTURE_RATIO, @@ -98,7 +118,7 @@ static const char *firmware_files[] = { "asix-sigma-phasor.fw", /* Frequency counter */ }; -static void hw_stop_acquisition(int device_index, gpointer session_device_id); +static int hw_stop_acquisition(int dev_index, gpointer session_data); static int sigma_read(void *buf, size_t size, struct sigma *sigma) { @@ -106,8 +126,8 @@ static int sigma_read(void *buf, size_t size, struct sigma *sigma) ret = ftdi_read_data(&sigma->ftdic, (unsigned char *)buf, size); if (ret < 0) { - sr_warn("ftdi_read_data failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + sr_err("sigma: ftdi_read_data failed: %s", + ftdi_get_error_string(&sigma->ftdic)); } return ret; @@ -119,10 +139,10 @@ static int sigma_write(void *buf, size_t size, struct sigma *sigma) ret = ftdi_write_data(&sigma->ftdic, (unsigned char *)buf, size); if (ret < 0) { - sr_warn("ftdi_write_data failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + sr_err("sigma: ftdi_write_data failed: %s", + ftdi_get_error_string(&sigma->ftdic)); } else if ((size_t) ret != size) { - sr_warn("ftdi_write_data did not complete write\n"); + sr_err("sigma: ftdi_write_data did not complete write\n"); } return ret; @@ -170,7 +190,7 @@ static uint8_t sigma_get_register(uint8_t reg, struct sigma *sigma) uint8_t value; if (1 != sigma_read_register(reg, &value, 1, sigma)) { - sr_warn("sigma_get_register: 1 byte expected"); + sr_err("sigma: sigma_get_register: 1 byte expected"); return 0; } @@ -317,12 +337,12 @@ static int bin2bitbang(const char *filename, f = g_fopen(filename, "rb"); if (!f) { - sr_warn("g_fopen(\"%s\", \"rb\")", filename); + sr_err("sigma: g_fopen(\"%s\", \"rb\")", filename); return SR_ERR; } if (-1 == fseek(f, 0, SEEK_END)) { - sr_warn("fseek on %s failed", filename); + sr_err("sigma: fseek on %s failed", filename); fclose(f); return SR_ERR; } @@ -332,13 +352,13 @@ static int bin2bitbang(const char *filename, fseek(f, 0, SEEK_SET); if (!(compressed_buf = g_try_malloc(file_size))) { - sr_err("asix: %s: compressed_buf malloc failed", __func__); + sr_err("sigma: %s: compressed_buf malloc failed", __func__); fclose(f); return SR_ERR_MALLOC; } if (!(firmware = g_try_malloc(buffer_size))) { - sr_err("asix: %s: firmware malloc failed", __func__); + sr_err("sigma: %s: firmware malloc failed", __func__); fclose(f); g_free(compressed_buf); return SR_ERR_MALLOC; @@ -356,7 +376,8 @@ static int bin2bitbang(const char *filename, if (ret < 0) { g_free(compressed_buf); g_free(firmware); - sr_warn("Could not unpack Sigma firmware. (Error %d)\n", ret); + sr_err("sigma: Could not unpack Sigma firmware. " + "(Error %d)\n", ret); return SR_ERR; } @@ -366,7 +387,7 @@ static int bin2bitbang(const char *filename, *buf = p = (unsigned char *)g_try_malloc(*buf_size); if (!p) { - sr_err("asix: %s: buf/p malloc failed", __func__); + sr_err("sigma: %s: buf/p malloc failed", __func__); g_free(compressed_buf); g_free(firmware); return SR_ERR_MALLOC; @@ -384,9 +405,9 @@ static int bin2bitbang(const char *filename, if (offset != *buf_size) { g_free(*buf); - sr_warn("Error reading firmware %s " - "offset=%ld, file_size=%ld, buf_size=%zd\n", - filename, offset, file_size, *buf_size); + sr_err("sigma: Error reading firmware %s " + "offset=%ld, file_size=%ld, buf_size=%zd\n", + filename, offset, file_size, *buf_size); return SR_ERR; } @@ -394,16 +415,16 @@ static int bin2bitbang(const char *filename, return SR_OK; } -static int hw_init(const char *deviceinfo) +static int hw_init(const char *devinfo) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct sigma *sigma; /* Avoid compiler warnings. */ - deviceinfo = deviceinfo; + (void)devinfo; if (!(sigma = g_try_malloc(sizeof(struct sigma)))) { - sr_err("asix: %s: sigma malloc failed", __func__); + sr_err("sigma: %s: sigma malloc failed", __func__); return 0; /* FIXME: Should be SR_ERR_MALLOC. */ } @@ -415,6 +436,7 @@ static int hw_init(const char *deviceinfo) goto free; sigma->cur_samplerate = 0; + sigma->period_ps = 0; sigma->limit_msec = 0; sigma->cur_firmware = -1; sigma->num_probes = 0; @@ -423,14 +445,15 @@ static int hw_init(const char *deviceinfo) sigma->use_triggers = 0; /* Register SIGMA device. */ - sdi = sr_device_instance_new(0, SR_ST_INITIALIZING, - USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION); - if (!sdi) + if (!(sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING, USB_VENDOR_NAME, + USB_MODEL_NAME, USB_MODEL_VERSION))) { + sr_err("sigma: %s: sdi was NULL", __func__); goto free; + } sdi->priv = sigma; - device_instances = g_slist_append(device_instances, sdi); + dev_insts = g_slist_append(dev_insts, sdi); /* We will open the device again when we need it. */ ftdi_usb_close(&sigma->ftdic); @@ -453,21 +476,21 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) /* Make sure it's an ASIX SIGMA. */ if ((ret = ftdi_usb_open_desc(&sigma->ftdic, USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) { - sr_warn("ftdi_usb_open failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + sr_err("sigma: ftdi_usb_open failed: %s", + ftdi_get_error_string(&sigma->ftdic)); return 0; } if ((ret = ftdi_set_bitmode(&sigma->ftdic, 0xdf, BITMODE_BITBANG)) < 0) { - sr_warn("ftdi_set_bitmode failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + sr_err("sigma: ftdi_set_bitmode failed: %s", + ftdi_get_error_string(&sigma->ftdic)); return 0; } /* Four times the speed of sigmalogan - Works well. */ if ((ret = ftdi_set_baudrate(&sigma->ftdic, 750000)) < 0) { - sr_warn("ftdi_set_baudrate failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + sr_err("sigma: ftdi_set_baudrate failed: %s", + ftdi_get_error_string(&sigma->ftdic)); return 0; } @@ -494,8 +517,8 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) firmware_files[firmware_idx]); if ((ret = bin2bitbang(firmware_path, &buf, &buf_size)) != SR_OK) { - sr_warn("An error occured while reading the firmware: %s", - firmware_path); + sr_err("sigma: An error occured while reading the firmware: %s", + firmware_path); return ret; } @@ -505,8 +528,8 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) g_free(buf); if ((ret = ftdi_set_bitmode(&sigma->ftdic, 0x00, BITMODE_RESET)) < 0) { - sr_warn("ftdi_set_bitmode failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + sr_err("sigma: ftdi_set_bitmode failed: %s", + ftdi_get_error_string(&sigma->ftdic)); return SR_ERR; } @@ -523,7 +546,7 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) ret = sigma_read(result, 3, sigma); if (ret != 3 || result[0] != 0xa6 || result[1] != 0x55 || result[2] != 0xaa) { - sr_warn("Configuration failed. Invalid reply received."); + sr_err("sigma: Configuration failed. Invalid reply received."); return SR_ERR; } @@ -532,13 +555,13 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) return SR_OK; } -static int hw_opendev(int device_index) +static int hw_opendev(int dev_index) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct sigma *sigma; int ret; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; sigma = sdi->priv; @@ -547,8 +570,8 @@ static int hw_opendev(int device_index) if ((ret = ftdi_usb_open_desc(&sigma->ftdic, USB_VENDOR, USB_PRODUCT, USB_DESCRIPTION, NULL)) < 0) { - sr_warn("ftdi_usb_open failed: %s", - ftdi_get_error_string(&sigma->ftdic)); + sr_err("sigma: ftdi_usb_open failed: %s", + ftdi_get_error_string(&sigma->ftdic)); return 0; } @@ -558,8 +581,7 @@ static int hw_opendev(int device_index) return SR_OK; } -static int set_samplerate(struct sr_device_instance *sdi, - uint64_t samplerate) +static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { int i, ret; struct sigma *sigma = sdi->priv; @@ -585,10 +607,11 @@ static int set_samplerate(struct sr_device_instance *sdi, } sigma->cur_samplerate = samplerate; + sigma->period_ps = 1000000000000 / samplerate; sigma->samples_per_event = 16 / sigma->num_probes; sigma->state.state = SIGMA_IDLE; - sr_info("Firmware uploaded"); + sr_info("sigma: Firmware uploaded"); return ret; } @@ -601,7 +624,7 @@ static int set_samplerate(struct sr_device_instance *sdi, * The Sigma supports complex triggers using boolean expressions, but this * has not been implemented yet. */ -static int configure_probes(struct sr_device_instance *sdi, GSList *probes) +static int configure_probes(struct sr_dev_inst *sdi, GSList *probes) { struct sigma *sigma = sdi->priv; struct sr_probe *probe; @@ -621,8 +644,8 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) if (sigma->cur_samplerate >= SR_MHZ(100)) { /* Fast trigger support. */ if (trigger_set) { - sr_warn("ASIX SIGMA only supports a single " - "pin trigger in 100 and 200MHz mode."); + sr_err("sigma: ASIX SIGMA only supports a single " + "pin trigger in 100 and 200MHz mode."); return SR_ERR; } if (probe->trigger[0] == 'f') @@ -630,9 +653,9 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) else if (probe->trigger[0] == 'r') sigma->trigger.risingmask |= probebit; else { - sr_warn("ASIX SIGMA only supports " - "rising/falling trigger in 100 " - "and 200MHz mode."); + sr_err("sigma: ASIX SIGMA only supports " + "rising/falling trigger in 100 " + "and 200MHz mode."); return SR_ERR; } @@ -662,8 +685,8 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) * does not permit ORed triggers. */ if (trigger_set > 1) { - sr_warn("ASIX SIGMA only supports 1 rising/" - "falling triggers."); + sr_err("sigma: ASIX SIGMA only supports 1 " + "rising/falling triggers."); return SR_ERR; } } @@ -675,56 +698,74 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) return SR_OK; } -static void hw_closedev(int device_index) +static int hw_closedev(int dev_index) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct sigma *sigma; - if ((sdi = sr_get_device_instance(device_instances, device_index))) - { - sigma = sdi->priv; - if (sdi->status == SR_ST_ACTIVE) - ftdi_usb_close(&sigma->ftdic); + 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? */ + } - sdi->status = SR_ST_INACTIVE; + if (!(sigma = 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); + + sdi->status = SR_ST_INACTIVE; + + return SR_OK; } -static void hw_cleanup(void) +static int hw_cleanup(void) { GSList *l; - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; + int ret = SR_OK; /* Properly close all devices. */ - for (l = device_instances; l; l = l->next) { - sdi = l->data; - if (sdi->priv != NULL) - free(sdi->priv); - sr_device_instance_free(sdi); + for (l = dev_insts; l; l = l->next) { + if (!(sdi = l->data)) { + /* Log error, but continue cleaning up the rest. */ + sr_err("sigma: %s: sdi was NULL, continuing", __func__); + ret = SR_ERR_BUG; + continue; + } + sr_dev_inst_free(sdi); } - g_slist_free(device_instances); - device_instances = NULL; + g_slist_free(dev_insts); + dev_insts = NULL; + + return ret; } -static void *hw_get_device_info(int device_index, int device_info_id) +static void *hw_dev_info_get(int dev_index, int dev_info_id) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct sigma *sigma; void *info = NULL; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { - fprintf(stderr, "It's NULL.\n"); + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { + sr_err("sigma: %s: sdi was NULL", __func__); return NULL; } sigma = sdi->priv; - switch (device_info_id) { - case SR_DI_INSTANCE: + switch (dev_info_id) { + case SR_DI_INST: info = sdi; break; case SR_DI_NUM_PROBES: - info = GINT_TO_POINTER(16); + info = GINT_TO_POINTER(NUM_PROBES); + break; + case SR_DI_PROBE_NAMES: + info = probe_names; break; case SR_DI_SAMPLERATES: info = &samplerates; @@ -740,44 +781,44 @@ static void *hw_get_device_info(int device_index, int device_info_id) return info; } -static int hw_get_status(int device_index) +static int hw_get_status(int dev_index) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; - sdi = sr_get_device_instance(device_instances, device_index); + sdi = sr_dev_inst_get(dev_insts, dev_index); if (sdi) return sdi->status; else return SR_ST_NOT_FOUND; } -static int *hw_get_capabilities(void) +static int *hw_hwcap_get_all(void) { - return capabilities; + return hwcaps; } -static int hw_set_configuration(int device_index, int capability, void *value) +static int hw_config_set(int dev_index, int hwcap, void *value) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct sigma *sigma; int ret; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; sigma = sdi->priv; - if (capability == SR_HWCAP_SAMPLERATE) { + if (hwcap == SR_HWCAP_SAMPLERATE) { ret = set_samplerate(sdi, *(uint64_t*) value); - } else if (capability == SR_HWCAP_PROBECONFIG) { + } else if (hwcap == SR_HWCAP_PROBECONFIG) { ret = configure_probes(sdi, value); - } else if (capability == SR_HWCAP_LIMIT_MSEC) { + } else if (hwcap == SR_HWCAP_LIMIT_MSEC) { sigma->limit_msec = *(uint64_t*) value; if (sigma->limit_msec > 0) ret = SR_OK; else ret = SR_ERR; - } else if (capability == SR_HWCAP_CAPTURE_RATIO) { + } else if (hwcap == SR_HWCAP_CAPTURE_RATIO) { sigma->capture_ratio = *(uint64_t*) value; if (sigma->capture_ratio < 0 || sigma->capture_ratio > 100) ret = SR_ERR; @@ -832,13 +873,14 @@ static int get_trigger_offset(uint16_t *samples, uint16_t last_sample, */ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, uint16_t *lastsample, int triggerpos, - uint16_t limit_chunk, void *user_data) + uint16_t limit_chunk, void *session_data) { - struct sr_device_instance *sdi = user_data; + struct sr_dev_inst *sdi = session_data; struct sigma *sigma = sdi->priv; uint16_t tsdiff, ts; uint16_t samples[65536 * sigma->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; @@ -883,9 +925,10 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, tosend = MIN(2048, n - sent); packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples + sent; sr_session_bus(sigma->session_id, &packet); sent += tosend; @@ -927,9 +970,10 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, if (tosend > 0) { packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples; sr_session_bus(sigma->session_id, &packet); sent += tosend; @@ -938,8 +982,6 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, /* Only send trigger if explicitly enabled. */ if (sigma->use_triggers) { packet.type = SR_DF_TRIGGER; - packet.length = 0; - packet.payload = 0; sr_session_bus(sigma->session_id, &packet); } } @@ -949,9 +991,10 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, if (tosend > 0) { packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples + sent; sr_session_bus(sigma->session_id, &packet); } @@ -961,9 +1004,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, return SR_OK; } -static int receive_data(int fd, int revents, void *user_data) +static int receive_data(int fd, int revents, void *session_data) { - struct sr_device_instance *sdi = user_data; + struct sr_dev_inst *sdi = session_data; struct sigma *sigma = sdi->priv; struct sr_datafeed_packet packet; const int chunks_per_read = 32; @@ -972,8 +1015,9 @@ static int receive_data(int fd, int revents, void *user_data) uint64_t running_msec; struct timeval tv; - fd = fd; - revents = revents; + /* Avoid compiler warnings. */ + (void)fd; + (void)revents; numchunks = (sigma->state.stoppos + 511) / 512; @@ -990,7 +1034,7 @@ static int receive_data(int fd, int revents, void *user_data) if (running_msec < sigma->limit_msec && numchunks < 32767) return FALSE; - hw_stop_acquisition(sdi->index, user_data); + hw_stop_acquisition(sdi->index, session_data); return FALSE; @@ -998,7 +1042,6 @@ static int receive_data(int fd, int revents, void *user_data) if (sigma->state.chunks_downloaded >= numchunks) { /* End of samples. */ packet.type = SR_DF_END; - packet.length = 0; sr_session_bus(sigma->session_id, &packet); sigma->state.state = SIGMA_IDLE; @@ -1009,11 +1052,13 @@ static int receive_data(int fd, int revents, void *user_data) newchunks = MIN(chunks_per_read, numchunks - sigma->state.chunks_downloaded); - sr_info("Downloading sample data: %.0f %%", + sr_info("sigma: Downloading sample data: %.0f %%", 100.0 * sigma->state.chunks_downloaded / numchunks); bufsz = sigma_read_dram(sigma->state.chunks_downloaded, newchunks, buf, sigma); + /* TODO: Check bufsz. For now, just avoid compiler warnings. */ + (void)bufsz; /* Find first ts. */ if (sigma->state.chunks_downloaded == 0) { @@ -1037,12 +1082,12 @@ static int receive_data(int fd, int revents, void *user_data) &sigma->state.lastts, &sigma->state.lastsample, sigma->state.triggerpos & 0x1ff, - limit_chunk, user_data); + limit_chunk, session_data); else decode_chunk_ts(buf + (i * CHUNK_SIZE), &sigma->state.lastts, &sigma->state.lastsample, - -1, limit_chunk, user_data); + -1, limit_chunk, session_data); ++sigma->state.chunks_downloaded; } @@ -1207,9 +1252,9 @@ static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma) return SR_OK; } -static int hw_start_acquisition(int device_index, gpointer session_device_id) +static int hw_start_acquisition(int dev_index, gpointer session_data) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct sigma *sigma; struct sr_datafeed_packet packet; struct sr_datafeed_header header; @@ -1219,9 +1264,10 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) struct triggerinout triggerinout_conf; struct triggerlut lut; - session_device_id = session_device_id; + /* Avoid compiler warnings. */ + (void)session_data; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) return SR_ERR; sigma = sdi->priv; @@ -1304,19 +1350,16 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) gettimeofday(&sigma->start_tv, 0); sigma_set_register(WRITE_MODE, 0x0d, sigma); - sigma->session_id = session_device_id; + sigma->session_id = session_data; /* Send header packet to the session bus. */ packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.samplerate = sigma->cur_samplerate; - header.protocol_id = SR_PROTO_RAW; header.num_logic_probes = sigma->num_probes; - header.num_analog_probes = 0; - sr_session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); /* Add capture source. */ sr_source_add(0, G_IO_IN, 10, receive_data, sdi); @@ -1326,18 +1369,24 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) return SR_OK; } -static void hw_stop_acquisition(int device_index, gpointer session_device_id) +static int hw_stop_acquisition(int dev_index, gpointer session_data) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct sigma *sigma; uint8_t modestatus; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) - return; + /* Avoid compiler warnings. */ + (void)session_data; - sigma = sdi->priv; + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { + sr_err("sigma: %s: sdi was NULL", __func__); + return SR_ERR_BUG; + } - session_device_id = session_device_id; + if (!(sigma = sdi->priv)) { + sr_err("sigma: %s: sdi->priv was NULL", __func__); + return SR_ERR_BUG; + } /* Stop acquisition. */ sigma_set_register(WRITE_MODE, 0x11, sigma); @@ -1350,18 +1399,19 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) /* Check if trigger has fired. */ modestatus = sigma_get_register(READ_MODE, sigma); - if (modestatus & 0x20) { + if (modestatus & 0x20) sigma->state.triggerchunk = sigma->state.triggerpos / 512; - - } else + else sigma->state.triggerchunk = -1; sigma->state.chunks_downloaded = 0; sigma->state.state = SIGMA_DOWNLOAD; + + return SR_OK; } -struct sr_device_plugin asix_sigma_plugin_info = { +SR_PRIV struct sr_dev_plugin asix_sigma_plugin_info = { .name = "asix-sigma", .longname = "ASIX SIGMA", .api_version = 1, @@ -1369,10 +1419,10 @@ struct sr_device_plugin asix_sigma_plugin_info = { .cleanup = hw_cleanup, .opendev = hw_opendev, .closedev = hw_closedev, - .get_device_info = hw_get_device_info, + .dev_info_get = hw_dev_info_get, .get_status = hw_get_status, - .get_capabilities = hw_get_capabilities, - .set_configuration = hw_set_configuration, + .hwcap_get_all = hw_hwcap_get_all, + .config_set = hw_config_set, .start_acquisition = hw_start_acquisition, .stop_acquisition = hw_stop_acquisition, };