2 * This file is part of the sigrok project.
4 * Copyright (C) 2010-2012 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>
41 #include "libsigrok.h"
42 #include "libsigrok-internal.h"
46 #define O_NONBLOCK FIONBIO
49 #define SERIALCOMM "115200/8n1"
51 static const int hwcaps[] = {
52 SR_HWCAP_LOGIC_ANALYZER,
54 SR_HWCAP_CAPTURE_RATIO,
55 SR_HWCAP_LIMIT_SAMPLES,
60 /* Probes are numbered 0-31 (on the PCB silkscreen). */
61 static const char *probe_names[NUM_PROBES + 1] = {
97 /* default supported samplerates, can be overridden by device metadata */
98 static const struct sr_samplerates samplerates = {
105 SR_PRIV struct sr_dev_driver ols_driver_info;
106 static struct sr_dev_driver *odi = &ols_driver_info;
108 static int send_shortcommand(struct sr_serial_dev_inst *serial,
113 sr_dbg("ols: sending cmd 0x%.2x", command);
115 if (serial_write(serial, buf, 1) != 1)
121 static int send_longcommand(struct sr_serial_dev_inst *serial,
122 uint8_t command, uint32_t data)
126 sr_dbg("ols: sending cmd 0x%.2x data 0x%.8x", command, data);
128 buf[1] = (data & 0xff000000) >> 24;
129 buf[2] = (data & 0xff0000) >> 16;
130 buf[3] = (data & 0xff00) >> 8;
131 buf[4] = data & 0xff;
132 if (serial_write(serial, buf, 5) != 5)
138 static int configure_probes(const struct sr_dev_inst *sdi)
140 struct dev_context *devc;
141 const struct sr_probe *probe;
143 int probe_bit, stage, i;
148 devc->probe_mask = 0;
149 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
150 devc->trigger_mask[i] = 0;
151 devc->trigger_value[i] = 0;
154 devc->num_stages = 0;
155 for (l = sdi->probes; l; l = l->next) {
156 probe = (const struct sr_probe *)l->data;
161 * Set up the probe mask for later configuration into the
164 probe_bit = 1 << (probe->index);
165 devc->probe_mask |= probe_bit;
170 /* Configure trigger mask and value. */
172 for (tc = probe->trigger; tc && *tc; tc++) {
173 devc->trigger_mask[stage] |= probe_bit;
175 devc->trigger_value[stage] |= probe_bit;
179 * TODO: Only supporting parallel mode, with
184 if (stage > devc->num_stages)
185 devc->num_stages = stage;
191 static uint32_t reverse16(uint32_t in)
195 out = (in & 0xff) << 8;
196 out |= (in & 0xff00) >> 8;
197 out |= (in & 0xff0000) << 8;
198 out |= (in & 0xff000000) >> 8;
203 static uint32_t reverse32(uint32_t in)
207 out = (in & 0xff) << 24;
208 out |= (in & 0xff00) << 8;
209 out |= (in & 0xff0000) >> 8;
210 out |= (in & 0xff000000) >> 24;
215 static struct dev_context *ols_dev_new(void)
217 struct dev_context *devc;
219 if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
220 sr_err("ols: %s: devc malloc failed", __func__);
224 devc->trigger_at = -1;
225 devc->probe_mask = 0xffffffff;
226 devc->cur_samplerate = SR_KHZ(200);
232 static struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
234 struct sr_dev_inst *sdi;
235 struct dev_context *devc;
236 struct sr_probe *probe;
237 uint32_t tmp_int, ui;
238 uint8_t key, type, token;
239 GString *tmp_str, *devname, *version;
242 sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, NULL, NULL, NULL);
244 devc = ols_dev_new();
247 devname = g_string_new("");
248 version = g_string_new("");
252 if (serial_read(serial, &key, 1) != 1 || key == 0x00)
258 /* NULL-terminated string */
259 tmp_str = g_string_new("");
260 while (serial_read(serial, &tmp_c, 1) == 1 && tmp_c != '\0')
261 g_string_append_c(tmp_str, tmp_c);
262 sr_dbg("ols: got metadata key 0x%.2x value '%s'",
267 devname = g_string_append(devname, tmp_str->str);
270 /* FPGA firmware version */
272 g_string_append(version, ", ");
273 g_string_append(version, "FPGA version ");
274 g_string_append(version, tmp_str->str);
277 /* Ancillary version */
279 g_string_append(version, ", ");
280 g_string_append(version, "Ancillary version ");
281 g_string_append(version, tmp_str->str);
284 sr_info("ols: unknown token 0x%.2x: '%s'",
285 token, tmp_str->str);
288 g_string_free(tmp_str, TRUE);
291 /* 32-bit unsigned integer */
292 if (serial_read(serial, &tmp_int, 4) != 4)
294 tmp_int = reverse32(tmp_int);
295 sr_dbg("ols: got metadata key 0x%.2x value 0x%.8x",
299 /* Number of usable probes */
300 for (ui = 0; ui < tmp_int; ui++) {
301 if (!(probe = sr_probe_new(ui, SR_PROBE_LOGIC, TRUE,
304 sdi->probes = g_slist_append(sdi->probes, probe);
308 /* Amount of sample memory available (bytes) */
309 devc->max_samples = tmp_int;
312 /* Amount of dynamic memory available (bytes) */
313 /* what is this for? */
316 /* Maximum sample rate (hz) */
317 devc->max_samplerate = tmp_int;
320 /* protocol version */
321 devc->protocol_version = tmp_int;
324 sr_info("ols: unknown token 0x%.2x: 0x%.8x",
330 /* 8-bit unsigned integer */
331 if (serial_read(serial, &tmp_c, 1) != 1)
333 sr_dbg("ols: got metadata key 0x%.2x value 0x%.2x",
337 /* Number of usable probes */
338 for (ui = 0; ui < tmp_c; ui++) {
339 if (!(probe = sr_probe_new(ui, SR_PROBE_LOGIC, TRUE,
342 sdi->probes = g_slist_append(sdi->probes, probe);
346 /* protocol version */
347 devc->protocol_version = tmp_c;
350 sr_info("ols: unknown token 0x%.2x: 0x%.2x",
361 sdi->model = devname->str;
362 sdi->version = version->str;
363 g_string_free(devname, FALSE);
364 g_string_free(version, FALSE);
369 static int hw_init(void)
371 struct drv_context *drvc;
373 if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
374 sr_err("ols: driver context malloc failed.");
375 return SR_ERR_MALLOC;
382 static GSList *hw_scan(GSList *options)
384 struct sr_hwopt *opt;
385 struct sr_dev_inst *sdi;
386 struct drv_context *drvc;
387 struct dev_context *devc;
388 struct sr_probe *probe;
389 struct sr_serial_dev_inst *serial;
393 const char *conn, *serialcomm;
400 conn = serialcomm = NULL;
401 for (l = options; l; l = l->next) {
403 switch (opt->hwopt) {
407 case SR_HWOPT_SERIALCOMM:
408 serialcomm = opt->value;
413 sr_err("ols: No serial port specified.");
417 if (serialcomm == NULL)
418 serialcomm = SERIALCOMM;
420 if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
423 /* The discovery procedure is like this: first send the Reset
424 * command (0x00) 5 times, since the device could be anywhere
425 * in a 5-byte command. Then send the ID command (0x02).
426 * If the device responds with 4 bytes ("OLS1" or "SLA1"), we
429 sr_info("ols: probing %s .", conn);
430 if (serial_open(serial, O_RDWR | O_NONBLOCK) != SR_OK)
434 for (i = 0; i < 5; i++) {
435 if ((ret = send_shortcommand(serial, CMD_RESET)) != SR_OK) {
436 sr_err("ols: port %s is not writable.", conn);
441 serial_close(serial);
442 sr_err("ols: Could not use port %s. Quitting.", conn);
445 send_shortcommand(serial, CMD_ID);
447 /* Wait 10ms for a response. */
450 probefd.fd = serial->fd;
451 probefd.events = G_IO_IN;
452 g_poll(&probefd, 1, 1);
454 if (probefd.revents != G_IO_IN)
456 if (serial_read(serial, buf, 4) != 4)
458 if (strncmp(buf, "1SLO", 4) && strncmp(buf, "1ALS", 4))
461 /* Definitely using the OLS protocol, check if it supports
462 * the metadata command.
464 send_shortcommand(serial, CMD_METADATA);
465 if (g_poll(&probefd, 1, 10) > 0) {
467 sdi = get_metadata(serial);
471 /* Not an OLS -- some other board that uses the sump protocol. */
472 sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
473 "Sump", "Logic Analyzer", "v1.0");
475 devc = ols_dev_new();
476 for (i = 0; i < 32; i++) {
477 if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
480 sdi->probes = g_slist_append(sdi->probes, probe);
484 devc->serial = serial;
485 drvc->instances = g_slist_append(drvc->instances, sdi);
486 devices = g_slist_append(devices, sdi);
488 serial_close(serial);
493 static GSList *hw_dev_list(void)
495 struct drv_context *drvc;
499 return drvc->instances;
502 static int hw_dev_open(struct sr_dev_inst *sdi)
504 struct dev_context *devc;
508 if (serial_open(devc->serial, O_RDWR) != SR_OK)
511 sdi->status = SR_ST_ACTIVE;
516 static int hw_dev_close(struct sr_dev_inst *sdi)
518 struct dev_context *devc;
522 if (devc->serial && devc->serial->fd != -1) {
523 serial_close(devc->serial);
524 sdi->status = SR_ST_INACTIVE;
530 static int hw_cleanup(void)
533 struct sr_dev_inst *sdi;
534 struct drv_context *drvc;
535 struct dev_context *devc;
538 if (!(drvc = odi->priv))
541 /* Properly close and free all devices. */
542 for (l = drvc->instances; l; l = l->next) {
543 if (!(sdi = l->data)) {
544 /* Log error, but continue cleaning up the rest. */
545 sr_err("ols: %s: sdi was NULL, continuing", __func__);
549 if (!(devc = sdi->priv)) {
550 /* Log error, but continue cleaning up the rest. */
551 sr_err("ols: %s: sdi->priv was NULL, continuing",
557 sr_serial_dev_inst_free(devc->serial);
558 sr_dev_inst_free(sdi);
560 g_slist_free(drvc->instances);
561 drvc->instances = NULL;
566 static int hw_info_get(int info_id, const void **data,
567 const struct sr_dev_inst *sdi)
569 struct dev_context *devc;
575 case SR_DI_NUM_PROBES:
576 *data = GINT_TO_POINTER(1);
578 case SR_DI_PROBE_NAMES:
581 case SR_DI_SAMPLERATES:
582 *data = &samplerates;
584 case SR_DI_TRIGGER_TYPES:
585 *data = (char *)TRIGGER_TYPES;
587 case SR_DI_CUR_SAMPLERATE:
590 *data = &devc->cur_samplerate;
601 static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
603 struct dev_context *devc;
606 if (devc->max_samplerate) {
607 if (samplerate > devc->max_samplerate)
608 return SR_ERR_SAMPLERATE;
609 } else if (samplerate < samplerates.low || samplerate > samplerates.high)
610 return SR_ERR_SAMPLERATE;
612 if (samplerate > CLOCK_RATE) {
613 devc->flag_reg |= FLAG_DEMUX;
614 devc->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
616 devc->flag_reg &= ~FLAG_DEMUX;
617 devc->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1;
620 /* Calculate actual samplerate used and complain if it is different
621 * from the requested.
623 devc->cur_samplerate = CLOCK_RATE / (devc->cur_samplerate_divider + 1);
624 if (devc->flag_reg & FLAG_DEMUX)
625 devc->cur_samplerate *= 2;
626 if (devc->cur_samplerate != samplerate)
627 sr_err("ols: can't match samplerate %" PRIu64 ", using %"
628 PRIu64, samplerate, devc->cur_samplerate);
633 static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
636 struct dev_context *devc;
638 const uint64_t *tmp_u64;
642 if (sdi->status != SR_ST_ACTIVE)
646 case SR_HWCAP_SAMPLERATE:
647 ret = set_samplerate(sdi, *(const uint64_t *)value);
649 case SR_HWCAP_LIMIT_SAMPLES:
651 if (*tmp_u64 < MIN_NUM_SAMPLES)
653 if (*tmp_u64 > devc->max_samples)
654 sr_err("ols: sample limit exceeds hw max");
655 devc->limit_samples = *tmp_u64;
656 sr_info("ols: sample limit %" PRIu64, devc->limit_samples);
659 case SR_HWCAP_CAPTURE_RATIO:
660 devc->capture_ratio = *(const uint64_t *)value;
661 if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
662 devc->capture_ratio = 0;
668 if (GPOINTER_TO_INT(value)) {
669 sr_info("ols: enabling RLE");
670 devc->flag_reg |= FLAG_RLE;
681 static void abort_acquisition(const struct sr_dev_inst *sdi)
683 struct sr_datafeed_packet packet;
684 struct dev_context *devc;
687 sr_source_remove(devc->serial->fd);
689 /* Terminate session */
690 packet.type = SR_DF_END;
691 sr_session_send(sdi, &packet);
697 static int receive_data(int fd, int revents, void *cb_data)
699 struct sr_datafeed_packet packet;
700 struct sr_datafeed_logic logic;
701 struct sr_dev_inst *sdi;
702 struct drv_context *drvc;
703 struct dev_context *devc;
705 int num_channels, offset, i, j;
710 /* Find this device's devc struct by its fd. */
712 for (l = drvc->instances; l; l = l->next) {
715 if (devc->serial->fd == fd)
720 /* Shouldn't happen. */
723 if (devc->num_transfers++ == 0) {
725 * First time round, means the device started sending data,
726 * and will not stop until done. If it stops sending for
727 * longer than it takes to send a byte, that means it's
728 * finished. We'll double that to 30ms to be sure...
730 sr_source_remove(fd);
731 sr_source_add(fd, G_IO_IN, 30, receive_data, cb_data);
732 /* TODO: Check malloc return code. */
733 devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4);
734 if (!devc->raw_sample_buf) {
735 sr_err("ols: %s: devc->raw_sample_buf malloc failed",
739 /* fill with 1010... for debugging */
740 memset(devc->raw_sample_buf, 0x82, devc->limit_samples * 4);
744 for (i = 0x20; i > 0x02; i /= 2) {
745 if ((devc->flag_reg & i) == 0)
749 if (revents == G_IO_IN) {
750 if (serial_read(devc->serial, &byte, 1) != 1)
753 /* Ignore it if we've read enough. */
754 if (devc->num_samples >= devc->limit_samples)
757 devc->sample[devc->num_bytes++] = byte;
758 sr_dbg("ols: received byte 0x%.2x", byte);
759 if (devc->num_bytes == num_channels) {
760 /* Got a full sample. */
761 sr_dbg("ols: received sample 0x%.*x",
762 devc->num_bytes * 2, *(int *)devc->sample);
763 if (devc->flag_reg & FLAG_RLE) {
765 * In RLE mode -1 should never come in as a
766 * sample, because bit 31 is the "count" flag.
768 if (devc->sample[devc->num_bytes - 1] & 0x80) {
769 devc->sample[devc->num_bytes - 1] &= 0x7f;
771 * FIXME: This will only work on
772 * little-endian systems.
774 devc->rle_count = *(int *)(devc->sample);
775 sr_dbg("ols: RLE count = %d", devc->rle_count);
780 devc->num_samples += devc->rle_count + 1;
781 if (devc->num_samples > devc->limit_samples) {
782 /* Save us from overrunning the buffer. */
783 devc->rle_count -= devc->num_samples - devc->limit_samples;
784 devc->num_samples = devc->limit_samples;
787 if (num_channels < 4) {
789 * Some channel groups may have been turned
790 * off, to speed up transfer between the
791 * hardware and the PC. Expand that here before
792 * submitting it over the session bus --
793 * whatever is listening on the bus will be
794 * expecting a full 32-bit sample, based on
795 * the number of probes.
798 memset(devc->tmp_sample, 0, 4);
799 for (i = 0; i < 4; i++) {
800 if (((devc->flag_reg >> 2) & (1 << i)) == 0) {
802 * This channel group was
803 * enabled, copy from received
806 devc->tmp_sample[i] = devc->sample[j++];
809 memcpy(devc->sample, devc->tmp_sample, 4);
810 sr_dbg("ols: full sample 0x%.8x", *(int *)devc->sample);
813 /* the OLS sends its sample buffer backwards.
814 * store it in reverse order here, so we can dump
815 * this on the session bus later.
817 offset = (devc->limit_samples - devc->num_samples) * 4;
818 for (i = 0; i <= devc->rle_count; i++) {
819 memcpy(devc->raw_sample_buf + offset + (i * 4),
822 memset(devc->sample, 0, 4);
828 * This is the main loop telling us a timeout was reached, or
829 * we've acquired all the samples we asked for -- we're done.
830 * Send the (properly-ordered) buffer to the frontend.
832 if (devc->trigger_at != -1) {
833 /* a trigger was set up, so we need to tell the frontend
836 if (devc->trigger_at > 0) {
837 /* there are pre-trigger samples, send those first */
838 packet.type = SR_DF_LOGIC;
839 packet.payload = &logic;
840 logic.length = devc->trigger_at * 4;
842 logic.data = devc->raw_sample_buf +
843 (devc->limit_samples - devc->num_samples) * 4;
844 sr_session_send(cb_data, &packet);
847 /* send the trigger */
848 packet.type = SR_DF_TRIGGER;
849 sr_session_send(cb_data, &packet);
851 /* send post-trigger samples */
852 packet.type = SR_DF_LOGIC;
853 packet.payload = &logic;
854 logic.length = (devc->num_samples * 4) - (devc->trigger_at * 4);
856 logic.data = devc->raw_sample_buf + devc->trigger_at * 4 +
857 (devc->limit_samples - devc->num_samples) * 4;
858 sr_session_send(cb_data, &packet);
860 /* no trigger was used */
861 packet.type = SR_DF_LOGIC;
862 packet.payload = &logic;
863 logic.length = devc->num_samples * 4;
865 logic.data = devc->raw_sample_buf +
866 (devc->limit_samples - devc->num_samples) * 4;
867 sr_session_send(cb_data, &packet);
869 g_free(devc->raw_sample_buf);
871 serial_flush(devc->serial);
872 abort_acquisition(sdi);
873 serial_close(devc->serial);
879 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
882 struct sr_datafeed_packet *packet;
883 struct sr_datafeed_header *header;
884 struct sr_datafeed_meta_logic meta;
885 struct dev_context *devc;
886 uint32_t trigger_config[4];
888 uint16_t readcount, delaycount;
889 uint8_t changrp_mask;
895 if (sdi->status != SR_ST_ACTIVE)
898 if (configure_probes(sdi) != SR_OK) {
899 sr_err("ols: failed to configured probes");
904 * Enable/disable channel groups in the flag register according to the
905 * probe mask. Calculate this here, because num_channels is needed
906 * to limit readcount.
910 for (i = 0; i < 4; i++) {
911 if (devc->probe_mask & (0xff << (i * 8))) {
912 changrp_mask |= (1 << i);
918 * Limit readcount to prevent reading past the end of the hardware
921 readcount = MIN(devc->max_samples / num_channels, devc->limit_samples) / 4;
923 memset(trigger_config, 0, 16);
924 trigger_config[devc->num_stages - 1] |= 0x08;
925 if (devc->trigger_mask[0]) {
926 delaycount = readcount * (1 - devc->capture_ratio / 100.0);
927 devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages;
929 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_0,
930 reverse32(devc->trigger_mask[0])) != SR_OK)
932 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_0,
933 reverse32(devc->trigger_value[0])) != SR_OK)
935 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_0,
936 trigger_config[0]) != SR_OK)
939 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_1,
940 reverse32(devc->trigger_mask[1])) != SR_OK)
942 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_1,
943 reverse32(devc->trigger_value[1])) != SR_OK)
945 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_1,
946 trigger_config[1]) != SR_OK)
949 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_2,
950 reverse32(devc->trigger_mask[2])) != SR_OK)
952 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_2,
953 reverse32(devc->trigger_value[2])) != SR_OK)
955 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_2,
956 trigger_config[2]) != SR_OK)
959 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_3,
960 reverse32(devc->trigger_mask[3])) != SR_OK)
962 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_3,
963 reverse32(devc->trigger_value[3])) != SR_OK)
965 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_3,
966 trigger_config[3]) != SR_OK)
969 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_0,
970 devc->trigger_mask[0]) != SR_OK)
972 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_0,
973 devc->trigger_value[0]) != SR_OK)
975 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_0,
976 0x00000008) != SR_OK)
978 delaycount = readcount;
981 sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
982 "demux %s)", devc->cur_samplerate, devc->cur_samplerate_divider,
983 devc->flag_reg & FLAG_DEMUX ? "on" : "off");
984 if (send_longcommand(devc->serial, CMD_SET_DIVIDER,
985 reverse32(devc->cur_samplerate_divider)) != SR_OK)
988 /* Send sample limit and pre/post-trigger capture ratio. */
989 data = ((readcount - 1) & 0xffff) << 16;
990 data |= (delaycount - 1) & 0xffff;
991 if (send_longcommand(devc->serial, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
994 /* The flag register wants them here, and 1 means "disable channel". */
995 devc->flag_reg |= ~(changrp_mask << 2) & 0x3c;
996 devc->flag_reg |= FLAG_FILTER;
998 data = (devc->flag_reg << 24) | ((devc->flag_reg << 8) & 0xff0000);
999 if (send_longcommand(devc->serial, CMD_SET_FLAGS, data) != SR_OK)
1002 /* Start acquisition on the device. */
1003 if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK)
1006 sr_source_add(devc->serial->fd, G_IO_IN, -1, receive_data,
1009 if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
1010 sr_err("ols: %s: packet malloc failed", __func__);
1011 return SR_ERR_MALLOC;
1014 if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
1015 sr_err("ols: %s: header malloc failed", __func__);
1017 return SR_ERR_MALLOC;
1020 /* Send header packet to the session bus. */
1021 packet->type = SR_DF_HEADER;
1022 packet->payload = (unsigned char *)header;
1023 header->feed_version = 1;
1024 gettimeofday(&header->starttime, NULL);
1025 sr_session_send(cb_data, packet);
1027 /* Send metadata about the SR_DF_LOGIC packets to come. */
1028 packet->type = SR_DF_META_LOGIC;
1029 packet->payload = &meta;
1030 meta.samplerate = devc->cur_samplerate;
1031 meta.num_probes = NUM_PROBES;
1032 sr_session_send(cb_data, packet);
1040 /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
1041 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
1043 /* Avoid compiler warnings. */
1046 abort_acquisition(sdi);
1051 SR_PRIV struct sr_dev_driver ols_driver_info = {
1053 .longname = "Openbench Logic Sniffer",
1056 .cleanup = hw_cleanup,
1058 .dev_list = hw_dev_list,
1059 .dev_clear = hw_cleanup,
1060 .dev_open = hw_dev_open,
1061 .dev_close = hw_dev_close,
1062 .info_get = hw_info_get,
1063 .dev_config_set = hw_dev_config_set,
1064 .dev_acquisition_start = hw_dev_acquisition_start,
1065 .dev_acquisition_stop = hw_dev_acquisition_stop,