X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fasix-sigma%2Fasix-sigma.c;h=9f85d5f7d9e90899c35cf1ba5e72ec4c70044862;hb=d68e2d1a21ac5c3f24d88b7689f98764e4d57c30;hp=5b6417d9b8c1cbba135c8b4b045adabbb483a8da;hpb=c91404191e6b31ffe40edd8de469876a02c81d57;p=libsigrok.git diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 5b6417d9..9f85d5f7 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -20,16 +20,16 @@ */ /* - * ASIX Sigma Logic Analyzer Driver + * ASIX SIGMA Logic Analyzer Driver */ -#include "config.h" #include #include #include #include #include -#include +#include "sigrok.h" +#include "sigrok-internal.h" #include "asix-sigma.h" #define USB_VENDOR 0xa600 @@ -39,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), @@ -56,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), @@ -97,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 device_index, gpointer session_data); static int sigma_read(void *buf, size_t size, struct sigma *sigma) { @@ -105,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) { - g_warning("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; @@ -118,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) { - g_warning("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) { - g_warning("ftdi_write_data did not complete write\n"); + sr_err("sigma: ftdi_write_data did not complete write\n"); } return ret; @@ -169,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)) { - g_warning("Sigma_get_register: 1 byte expected"); + sr_err("sigma: sigma_get_register: 1 byte expected"); return 0; } @@ -316,26 +337,31 @@ static int bin2bitbang(const char *filename, f = g_fopen(filename, "rb"); if (!f) { - g_warning("g_fopen(\"%s\", \"rb\")", filename); - return -1; + sr_err("sigma: g_fopen(\"%s\", \"rb\")", filename); + return SR_ERR; } if (-1 == fseek(f, 0, SEEK_END)) { - g_warning("fseek on %s failed", filename); + sr_err("sigma: fseek on %s failed", filename); fclose(f); - return -1; + return SR_ERR; } file_size = ftell(f); fseek(f, 0, SEEK_SET); - compressed_buf = g_malloc(file_size); - firmware = g_malloc(buffer_size); + if (!(compressed_buf = g_try_malloc(file_size))) { + sr_err("sigma: %s: compressed_buf malloc failed", __func__); + fclose(f); + return SR_ERR_MALLOC; + } - if (!compressed_buf || !firmware) { - g_warning("Error allocating buffers"); - return -1; + if (!(firmware = g_try_malloc(buffer_size))) { + sr_err("sigma: %s: firmware malloc failed", __func__); + fclose(f); + g_free(compressed_buf); + return SR_ERR_MALLOC; } csize = 0; @@ -350,19 +376,21 @@ static int bin2bitbang(const char *filename, if (ret < 0) { g_free(compressed_buf); g_free(firmware); - g_warning("Could not unpack Sigma firmware. (Error %d)\n", ret); - return -1; + sr_err("sigma: Could not unpack Sigma firmware. " + "(Error %d)\n", ret); + return SR_ERR; } g_free(compressed_buf); *buf_size = fwsize * 2 * 8; - *buf = p = (unsigned char *)g_malloc(*buf_size); - + *buf = p = (unsigned char *)g_try_malloc(*buf_size); if (!p) { - g_warning("Error allocating buffers"); - return -1; + sr_err("sigma: %s: buf/p malloc failed", __func__); + g_free(compressed_buf); + g_free(firmware); + return SR_ERR_MALLOC; } for (i = 0; i < fwsize; ++i) { @@ -377,25 +405,28 @@ static int bin2bitbang(const char *filename, if (offset != *buf_size) { g_free(*buf); - g_warning("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 -1; + return SR_ERR; } - return 0; + return SR_OK; } static int hw_init(const char *deviceinfo) { - struct sr_device_instance *sdi; - struct sigma *sigma = g_malloc(sizeof(struct sigma)); + struct sr_dev_inst *sdi; + struct sigma *sigma; - deviceinfo = deviceinfo; + /* Avoid compiler warnings. */ + (void)deviceinfo; - if (!sigma) - return 0; + if (!(sigma = g_try_malloc(sizeof(struct sigma)))) { + sr_err("sigma: %s: sigma malloc failed", __func__); + return 0; /* FIXME: Should be SR_ERR_MALLOC. */ + } ftdi_init(&sigma->ftdic); @@ -405,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; @@ -413,21 +445,22 @@ 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); return 1; free: - free(sigma); + g_free(sigma); return 0; } @@ -443,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) { - g_warning("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) { - g_warning("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) { - g_warning("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; } @@ -483,10 +516,10 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) snprintf(firmware_path, sizeof(firmware_path), "%s/%s", FIRMWARE_DIR, firmware_files[firmware_idx]); - if (-1 == bin2bitbang(firmware_path, &buf, &buf_size)) { - g_warning("An error occured while reading the firmware: %s", - firmware_path); - return SR_ERR; + if ((ret = bin2bitbang(firmware_path, &buf, &buf_size)) != SR_OK) { + sr_err("sigma: An error occured while reading the firmware: %s", + firmware_path); + return ret; } /* Upload firmare. */ @@ -495,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) { - g_warning("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; } @@ -513,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) { - g_warning("Configuration failed. Invalid reply received."); + sr_err("sigma: Configuration failed. Invalid reply received."); return SR_ERR; } @@ -524,11 +557,11 @@ static int upload_firmware(int firmware_idx, struct sigma *sigma) static int hw_opendev(int device_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, device_index))) return SR_ERR; sigma = sdi->priv; @@ -537,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) { - g_warning("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; } @@ -548,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; @@ -575,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; - g_message("Firmware uploaded"); + sr_info("sigma: Firmware uploaded"); return ret; } @@ -591,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; @@ -611,9 +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) { - g_warning("Asix Sigma only supports a single " - "pin trigger in 100 and 200 " - "MHz 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') @@ -621,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 { - g_warning("Asix Sigma only supports " - "rising/falling trigger in 100 " - "and 200 MHz mode."); + sr_err("sigma: ASIX SIGMA only supports " + "rising/falling trigger in 100 " + "and 200MHz mode."); return SR_ERR; } @@ -653,8 +685,8 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) * does not permit ORed triggers. */ if (trigger_set > 1) { - g_warning("Asix Sigma only supports 1 rising/" - "falling triggers."); + sr_err("sigma: ASIX SIGMA only supports 1 " + "rising/falling triggers."); return SR_ERR; } } @@ -666,45 +698,60 @@ 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 device_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, device_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) { - 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, device_index))) { + sr_err("sigma: %s: sdi was NULL", __func__); return NULL; } @@ -715,7 +762,10 @@ static void *hw_get_device_info(int device_index, int device_info_id) 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; @@ -733,9 +783,9 @@ static void *hw_get_device_info(int device_index, int device_info_id) static int hw_get_status(int device_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, device_index); if (sdi) return sdi->status; else @@ -749,11 +799,11 @@ static int *hw_get_capabilities(void) static int hw_set_configuration(int device_index, int capability, 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, device_index))) return SR_ERR; sigma = sdi->priv; @@ -823,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; @@ -874,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; @@ -918,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; @@ -929,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); } } @@ -940,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); } @@ -952,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; @@ -963,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; @@ -981,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; @@ -989,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; @@ -1000,11 +1052,13 @@ static int receive_data(int fd, int revents, void *user_data) newchunks = MIN(chunks_per_read, numchunks - sigma->state.chunks_downloaded); - g_message("Downloading sample data: %.0f %%", - 100.0 * sigma->state.chunks_downloaded / numchunks); + 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) { @@ -1028,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; } @@ -1198,29 +1252,31 @@ 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 device_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; struct clockselect_50 clockselect; - int frac; + int frac, triggerpin, ret; uint8_t triggerselect; struct triggerinout triggerinout_conf; struct triggerlut lut; - int triggerpin; - 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, device_index))) return SR_ERR; sigma = sdi->priv; /* If the samplerate has not been set, default to 200 KHz. */ - if (sigma->cur_firmware == -1) - set_samplerate(sdi, SR_KHZ(200)); + if (sigma->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); @@ -1294,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); @@ -1316,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 device_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, device_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); @@ -1340,29 +1399,30 @@ 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 = { - "asix-sigma", - "ASIX SIGMA", - 1, - hw_init, - hw_cleanup, - hw_opendev, - hw_closedev, - hw_get_device_info, - hw_get_status, - hw_get_capabilities, - hw_set_configuration, - hw_start_acquisition, - hw_stop_acquisition, +SR_PRIV struct sr_device_plugin asix_sigma_plugin_info = { + .name = "asix-sigma", + .longname = "ASIX SIGMA", + .api_version = 1, + .init = hw_init, + .cleanup = hw_cleanup, + .opendev = hw_opendev, + .closedev = hw_closedev, + .get_device_info = hw_get_device_info, + .get_status = hw_get_status, + .get_capabilities = hw_get_capabilities, + .set_configuration = hw_set_configuration, + .start_acquisition = hw_start_acquisition, + .stop_acquisition = hw_stop_acquisition, };