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"
45 #define SERIALCOMM "115200/8n1"
47 static const int hwcaps[] = {
48 SR_HWCAP_LOGIC_ANALYZER,
50 SR_HWCAP_CAPTURE_RATIO,
51 SR_HWCAP_LIMIT_SAMPLES,
56 /* Probes are numbered 0-31 (on the PCB silkscreen). */
57 static const char *probe_names[NUM_PROBES + 1] = {
93 /* default supported samplerates, can be overridden by device metadata */
94 static const struct sr_samplerates samplerates = {
101 SR_PRIV struct sr_dev_driver ols_driver_info;
102 static struct sr_dev_driver *di = &ols_driver_info;
104 static int send_shortcommand(struct sr_serial_dev_inst *serial,
109 sr_dbg("Sending cmd 0x%.2x.", command);
111 if (serial_write(serial, buf, 1) != 1)
117 static int send_longcommand(struct sr_serial_dev_inst *serial,
118 uint8_t command, uint32_t data)
122 sr_dbg("Sending cmd 0x%.2x data 0x%.8x.", command, data);
124 buf[1] = (data & 0xff000000) >> 24;
125 buf[2] = (data & 0xff0000) >> 16;
126 buf[3] = (data & 0xff00) >> 8;
127 buf[4] = data & 0xff;
128 if (serial_write(serial, buf, 5) != 5)
134 static int configure_probes(const struct sr_dev_inst *sdi)
136 struct dev_context *devc;
137 const struct sr_probe *probe;
139 int probe_bit, stage, i;
144 devc->probe_mask = 0;
145 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
146 devc->trigger_mask[i] = 0;
147 devc->trigger_value[i] = 0;
150 devc->num_stages = 0;
151 for (l = sdi->probes; l; l = l->next) {
152 probe = (const struct sr_probe *)l->data;
157 * Set up the probe mask for later configuration into the
160 probe_bit = 1 << (probe->index);
161 devc->probe_mask |= probe_bit;
166 /* Configure trigger mask and value. */
168 for (tc = probe->trigger; tc && *tc; tc++) {
169 devc->trigger_mask[stage] |= probe_bit;
171 devc->trigger_value[stage] |= probe_bit;
175 * TODO: Only supporting parallel mode, with
180 if (stage > devc->num_stages)
181 devc->num_stages = stage;
187 static uint32_t reverse16(uint32_t in)
191 out = (in & 0xff) << 8;
192 out |= (in & 0xff00) >> 8;
193 out |= (in & 0xff0000) << 8;
194 out |= (in & 0xff000000) >> 8;
199 static uint32_t reverse32(uint32_t in)
203 out = (in & 0xff) << 24;
204 out |= (in & 0xff00) << 8;
205 out |= (in & 0xff0000) >> 8;
206 out |= (in & 0xff000000) >> 24;
211 static struct dev_context *ols_dev_new(void)
213 struct dev_context *devc;
215 if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
216 sr_err("Device context malloc failed.");
220 devc->trigger_at = -1;
221 devc->probe_mask = 0xffffffff;
222 devc->cur_samplerate = SR_KHZ(200);
228 static struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial)
230 struct sr_dev_inst *sdi;
231 struct dev_context *devc;
232 struct sr_probe *probe;
233 uint32_t tmp_int, ui;
234 uint8_t key, type, token;
235 GString *tmp_str, *devname, *version;
238 sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, NULL, NULL, NULL);
240 devc = ols_dev_new();
243 devname = g_string_new("");
244 version = g_string_new("");
248 if (serial_read(serial, &key, 1) != 1 || key == 0x00)
254 /* NULL-terminated string */
255 tmp_str = g_string_new("");
256 while (serial_read(serial, &tmp_c, 1) == 1 && tmp_c != '\0')
257 g_string_append_c(tmp_str, tmp_c);
258 sr_dbg("Got metadata key 0x%.2x value '%s'.",
263 devname = g_string_append(devname, tmp_str->str);
266 /* FPGA firmware version */
268 g_string_append(version, ", ");
269 g_string_append(version, "FPGA version ");
270 g_string_append(version, tmp_str->str);
273 /* Ancillary version */
275 g_string_append(version, ", ");
276 g_string_append(version, "Ancillary version ");
277 g_string_append(version, tmp_str->str);
280 sr_info("ols: unknown token 0x%.2x: '%s'",
281 token, tmp_str->str);
284 g_string_free(tmp_str, TRUE);
287 /* 32-bit unsigned integer */
288 if (serial_read(serial, &tmp_int, 4) != 4)
290 tmp_int = reverse32(tmp_int);
291 sr_dbg("Got metadata key 0x%.2x value 0x%.8x.",
295 /* Number of usable probes */
296 for (ui = 0; ui < tmp_int; ui++) {
297 if (!(probe = sr_probe_new(ui, SR_PROBE_LOGIC, TRUE,
300 sdi->probes = g_slist_append(sdi->probes, probe);
304 /* Amount of sample memory available (bytes) */
305 devc->max_samples = tmp_int;
308 /* Amount of dynamic memory available (bytes) */
309 /* what is this for? */
312 /* Maximum sample rate (hz) */
313 devc->max_samplerate = tmp_int;
316 /* protocol version */
317 devc->protocol_version = tmp_int;
320 sr_info("Unknown token 0x%.2x: 0x%.8x.",
326 /* 8-bit unsigned integer */
327 if (serial_read(serial, &tmp_c, 1) != 1)
329 sr_dbg("Got metadata key 0x%.2x value 0x%.2x.",
333 /* Number of usable probes */
334 for (ui = 0; ui < tmp_c; ui++) {
335 if (!(probe = sr_probe_new(ui, SR_PROBE_LOGIC, TRUE,
338 sdi->probes = g_slist_append(sdi->probes, probe);
342 /* protocol version */
343 devc->protocol_version = tmp_c;
346 sr_info("Unknown token 0x%.2x: 0x%.2x.",
357 sdi->model = devname->str;
358 sdi->version = version->str;
359 g_string_free(devname, FALSE);
360 g_string_free(version, FALSE);
365 static int hw_init(struct sr_context *sr_ctx)
367 struct drv_context *drvc;
369 if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
370 sr_err("Driver context malloc failed.");
371 return SR_ERR_MALLOC;
373 drvc->sr_ctx = sr_ctx;
379 static GSList *hw_scan(GSList *options)
381 struct sr_hwopt *opt;
382 struct sr_dev_inst *sdi;
383 struct drv_context *drvc;
384 struct dev_context *devc;
385 struct sr_probe *probe;
386 struct sr_serial_dev_inst *serial;
390 const char *conn, *serialcomm;
397 conn = serialcomm = NULL;
398 for (l = options; l; l = l->next) {
400 switch (opt->hwopt) {
404 case SR_HWOPT_SERIALCOMM:
405 serialcomm = opt->value;
412 if (serialcomm == NULL)
413 serialcomm = SERIALCOMM;
415 if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
418 /* The discovery procedure is like this: first send the Reset
419 * command (0x00) 5 times, since the device could be anywhere
420 * in a 5-byte command. Then send the ID command (0x02).
421 * If the device responds with 4 bytes ("OLS1" or "SLA1"), we
424 sr_info("Probing %s.", conn);
425 if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
429 for (i = 0; i < 5; i++) {
430 if ((ret = send_shortcommand(serial, CMD_RESET)) != SR_OK) {
431 sr_err("Port %s is not writable.", conn);
436 serial_close(serial);
437 sr_err("Could not use port %s. Quitting.", conn);
440 send_shortcommand(serial, CMD_ID);
442 /* Wait 10ms for a response. */
445 probefd.fd = serial->fd;
446 probefd.events = G_IO_IN;
447 g_poll(&probefd, 1, 1);
449 if (probefd.revents != G_IO_IN)
451 if (serial_read(serial, buf, 4) != 4)
453 if (strncmp(buf, "1SLO", 4) && strncmp(buf, "1ALS", 4))
456 /* Definitely using the OLS protocol, check if it supports
457 * the metadata command.
459 send_shortcommand(serial, CMD_METADATA);
460 if (g_poll(&probefd, 1, 10) > 0) {
462 sdi = get_metadata(serial);
466 /* Not an OLS -- some other board that uses the sump protocol. */
467 sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
468 "Sump", "Logic Analyzer", "v1.0");
470 devc = ols_dev_new();
471 for (i = 0; i < 32; i++) {
472 if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
475 sdi->probes = g_slist_append(sdi->probes, probe);
479 devc->serial = serial;
480 drvc->instances = g_slist_append(drvc->instances, sdi);
481 devices = g_slist_append(devices, sdi);
483 serial_close(serial);
488 static GSList *hw_dev_list(void)
490 struct drv_context *drvc;
494 return drvc->instances;
497 static int hw_dev_open(struct sr_dev_inst *sdi)
499 struct dev_context *devc;
503 if (serial_open(devc->serial, SERIAL_RDWR) != SR_OK)
506 sdi->status = SR_ST_ACTIVE;
511 static int hw_dev_close(struct sr_dev_inst *sdi)
513 struct dev_context *devc;
517 if (devc->serial && devc->serial->fd != -1) {
518 serial_close(devc->serial);
519 sdi->status = SR_ST_INACTIVE;
525 static int hw_cleanup(void)
528 struct sr_dev_inst *sdi;
529 struct drv_context *drvc;
530 struct dev_context *devc;
533 if (!(drvc = di->priv))
536 /* Properly close and free all devices. */
537 for (l = drvc->instances; l; l = l->next) {
538 if (!(sdi = l->data)) {
539 /* Log error, but continue cleaning up the rest. */
540 sr_err("%s: sdi was NULL, continuing", __func__);
544 if (!(devc = sdi->priv)) {
545 /* Log error, but continue cleaning up the rest. */
546 sr_err("%s: sdi->priv was NULL, continuing", __func__);
551 sr_serial_dev_inst_free(devc->serial);
552 sr_dev_inst_free(sdi);
554 g_slist_free(drvc->instances);
555 drvc->instances = NULL;
560 static int hw_info_get(int info_id, const void **data,
561 const struct sr_dev_inst *sdi)
563 struct dev_context *devc;
569 case SR_DI_NUM_PROBES:
570 *data = GINT_TO_POINTER(1);
572 case SR_DI_PROBE_NAMES:
575 case SR_DI_SAMPLERATES:
576 *data = &samplerates;
578 case SR_DI_TRIGGER_TYPES:
579 *data = (char *)TRIGGER_TYPES;
581 case SR_DI_CUR_SAMPLERATE:
584 *data = &devc->cur_samplerate;
595 static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
597 struct dev_context *devc;
600 if (devc->max_samplerate) {
601 if (samplerate > devc->max_samplerate)
602 return SR_ERR_SAMPLERATE;
603 } else if (samplerate < samplerates.low || samplerate > samplerates.high)
604 return SR_ERR_SAMPLERATE;
606 if (samplerate > CLOCK_RATE) {
607 devc->flag_reg |= FLAG_DEMUX;
608 devc->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
610 devc->flag_reg &= ~FLAG_DEMUX;
611 devc->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1;
614 /* Calculate actual samplerate used and complain if it is different
615 * from the requested.
617 devc->cur_samplerate = CLOCK_RATE / (devc->cur_samplerate_divider + 1);
618 if (devc->flag_reg & FLAG_DEMUX)
619 devc->cur_samplerate *= 2;
620 if (devc->cur_samplerate != samplerate)
621 sr_err("Can't match samplerate %" PRIu64 ", using %"
622 PRIu64 ".", samplerate, devc->cur_samplerate);
627 static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
630 struct dev_context *devc;
632 const uint64_t *tmp_u64;
636 if (sdi->status != SR_ST_ACTIVE)
640 case SR_HWCAP_SAMPLERATE:
641 ret = set_samplerate(sdi, *(const uint64_t *)value);
643 case SR_HWCAP_LIMIT_SAMPLES:
645 if (*tmp_u64 < MIN_NUM_SAMPLES)
647 if (*tmp_u64 > devc->max_samples)
648 sr_err("Sample limit exceeds hardware maximum.");
649 devc->limit_samples = *tmp_u64;
650 sr_info("Sample limit is %" PRIu64 ".", devc->limit_samples);
653 case SR_HWCAP_CAPTURE_RATIO:
654 devc->capture_ratio = *(const uint64_t *)value;
655 if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
656 devc->capture_ratio = 0;
662 if (GPOINTER_TO_INT(value)) {
663 sr_info("Enabling RLE.");
664 devc->flag_reg |= FLAG_RLE;
675 static void abort_acquisition(const struct sr_dev_inst *sdi)
677 struct sr_datafeed_packet packet;
678 struct dev_context *devc;
681 sr_source_remove(devc->serial->fd);
683 /* Terminate session */
684 packet.type = SR_DF_END;
685 sr_session_send(sdi, &packet);
688 static int receive_data(int fd, int revents, void *cb_data)
690 struct sr_datafeed_packet packet;
691 struct sr_datafeed_logic logic;
692 struct sr_dev_inst *sdi;
693 struct drv_context *drvc;
694 struct dev_context *devc;
696 int num_channels, offset, i, j;
701 /* Find this device's devc struct by its fd. */
703 for (l = drvc->instances; l; l = l->next) {
706 if (devc->serial->fd == fd)
711 /* Shouldn't happen. */
714 if (devc->num_transfers++ == 0) {
716 * First time round, means the device started sending data,
717 * and will not stop until done. If it stops sending for
718 * longer than it takes to send a byte, that means it's
719 * finished. We'll double that to 30ms to be sure...
721 sr_source_remove(fd);
722 sr_source_add(fd, G_IO_IN, 30, receive_data, cb_data);
723 devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4);
724 if (!devc->raw_sample_buf) {
725 sr_err("Sample buffer malloc failed.");
728 /* fill with 1010... for debugging */
729 memset(devc->raw_sample_buf, 0x82, devc->limit_samples * 4);
733 for (i = 0x20; i > 0x02; i /= 2) {
734 if ((devc->flag_reg & i) == 0)
738 if (revents == G_IO_IN) {
739 if (serial_read(devc->serial, &byte, 1) != 1)
742 /* Ignore it if we've read enough. */
743 if (devc->num_samples >= devc->limit_samples)
746 devc->sample[devc->num_bytes++] = byte;
747 sr_dbg("Received byte 0x%.2x.", byte);
748 if (devc->num_bytes == num_channels) {
749 /* Got a full sample. */
750 sr_dbg("Received sample 0x%.*x.",
751 devc->num_bytes * 2, *(int *)devc->sample);
752 if (devc->flag_reg & FLAG_RLE) {
754 * In RLE mode -1 should never come in as a
755 * sample, because bit 31 is the "count" flag.
757 if (devc->sample[devc->num_bytes - 1] & 0x80) {
758 devc->sample[devc->num_bytes - 1] &= 0x7f;
760 * FIXME: This will only work on
761 * little-endian systems.
763 devc->rle_count = *(int *)(devc->sample);
764 sr_dbg("RLE count: %d.", devc->rle_count);
769 devc->num_samples += devc->rle_count + 1;
770 if (devc->num_samples > devc->limit_samples) {
771 /* Save us from overrunning the buffer. */
772 devc->rle_count -= devc->num_samples - devc->limit_samples;
773 devc->num_samples = devc->limit_samples;
776 if (num_channels < 4) {
778 * Some channel groups may have been turned
779 * off, to speed up transfer between the
780 * hardware and the PC. Expand that here before
781 * submitting it over the session bus --
782 * whatever is listening on the bus will be
783 * expecting a full 32-bit sample, based on
784 * the number of probes.
787 memset(devc->tmp_sample, 0, 4);
788 for (i = 0; i < 4; i++) {
789 if (((devc->flag_reg >> 2) & (1 << i)) == 0) {
791 * This channel group was
792 * enabled, copy from received
795 devc->tmp_sample[i] = devc->sample[j++];
798 memcpy(devc->sample, devc->tmp_sample, 4);
799 sr_dbg("Full sample: 0x%.8x.", *(int *)devc->sample);
802 /* the OLS sends its sample buffer backwards.
803 * store it in reverse order here, so we can dump
804 * this on the session bus later.
806 offset = (devc->limit_samples - devc->num_samples) * 4;
807 for (i = 0; i <= devc->rle_count; i++) {
808 memcpy(devc->raw_sample_buf + offset + (i * 4),
811 memset(devc->sample, 0, 4);
817 * This is the main loop telling us a timeout was reached, or
818 * we've acquired all the samples we asked for -- we're done.
819 * Send the (properly-ordered) buffer to the frontend.
821 if (devc->trigger_at != -1) {
822 /* a trigger was set up, so we need to tell the frontend
825 if (devc->trigger_at > 0) {
826 /* there are pre-trigger samples, send those first */
827 packet.type = SR_DF_LOGIC;
828 packet.payload = &logic;
829 logic.length = devc->trigger_at * 4;
831 logic.data = devc->raw_sample_buf +
832 (devc->limit_samples - devc->num_samples) * 4;
833 sr_session_send(cb_data, &packet);
836 /* send the trigger */
837 packet.type = SR_DF_TRIGGER;
838 sr_session_send(cb_data, &packet);
840 /* send post-trigger samples */
841 packet.type = SR_DF_LOGIC;
842 packet.payload = &logic;
843 logic.length = (devc->num_samples * 4) - (devc->trigger_at * 4);
845 logic.data = devc->raw_sample_buf + devc->trigger_at * 4 +
846 (devc->limit_samples - devc->num_samples) * 4;
847 sr_session_send(cb_data, &packet);
849 /* no trigger was used */
850 packet.type = SR_DF_LOGIC;
851 packet.payload = &logic;
852 logic.length = devc->num_samples * 4;
854 logic.data = devc->raw_sample_buf +
855 (devc->limit_samples - devc->num_samples) * 4;
856 sr_session_send(cb_data, &packet);
858 g_free(devc->raw_sample_buf);
860 serial_flush(devc->serial);
861 abort_acquisition(sdi);
862 serial_close(devc->serial);
868 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
871 struct sr_datafeed_packet *packet;
872 struct sr_datafeed_header *header;
873 struct sr_datafeed_meta_logic meta;
874 struct dev_context *devc;
875 uint32_t trigger_config[4];
877 uint16_t readcount, delaycount;
878 uint8_t changrp_mask;
884 if (sdi->status != SR_ST_ACTIVE)
887 if (configure_probes(sdi) != SR_OK) {
888 sr_err("Failed to configure probes.");
893 * Enable/disable channel groups in the flag register according to the
894 * probe mask. Calculate this here, because num_channels is needed
895 * to limit readcount.
899 for (i = 0; i < 4; i++) {
900 if (devc->probe_mask & (0xff << (i * 8))) {
901 changrp_mask |= (1 << i);
907 * Limit readcount to prevent reading past the end of the hardware
910 readcount = MIN(devc->max_samples / num_channels, devc->limit_samples) / 4;
912 memset(trigger_config, 0, 16);
913 trigger_config[devc->num_stages - 1] |= 0x08;
914 if (devc->trigger_mask[0]) {
915 delaycount = readcount * (1 - devc->capture_ratio / 100.0);
916 devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages;
918 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_0,
919 reverse32(devc->trigger_mask[0])) != SR_OK)
921 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_0,
922 reverse32(devc->trigger_value[0])) != SR_OK)
924 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_0,
925 trigger_config[0]) != SR_OK)
928 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_1,
929 reverse32(devc->trigger_mask[1])) != SR_OK)
931 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_1,
932 reverse32(devc->trigger_value[1])) != SR_OK)
934 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_1,
935 trigger_config[1]) != SR_OK)
938 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_2,
939 reverse32(devc->trigger_mask[2])) != SR_OK)
941 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_2,
942 reverse32(devc->trigger_value[2])) != SR_OK)
944 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_2,
945 trigger_config[2]) != SR_OK)
948 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_3,
949 reverse32(devc->trigger_mask[3])) != SR_OK)
951 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_3,
952 reverse32(devc->trigger_value[3])) != SR_OK)
954 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_3,
955 trigger_config[3]) != SR_OK)
958 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_0,
959 devc->trigger_mask[0]) != SR_OK)
961 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_0,
962 devc->trigger_value[0]) != SR_OK)
964 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_0,
965 0x00000008) != SR_OK)
967 delaycount = readcount;
970 sr_info("Setting samplerate to %" PRIu64 "Hz (divider %u, "
971 "demux %s)", devc->cur_samplerate, devc->cur_samplerate_divider,
972 devc->flag_reg & FLAG_DEMUX ? "on" : "off");
973 if (send_longcommand(devc->serial, CMD_SET_DIVIDER,
974 reverse32(devc->cur_samplerate_divider)) != SR_OK)
977 /* Send sample limit and pre/post-trigger capture ratio. */
978 data = ((readcount - 1) & 0xffff) << 16;
979 data |= (delaycount - 1) & 0xffff;
980 if (send_longcommand(devc->serial, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
983 /* The flag register wants them here, and 1 means "disable channel". */
984 devc->flag_reg |= ~(changrp_mask << 2) & 0x3c;
985 devc->flag_reg |= FLAG_FILTER;
987 data = (devc->flag_reg << 24) | ((devc->flag_reg << 8) & 0xff0000);
988 if (send_longcommand(devc->serial, CMD_SET_FLAGS, data) != SR_OK)
991 /* Start acquisition on the device. */
992 if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK)
995 sr_source_add(devc->serial->fd, G_IO_IN, -1, receive_data,
998 if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
999 sr_err("Datafeed packet malloc failed.");
1000 return SR_ERR_MALLOC;
1003 if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
1004 sr_err("Datafeed header malloc failed.");
1006 return SR_ERR_MALLOC;
1009 /* Send header packet to the session bus. */
1010 packet->type = SR_DF_HEADER;
1011 packet->payload = (unsigned char *)header;
1012 header->feed_version = 1;
1013 gettimeofday(&header->starttime, NULL);
1014 sr_session_send(cb_data, packet);
1016 /* Send metadata about the SR_DF_LOGIC packets to come. */
1017 packet->type = SR_DF_META_LOGIC;
1018 packet->payload = &meta;
1019 meta.samplerate = devc->cur_samplerate;
1020 meta.num_probes = NUM_PROBES;
1021 sr_session_send(cb_data, packet);
1029 /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
1030 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
1032 /* Avoid compiler warnings. */
1035 abort_acquisition(sdi);
1040 SR_PRIV struct sr_dev_driver ols_driver_info = {
1042 .longname = "Openbench Logic Sniffer",
1045 .cleanup = hw_cleanup,
1047 .dev_list = hw_dev_list,
1048 .dev_clear = hw_cleanup,
1049 .dev_open = hw_dev_open,
1050 .dev_close = hw_dev_close,
1051 .info_get = hw_info_get,
1052 .dev_config_set = hw_dev_config_set,
1053 .dev_acquisition_start = hw_dev_acquisition_start,
1054 .dev_acquisition_stop = hw_dev_acquisition_stop,