X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=hardware%2Fopenbench-logic-sniffer%2Fols.c;h=51379d930391c95517b74888612e5ab326d43273;hb=cd009d55619181e2fa7e7112f32fe85e4b49cf14;hp=d5eb8ac918c27259d8e01f47f7b15b772c8c12bc;hpb=d32d961d17e3c7f409912062e5c336c19b6ef270;p=libsigrok.git diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index d5eb8ac9..51379d93 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -24,7 +24,9 @@ #include #include #include -#ifndef _WIN32 +#ifdef _WIN32 +#include +#else #include #endif #include @@ -47,7 +49,7 @@ #define NUM_TRIGGER_STAGES 4 #define TRIGGER_TYPES "01" #define SERIAL_SPEED B115200 -#define CLOCK_RATE MHZ(100) +#define CLOCK_RATE SR_MHZ(100) #define MIN_NUM_SAMPLES 4 /* Command opcodes */ @@ -82,21 +84,21 @@ #define FLAG_RLE 0x0100 static int capabilities[] = { - HWCAP_LOGIC_ANALYZER, - HWCAP_SAMPLERATE, - HWCAP_CAPTURE_RATIO, - HWCAP_LIMIT_SAMPLES, + SR_HWCAP_LOGIC_ANALYZER, + SR_HWCAP_SAMPLERATE, + SR_HWCAP_CAPTURE_RATIO, + SR_HWCAP_LIMIT_SAMPLES, 0, }; -static struct samplerates samplerates = { - 10, - MHZ(200), - 1, - 0, +static struct sr_samplerates samplerates = { + SR_HZ(10), + SR_MHZ(200), + SR_HZ(1), + NULL, }; -/* List of struct serial_device_instance */ +/* List of struct sr_serial_device_instance */ static GSList *device_instances = NULL; /* Current state of the flag register */ @@ -145,7 +147,7 @@ static int send_longcommand(int fd, uint8_t command, uint32_t data) static int configure_probes(GSList *probes) { - struct probe *probe; + struct sr_probe *probe; GSList *l; int probe_bit, stage, i; char *tc; @@ -158,7 +160,7 @@ static int configure_probes(GSList *probes) num_stages = 0; for (l = probes; l; l = l->next) { - probe = (struct probe *)l->data; + probe = (struct sr_probe *)l->data; if (!probe->enabled) continue; @@ -217,7 +219,7 @@ static uint32_t reverse32(uint32_t in) return out; } -static int hw_init(char *deviceinfo) +static int hw_init(const char *deviceinfo) { struct sr_device_instance *sdi; GSList *ports, *l; @@ -287,15 +289,15 @@ static int hw_init(char *deviceinfo) || !strncmp(buf, "1ALS", 4)) { if (!strncmp(buf, "1SLO", 4)) sdi = sr_device_instance_new - (final_devcnt, ST_INACTIVE, + (final_devcnt, SR_ST_INACTIVE, "Openbench", "Logic Sniffer", "v1.0"); else sdi = sr_device_instance_new - (final_devcnt, ST_INACTIVE, + (final_devcnt, SR_ST_INACTIVE, "Openbench", "Logic Sniffer", "v1.0"); - sdi->serial = serial_device_instance_new + sdi->serial = sr_serial_device_instance_new (device_names[i], -1); device_instances = g_slist_append(device_instances, sdi); @@ -319,7 +321,7 @@ static int hw_init(char *deviceinfo) free(serial_params); g_slist_free(ports); - cur_samplerate = samplerates.low; + cur_samplerate = SR_KHZ(200); return final_devcnt; } @@ -335,7 +337,7 @@ static int hw_opendev(int device_index) if (sdi->serial->fd == -1) return SR_ERR; - sdi->status = ST_ACTIVE; + sdi->status = SR_ST_ACTIVE; return SR_OK; } @@ -350,7 +352,7 @@ static void hw_closedev(int device_index) if (sdi->serial->fd != -1) { serial_close(sdi->serial->fd); sdi->serial->fd = -1; - sdi->status = ST_INACTIVE; + sdi->status = SR_ST_INACTIVE; } } @@ -380,19 +382,19 @@ static void *hw_get_device_info(int device_index, int device_info_id) info = NULL; 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(NUM_PROBES); 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 = &cur_samplerate; break; } @@ -405,7 +407,7 @@ static int hw_get_status(int device_index) struct sr_device_instance *sdi; if (!(sdi = sr_get_device_instance(device_instances, device_index))) - return ST_NOT_FOUND; + return SR_ST_NOT_FOUND; return sdi->status; } @@ -450,18 +452,18 @@ static int hw_set_configuration(int device_index, int capability, void *value) if (!(sdi = sr_get_device_instance(device_instances, device_index))) return SR_ERR; - if (sdi->status != ST_ACTIVE) + if (sdi->status != SR_ST_ACTIVE) return SR_ERR; switch (capability) { - case HWCAP_SAMPLERATE: + case SR_HWCAP_SAMPLERATE: tmp_u64 = value; ret = set_configuration_samplerate(sdi, *tmp_u64); break; - case HWCAP_PROBECONFIG: + case SR_HWCAP_PROBECONFIG: ret = configure_probes((GSList *) value); break; - case HWCAP_LIMIT_SAMPLES: + case SR_HWCAP_LIMIT_SAMPLES: tmp_u64 = value; if (*tmp_u64 < MIN_NUM_SAMPLES) return SR_ERR; @@ -469,7 +471,7 @@ static int hw_set_configuration(int device_index, int capability, void *value) g_message("ols: sample limit %" PRIu64, limit_samples); ret = SR_OK; break; - case HWCAP_CAPTURE_RATIO: + case SR_HWCAP_CAPTURE_RATIO: tmp_u64 = value; capture_ratio = *tmp_u64; if (capture_ratio < 0 || capture_ratio > 100) { @@ -494,7 +496,7 @@ static int receive_data(int fd, int revents, void *user_data) static unsigned char tmp_sample[4]; static unsigned char *raw_sample_buf = NULL; int count, buflen, num_channels, offset, i, j; - struct datafeed_packet packet; + struct sr_datafeed_packet packet; unsigned char byte, *buffer; if (num_transfers++ == 0) { @@ -504,8 +506,8 @@ static int receive_data(int fd, int revents, void *user_data) * longer than it takes to send a byte, that means it's * finished. We'll double that to 30ms to be sure... */ - source_remove(fd); - source_add(fd, G_IO_IN, 30, receive_data, user_data); + sr_source_remove(fd); + sr_source_add(fd, G_IO_IN, 30, receive_data, user_data); raw_sample_buf = malloc(limit_samples * 4); /* fill with 1010... for debugging */ memset(raw_sample_buf, 0x82, limit_samples * 4); @@ -612,36 +614,36 @@ static int receive_data(int fd, int revents, void *user_data) */ if (trigger_at > 0) { /* there are pre-trigger samples, send those first */ - packet.type = DF_LOGIC; + packet.type = SR_DF_LOGIC; packet.length = trigger_at * 4; packet.unitsize = 4; packet.payload = raw_sample_buf; - session_bus(user_data, &packet); + sr_session_bus(user_data, &packet); } - packet.type = DF_TRIGGER; + packet.type = SR_DF_TRIGGER; packet.length = 0; - session_bus(user_data, &packet); + sr_session_bus(user_data, &packet); - packet.type = DF_LOGIC; + packet.type = SR_DF_LOGIC; packet.length = (limit_samples * 4) - (trigger_at * 4); packet.unitsize = 4; packet.payload = raw_sample_buf + trigger_at * 4; - session_bus(user_data, &packet); + sr_session_bus(user_data, &packet); } else { - packet.type = DF_LOGIC; + packet.type = SR_DF_LOGIC; packet.length = limit_samples * 4; packet.unitsize = 4; packet.payload = raw_sample_buf; - session_bus(user_data, &packet); + sr_session_bus(user_data, &packet); } free(raw_sample_buf); serial_flush(fd); serial_close(fd); - packet.type = DF_END; + packet.type = SR_DF_END; packet.length = 0; - session_bus(user_data, &packet); + sr_session_bus(user_data, &packet); } return TRUE; @@ -650,8 +652,8 @@ static int receive_data(int fd, int revents, void *user_data) static int hw_start_acquisition(int device_index, gpointer session_device_id) { int i; - struct datafeed_packet *packet; - struct datafeed_header *header; + struct sr_datafeed_packet *packet; + struct sr_datafeed_header *header; struct sr_device_instance *sdi; uint32_t trigger_config[4]; uint32_t data; @@ -661,7 +663,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) if (!(sdi = sr_get_device_instance(device_instances, device_index))) return SR_ERR; - if (sdi->status != ST_ACTIVE) + if (sdi->status != SR_ST_ACTIVE) return SR_ERR; readcount = limit_samples / 4; @@ -753,24 +755,24 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) if (send_shortcommand(sdi->serial->fd, CMD_RUN) != SR_OK) return SR_ERR; - source_add(sdi->serial->fd, G_IO_IN, -1, receive_data, - session_device_id); + sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data, + session_device_id); /* Send header packet to the session bus. */ - packet = g_malloc(sizeof(struct datafeed_packet)); - header = g_malloc(sizeof(struct datafeed_header)); + packet = g_malloc(sizeof(struct sr_datafeed_packet)); + header = g_malloc(sizeof(struct sr_datafeed_header)); if (!packet || !header) return SR_ERR; - packet->type = DF_HEADER; - packet->length = sizeof(struct datafeed_header); + packet->type = SR_DF_HEADER; + packet->length = sizeof(struct sr_datafeed_header); packet->payload = (unsigned char *)header; header->feed_version = 1; gettimeofday(&header->starttime, NULL); header->samplerate = cur_samplerate; - header->protocol_id = PROTO_RAW; + header->protocol_id = SR_PROTO_RAW; header->num_logic_probes = NUM_PROBES; header->num_analog_probes = 0; - session_bus(session_device_id, packet); + sr_session_bus(session_device_id, packet); g_free(header); g_free(packet); @@ -779,18 +781,19 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) static void hw_stop_acquisition(int device_index, gpointer session_device_id) { - struct datafeed_packet packet; + struct sr_datafeed_packet packet; /* Avoid compiler warnings. */ device_index = device_index; - packet.type = DF_END; + packet.type = SR_DF_END; packet.length = 0; - session_bus(session_device_id, &packet); + sr_session_bus(session_device_id, &packet); } -struct device_plugin ols_plugin_info = { +struct sr_device_plugin ols_plugin_info = { "ols", + "Openbench Logic Sniffer", 1, hw_init, hw_cleanup,