X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fasix-sigma%2Fasix-sigma.c;h=bc36764edfcd9df5d753157df03a28fc3bbe1a24;hb=54ac5277c5e462f1778300b9bc3fdd4709ecb2dc;hp=de89f7acc947e91abeef0ff864039e00cb9b2981;hpb=9f8274a544865838f880c4849c28b6129141cf99;p=libsigrok.git diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index de89f7ac..bc36764e 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 @@ -54,7 +56,7 @@ static uint64_t supported_samplerates[] = { 0, }; -static struct samplerates samplerates = { +static struct sr_samplerates samplerates = { KHZ(200), MHZ(200), 0, @@ -62,12 +64,12 @@ static struct samplerates 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; } @@ -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,7 +602,7 @@ 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) @@ -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; @@ -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; @@ -1295,19 +1297,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,7 +1351,7 @@ 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,