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(int fd, uint8_t command)
112 sr_dbg("ols: sending cmd 0x%.2x", command);
114 if (serial_write(fd, buf, 1) != 1)
120 static int send_longcommand(int fd, uint8_t command, uint32_t data)
124 sr_dbg("ols: sending cmd 0x%.2x data 0x%.8x", command, data);
126 buf[1] = (data & 0xff000000) >> 24;
127 buf[2] = (data & 0xff0000) >> 16;
128 buf[3] = (data & 0xff00) >> 8;
129 buf[4] = data & 0xff;
130 if (serial_write(fd, buf, 5) != 5)
136 static int configure_probes(const struct sr_dev_inst *sdi)
138 struct dev_context *devc;
139 const struct sr_probe *probe;
141 int probe_bit, stage, i;
146 devc->probe_mask = 0;
147 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
148 devc->trigger_mask[i] = 0;
149 devc->trigger_value[i] = 0;
152 devc->num_stages = 0;
153 for (l = sdi->probes; l; l = l->next) {
154 probe = (const struct sr_probe *)l->data;
159 * Set up the probe mask for later configuration into the
162 probe_bit = 1 << (probe->index);
163 devc->probe_mask |= probe_bit;
168 /* Configure trigger mask and value. */
170 for (tc = probe->trigger; tc && *tc; tc++) {
171 devc->trigger_mask[stage] |= probe_bit;
173 devc->trigger_value[stage] |= probe_bit;
177 * TODO: Only supporting parallel mode, with
182 if (stage > devc->num_stages)
183 devc->num_stages = stage;
189 static uint32_t reverse16(uint32_t in)
193 out = (in & 0xff) << 8;
194 out |= (in & 0xff00) >> 8;
195 out |= (in & 0xff0000) << 8;
196 out |= (in & 0xff000000) >> 8;
201 static uint32_t reverse32(uint32_t in)
205 out = (in & 0xff) << 24;
206 out |= (in & 0xff00) << 8;
207 out |= (in & 0xff0000) >> 8;
208 out |= (in & 0xff000000) >> 24;
213 static struct dev_context *ols_dev_new(void)
215 struct dev_context *devc;
217 if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
218 sr_err("ols: %s: devc malloc failed", __func__);
222 devc->trigger_at = -1;
223 devc->probe_mask = 0xffffffff;
224 devc->cur_samplerate = SR_KHZ(200);
230 static struct sr_dev_inst *get_metadata(int fd)
232 struct sr_dev_inst *sdi;
233 struct dev_context *devc;
234 struct sr_probe *probe;
235 uint32_t tmp_int, ui;
236 uint8_t key, type, token;
237 GString *tmp_str, *devname, *version;
240 sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, NULL, NULL, NULL);
242 devc = ols_dev_new();
245 devname = g_string_new("");
246 version = g_string_new("");
250 if (serial_read(fd, &key, 1) != 1 || key == 0x00)
256 /* NULL-terminated string */
257 tmp_str = g_string_new("");
258 while (serial_read(fd, &tmp_c, 1) == 1 && tmp_c != '\0')
259 g_string_append_c(tmp_str, tmp_c);
260 sr_dbg("ols: got metadata key 0x%.2x value '%s'",
265 devname = g_string_append(devname, tmp_str->str);
268 /* FPGA firmware version */
270 g_string_append(version, ", ");
271 g_string_append(version, "FPGA version ");
272 g_string_append(version, tmp_str->str);
275 /* Ancillary version */
277 g_string_append(version, ", ");
278 g_string_append(version, "Ancillary version ");
279 g_string_append(version, tmp_str->str);
282 sr_info("ols: unknown token 0x%.2x: '%s'",
283 token, tmp_str->str);
286 g_string_free(tmp_str, TRUE);
289 /* 32-bit unsigned integer */
290 if (serial_read(fd, &tmp_int, 4) != 4)
292 tmp_int = reverse32(tmp_int);
293 sr_dbg("ols: got metadata key 0x%.2x value 0x%.8x",
297 /* Number of usable probes */
298 for (ui = 0; ui < tmp_int; ui++) {
299 if (!(probe = sr_probe_new(ui, SR_PROBE_LOGIC, TRUE,
302 sdi->probes = g_slist_append(sdi->probes, probe);
306 /* Amount of sample memory available (bytes) */
307 devc->max_samples = tmp_int;
310 /* Amount of dynamic memory available (bytes) */
311 /* what is this for? */
314 /* Maximum sample rate (hz) */
315 devc->max_samplerate = tmp_int;
318 /* protocol version */
319 devc->protocol_version = tmp_int;
322 sr_info("ols: unknown token 0x%.2x: 0x%.8x",
328 /* 8-bit unsigned integer */
329 if (serial_read(fd, &tmp_c, 1) != 1)
331 sr_dbg("ols: got metadata key 0x%.2x value 0x%.2x",
335 /* Number of usable probes */
336 for (ui = 0; ui < tmp_c; ui++) {
337 if (!(probe = sr_probe_new(ui, SR_PROBE_LOGIC, TRUE,
340 sdi->probes = g_slist_append(sdi->probes, probe);
344 /* protocol version */
345 devc->protocol_version = tmp_c;
348 sr_info("ols: unknown token 0x%.2x: 0x%.2x",
359 sdi->model = devname->str;
360 sdi->version = version->str;
361 g_string_free(devname, FALSE);
362 g_string_free(version, FALSE);
367 static int hw_init(void)
369 struct drv_context *drvc;
371 if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
372 sr_err("ols: driver context malloc failed.");
373 return SR_ERR_MALLOC;
380 static GSList *hw_scan(GSList *options)
382 struct sr_hwopt *opt;
383 struct sr_dev_inst *sdi;
384 struct drv_context *drvc;
385 struct dev_context *devc;
386 struct sr_probe *probe;
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;
410 sr_err("ols: No serial port specified.");
414 if (serialcomm == NULL)
415 serialcomm = g_strdup(SERIALCOMM);
417 /* The discovery procedure is like this: first send the Reset
418 * command (0x00) 5 times, since the device could be anywhere
419 * in a 5-byte command. Then send the ID command (0x02).
420 * If the device responds with 4 bytes ("OLS1" or "SLA1"), we
423 sr_info("ols: probing %s .", conn);
424 fd = serial_open(conn, O_RDWR | O_NONBLOCK);
426 sr_err("ols: could not open port %s .", conn);
430 serial_set_paramstr(fd, serialcomm);
432 for (i = 0; i < 5; i++) {
433 if ((ret = send_shortcommand(fd, CMD_RESET)) != SR_OK) {
434 sr_err("ols: port %s is not writable.", conn);
440 sr_err("ols: Could not use port %s. Quitting.", conn);
443 send_shortcommand(fd, CMD_ID);
445 /* Wait 10ms for a response. */
449 probefd.events = G_IO_IN;
450 g_poll(&probefd, 1, 1);
452 if (probefd.revents != G_IO_IN)
454 if (serial_read(probefd.fd, buf, 4) != 4)
456 if (strncmp(buf, "1SLO", 4) && strncmp(buf, "1ALS", 4))
459 /* Definitely using the OLS protocol, check if it supports
460 * the metadata command.
462 send_shortcommand(probefd.fd, CMD_METADATA);
463 if (g_poll(&probefd, 1, 10) > 0) {
465 sdi = get_metadata(fd);
469 /* Not an OLS -- some other board that uses the sump protocol. */
470 sdi = sr_dev_inst_new(0, SR_ST_INACTIVE,
471 "Sump", "Logic Analyzer", "v1.0");
473 devc = ols_dev_new();
474 for (i = 0; i < 32; i++) {
475 if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
478 sdi->probes = g_slist_append(sdi->probes, probe);
482 devc->serial = sr_serial_dev_inst_new(conn, -1);
483 drvc->instances = g_slist_append(drvc->instances, sdi);
484 devices = g_slist_append(devices, sdi);
491 static GSList *hw_dev_list(void)
493 struct drv_context *drvc;
497 return drvc->instances;
500 static int hw_dev_open(struct sr_dev_inst *sdi)
502 struct dev_context *devc;
506 devc->serial->fd = serial_open(devc->serial->port, O_RDWR);
507 if (devc->serial->fd == -1)
510 sdi->status = SR_ST_ACTIVE;
515 static int hw_dev_close(struct sr_dev_inst *sdi)
517 struct dev_context *devc;
521 if (devc->serial->fd != -1) {
522 serial_close(devc->serial->fd);
523 devc->serial->fd = -1;
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",
556 /* TODO: Check for serial != NULL. */
557 if (devc->serial->fd != -1)
558 serial_close(devc->serial->fd);
559 sr_serial_dev_inst_free(devc->serial);
560 sr_dev_inst_free(sdi);
562 g_slist_free(drvc->instances);
563 drvc->instances = NULL;
568 static int hw_info_get(int info_id, const void **data,
569 const struct sr_dev_inst *sdi)
571 struct dev_context *devc;
577 case SR_DI_NUM_PROBES:
578 *data = GINT_TO_POINTER(1);
580 case SR_DI_PROBE_NAMES:
583 case SR_DI_SAMPLERATES:
584 *data = &samplerates;
586 case SR_DI_TRIGGER_TYPES:
587 *data = (char *)TRIGGER_TYPES;
589 case SR_DI_CUR_SAMPLERATE:
592 *data = &devc->cur_samplerate;
603 static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
605 struct dev_context *devc;
608 if (devc->max_samplerate) {
609 if (samplerate > devc->max_samplerate)
610 return SR_ERR_SAMPLERATE;
611 } else if (samplerate < samplerates.low || samplerate > samplerates.high)
612 return SR_ERR_SAMPLERATE;
614 if (samplerate > CLOCK_RATE) {
615 devc->flag_reg |= FLAG_DEMUX;
616 devc->cur_samplerate_divider = (CLOCK_RATE * 2 / samplerate) - 1;
618 devc->flag_reg &= ~FLAG_DEMUX;
619 devc->cur_samplerate_divider = (CLOCK_RATE / samplerate) - 1;
622 /* Calculate actual samplerate used and complain if it is different
623 * from the requested.
625 devc->cur_samplerate = CLOCK_RATE / (devc->cur_samplerate_divider + 1);
626 if (devc->flag_reg & FLAG_DEMUX)
627 devc->cur_samplerate *= 2;
628 if (devc->cur_samplerate != samplerate)
629 sr_err("ols: can't match samplerate %" PRIu64 ", using %"
630 PRIu64, samplerate, devc->cur_samplerate);
635 static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
638 struct dev_context *devc;
640 const uint64_t *tmp_u64;
644 if (sdi->status != SR_ST_ACTIVE)
648 case SR_HWCAP_SAMPLERATE:
649 ret = set_samplerate(sdi, *(const uint64_t *)value);
651 case SR_HWCAP_LIMIT_SAMPLES:
653 if (*tmp_u64 < MIN_NUM_SAMPLES)
655 if (*tmp_u64 > devc->max_samples)
656 sr_err("ols: sample limit exceeds hw max");
657 devc->limit_samples = *tmp_u64;
658 sr_info("ols: sample limit %" PRIu64, devc->limit_samples);
661 case SR_HWCAP_CAPTURE_RATIO:
662 devc->capture_ratio = *(const uint64_t *)value;
663 if (devc->capture_ratio < 0 || devc->capture_ratio > 100) {
664 devc->capture_ratio = 0;
670 if (GPOINTER_TO_INT(value)) {
671 sr_info("ols: enabling RLE");
672 devc->flag_reg |= FLAG_RLE;
683 static void abort_acquisition(const struct sr_dev_inst *sdi)
685 struct sr_datafeed_packet packet;
686 struct dev_context *devc;
689 sr_source_remove(devc->serial->fd);
691 /* Terminate session */
692 packet.type = SR_DF_END;
693 sr_session_send(sdi, &packet);
699 static int receive_data(int fd, int revents, void *cb_data)
701 struct sr_datafeed_packet packet;
702 struct sr_datafeed_logic logic;
703 struct sr_dev_inst *sdi;
704 struct drv_context *drvc;
705 struct dev_context *devc;
707 int num_channels, offset, i, j;
712 /* Find this device's devc struct by its fd. */
714 for (l = drvc->instances; l; l = l->next) {
717 if (devc->serial->fd == fd) {
723 /* Shouldn't happen. */
726 if (devc->num_transfers++ == 0) {
728 * First time round, means the device started sending data,
729 * and will not stop until done. If it stops sending for
730 * longer than it takes to send a byte, that means it's
731 * finished. We'll double that to 30ms to be sure...
733 sr_source_remove(fd);
734 sr_source_add(fd, G_IO_IN, 30, receive_data, cb_data);
735 /* TODO: Check malloc return code. */
736 devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4);
737 if (!devc->raw_sample_buf) {
738 sr_err("ols: %s: devc->raw_sample_buf malloc failed",
742 /* fill with 1010... for debugging */
743 memset(devc->raw_sample_buf, 0x82, devc->limit_samples * 4);
747 for (i = 0x20; i > 0x02; i /= 2) {
748 if ((devc->flag_reg & i) == 0)
752 if (revents == G_IO_IN) {
753 if (serial_read(fd, &byte, 1) != 1)
756 /* Ignore it if we've read enough. */
757 if (devc->num_samples >= devc->limit_samples)
760 devc->sample[devc->num_bytes++] = byte;
761 sr_dbg("ols: received byte 0x%.2x", byte);
762 if (devc->num_bytes == num_channels) {
763 /* Got a full sample. */
764 sr_dbg("ols: received sample 0x%.*x",
765 devc->num_bytes * 2, *(int *)devc->sample);
766 if (devc->flag_reg & FLAG_RLE) {
768 * In RLE mode -1 should never come in as a
769 * sample, because bit 31 is the "count" flag.
771 if (devc->sample[devc->num_bytes - 1] & 0x80) {
772 devc->sample[devc->num_bytes - 1] &= 0x7f;
774 * FIXME: This will only work on
775 * little-endian systems.
777 devc->rle_count = *(int *)(devc->sample);
778 sr_dbg("ols: RLE count = %d", devc->rle_count);
783 devc->num_samples += devc->rle_count + 1;
784 if (devc->num_samples > devc->limit_samples) {
785 /* Save us from overrunning the buffer. */
786 devc->rle_count -= devc->num_samples - devc->limit_samples;
787 devc->num_samples = devc->limit_samples;
790 if (num_channels < 4) {
792 * Some channel groups may have been turned
793 * off, to speed up transfer between the
794 * hardware and the PC. Expand that here before
795 * submitting it over the session bus --
796 * whatever is listening on the bus will be
797 * expecting a full 32-bit sample, based on
798 * the number of probes.
801 memset(devc->tmp_sample, 0, 4);
802 for (i = 0; i < 4; i++) {
803 if (((devc->flag_reg >> 2) & (1 << i)) == 0) {
805 * This channel group was
806 * enabled, copy from received
809 devc->tmp_sample[i] = devc->sample[j++];
812 memcpy(devc->sample, devc->tmp_sample, 4);
813 sr_dbg("ols: full sample 0x%.8x", *(int *)devc->sample);
816 /* the OLS sends its sample buffer backwards.
817 * store it in reverse order here, so we can dump
818 * this on the session bus later.
820 offset = (devc->limit_samples - devc->num_samples) * 4;
821 for (i = 0; i <= devc->rle_count; i++) {
822 memcpy(devc->raw_sample_buf + offset + (i * 4),
825 memset(devc->sample, 0, 4);
831 * This is the main loop telling us a timeout was reached, or
832 * we've acquired all the samples we asked for -- we're done.
833 * Send the (properly-ordered) buffer to the frontend.
835 if (devc->trigger_at != -1) {
836 /* a trigger was set up, so we need to tell the frontend
839 if (devc->trigger_at > 0) {
840 /* there are pre-trigger samples, send those first */
841 packet.type = SR_DF_LOGIC;
842 packet.payload = &logic;
843 logic.length = devc->trigger_at * 4;
845 logic.data = devc->raw_sample_buf +
846 (devc->limit_samples - devc->num_samples) * 4;
847 sr_session_send(cb_data, &packet);
850 /* send the trigger */
851 packet.type = SR_DF_TRIGGER;
852 sr_session_send(cb_data, &packet);
854 /* send post-trigger samples */
855 packet.type = SR_DF_LOGIC;
856 packet.payload = &logic;
857 logic.length = (devc->num_samples * 4) - (devc->trigger_at * 4);
859 logic.data = devc->raw_sample_buf + devc->trigger_at * 4 +
860 (devc->limit_samples - devc->num_samples) * 4;
861 sr_session_send(cb_data, &packet);
863 /* no trigger was used */
864 packet.type = SR_DF_LOGIC;
865 packet.payload = &logic;
866 logic.length = devc->num_samples * 4;
868 logic.data = devc->raw_sample_buf +
869 (devc->limit_samples - devc->num_samples) * 4;
870 sr_session_send(cb_data, &packet);
872 g_free(devc->raw_sample_buf);
877 abort_acquisition(sdi);
883 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
886 struct sr_datafeed_packet *packet;
887 struct sr_datafeed_header *header;
888 struct sr_datafeed_meta_logic meta;
889 struct dev_context *devc;
890 uint32_t trigger_config[4];
892 uint16_t readcount, delaycount;
893 uint8_t changrp_mask;
899 if (sdi->status != SR_ST_ACTIVE)
902 if (configure_probes(sdi) != SR_OK) {
903 sr_err("ols: failed to configured probes");
908 * Enable/disable channel groups in the flag register according to the
909 * probe mask. Calculate this here, because num_channels is needed
910 * to limit readcount.
914 for (i = 0; i < 4; i++) {
915 if (devc->probe_mask & (0xff << (i * 8))) {
916 changrp_mask |= (1 << i);
922 * Limit readcount to prevent reading past the end of the hardware
925 readcount = MIN(devc->max_samples / num_channels, devc->limit_samples) / 4;
927 memset(trigger_config, 0, 16);
928 trigger_config[devc->num_stages - 1] |= 0x08;
929 if (devc->trigger_mask[0]) {
930 delaycount = readcount * (1 - devc->capture_ratio / 100.0);
931 devc->trigger_at = (readcount - delaycount) * 4 - devc->num_stages;
933 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_MASK_0,
934 reverse32(devc->trigger_mask[0])) != SR_OK)
936 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_VALUE_0,
937 reverse32(devc->trigger_value[0])) != SR_OK)
939 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
940 trigger_config[0]) != SR_OK)
943 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_MASK_1,
944 reverse32(devc->trigger_mask[1])) != SR_OK)
946 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_VALUE_1,
947 reverse32(devc->trigger_value[1])) != SR_OK)
949 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_CONFIG_1,
950 trigger_config[1]) != SR_OK)
953 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_MASK_2,
954 reverse32(devc->trigger_mask[2])) != SR_OK)
956 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_VALUE_2,
957 reverse32(devc->trigger_value[2])) != SR_OK)
959 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_CONFIG_2,
960 trigger_config[2]) != SR_OK)
963 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_MASK_3,
964 reverse32(devc->trigger_mask[3])) != SR_OK)
966 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_VALUE_3,
967 reverse32(devc->trigger_value[3])) != SR_OK)
969 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_CONFIG_3,
970 trigger_config[3]) != SR_OK)
973 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_MASK_0,
974 devc->trigger_mask[0]) != SR_OK)
976 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_VALUE_0,
977 devc->trigger_value[0]) != SR_OK)
979 if (send_longcommand(devc->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
980 0x00000008) != SR_OK)
982 delaycount = readcount;
985 sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
986 "demux %s)", devc->cur_samplerate, devc->cur_samplerate_divider,
987 devc->flag_reg & FLAG_DEMUX ? "on" : "off");
988 if (send_longcommand(devc->serial->fd, CMD_SET_DIVIDER,
989 reverse32(devc->cur_samplerate_divider)) != SR_OK)
992 /* Send sample limit and pre/post-trigger capture ratio. */
993 data = ((readcount - 1) & 0xffff) << 16;
994 data |= (delaycount - 1) & 0xffff;
995 if (send_longcommand(devc->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
998 /* The flag register wants them here, and 1 means "disable channel". */
999 devc->flag_reg |= ~(changrp_mask << 2) & 0x3c;
1000 devc->flag_reg |= FLAG_FILTER;
1001 devc->rle_count = 0;
1002 data = (devc->flag_reg << 24) | ((devc->flag_reg << 8) & 0xff0000);
1003 if (send_longcommand(devc->serial->fd, CMD_SET_FLAGS, data) != SR_OK)
1006 /* Start acquisition on the device. */
1007 if (send_shortcommand(devc->serial->fd, CMD_RUN) != SR_OK)
1010 sr_source_add(devc->serial->fd, G_IO_IN, -1, receive_data,
1013 if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
1014 sr_err("ols: %s: packet malloc failed", __func__);
1015 return SR_ERR_MALLOC;
1018 if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
1019 sr_err("ols: %s: header malloc failed", __func__);
1021 return SR_ERR_MALLOC;
1024 /* Send header packet to the session bus. */
1025 packet->type = SR_DF_HEADER;
1026 packet->payload = (unsigned char *)header;
1027 header->feed_version = 1;
1028 gettimeofday(&header->starttime, NULL);
1029 sr_session_send(cb_data, packet);
1031 /* Send metadata about the SR_DF_LOGIC packets to come. */
1032 packet->type = SR_DF_META_LOGIC;
1033 packet->payload = &meta;
1034 meta.samplerate = devc->cur_samplerate;
1035 meta.num_probes = NUM_PROBES;
1036 sr_session_send(cb_data, packet);
1044 /* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
1045 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
1047 /* Avoid compiler warnings. */
1050 abort_acquisition(sdi);
1055 SR_PRIV struct sr_dev_driver ols_driver_info = {
1057 .longname = "Openbench Logic Sniffer",
1060 .cleanup = hw_cleanup,
1062 .dev_list = hw_dev_list,
1063 .dev_clear = hw_cleanup,
1064 .dev_open = hw_dev_open,
1065 .dev_close = hw_dev_close,
1066 .info_get = hw_info_get,
1067 .dev_config_set = hw_dev_config_set,
1068 .dev_acquisition_start = hw_dev_acquisition_start,
1069 .dev_acquisition_stop = hw_dev_acquisition_stop,