X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fasix-sigma%2Fasix-sigma.c;h=3cd83d358a7b7a94e6228a1cb5e6ec6dc1ddca21;hb=8a7b47cdfae4a4a95e92958beab41a4985e8f8e3;hp=a987e3f35be512e814fd5cdc62b2712cbef217fa;hpb=b9c735a275512ce82da7f66275c7cb62eaf66b60;p=libsigrok.git diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index a987e3f3..3cd83d35 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -23,11 +23,13 @@ * ASIX Sigma Logic Analyzer Driver */ +#include "config.h" +#include +#include #include #include #include #include -#include #include "asix-sigma.h" #define USB_VENDOR 0xa600 @@ -41,33 +43,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, }; @@ -312,9 +314,9 @@ 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); + g_warning("g_fopen(\"%s\", \"rb\")", filename); return -1; } @@ -385,7 +387,7 @@ static int bin2bitbang(const char *filename, return 0; } -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)); @@ -411,7 +413,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; @@ -541,7 +543,7 @@ static int hw_opendev(int device_index) return 0; } - sdi->status = ST_ACTIVE; + sdi->status = SR_ST_ACTIVE; return SR_OK; } @@ -559,15 +561,15 @@ 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; } @@ -592,7 +594,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,13 +602,13 @@ 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 " @@ -672,10 +674,10 @@ static void hw_closedev(int device_index) if ((sdi = sr_get_device_instance(device_instances, device_index))) { sigma = sdi->priv; - if (sdi->status == ST_ACTIVE) + if (sdi->status == SR_ST_ACTIVE) ftdi_usb_close(&sigma->ftdic); - sdi->status = ST_INACTIVE; + sdi->status = SR_ST_INACTIVE; } } @@ -709,19 +711,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; } @@ -737,7 +739,7 @@ static int hw_get_status(int device_index) if (sdi) return sdi->status; else - return ST_NOT_FOUND; + return SR_ST_NOT_FOUND; } static int *hw_get_capabilities(void) @@ -756,17 +758,17 @@ static int hw_set_configuration(int device_index, int capability, void *value) 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; @@ -837,7 +839,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 +873,11 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, while (sent < n) { tosend = MIN(2048, n - sent); - packet.type = DF_LOGIC; + packet.type = SR_DF_LOGIC; packet.length = tosend * sizeof(uint16_t); packet.unitsize = 2; packet.payload = samples + sent; - session_bus(sigma->session_id, &packet); + sr_session_bus(sigma->session_id, &packet); sent += tosend; } @@ -915,21 +917,21 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, &sigma->trigger); if (tosend > 0) { - packet.type = DF_LOGIC; + packet.type = SR_DF_LOGIC; packet.length = tosend * sizeof(uint16_t); packet.unitsize = 2; packet.payload = samples; - session_bus(sigma->session_id, &packet); + sr_session_bus(sigma->session_id, &packet); sent += tosend; } /* Only send trigger if explicitly enabled. */ if (sigma->use_triggers) { - packet.type = DF_TRIGGER; + packet.type = SR_DF_TRIGGER; packet.length = 0; packet.payload = 0; - session_bus(sigma->session_id, &packet); + sr_session_bus(sigma->session_id, &packet); } } @@ -937,11 +939,11 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, tosend = n - sent; if (tosend > 0) { - packet.type = DF_LOGIC; + packet.type = SR_DF_LOGIC; packet.length = tosend * sizeof(uint16_t); packet.unitsize = 2; packet.payload = samples + sent; - session_bus(sigma->session_id, &packet); + sr_session_bus(sigma->session_id, &packet); } *lastsample = samples[n - 1]; @@ -986,9 +988,9 @@ static int receive_data(int fd, int revents, void *user_data) } else if (sigma->state.state == SIGMA_DOWNLOAD) { if (sigma->state.chunks_downloaded >= numchunks) { /* End of samples. */ - packet.type = DF_END; + packet.type = SR_DF_END; packet.length = 0; - session_bus(sigma->session_id, &packet); + sr_session_bus(sigma->session_id, &packet); sigma->state.state = SIGMA_IDLE; @@ -1203,11 +1205,10 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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; @@ -1217,14 +1218,16 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) 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 +1244,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 +1265,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 +1276,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; @@ -1295,19 +1298,19 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) sigma->session_id = session_device_id; /* Send header packet to the session bus. */ - packet.type = DF_HEADER; + 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 = PROTO_RAW; + header.protocol_id = SR_PROTO_RAW; header.num_logic_probes = sigma->num_probes; header.num_analog_probes = 0; - session_bus(session_device_id, &packet); + sr_session_bus(session_device_id, &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; @@ -1349,8 +1352,9 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) sigma->state.state = SIGMA_DOWNLOAD; } -struct device_plugin asix_sigma_plugin_info = { +struct sr_device_plugin asix_sigma_plugin_info = { "asix-sigma", + "ASIX SIGMA", 1, hw_init, hw_cleanup,