]> sigrok.org Git - libsigrok.git/blob - hardware/saleae-logic/saleae-logic.c
use flexible sample limit specification (k/m/g)
[libsigrok.git] / hardware / saleae-logic / saleae-logic.c
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <sys/time.h>
23 #include <inttypes.h>
24 #include <glib.h>
25 #include <libusb.h>
26 #include <sigrok.h>
27 #include "config.h"
28
29 #define USB_VENDOR                      0x0925
30 #define USB_PRODUCT                     0x3881
31 #define USB_VENDOR_NAME                 "Saleae"
32 #define USB_MODEL_NAME                  "Logic"
33 #define USB_MODEL_VERSION               ""
34
35 #define USB_INTERFACE                   0
36 #define USB_CONFIGURATION               1
37 #define NUM_PROBES                      8
38 #define NUM_TRIGGER_STAGES              4
39 #define TRIGGER_TYPES                   "01"
40 #define FIRMWARE                        FIRMWARE_DIR "/saleae-logic.fw"
41
42 /* delay in ms */
43 #define FIRMWARE_RENUM_DELAY            2000
44 #define NUM_SIMUL_TRANSFERS             10
45 #define MAX_EMPTY_TRANSFERS             (NUM_SIMUL_TRANSFERS * 2)
46
47 /* Software trigger implementation: positive values indicate trigger stage. */
48 #define TRIGGER_FIRED                   -1
49
50 /* There is only one model Saleae Logic, and this is what it supports: */
51 static int capabilities[] = {
52         HWCAP_LOGIC_ANALYZER,
53         HWCAP_SAMPLERATE,
54
55         /* These are really implemented in the driver, not the hardware. */
56         HWCAP_LIMIT_SAMPLES,
57         0,
58 };
59
60 /* List of struct sigrok_device_instance, maintained by opendev()/closedev(). */
61 static GSList *device_instances = NULL;
62
63 /*
64  * Since we can't keep track of a Saleae Logic device after upgrading the
65  * firmware -- it re-enumerates into a different device address after the
66  * upgrade -- this is like a global lock. No device will open until a proper
67  * delay after the last device was upgraded.
68  */
69 GTimeVal firmware_updated = { 0, 0 };
70
71 static libusb_context *usb_context = NULL;
72
73 static uint64_t supported_samplerates[] = {
74         KHZ(200),
75         KHZ(250),
76         KHZ(500),
77         MHZ(1),
78         MHZ(2),
79         MHZ(4),
80         MHZ(8),
81         MHZ(12),
82         MHZ(16),
83         MHZ(24),
84         0,
85 };
86
87 static struct samplerates samplerates = {
88         KHZ(200),
89         MHZ(24),
90         0,
91         supported_samplerates,
92 };
93
94 /* TODO: All of these should go in a device-specific struct. */
95 static uint64_t cur_samplerate = 0;
96 static uint64_t limit_samples = 0;
97 static uint8_t probe_mask = 0;
98 static uint8_t trigger_mask[NUM_TRIGGER_STAGES] = { 0 };
99 static uint8_t trigger_value[NUM_TRIGGER_STAGES] = { 0 };
100 static uint8_t trigger_buffer[NUM_TRIGGER_STAGES] = { 0 };
101
102 int trigger_stage = TRIGGER_FIRED;
103
104 static int hw_set_configuration(int device_index, int capability, void *value);
105 static void hw_stop_acquisition(int device_index, gpointer session_device_id);
106
107 /**
108  * Check the USB configuration to determine if this is a Saleae Logic.
109  *
110  * @return 1 if the device's configuration profile match the Logic firmware's
111  *         configuration, 0 otherwise.
112  */
113 int check_conf_profile(libusb_device *dev)
114 {
115         struct libusb_device_descriptor des;
116         struct libusb_config_descriptor *conf_dsc = NULL;
117         const struct libusb_interface_descriptor *intf_dsc;
118         int ret = -1;
119
120         while (ret == -1) {
121                 /* Assume it's not a Saleae Logic unless proven wrong. */
122                 ret = 0;
123
124                 if (libusb_get_device_descriptor(dev, &des) != 0)
125                         break;
126
127                 if (des.bNumConfigurations != 1)
128                         /* Need exactly 1 configuration. */
129                         break;
130
131                 if (libusb_get_config_descriptor(dev, 0, &conf_dsc) != 0)
132                         break;
133
134                 if (conf_dsc->bNumInterfaces != 1)
135                         /* Need exactly 1 interface. */
136                         break;
137
138                 if (conf_dsc->interface[0].num_altsetting != 1)
139                         /* Need just one alternate setting. */
140                         break;
141
142                 intf_dsc = &(conf_dsc->interface[0].altsetting[0]);
143                 if (intf_dsc->bNumEndpoints != 2)
144                         /* Need 2 endpoints. */
145                         break;
146
147                 if ((intf_dsc->endpoint[0].bEndpointAddress & 0x8f) !=
148                     (1 | LIBUSB_ENDPOINT_OUT))
149                         /* First endpoint should be 1 (outbound). */
150                         break;
151
152                 if ((intf_dsc->endpoint[1].bEndpointAddress & 0x8f) !=
153                     (2 | LIBUSB_ENDPOINT_IN))
154                         /* First endpoint should be 2 (inbound). */
155                         break;
156
157                 /* If we made it here, it must be a Saleae Logic. */
158                 ret = 1;
159         }
160
161         if (conf_dsc)
162                 libusb_free_config_descriptor(conf_dsc);
163
164         return ret;
165 }
166
167 struct sigrok_device_instance *sl_open_device(int device_index)
168 {
169         struct sigrok_device_instance *sdi;
170         libusb_device **devlist;
171         struct libusb_device_descriptor des;
172         int err, skip, i;
173
174         if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
175                 return NULL;
176
177         libusb_get_device_list(usb_context, &devlist);
178         if (sdi->status == ST_INITIALIZING) {
179                 /*
180                  * This device was renumerating last time we touched it.
181                  * opendev() guarantees we've waited long enough for it to
182                  * have booted properly, so now we need to find it on
183                  * the bus and record its new address.
184                  */
185                 skip = 0;
186                 for (i = 0; devlist[i]; i++) {
187                         /* TODO: Error handling. */
188                         err = opendev2(device_index, &sdi, devlist[i], &des,
189                                        &skip, USB_VENDOR, USB_PRODUCT,
190                                        USB_INTERFACE);
191                 }
192         } else if (sdi->status == ST_INACTIVE) {
193                 /*
194                  * This device is fully enumerated, so we need to find this
195                  * device by vendor, product, bus and address.
196                  */
197                 libusb_get_device_list(usb_context, &devlist);
198                 for (i = 0; devlist[i]; i++) {
199                         /* TODO: Error handling. */
200                         err = opendev3(&sdi, devlist[i], &des, USB_VENDOR,
201                                        USB_PRODUCT, USB_INTERFACE);
202                 }
203         } else {
204                 /* Status must be ST_ACTIVE, i.e. already in use... */
205                 sdi = NULL;
206         }
207         libusb_free_device_list(devlist, 1);
208
209         if (sdi && sdi->status != ST_ACTIVE)
210                 sdi = NULL;
211
212         return sdi;
213 }
214
215 int upload_firmware(libusb_device *dev)
216 {
217         int ret;
218
219         ret = ezusb_upload_firmware(dev, USB_CONFIGURATION, FIRMWARE);
220         if (ret != 0)
221                 return 1;
222
223         /* Remember when the last firmware update was done. */
224         g_get_current_time(&firmware_updated);
225
226         return 0;
227 }
228
229 static void close_device(struct sigrok_device_instance *sdi)
230 {
231         if (sdi->usb->devhdl == NULL)
232                 return;
233
234         g_message("closing device %d on %d.%d interface %d", sdi->index,
235                   sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
236         libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
237         libusb_close(sdi->usb->devhdl);
238         sdi->usb->devhdl = NULL;
239         sdi->status = ST_INACTIVE;
240 }
241
242 static int configure_probes(GSList *probes)
243 {
244         struct probe *probe;
245         GSList *l;
246         int probe_bit, stage, i;
247         char *tc;
248
249         probe_mask = 0;
250         for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
251                 trigger_mask[i] = 0;
252                 trigger_value[i] = 0;
253         }
254
255         stage = -1;
256         for (l = probes; l; l = l->next) {
257                 probe = (struct probe *)l->data;
258                 if (probe->enabled == FALSE)
259                         continue;
260                 probe_bit = 1 << (probe->index - 1);
261                 probe_mask |= probe_bit;
262                 if (!(probe->trigger))
263                         continue;
264
265                 stage = 0;
266                 for (tc = probe->trigger; *tc; tc++) {
267                         trigger_mask[stage] |= probe_bit;
268                         if (*tc == '1')
269                                 trigger_value[stage] |= probe_bit;
270                         stage++;
271                         if (stage > NUM_TRIGGER_STAGES)
272                                 return SIGROK_ERR;
273                 }
274         }
275
276         if (stage == -1)
277                 /*
278                  * We didn't configure any triggers, make sure acquisition
279                  * doesn't wait for any.
280                  */
281                 trigger_stage = TRIGGER_FIRED;
282         else
283                 trigger_stage = 0;
284
285         return SIGROK_OK;
286 }
287
288 /*
289  * API callbacks
290  */
291
292 static int hw_init(char *deviceinfo)
293 {
294         struct sigrok_device_instance *sdi;
295         struct libusb_device_descriptor des;
296         libusb_device **devlist;
297         int err, devcnt, i;
298
299         /* QUICK HACK */
300         deviceinfo = deviceinfo;
301
302         if (libusb_init(&usb_context) != 0) {
303                 g_warning("Failed to initialize USB.");
304                 return 0;
305         }
306         libusb_set_debug(usb_context, 3);
307
308         /* Find all Saleae Logic devices and upload firmware to all of them. */
309         devcnt = 0;
310         libusb_get_device_list(usb_context, &devlist);
311         for (i = 0; devlist[i]; i++) {
312                 err = libusb_get_device_descriptor(devlist[i], &des);
313                 if (err != 0) {
314                         g_warning("failed to get device descriptor: %d", err);
315                         continue;
316                 }
317
318                 if (des.idVendor != USB_VENDOR || des.idProduct != USB_PRODUCT)
319                         continue; /* Not a Saleae Logic... */
320
321                 sdi = sigrok_device_instance_new(devcnt, ST_INITIALIZING,
322                         USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION);
323                 if (!sdi)
324                         return 0;
325                 device_instances = g_slist_append(device_instances, sdi);
326
327                 if (check_conf_profile(devlist[i]) == 0) {
328                         /*
329                          * Continue on the off chance that the device is in a
330                          * working state. TODO: Could maybe try a USB reset,
331                          * or uploading the firmware again.
332                          */
333                         if (upload_firmware(devlist[i]) > 0)
334                                 g_warning("firmware upload failed for "
335                                           "device %d", devcnt);
336
337                         sdi->usb = usb_device_instance_new
338                                 (libusb_get_bus_number(devlist[i]), 0, NULL);
339                 } else {
340                         /* Already has the firmware, so fix the new address. */
341                         sdi->usb = usb_device_instance_new
342                             (libusb_get_bus_number(devlist[i]),
343                              libusb_get_device_address(devlist[i]), NULL);
344                 }
345                 devcnt++;
346         }
347         libusb_free_device_list(devlist, 1);
348
349         return devcnt;
350 }
351
352 static int hw_opendev(int device_index)
353 {
354         GTimeVal cur_time;
355         struct sigrok_device_instance *sdi;
356         int timediff, err;
357         unsigned int cur, upd;
358
359         if (firmware_updated.tv_sec > 0) {
360                 /* Firmware was recently uploaded. */
361                 g_get_current_time(&cur_time);
362                 cur = cur_time.tv_sec * 1000 + cur_time.tv_usec / 1000;
363                 upd = firmware_updated.tv_sec * 1000 +
364                       firmware_updated.tv_usec / 1000;
365                 timediff = cur - upd;
366                 if (timediff < FIRMWARE_RENUM_DELAY) {
367                         timediff = FIRMWARE_RENUM_DELAY - timediff;
368                         g_message("waiting %d ms for device to reset",
369                                   timediff);
370                         g_usleep(timediff * 1000);
371                         firmware_updated.tv_sec = 0;
372                 }
373         }
374
375         if (!(sdi = sl_open_device(device_index))) {
376                 g_warning("unable to open device");
377                 return SIGROK_ERR;
378         }
379
380         err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
381         if (err != 0) {
382                 g_warning("Unable to claim interface: %d", err);
383                 return SIGROK_ERR;
384         }
385
386         if (cur_samplerate == 0) {
387                 /* Samplerate hasn't been set; default to the slowest one. */
388                 if (hw_set_configuration(device_index, HWCAP_SAMPLERATE,
389                     &supported_samplerates[0]) == SIGROK_ERR)
390                         return SIGROK_ERR;
391         }
392
393         return SIGROK_OK;
394 }
395
396 static void hw_closedev(int device_index)
397 {
398         struct sigrok_device_instance *sdi;
399
400         if ((sdi = get_sigrok_device_instance(device_instances, device_index)))
401                 close_device(sdi);
402 }
403
404 static void hw_cleanup(void)
405 {
406         GSList *l;
407
408         /* Properly close all devices... */
409         for (l = device_instances; l; l = l->next)
410                 close_device((struct sigrok_device_instance *)l->data);
411
412         /* ...and free all their memory. */
413         for (l = device_instances; l; l = l->next)
414                 g_free(l->data);
415         g_slist_free(device_instances);
416         device_instances = NULL;
417
418         if (usb_context)
419                 libusb_exit(usb_context);
420         usb_context = NULL;
421 }
422
423 static void *hw_get_device_info(int device_index, int device_info_id)
424 {
425         struct sigrok_device_instance *sdi;
426         void *info = NULL;
427
428         if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
429                 return NULL;
430
431         switch (device_info_id) {
432         case DI_INSTANCE:
433                 info = sdi;
434                 break;
435         case DI_NUM_PROBES:
436                 info = GINT_TO_POINTER(NUM_PROBES);
437                 break;
438         case DI_SAMPLERATES:
439                 info = &samplerates;
440                 break;
441         case DI_TRIGGER_TYPES:
442                 info = TRIGGER_TYPES;
443                 break;
444         case DI_CUR_SAMPLERATE:
445                 info = &cur_samplerate;
446                 break;
447         }
448
449         return info;
450 }
451
452 static int hw_get_status(int device_index)
453 {
454         struct sigrok_device_instance *sdi;
455
456         sdi = get_sigrok_device_instance(device_instances, device_index);
457         if (sdi)
458                 return sdi->status;
459         else
460                 return ST_NOT_FOUND;
461 }
462
463 static int *hw_get_capabilities(void)
464 {
465         return capabilities;
466 }
467
468 static int set_configuration_samplerate(struct sigrok_device_instance *sdi,
469                                         uint64_t samplerate)
470 {
471         uint8_t divider;
472         int ret, result, i;
473         unsigned char buf[2];
474
475         for (i = 0; supported_samplerates[i]; i++) {
476                 if (supported_samplerates[i] == samplerate)
477                         break;
478         }
479         if (supported_samplerates[i] == 0)
480                 return SIGROK_ERR_SAMPLERATE;
481
482         divider = (uint8_t) (48 / (samplerate / 1000000.0)) - 1;
483
484         g_message("setting samplerate to %" PRIu64 " Hz (divider %d)",
485                   samplerate, divider);
486         buf[0] = 0x01;
487         buf[1] = divider;
488         ret = libusb_bulk_transfer(sdi->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT,
489                                    buf, 2, &result, 500);
490         if (ret != 0) {
491                 g_warning("failed to set samplerate: %d", ret);
492                 return SIGROK_ERR;
493         }
494         cur_samplerate = samplerate;
495
496         return SIGROK_OK;
497 }
498
499 static int hw_set_configuration(int device_index, int capability, void *value)
500 {
501         struct sigrok_device_instance *sdi;
502         int ret;
503         uint64_t *tmp_u64;
504
505         if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
506                 return SIGROK_ERR;
507
508         if (capability == HWCAP_SAMPLERATE) {
509                 tmp_u64 = value;
510                 ret = set_configuration_samplerate(sdi, *tmp_u64);
511         } else if (capability == HWCAP_PROBECONFIG) {
512                 ret = configure_probes((GSList *) value);
513         } else if (capability == HWCAP_LIMIT_SAMPLES) {
514                 tmp_u64 = value;
515                 limit_samples = *tmp_u64;
516                 ret = SIGROK_OK;
517         } else {
518                 ret = SIGROK_ERR;
519         }
520
521         return ret;
522 }
523
524 static int receive_data(int fd, int revents, void *user_data)
525 {
526         struct timeval tv;
527
528         /* QUICK HACK */
529         fd = fd;
530         revents = revents;
531         user_data = user_data;
532
533         tv.tv_sec = tv.tv_usec = 0;
534         libusb_handle_events_timeout(usb_context, &tv);
535
536         return TRUE;
537 }
538
539 static void trigger_helper(int i, unsigned char *cur_buf,
540                            struct datafeed_packet *packet, void *user_data,
541                            int *trigger_offset)
542 {
543         if ((cur_buf[i] & trigger_mask[trigger_stage])
544             == trigger_value[trigger_stage]) {
545                 /* Match on this trigger stage. */
546                 trigger_buffer[trigger_stage] = cur_buf[i];
547                 trigger_stage++;
548                 if (trigger_stage == NUM_TRIGGER_STAGES
549                     || trigger_mask[trigger_stage] == 0) {
550                         /* Match on all trigger stages, we're done. */
551                         *trigger_offset = i + 1;
552
553                         /*
554                          * TODO: Send pre-trigger buffer to session bus.
555                          * Tell the frontend we hit the trigger here.
556                          */
557                         packet->type = DF_TRIGGER;
558                         packet->length = 0;
559                         session_bus(user_data, packet);
560
561                         /*
562                          * Send the samples that triggered it, since we're
563                          * skipping past them.
564                          */
565                         packet->type = DF_LOGIC8;
566                         packet->length = trigger_stage;
567                         packet->payload = trigger_buffer;
568                         session_bus(user_data, packet);
569                         // break; // FIXME???
570
571                         trigger_stage = TRIGGER_FIRED;
572                 }
573                 return;
574         }
575
576         /*
577          * We had a match before, but not in the next sample. However, we may
578          * have a match on this stage in the next bit -- trigger on 0001 will
579          * fail on seeing 00001, so we need to go back to stage 0 -- but at
580          * the next sample from the one that matched originally, which the
581          * counter increment at the end of the loop takes care of.
582          */
583         if (trigger_stage > 0) {
584                 i -= trigger_stage;
585                 if (i < -1)
586                         i = -1; /* Oops, went back past this buffer. */
587                 /* Reset trigger stage. */
588                 trigger_stage = 0;
589         }
590 }
591
592 void receive_transfer(struct libusb_transfer *transfer)
593 {
594         static int num_samples = 0;
595         static int empty_transfer_count = 0;
596         struct datafeed_packet packet;
597         void *user_data;
598         int cur_buflen, trigger_offset, i;
599         unsigned char *cur_buf, *new_buf;
600
601         /* hw_stop_acquisition() is telling us to stop. */
602         if (transfer == NULL)
603                 num_samples = -1;
604
605         /*
606          * If acquisition has already ended, just free any queued up
607          * transfer that come in.
608          */
609         if (num_samples == -1) {
610                 if (transfer)
611                         libusb_free_transfer(transfer);
612                 return;
613         }
614
615         g_message("receive_transfer(): status %d received %d bytes",
616                   transfer->status, transfer->actual_length);
617
618         /* Save incoming transfer before reusing the transfer struct. */
619         cur_buf = transfer->buffer;
620         cur_buflen = transfer->actual_length;
621         user_data = transfer->user_data;
622
623         /* Fire off a new request. */
624         new_buf = g_malloc(4096);
625         transfer->buffer = new_buf;
626         transfer->length = 4096;
627         if (libusb_submit_transfer(transfer) != 0) {
628                 /* TODO: Stop session? */
629                 g_warning("eek");
630         }
631
632         if (cur_buflen == 0) {
633                 empty_transfer_count++;
634                 if (empty_transfer_count > MAX_EMPTY_TRANSFERS) {
635                         /*
636                          * The FX2 gave up. End the acquisition, the frontend
637                          * will work out that the samplecount is short.
638                          */
639                         hw_stop_acquisition(-1, user_data);
640                 }
641                 return;
642         } else {
643                 empty_transfer_count = 0;
644         }
645
646         trigger_offset = 0;
647         if (trigger_stage >= 0) {
648                 for (i = 0; i < cur_buflen; i++) {
649                         trigger_helper(i, cur_buf, &packet, user_data,
650                                        &trigger_offset);
651                 }
652         }
653
654         if (trigger_stage == TRIGGER_FIRED) {
655                 /* Send the incoming transfer to the session bus. */
656                 packet.type = DF_LOGIC8;
657                 packet.length = cur_buflen - trigger_offset;
658                 packet.payload = cur_buf + trigger_offset;
659                 session_bus(user_data, &packet);
660                 g_free(cur_buf);
661
662                 num_samples += cur_buflen;
663                 if ((unsigned int)num_samples > limit_samples) {
664                         hw_stop_acquisition(-1, user_data);
665                 }
666         } else {
667                 /*
668                  * TODO: Buffer pre-trigger data in capture
669                  * ratio-sized buffer.
670                  */
671         }
672 }
673
674 static int hw_start_acquisition(int device_index, gpointer session_device_id)
675 {
676         struct sigrok_device_instance *sdi;
677         struct datafeed_packet *packet;
678         struct datafeed_header *header;
679         struct libusb_transfer *transfer;
680         const struct libusb_pollfd **lupfd;
681         int size, i;
682         unsigned char *buf;
683
684         if (!(sdi = get_sigrok_device_instance(device_instances, device_index)))
685                 return SIGROK_ERR;
686
687         packet = g_malloc(sizeof(struct datafeed_packet));
688         header = g_malloc(sizeof(struct datafeed_header));
689         if (!packet || !header)
690                 return SIGROK_ERR;
691
692         /* Start with 2K transfer, subsequently increased to 4K. */
693         size = 2048;
694         for (i = 0; i < NUM_SIMUL_TRANSFERS; i++) {
695                 buf = g_malloc(size);
696                 transfer = libusb_alloc_transfer(0);
697                 libusb_fill_bulk_transfer(transfer, sdi->usb->devhdl,
698                                 2 | LIBUSB_ENDPOINT_IN, buf, size,
699                                 receive_transfer, session_device_id, 40);
700                 if (libusb_submit_transfer(transfer) != 0) {
701                         /* TODO: Free them all. */
702                         libusb_free_transfer(transfer);
703                         g_free(buf);
704                         return SIGROK_ERR;
705                 }
706                 size = 4096;
707         }
708
709         lupfd = libusb_get_pollfds(usb_context);
710         for (i = 0; lupfd[i]; i++)
711                 source_add(lupfd[i]->fd, lupfd[i]->events, 40, receive_data,
712                            NULL);
713         free(lupfd);
714
715         packet->type = DF_HEADER;
716         packet->length = sizeof(struct datafeed_header);
717         packet->payload = (unsigned char *)header;
718         header->feed_version = 1;
719         gettimeofday(&header->starttime, NULL);
720         header->samplerate = cur_samplerate;
721         header->protocol_id = PROTO_RAW;
722         header->num_probes = NUM_PROBES;
723         session_bus(session_device_id, packet);
724         g_free(header);
725         g_free(packet);
726
727         return SIGROK_OK;
728 }
729
730 /* This stops acquisition on ALL devices, ignoring device_index. */
731 static void hw_stop_acquisition(int device_index, gpointer session_device_id)
732 {
733         struct datafeed_packet packet;
734
735         /* QUICK HACK */
736         device_index = device_index;
737
738         packet.type = DF_END;
739         session_bus(session_device_id, &packet);
740
741         receive_transfer(NULL);
742
743         /* TODO: Need to cancel and free any queued up transfers. */
744 }
745
746 struct device_plugin saleae_logic_plugin_info = {
747         "saleae-logic",
748         1,
749         hw_init,
750         hw_cleanup,
751
752         hw_opendev,
753         hw_closedev,
754         hw_get_device_info,
755         hw_get_status,
756         hw_get_capabilities,
757         hw_set_configuration,
758         hw_start_acquisition,
759         hw_stop_acquisition,
760 };