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("ols: 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("ols: 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("ols: %s: devc malloc failed", __func__);
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("ols: 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("ols: 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("ols: unknown token 0x%.2x: 0x%.8x",
326 /* 8-bit unsigned integer */
327 if (serial_read(serial, &tmp_c, 1) != 1)
329 sr_dbg("ols: 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("ols: 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("ols: 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("ols: 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("ols: port %s is not writable.", conn);
436 serial_close(serial);
437 sr_err("ols: 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("ols: %s: sdi was NULL, continuing", __func__);
544 if (!(devc = sdi->priv)) {
545 /* Log error, but continue cleaning up the rest. */
546 sr_err("ols: %s: sdi->priv was NULL, continuing",
552 sr_serial_dev_inst_free(devc->serial);
553 sr_dev_inst_free(sdi);
555 g_slist_free(drvc->instances);
556 drvc->instances = NULL;
561 static int hw_info_get(int info_id, const void **data,
562 const struct sr_dev_inst *sdi)
564 struct dev_context *devc;
570 case SR_DI_NUM_PROBES:
571 *data = GINT_TO_POINTER(1);
573 case SR_DI_PROBE_NAMES:
576 case SR_DI_SAMPLERATES:
577 *data = &samplerates;
579 case SR_DI_TRIGGER_TYPES:
580 *data = (char *)TRIGGER_TYPES;
582 case SR_DI_CUR_SAMPLERATE:
585 *data = &devc->cur_samplerate;
596 static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
598 struct dev_context *devc;
601 if (devc->max_samplerate) {
602 if (samplerate > devc->max_samplerate)
603 return SR_ERR_SAMPLERATE;
604 } else if (samplerate < samplerates.low || samplerate > samplerates.high)
605 return SR_ERR_SAMPLERATE;
607 if (samplerate > CLOCK_RATE) {
608 devc->flag_reg |= FLAG_DEMUX;
609 devc->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
611 devc->flag_reg &= ~FLAG_DEMUX;
612 devc->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1;
615 /* Calculate actual samplerate used and complain if it is different
616 * from the requested.
618 devc->cur_samplerate = CLOCK_RATE / (devc->cur_samplerate_divider + 1);
619 if (devc->flag_reg & FLAG_DEMUX)
620 devc->cur_samplerate *= 2;
621 if (devc->cur_samplerate != samplerate)
622 sr_err("ols: can't match samplerate %" PRIu64 ", using %"
623 PRIu64, samplerate, devc->cur_samplerate);
628 static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
631 struct dev_context *devc;
633 const uint64_t *tmp_u64;
637 if (sdi->status != SR_ST_ACTIVE)
641 case SR_HWCAP_SAMPLERATE:
642 ret = set_samplerate(sdi, *(const uint64_t *)value);
644 case SR_HWCAP_LIMIT_SAMPLES:
646 if (*tmp_u64 < MIN_NUM_SAMPLES)
648 if (*tmp_u64 > devc->max_samples)
649 sr_err("ols: sample limit exceeds hw max");
650 devc->limit_samples = *tmp_u64;
651 sr_info("ols: sample limit %" PRIu64, devc->limit_samples);
654 case SR_HWCAP_CAPTURE_RATIO:
655 devc->capture_ratio = *(const uint64_t *)value;
656 if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
657 devc->capture_ratio = 0;
663 if (GPOINTER_TO_INT(value)) {
664 sr_info("ols: enabling RLE");
665 devc->flag_reg |= FLAG_RLE;
676 static void abort_acquisition(const struct sr_dev_inst *sdi)
678 struct sr_datafeed_packet packet;
679 struct dev_context *devc;
682 sr_source_remove(devc->serial->fd);
684 /* Terminate session */
685 packet.type = SR_DF_END;
686 sr_session_send(sdi, &packet);
692 static int receive_data(int fd, int revents, void *cb_data)
694 struct sr_datafeed_packet packet;
695 struct sr_datafeed_logic logic;
696 struct sr_dev_inst *sdi;
697 struct drv_context *drvc;
698 struct dev_context *devc;
700 int num_channels, offset, i, j;
705 /* Find this device's devc struct by its fd. */
707 for (l = drvc->instances; l; l = l->next) {
710 if (devc->serial->fd == fd)
715 /* Shouldn't happen. */
718 if (devc->num_transfers++ == 0) {
720 * First time round, means the device started sending data,
721 * and will not stop until done. If it stops sending for
722 * longer than it takes to send a byte, that means it's
723 * finished. We'll double that to 30ms to be sure...
725 sr_source_remove(fd);
726 sr_source_add(fd, G_IO_IN, 30, receive_data, cb_data);
727 /* TODO: Check malloc return code. */
728 devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4);
729 if (!devc->raw_sample_buf) {
730 sr_err("ols: %s: devc->raw_sample_buf malloc failed",
734 /* fill with 1010... for debugging */
735 memset(devc->raw_sample_buf, 0x82, devc->limit_samples * 4);
739 for (i = 0x20; i > 0x02; i /= 2) {
740 if ((devc->flag_reg & i) == 0)
744 if (revents == G_IO_IN) {
745 if (serial_read(devc->serial, &byte, 1) != 1)
748 /* Ignore it if we've read enough. */
749 if (devc->num_samples >= devc->limit_samples)
752 devc->sample[devc->num_bytes++] = byte;
753 sr_dbg("ols: received byte 0x%.2x", byte);
754 if (devc->num_bytes == num_channels) {
755 /* Got a full sample. */
756 sr_dbg("ols: received sample 0x%.*x",
757 devc->num_bytes * 2, *(int *)devc->sample);
758 if (devc->flag_reg & FLAG_RLE) {
760 * In RLE mode -1 should never come in as a
761 * sample, because bit 31 is the "count" flag.
763 if (devc->sample[devc->num_bytes - 1] & 0x80) {
764 devc->sample[devc->num_bytes - 1] &= 0x7f;
766 * FIXME: This will only work on
767 * little-endian systems.
769 devc->rle_count = *(int *)(devc->sample);
770 sr_dbg("ols: RLE count = %d", devc->rle_count);
775 devc->num_samples += devc->rle_count + 1;
776 if (devc->num_samples > devc->limit_samples) {
777 /* Save us from overrunning the buffer. */
778 devc->rle_count -= devc->num_samples - devc->limit_samples;
779 devc->num_samples = devc->limit_samples;
782 if (num_channels < 4) {
784 * Some channel groups may have been turned
785 * off, to speed up transfer between the
786 * hardware and the PC. Expand that here before
787 * submitting it over the session bus --
788 * whatever is listening on the bus will be
789 * expecting a full 32-bit sample, based on
790 * the number of probes.
793 memset(devc->tmp_sample, 0, 4);
794 for (i = 0; i < 4; i++) {
795 if (((devc->flag_reg >> 2) & (1 << i)) == 0) {
797 * This channel group was
798 * enabled, copy from received
801 devc->tmp_sample[i] = devc->sample[j++];
804 memcpy(devc->sample, devc->tmp_sample, 4);
805 sr_dbg("ols: full sample 0x%.8x", *(int *)devc->sample);
808 /* the OLS sends its sample buffer backwards.
809 * store it in reverse order here, so we can dump
810 * this on the session bus later.
812 offset = (devc->limit_samples - devc->num_samples) * 4;
813 for (i = 0; i <= devc->rle_count; i++) {
814 memcpy(devc->raw_sample_buf + offset + (i * 4),
817 memset(devc->sample, 0, 4);
823 * This is the main loop telling us a timeout was reached, or
824 * we've acquired all the samples we asked for -- we're done.
825 * Send the (properly-ordered) buffer to the frontend.
827 if (devc->trigger_at != -1) {
828 /* a trigger was set up, so we need to tell the frontend
831 if (devc->trigger_at > 0) {
832 /* there are pre-trigger samples, send those first */
833 packet.type = SR_DF_LOGIC;
834 packet.payload = &logic;
835 logic.length = devc->trigger_at * 4;
837 logic.data = devc->raw_sample_buf +
838 (devc->limit_samples - devc->num_samples) * 4;
839 sr_session_send(cb_data, &packet);
842 /* send the trigger */
843 packet.type = SR_DF_TRIGGER;
844 sr_session_send(cb_data, &packet);
846 /* send post-trigger samples */
847 packet.type = SR_DF_LOGIC;
848 packet.payload = &logic;
849 logic.length = (devc->num_samples * 4) - (devc->trigger_at * 4);
851 logic.data = devc->raw_sample_buf + devc->trigger_at * 4 +
852 (devc->limit_samples - devc->num_samples) * 4;
853 sr_session_send(cb_data, &packet);
855 /* no trigger was used */
856 packet.type = SR_DF_LOGIC;
857 packet.payload = &logic;
858 logic.length = devc->num_samples * 4;
860 logic.data = devc->raw_sample_buf +
861 (devc->limit_samples - devc->num_samples) * 4;
862 sr_session_send(cb_data, &packet);
864 g_free(devc->raw_sample_buf);
866 serial_flush(devc->serial);
867 abort_acquisition(sdi);
868 serial_close(devc->serial);
874 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
877 struct sr_datafeed_packet *packet;
878 struct sr_datafeed_header *header;
879 struct sr_datafeed_meta_logic meta;
880 struct dev_context *devc;
881 uint32_t trigger_config[4];
883 uint16_t readcount, delaycount;
884 uint8_t changrp_mask;
890 if (sdi->status != SR_ST_ACTIVE)
893 if (configure_probes(sdi) != SR_OK) {
894 sr_err("ols: failed to configured probes");
899 * Enable/disable channel groups in the flag register according to the
900 * probe mask. Calculate this here, because num_channels is needed
901 * to limit readcount.
905 for (i = 0; i < 4; i++) {
906 if (devc->probe_mask & (0xff << (i * 8))) {
907 changrp_mask |= (1 << i);
913 * Limit readcount to prevent reading past the end of the hardware
916 readcount = MIN(devc->max_samples / num_channels, devc->limit_samples) / 4;
918 memset(trigger_config, 0, 16);
919 trigger_config[devc->num_stages - 1] |= 0x08;
920 if (devc->trigger_mask[0]) {
921 delaycount = readcount * (1 - devc->capture_ratio / 100.0);
922 devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages;
924 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_0,
925 reverse32(devc->trigger_mask[0])) != SR_OK)
927 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_0,
928 reverse32(devc->trigger_value[0])) != SR_OK)
930 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_0,
931 trigger_config[0]) != SR_OK)
934 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_1,
935 reverse32(devc->trigger_mask[1])) != SR_OK)
937 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_1,
938 reverse32(devc->trigger_value[1])) != SR_OK)
940 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_1,
941 trigger_config[1]) != SR_OK)
944 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_2,
945 reverse32(devc->trigger_mask[2])) != SR_OK)
947 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_2,
948 reverse32(devc->trigger_value[2])) != SR_OK)
950 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_2,
951 trigger_config[2]) != SR_OK)
954 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_3,
955 reverse32(devc->trigger_mask[3])) != SR_OK)
957 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_3,
958 reverse32(devc->trigger_value[3])) != SR_OK)
960 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_3,
961 trigger_config[3]) != SR_OK)
964 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_MASK_0,
965 devc->trigger_mask[0]) != SR_OK)
967 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_VALUE_0,
968 devc->trigger_value[0]) != SR_OK)
970 if (send_longcommand(devc->serial, CMD_SET_TRIGGER_CONFIG_0,
971 0x00000008) != SR_OK)
973 delaycount = readcount;
976 sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
977 "demux %s)", devc->cur_samplerate, devc->cur_samplerate_divider,
978 devc->flag_reg & FLAG_DEMUX ? "on" : "off");
979 if (send_longcommand(devc->serial, CMD_SET_DIVIDER,
980 reverse32(devc->cur_samplerate_divider)) != SR_OK)
983 /* Send sample limit and pre/post-trigger capture ratio. */
984 data = ((readcount - 1) & 0xffff) << 16;
985 data |= (delaycount - 1) & 0xffff;
986 if (send_longcommand(devc->serial, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
989 /* The flag register wants them here, and 1 means "disable channel". */
990 devc->flag_reg |= ~(changrp_mask << 2) & 0x3c;
991 devc->flag_reg |= FLAG_FILTER;
993 data = (devc->flag_reg << 24) | ((devc->flag_reg << 8) & 0xff0000);
994 if (send_longcommand(devc->serial, CMD_SET_FLAGS, data) != SR_OK)
997 /* Start acquisition on the device. */
998 if (send_shortcommand(devc->serial, CMD_RUN) != SR_OK)
1001 sr_source_add(devc->serial->fd, G_IO_IN, -1, receive_data,
1004 if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
1005 sr_err("ols: %s: packet malloc failed", __func__);
1006 return SR_ERR_MALLOC;
1009 if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
1010 sr_err("ols: %s: header malloc failed", __func__);
1012 return SR_ERR_MALLOC;
1015 /* Send header packet to the session bus. */
1016 packet->type = SR_DF_HEADER;
1017 packet->payload = (unsigned char *)header;
1018 header->feed_version = 1;
1019 gettimeofday(&header->starttime, NULL);
1020 sr_session_send(cb_data, packet);
1022 /* Send metadata about the SR_DF_LOGIC packets to come. */
1023 packet->type = SR_DF_META_LOGIC;
1024 packet->payload = &meta;
1025 meta.samplerate = devc->cur_samplerate;
1026 meta.num_probes = NUM_PROBES;
1027 sr_session_send(cb_data, packet);
1035 /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
1036 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
1038 /* Avoid compiler warnings. */
1041 abort_acquisition(sdi);
1046 SR_PRIV struct sr_dev_driver ols_driver_info = {
1048 .longname = "Openbench Logic Sniffer",
1051 .cleanup = hw_cleanup,
1053 .dev_list = hw_dev_list,
1054 .dev_clear = hw_cleanup,
1055 .dev_open = hw_dev_open,
1056 .dev_close = hw_dev_close,
1057 .info_get = hw_info_get,
1058 .dev_config_set = hw_dev_config_set,
1059 .dev_acquisition_start = hw_dev_acquisition_start,
1060 .dev_acquisition_stop = hw_dev_acquisition_stop,