2 * This file is part of the sigrok project.
4 * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/types.h>
38 #include <arpa/inet.h>
42 #include <sigrok-internal.h>
46 #define O_NONBLOCK FIONBIO
49 static int capabilities[] = {
50 SR_HWCAP_LOGIC_ANALYZER,
52 SR_HWCAP_CAPTURE_RATIO,
53 SR_HWCAP_LIMIT_SAMPLES,
58 /* default supported samplerates, can be overridden by device metadata */
59 static struct sr_samplerates samplerates = {
66 /* List of struct sr_serial_device_instance */
67 static GSList *device_instances = NULL;
69 static int send_shortcommand(int fd, uint8_t command)
73 sr_dbg("ols: sending cmd 0x%.2x", command);
75 if (serial_write(fd, buf, 1) != 1)
81 static int send_longcommand(int fd, uint8_t command, uint32_t data)
85 sr_dbg("ols: sending cmd 0x%.2x data 0x%.8x", command, data);
87 buf[1] = (data & 0xff000000) >> 24;
88 buf[2] = (data & 0xff0000) >> 16;
89 buf[3] = (data & 0xff00) >> 8;
91 if (serial_write(fd, buf, 5) != 5)
97 static int configure_probes(struct ols_device *ols, GSList *probes)
99 struct sr_probe *probe;
101 int probe_bit, stage, i;
105 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
106 ols->trigger_mask[i] = 0;
107 ols->trigger_value[i] = 0;
111 for (l = probes; l; l = l->next) {
112 probe = (struct sr_probe *)l->data;
117 * Set up the probe mask for later configuration into the
120 probe_bit = 1 << (probe->index - 1);
121 ols->probe_mask |= probe_bit;
126 /* Configure trigger mask and value. */
128 for (tc = probe->trigger; tc && *tc; tc++) {
129 ols->trigger_mask[stage] |= probe_bit;
131 ols->trigger_value[stage] |= probe_bit;
135 * TODO: Only supporting parallel mode, with
140 if (stage > ols->num_stages)
141 ols->num_stages = stage;
147 static uint32_t reverse16(uint32_t in)
151 out = (in & 0xff) << 8;
152 out |= (in & 0xff00) >> 8;
153 out |= (in & 0xff0000) << 8;
154 out |= (in & 0xff000000) >> 8;
159 static uint32_t reverse32(uint32_t in)
163 out = (in & 0xff) << 24;
164 out |= (in & 0xff00) << 8;
165 out |= (in & 0xff0000) >> 8;
166 out |= (in & 0xff000000) >> 24;
171 static struct ols_device *ols_device_new(void)
173 struct ols_device *ols;
175 /* TODO: Is 'ols' ever g_free()'d? */
176 if (!(ols = g_try_malloc0(sizeof(struct ols_device)))) {
177 sr_err("ols: %s: ols malloc failed", __func__);
181 ols->trigger_at = -1;
182 ols->probe_mask = 0xffffffff;
183 ols->cur_samplerate = SR_KHZ(200);
184 ols->period_ps = 5000000;
189 static struct sr_device_instance *get_metadata(int fd)
191 struct sr_device_instance *sdi;
192 struct ols_device *ols;
194 uint8_t key, type, token;
195 GString *tmp_str, *devicename, *version;
198 sdi = sr_device_instance_new(0, SR_ST_INACTIVE, NULL, NULL, NULL);
199 ols = ols_device_new();
202 devicename = g_string_new("");
203 version = g_string_new("");
207 if (serial_read(fd, &key, 1) != 1 || key == 0x00)
213 /* NULL-terminated string */
214 tmp_str = g_string_new("");
215 while (serial_read(fd, &tmp_c, 1) == 1 && tmp_c != '\0')
216 g_string_append_c(tmp_str, tmp_c);
217 sr_dbg("ols: got metadata key 0x%.2x value '%s'",
222 devicename = g_string_append(devicename, tmp_str->str);
225 /* FPGA firmware version */
227 g_string_append(version, ", ");
228 g_string_append(version, "FPGA version ");
229 g_string_append(version, tmp_str->str);
232 /* Ancillary version */
234 g_string_append(version, ", ");
235 g_string_append(version, "Ancillary version ");
236 g_string_append(version, tmp_str->str);
239 sr_info("ols: unknown token 0x%.2x: '%s'",
240 token, tmp_str->str);
243 g_string_free(tmp_str, TRUE);
246 /* 32-bit unsigned integer */
247 if (serial_read(fd, &tmp_int, 4) != 4)
249 tmp_int = reverse32(tmp_int);
250 sr_dbg("ols: got metadata key 0x%.2x value 0x%.8x",
254 /* Number of usable probes */
255 ols->num_probes = tmp_int;
258 /* Amount of sample memory available (bytes) */
259 ols->max_samples = tmp_int;
262 /* Amount of dynamic memory available (bytes) */
263 /* what is this for? */
266 /* Maximum sample rate (hz) */
267 ols->max_samplerate = tmp_int;
270 /* protocol version */
271 ols->protocol_version = tmp_int;
274 sr_info("ols: unknown token 0x%.2x: 0x%.8x",
280 /* 8-bit unsigned integer */
281 if (serial_read(fd, &tmp_c, 1) != 1)
283 sr_dbg("ols: got metadata key 0x%.2x value 0x%.2x",
287 /* Number of usable probes */
288 ols->num_probes = tmp_c;
291 /* protocol version */
292 ols->protocol_version = tmp_c;
295 sr_info("ols: unknown token 0x%.2x: 0x%.2x",
306 sdi->model = devicename->str;
307 sdi->version = version->str;
308 g_string_free(devicename, FALSE);
309 g_string_free(version, FALSE);
314 static int hw_init(const char *deviceinfo)
316 struct sr_device_instance *sdi;
317 struct ols_device *ols;
319 GPollFD *fds, probefd;
320 int devcnt, final_devcnt, num_ports, fd, ret, i;
321 char buf[8], **device_names, **serial_params;
326 ports = g_slist_append(NULL, strdup(deviceinfo));
328 /* No specific device given, so scan all serial ports. */
329 ports = list_serial_ports();
331 num_ports = g_slist_length(ports);
333 if (!(fds = g_try_malloc0(num_ports * sizeof(GPollFD)))) {
334 sr_err("ols: %s: fds malloc failed", __func__);
335 goto hw_init_free_ports; /* TODO: SR_ERR_MALLOC. */
338 if (!(device_names = g_try_malloc(num_ports * sizeof(char *)))) {
339 sr_err("ols: %s: device_names malloc failed", __func__);
340 goto hw_init_free_fds; /* TODO: SR_ERR_MALLOC. */
343 if (!(serial_params = g_try_malloc(num_ports * sizeof(char *)))) {
344 sr_err("ols: %s: serial_params malloc failed", __func__);
345 goto hw_init_free_device_names; /* TODO: SR_ERR_MALLOC. */
349 for (l = ports; l; l = l->next) {
350 /* The discovery procedure is like this: first send the Reset
351 * command (0x00) 5 times, since the device could be anywhere
352 * in a 5-byte command. Then send the ID command (0x02).
353 * If the device responds with 4 bytes ("OLS1" or "SLA1"), we
356 * Since it may take the device a while to respond at 115Kb/s,
357 * we do all the sending first, then wait for all of them to
358 * respond with g_poll().
360 sr_info("ols: probing %s...", (char *)l->data);
361 fd = serial_open(l->data, O_RDWR | O_NONBLOCK);
363 serial_params[devcnt] = serial_backup_params(fd);
364 serial_set_params(fd, 115200, 8, 0, 1, 2);
366 for (i = 0; i < 5; i++) {
367 if ((ret = send_shortcommand(fd,
368 CMD_RESET)) != SR_OK) {
369 /* Serial port is not writable. */
374 serial_restore_params(fd,
375 serial_params[devcnt]);
379 send_shortcommand(fd, CMD_ID);
381 fds[devcnt].events = G_IO_IN;
382 device_names[devcnt] = strdup(l->data);
388 /* 2ms isn't enough for reliable transfer with pl2303, let's try 10 */
391 g_poll(fds, devcnt, 1);
393 for (i = 0; i < devcnt; i++) {
394 if (fds[i].revents != G_IO_IN)
396 if (serial_read(fds[i].fd, buf, 4) != 4)
398 if (strncmp(buf, "1SLO", 4) && strncmp(buf, "1ALS", 4))
401 /* definitely using the OLS protocol, check if it supports
402 * the metadata command
404 send_shortcommand(fds[i].fd, CMD_METADATA);
405 probefd.fd = fds[i].fd;
406 probefd.events = G_IO_IN;
407 if (g_poll(&probefd, 1, 10) > 0) {
409 sdi = get_metadata(fds[i].fd);
410 sdi->index = final_devcnt;
412 /* not an OLS -- some other board that uses the sump protocol */
413 sdi = sr_device_instance_new(final_devcnt, SR_ST_INACTIVE,
414 "Sump", "Logic Analyzer", "v1.0");
415 ols = ols_device_new();
416 ols->num_probes = 32;
419 sdi->serial = sr_serial_device_instance_new(device_names[i], -1);
420 device_instances = g_slist_append(device_instances, sdi);
422 serial_close(fds[i].fd);
426 /* clean up after all the probing */
427 for (i = 0; i < devcnt; i++) {
428 if (fds[i].fd != 0) {
429 serial_restore_params(fds[i].fd, serial_params[i]);
430 serial_close(fds[i].fd);
432 free(serial_params[i]);
433 free(device_names[i]);
436 g_free(serial_params);
437 hw_init_free_device_names:
438 g_free(device_names);
447 static int hw_opendev(int device_index)
449 struct sr_device_instance *sdi;
451 if (!(sdi = sr_get_device_instance(device_instances, device_index)))
454 sdi->serial->fd = serial_open(sdi->serial->port, O_RDWR);
455 if (sdi->serial->fd == -1)
458 sdi->status = SR_ST_ACTIVE;
463 static int hw_closedev(int device_index)
465 struct sr_device_instance *sdi;
467 if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
468 sr_err("ols: %s: sdi was NULL", __func__);
469 return SR_ERR; /* TODO: SR_ERR_ARG? */
473 if (sdi->serial->fd != -1) {
474 serial_close(sdi->serial->fd);
475 sdi->serial->fd = -1;
476 sdi->status = SR_ST_INACTIVE;
482 static void hw_cleanup(void)
485 struct sr_device_instance *sdi;
487 /* Properly close and free all devices. */
488 for (l = device_instances; l; l = l->next) {
490 if (sdi->serial->fd != -1)
491 serial_close(sdi->serial->fd);
492 sr_device_instance_free(sdi);
494 g_slist_free(device_instances);
495 device_instances = NULL;
498 static void *hw_get_device_info(int device_index, int device_info_id)
500 struct sr_device_instance *sdi;
501 struct ols_device *ols;
504 if (!(sdi = sr_get_device_instance(device_instances, device_index)))
509 switch (device_info_id) {
513 case SR_DI_NUM_PROBES:
514 info = GINT_TO_POINTER(NUM_PROBES);
516 case SR_DI_SAMPLERATES:
519 case SR_DI_TRIGGER_TYPES:
520 info = (char *)TRIGGER_TYPES;
522 case SR_DI_CUR_SAMPLERATE:
523 info = &ols->cur_samplerate;
530 static int hw_get_status(int device_index)
532 struct sr_device_instance *sdi;
534 if (!(sdi = sr_get_device_instance(device_instances, device_index)))
535 return SR_ST_NOT_FOUND;
540 static int *hw_get_capabilities(void)
545 static int set_configuration_samplerate(struct sr_device_instance *sdi,
548 struct ols_device *ols;
551 if (ols->max_samplerate) {
552 if (samplerate > ols->max_samplerate)
553 return SR_ERR_SAMPLERATE;
554 } else if (samplerate < samplerates.low || samplerate > samplerates.high)
555 return SR_ERR_SAMPLERATE;
557 ols->cur_samplerate = samplerate;
558 ols->period_ps = 1000000000000 / samplerate;
559 if (samplerate > CLOCK_RATE) {
560 ols->flag_reg |= FLAG_DEMUX;
561 ols->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
563 ols->flag_reg &= ~FLAG_DEMUX;
564 ols->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1;
570 static int hw_set_configuration(int device_index, int capability, void *value)
572 struct sr_device_instance *sdi;
573 struct ols_device *ols;
577 if (!(sdi = sr_get_device_instance(device_instances, device_index)))
581 if (sdi->status != SR_ST_ACTIVE)
584 switch (capability) {
585 case SR_HWCAP_SAMPLERATE:
587 ret = set_configuration_samplerate(sdi, *tmp_u64);
589 case SR_HWCAP_PROBECONFIG:
590 ret = configure_probes(ols, (GSList *) value);
592 case SR_HWCAP_LIMIT_SAMPLES:
594 if (*tmp_u64 < MIN_NUM_SAMPLES)
596 if (*tmp_u64 > ols->max_samples)
597 sr_warn("ols: sample limit exceeds hw max");
598 ols->limit_samples = *tmp_u64;
599 sr_info("ols: sample limit %" PRIu64, ols->limit_samples);
602 case SR_HWCAP_CAPTURE_RATIO:
604 ols->capture_ratio = *tmp_u64;
605 if (ols->capture_ratio < 0 || ols->capture_ratio > 100) {
606 ols->capture_ratio = 0;
612 if (!strcmp(value, "on")) {
613 sr_info("ols: enabling RLE");
614 ols->flag_reg |= FLAG_RLE;
625 static int receive_data(int fd, int revents, void *session_data)
627 struct sr_datafeed_packet packet;
628 struct sr_datafeed_logic logic;
629 struct sr_device_instance *sdi;
630 struct ols_device *ols;
632 int num_channels, offset, i, j;
635 /* find this device's ols_device struct by its fd */
637 for (l = device_instances; l; l = l->next) {
639 if (sdi->serial->fd == fd) {
645 /* shouldn't happen */
648 if (ols->num_transfers++ == 0) {
650 * First time round, means the device started sending data,
651 * and will not stop until done. If it stops sending for
652 * longer than it takes to send a byte, that means it's
653 * finished. We'll double that to 30ms to be sure...
655 sr_source_remove(fd);
656 sr_source_add(fd, G_IO_IN, 30, receive_data, session_data);
657 ols->raw_sample_buf = g_try_malloc(ols->limit_samples * 4);
658 if (!ols->raw_sample_buf) {
659 sr_err("ols: %s: ols->raw_sample_buf malloc failed",
663 /* fill with 1010... for debugging */
664 memset(ols->raw_sample_buf, 0x82, ols->limit_samples * 4);
668 for (i = 0x20; i > 0x02; i /= 2) {
669 if ((ols->flag_reg & i) == 0)
673 if (revents == G_IO_IN) {
674 if (serial_read(fd, &byte, 1) != 1)
677 /* Ignore it if we've read enough. */
678 if (ols->num_samples >= ols->limit_samples)
681 ols->sample[ols->num_bytes++] = byte;
682 sr_dbg("ols: received byte 0x%.2x", byte);
683 if (ols->num_bytes == num_channels) {
684 /* Got a full sample. */
685 sr_dbg("ols: received sample 0x%.*x",
686 ols->num_bytes * 2, *(int *)ols->sample);
687 if (ols->flag_reg & FLAG_RLE) {
689 * In RLE mode -1 should never come in as a
690 * sample, because bit 31 is the "count" flag.
692 if (ols->sample[ols->num_bytes - 1] & 0x80) {
693 ols->sample[ols->num_bytes - 1] &= 0x7f;
695 * FIXME: This will only work on
696 * little-endian systems.
698 ols->rle_count = *(int *)(ols->sample);
699 sr_dbg("ols: RLE count = %d", ols->rle_count);
704 ols->num_samples += ols->rle_count + 1;
705 if (ols->num_samples > ols->limit_samples) {
706 /* Save us from overrunning the buffer. */
707 ols->rle_count -= ols->num_samples - ols->limit_samples;
708 ols->num_samples = ols->limit_samples;
711 if (num_channels < 4) {
713 * Some channel groups may have been turned
714 * off, to speed up transfer between the
715 * hardware and the PC. Expand that here before
716 * submitting it over the session bus --
717 * whatever is listening on the bus will be
718 * expecting a full 32-bit sample, based on
719 * the number of probes.
722 memset(ols->tmp_sample, 0, 4);
723 for (i = 0; i < 4; i++) {
724 if (((ols->flag_reg >> 2) & (1 << i)) == 0) {
726 * This channel group was
727 * enabled, copy from received
730 ols->tmp_sample[i] = ols->sample[j++];
733 memcpy(ols->sample, ols->tmp_sample, 4);
734 sr_dbg("ols: full sample 0x%.8x", *(int *)ols->sample);
737 /* the OLS sends its sample buffer backwards.
738 * store it in reverse order here, so we can dump
739 * this on the session bus later.
741 offset = (ols->limit_samples - ols->num_samples) * 4;
742 for (i = 0; i <= ols->rle_count; i++) {
743 memcpy(ols->raw_sample_buf + offset + (i * 4),
746 memset(ols->sample, 0, 4);
752 * This is the main loop telling us a timeout was reached, or
753 * we've acquired all the samples we asked for -- we're done.
754 * Send the (properly-ordered) buffer to the frontend.
756 if (ols->trigger_at != -1) {
757 /* a trigger was set up, so we need to tell the frontend
760 if (ols->trigger_at > 0) {
761 /* there are pre-trigger samples, send those first */
762 packet.type = SR_DF_LOGIC;
763 packet.timeoffset = 0;
764 packet.duration = ols->trigger_at * ols->period_ps;
765 packet.payload = &logic;
766 logic.length = ols->trigger_at * 4;
768 logic.data = ols->raw_sample_buf +
769 (ols->limit_samples - ols->num_samples) * 4;
770 sr_session_bus(session_data, &packet);
773 /* send the trigger */
774 packet.type = SR_DF_TRIGGER;
775 packet.timeoffset = ols->trigger_at * ols->period_ps;
777 sr_session_bus(session_data, &packet);
779 /* send post-trigger samples */
780 packet.type = SR_DF_LOGIC;
781 packet.timeoffset = ols->trigger_at * ols->period_ps;
782 packet.duration = (ols->num_samples - ols->trigger_at) * ols->period_ps;
783 packet.payload = &logic;
784 logic.length = (ols->num_samples * 4) - (ols->trigger_at * 4);
786 logic.data = ols->raw_sample_buf + ols->trigger_at * 4 +
787 (ols->limit_samples - ols->num_samples) * 4;
788 sr_session_bus(session_data, &packet);
790 /* no trigger was used */
791 packet.type = SR_DF_LOGIC;
792 packet.timeoffset = 0;
793 packet.duration = ols->num_samples * ols->period_ps;
794 packet.payload = &logic;
795 logic.length = ols->num_samples * 4;
797 logic.data = ols->raw_sample_buf +
798 (ols->limit_samples - ols->num_samples) * 4;
799 sr_session_bus(session_data, &packet);
801 g_free(ols->raw_sample_buf);
805 packet.type = SR_DF_END;
806 packet.timeoffset = ols->num_samples * ols->period_ps;
808 sr_session_bus(session_data, &packet);
814 static int hw_start_acquisition(int device_index, gpointer session_data)
816 struct sr_datafeed_packet *packet;
817 struct sr_datafeed_header *header;
818 struct sr_device_instance *sdi;
819 struct ols_device *ols;
820 uint32_t trigger_config[4];
822 uint16_t readcount, delaycount;
823 uint8_t changrp_mask;
827 if (!(sdi = sr_get_device_instance(device_instances, device_index)))
832 if (sdi->status != SR_ST_ACTIVE)
836 * Enable/disable channel groups in the flag register according to the
837 * probe mask. Calculate this here, because num_channels is needed
838 * to limit readcount.
842 for (i = 0; i < 4; i++) {
843 if (ols->probe_mask & (0xff << (i * 8))) {
844 changrp_mask |= (1 << i);
850 * Limit readcount to prevent reading past the end of the hardware
853 readcount = MIN(ols->max_samples / num_channels, ols->limit_samples) / 4;
855 memset(trigger_config, 0, 16);
856 trigger_config[ols->num_stages - 1] |= 0x08;
857 if (ols->trigger_mask[0]) {
858 delaycount = readcount * (1 - ols->capture_ratio / 100.0);
859 ols->trigger_at = (readcount - delaycount) * 4 - ols->num_stages;
861 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_0,
862 reverse32(ols->trigger_mask[0])) != SR_OK)
864 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_0,
865 reverse32(ols->trigger_value[0])) != SR_OK)
867 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
868 trigger_config[0]) != SR_OK)
871 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_1,
872 reverse32(ols->trigger_mask[1])) != SR_OK)
874 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_1,
875 reverse32(ols->trigger_value[1])) != SR_OK)
877 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_1,
878 trigger_config[1]) != SR_OK)
881 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_2,
882 reverse32(ols->trigger_mask[2])) != SR_OK)
884 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_2,
885 reverse32(ols->trigger_value[2])) != SR_OK)
887 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_2,
888 trigger_config[2]) != SR_OK)
891 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_3,
892 reverse32(ols->trigger_mask[3])) != SR_OK)
894 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_3,
895 reverse32(ols->trigger_value[3])) != SR_OK)
897 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_3,
898 trigger_config[3]) != SR_OK)
901 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_0,
902 ols->trigger_mask[0]) != SR_OK)
904 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_0,
905 ols->trigger_value[0]) != SR_OK)
907 if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
908 0x00000008) != SR_OK)
910 delaycount = readcount;
913 sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
914 "demux %s)", ols->cur_samplerate, ols->cur_samplerate_divider,
915 ols->flag_reg & FLAG_DEMUX ? "on" : "off");
916 if (send_longcommand(sdi->serial->fd, CMD_SET_DIVIDER,
917 reverse32(ols->cur_samplerate_divider)) != SR_OK)
920 /* Send sample limit and pre/post-trigger capture ratio. */
921 data = ((readcount - 1) & 0xffff) << 16;
922 data |= (delaycount - 1) & 0xffff;
923 if (send_longcommand(sdi->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
926 /* The flag register wants them here, and 1 means "disable channel". */
927 ols->flag_reg |= ~(changrp_mask << 2) & 0x3c;
928 ols->flag_reg |= FLAG_FILTER;
930 data = (ols->flag_reg << 24) | ((ols->flag_reg << 8) & 0xff0000);
931 if (send_longcommand(sdi->serial->fd, CMD_SET_FLAGS, data) != SR_OK)
934 /* Start acquisition on the device. */
935 if (send_shortcommand(sdi->serial->fd, CMD_RUN) != SR_OK)
938 sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data,
941 if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
942 sr_err("ols: %s: packet malloc failed", __func__);
943 return SR_ERR_MALLOC;
946 if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
947 sr_err("ols: %s: header malloc failed", __func__);
949 return SR_ERR_MALLOC;
952 /* Send header packet to the session bus. */
953 packet->type = SR_DF_HEADER;
954 packet->payload = (unsigned char *)header;
955 header->feed_version = 1;
956 gettimeofday(&header->starttime, NULL);
957 header->samplerate = ols->cur_samplerate;
958 header->num_logic_probes = NUM_PROBES;
959 header->num_analog_probes = 0;
960 sr_session_bus(session_data, packet);
968 static void hw_stop_acquisition(int device_index, gpointer session_device_id)
970 struct sr_datafeed_packet packet;
972 /* Avoid compiler warnings. */
973 device_index = device_index;
975 packet.type = SR_DF_END;
976 sr_session_bus(session_device_id, &packet);
979 struct sr_device_plugin ols_plugin_info = {
981 .longname = "Openbench Logic Sniffer",
984 .cleanup = hw_cleanup,
985 .opendev = hw_opendev,
986 .closedev = hw_closedev,
987 .get_device_info = hw_get_device_info,
988 .get_status = hw_get_status,
989 .get_capabilities = hw_get_capabilities,
990 .set_configuration = hw_set_configuration,
991 .start_acquisition = hw_start_acquisition,
992 .stop_acquisition = hw_stop_acquisition,