X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fasix-sigma%2Fasix-sigma.c;h=e7d6f7833103bd608a4a29344bbec7ec2ad9f4ea;hb=719c5a934c7705466a449854b876b9962eb4cb5e;hp=1162b63cfbe3d81deab961370157344c9a640d07;hpb=a00ba012288726678e1a270961c8d4f46f3dbd33;p=libsigrok.git diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 1162b63c..e7d6f783 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -20,14 +20,17 @@ */ /* - * ASIX Sigma Logic Analyzer Driver + * ASIX SIGMA Logic Analyzer Driver */ +#include "config.h" +#include +#include #include #include #include #include -#include +#include #include "asix-sigma.h" #define USB_VENDOR 0xa600 @@ -41,33 +44,33 @@ static GSList *device_instances = NULL; static uint64_t supported_samplerates[] = { - KHZ(200), - KHZ(250), - KHZ(500), - MHZ(1), - MHZ(5), - MHZ(10), - MHZ(25), - MHZ(50), - MHZ(100), - MHZ(200), + SR_KHZ(200), + SR_KHZ(250), + SR_KHZ(500), + SR_MHZ(1), + SR_MHZ(5), + SR_MHZ(10), + SR_MHZ(25), + SR_MHZ(50), + SR_MHZ(100), + SR_MHZ(200), 0, }; -static struct samplerates samplerates = { - KHZ(200), - MHZ(200), - 0, +static struct sr_samplerates samplerates = { + SR_KHZ(200), + SR_MHZ(200), + SR_HZ(0), supported_samplerates, }; static int capabilities[] = { - HWCAP_LOGIC_ANALYZER, - HWCAP_SAMPLERATE, - HWCAP_CAPTURE_RATIO, - HWCAP_PROBECONFIG, + SR_HWCAP_LOGIC_ANALYZER, + SR_HWCAP_SAMPLERATE, + SR_HWCAP_CAPTURE_RATIO, + SR_HWCAP_PROBECONFIG, - HWCAP_LIMIT_MSEC, + SR_HWCAP_LIMIT_MSEC, 0, }; @@ -95,7 +98,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 void hw_stop_acquisition(int device_index, gpointer session_data); static int sigma_read(void *buf, size_t size, struct sigma *sigma) { @@ -103,8 +106,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_warn("ftdi_read_data failed: %s", + ftdi_get_error_string(&sigma->ftdic)); } return ret; @@ -116,10 +119,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_warn("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_warn("ftdi_write_data did not complete write\n"); } return ret; @@ -167,7 +170,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_warn("sigma_get_register: 1 byte expected"); return 0; } @@ -312,28 +315,33 @@ static int bin2bitbang(const char *filename, int c, ret, bit, v; uint32_t imm = 0x3f6df2ab; - f = fopen(filename, "r"); + f = g_fopen(filename, "rb"); if (!f) { - g_warning("fopen(\"%s\", \"r\")", filename); - return -1; + sr_warn("g_fopen(\"%s\", \"rb\")", filename); + return SR_ERR; } if (-1 == fseek(f, 0, SEEK_END)) { - g_warning("fseek on %s failed", filename); + sr_warn("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; @@ -348,19 +356,20 @@ 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_warn("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) { @@ -375,25 +384,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_warn("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(char *deviceinfo) +static int hw_init(const char *deviceinfo) { struct sr_device_instance *sdi; - struct sigma *sigma = g_malloc(sizeof(struct sigma)); + struct sigma *sigma; + /* Avoid compiler warnings. */ deviceinfo = 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); @@ -403,6 +415,7 @@ static int hw_init(char *deviceinfo) goto free; sigma->cur_samplerate = 0; + sigma->period_ps = 0; sigma->limit_msec = 0; sigma->cur_firmware = -1; sigma->num_probes = 0; @@ -411,7 +424,7 @@ static int hw_init(char *deviceinfo) sigma->use_triggers = 0; /* Register SIGMA device. */ - sdi = sr_device_instance_new(0, ST_INITIALIZING, + sdi = sr_device_instance_new(0, SR_ST_INITIALIZING, USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION); if (!sdi) goto free; @@ -425,7 +438,7 @@ static int hw_init(char *deviceinfo) return 1; free: - free(sigma); + g_free(sigma); return 0; } @@ -441,21 +454,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_warn("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_warn("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_warn("ftdi_set_baudrate failed: %s", + ftdi_get_error_string(&sigma->ftdic)); return 0; } @@ -481,10 +494,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_warn("An error occured while reading the firmware: %s", + firmware_path); + return ret; } /* Upload firmare. */ @@ -493,8 +506,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_warn("ftdi_set_bitmode failed: %s", + ftdi_get_error_string(&sigma->ftdic)); return SR_ERR; } @@ -511,7 +524,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_warn("Configuration failed. Invalid reply received."); return SR_ERR; } @@ -526,7 +539,7 @@ static int hw_opendev(int device_index) struct sigma *sigma; int ret; - if (!(sdi = get_sr_device_instance(device_instances, device_index))) + if (!(sdi = sr_get_device_instance(device_instances, device_index))) return SR_ERR; sigma = sdi->priv; @@ -535,13 +548,13 @@ 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", + sr_warn("ftdi_usb_open failed: %s", ftdi_get_error_string(&sigma->ftdic)); return 0; } - sdi->status = ST_ACTIVE; + sdi->status = SR_ST_ACTIVE; return SR_OK; } @@ -559,24 +572,25 @@ static int set_samplerate(struct sr_device_instance *sdi, if (supported_samplerates[i] == 0) return SR_ERR_SAMPLERATE; - if (samplerate <= MHZ(50)) { + if (samplerate <= SR_MHZ(50)) { ret = upload_firmware(0, sigma); sigma->num_probes = 16; } - if (samplerate == MHZ(100)) { + if (samplerate == SR_MHZ(100)) { ret = upload_firmware(1, sigma); sigma->num_probes = 8; } - else if (samplerate == MHZ(200)) { + else if (samplerate == SR_MHZ(200)) { ret = upload_firmware(2, sigma); sigma->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; - g_message("Firmware uploaded"); + sr_info("Firmware uploaded"); return ret; } @@ -592,7 +606,7 @@ static int set_samplerate(struct sr_device_instance *sdi, static int configure_probes(struct sr_device_instance *sdi, GSList *probes) { struct sigma *sigma = sdi->priv; - struct probe *probe; + struct sr_probe *probe; GSList *l; int trigger_set = 0; int probebit; @@ -600,18 +614,17 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) memset(&sigma->trigger, 0, sizeof(struct sigma_trigger)); for (l = probes; l; l = l->next) { - probe = (struct probe *)l->data; + probe = (struct sr_probe *)l->data; probebit = 1 << (probe->index - 1); if (!probe->enabled || !probe->trigger) continue; - if (sigma->cur_samplerate >= MHZ(100)) { + 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_warn("ASIX SIGMA only supports a single " + "pin trigger in 100 and 200MHz mode."); return SR_ERR; } if (probe->trigger[0] == 'f') @@ -619,9 +632,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_warn("ASIX SIGMA only supports " + "rising/falling trigger in 100 " + "and 200MHz mode."); return SR_ERR; } @@ -651,8 +664,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_warn("ASIX SIGMA only supports 1 rising/" + "falling triggers."); return SR_ERR; } } @@ -664,19 +677,28 @@ 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 sigma *sigma; - if ((sdi = get_sr_device_instance(device_instances, device_index))) - { - sigma = sdi->priv; - if (sdi->status == ST_ACTIVE) - ftdi_usb_close(&sigma->ftdic); + if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + sr_err("sigma: %s: sdi was NULL", __func__); + return SR_ERR; /* TODO: SR_ERR_ARG? */ + } - sdi->status = 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) @@ -701,7 +723,7 @@ static void *hw_get_device_info(int device_index, int device_info_id) struct sigma *sigma; void *info = NULL; - if (!(sdi = get_sr_device_instance(device_instances, device_index))) { + if (!(sdi = sr_get_device_instance(device_instances, device_index))) { fprintf(stderr, "It's NULL.\n"); return NULL; } @@ -709,19 +731,19 @@ static void *hw_get_device_info(int device_index, int device_info_id) sigma = sdi->priv; switch (device_info_id) { - case DI_INSTANCE: + case SR_DI_INSTANCE: info = sdi; break; - case DI_NUM_PROBES: + case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(16); break; - case DI_SAMPLERATES: + case SR_DI_SAMPLERATES: info = &samplerates; break; - case DI_TRIGGER_TYPES: + case SR_DI_TRIGGER_TYPES: info = (char *)TRIGGER_TYPES; break; - case DI_CUR_SAMPLERATE: + case SR_DI_CUR_SAMPLERATE: info = &sigma->cur_samplerate; break; } @@ -733,11 +755,11 @@ static int hw_get_status(int device_index) { struct sr_device_instance *sdi; - sdi = get_sr_device_instance(device_instances, device_index); + sdi = sr_get_device_instance(device_instances, device_index); if (sdi) return sdi->status; else - return ST_NOT_FOUND; + return SR_ST_NOT_FOUND; } static int *hw_get_capabilities(void) @@ -751,22 +773,22 @@ static int hw_set_configuration(int device_index, int capability, void *value) struct sigma *sigma; int ret; - if (!(sdi = get_sr_device_instance(device_instances, device_index))) + if (!(sdi = sr_get_device_instance(device_instances, device_index))) return SR_ERR; sigma = sdi->priv; - if (capability == HWCAP_SAMPLERATE) { + if (capability == SR_HWCAP_SAMPLERATE) { ret = set_samplerate(sdi, *(uint64_t*) value); - } else if (capability == HWCAP_PROBECONFIG) { + } else if (capability == SR_HWCAP_PROBECONFIG) { ret = configure_probes(sdi, value); - } else if (capability == HWCAP_LIMIT_MSEC) { + } else if (capability == 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 == HWCAP_CAPTURE_RATIO) { + } else if (capability == SR_HWCAP_CAPTURE_RATIO) { sigma->capture_ratio = *(uint64_t*) value; if (sigma->capture_ratio < 0 || sigma->capture_ratio > 100) ret = SR_ERR; @@ -821,13 +843,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_device_instance *sdi = session_data; struct sigma *sigma = sdi->priv; uint16_t tsdiff, ts; uint16_t samples[65536 * sigma->samples_per_event]; - struct datafeed_packet packet; + 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; @@ -837,7 +860,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, /* Check if trigger is in this chunk. */ if (triggerpos != -1) { - if (sigma->cur_samplerate <= MHZ(50)) + if (sigma->cur_samplerate <= SR_MHZ(50)) triggerpos -= EVENTS_PER_CLUSTER - 1; if (triggerpos < 0) @@ -871,11 +894,15 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, while (sent < n) { tosend = MIN(2048, n - sent); - packet.type = DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; - session_bus(sigma->session_id, &packet); + packet.type = SR_DF_LOGIC; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + 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; } @@ -915,21 +942,26 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, &sigma->trigger); if (tosend > 0) { - packet.type = DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples; - session_bus(sigma->session_id, &packet); + packet.type = SR_DF_LOGIC; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples; + sr_session_bus(sigma->session_id, &packet); sent += tosend; } /* Only send trigger if explicitly enabled. */ if (sigma->use_triggers) { - packet.type = DF_TRIGGER; - packet.length = 0; - packet.payload = 0; - session_bus(sigma->session_id, &packet); + packet.type = SR_DF_TRIGGER; + /* TODO: fill in timeoffset only */ + packet.timeoffset = 0; + packet.duration = 0; + sr_session_bus(sigma->session_id, &packet); } } @@ -937,11 +969,15 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, tosend = n - sent; if (tosend > 0) { - packet.type = DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; - session_bus(sigma->session_id, &packet); + packet.type = SR_DF_LOGIC; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples + sent; + sr_session_bus(sigma->session_id, &packet); } *lastsample = samples[n - 1]; @@ -950,11 +986,11 @@ 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_device_instance *sdi = session_data; struct sigma *sigma = sdi->priv; - struct datafeed_packet packet; + struct sr_datafeed_packet packet; const int chunks_per_read = 32; unsigned char buf[chunks_per_read * CHUNK_SIZE]; int bufsz, numchunks, i, newchunks; @@ -979,16 +1015,15 @@ 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; } else if (sigma->state.state == SIGMA_DOWNLOAD) { if (sigma->state.chunks_downloaded >= numchunks) { /* End of samples. */ - packet.type = DF_END; - packet.length = 0; - session_bus(sigma->session_id, &packet); + packet.type = SR_DF_END; + sr_session_bus(sigma->session_id, &packet); sigma->state.state = SIGMA_IDLE; @@ -998,11 +1033,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("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) { @@ -1026,12 +1063,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; } @@ -1196,35 +1233,36 @@ 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 sigma *sigma; - struct datafeed_packet packet; - struct datafeed_header header; + 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; + session_data = session_data; - if (!(sdi = get_sr_device_instance(device_instances, device_index))) + if (!(sdi = sr_get_device_instance(device_instances, 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, 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); /* 100 and 200 MHz mode. */ - if (sigma->cur_samplerate >= MHZ(100)) { + if (sigma->cur_samplerate >= SR_MHZ(100)) { sigma_set_register(WRITE_TRIGGER_SELECT1, 0x81, sigma); /* Find which pin to trigger on from mask. */ @@ -1241,7 +1279,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) triggerselect |= 1 << 3; /* All other modes. */ - } else if (sigma->cur_samplerate <= MHZ(50)) { + } else if (sigma->cur_samplerate <= SR_MHZ(50)) { build_basic_trigger(&lut, sigma); sigma_write_trigger_lut(&lut, sigma); @@ -1262,10 +1300,10 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) sigma_set_register(WRITE_TRIGGER_SELECT1, triggerselect, sigma); /* Set clock select register. */ - if (sigma->cur_samplerate == MHZ(200)) + if (sigma->cur_samplerate == SR_MHZ(200)) /* Enable 4 probes. */ sigma_set_register(WRITE_CLOCK_SELECT, 0xf0, sigma); - else if (sigma->cur_samplerate == MHZ(100)) + else if (sigma->cur_samplerate == SR_MHZ(100)) /* Enable 8 probes. */ sigma_set_register(WRITE_CLOCK_SELECT, 0x00, sigma); else { @@ -1273,7 +1311,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) * 50 MHz mode (or fraction thereof). Any fraction down to * 50 MHz / 256 can be used, but is not supported by sigrok API. */ - frac = MHZ(50) / sigma->cur_samplerate - 1; + frac = SR_MHZ(50) / sigma->cur_samplerate - 1; clockselect.async = 0; clockselect.fraction = frac; @@ -1292,40 +1330,38 @@ 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 = DF_HEADER; - packet.length = sizeof(struct datafeed_header); + packet.type = SR_DF_HEADER; packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.samplerate = sigma->cur_samplerate; - header.protocol_id = PROTO_RAW; header.num_logic_probes = sigma->num_probes; header.num_analog_probes = 0; - session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); /* Add capture source. */ - source_add(0, G_IO_IN, 10, receive_data, sdi); + sr_source_add(0, G_IO_IN, 10, receive_data, sdi); sigma->state.state = SIGMA_CAPTURE; return SR_OK; } -static void hw_stop_acquisition(int device_index, gpointer session_device_id) +static void hw_stop_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct sigma *sigma; uint8_t modestatus; - if (!(sdi = get_sr_device_instance(device_instances, device_index))) + if (!(sdi = sr_get_device_instance(device_instances, device_index))) return; sigma = sdi->priv; - session_device_id = session_device_id; + session_data = session_data; /* Stop acquisition. */ sigma_set_register(WRITE_MODE, 0x11, sigma); @@ -1349,17 +1385,18 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) sigma->state.state = SIGMA_DOWNLOAD; } -struct device_plugin asix_sigma_plugin_info = { - "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, +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, };