29 #include "sigrok-internal.h"
32 #define USB_VENDOR 0x0c12
34 #define VENDOR_NAME "ZEROPLUS"
35 #define MODEL_NAME "Logic Cube LAP-C"
36 #define MODEL_VERSION NULL
39 #define USB_INTERFACE 0
40 #define USB_CONFIGURATION 1
41 #define NUM_TRIGGER_STAGES 4
42 #define TRIGGER_TYPES "01"
44 #define PACKET_SIZE 2048
58 static model_t zeroplus_models[] = {
59 {0x7009,
"LAP-C(16064)", 16, 64, 100},
60 {0x700A,
"LAP-C(16128)", 16, 128, 200},
61 {0x700B,
"LAP-C(32128)", 32, 128, 200},
62 {0x700C,
"LAP-C(321000)", 32, 1024, 200},
63 {0x700D,
"LAP-C(322000)", 32, 2048, 200},
64 {0x700E,
"LAP-C(16032)", 16, 32, 100},
65 {0x7016,
"LAP-C(162000)", 16, 2048, 200},
68 static int hwcaps[] = {
83 static const char *probe_names[
NUM_PROBES + 1] = {
104 static GSList *dev_insts = NULL;
106 static libusb_context *usb_context = NULL;
117 static uint64_t supported_samplerates[] = {
143 supported_samplerates,
157 struct sr_usb_dev_inst *
usb;
160 static int hw_dev_config_set(
int dev_index,
int hwcap,
void *value);
162 static unsigned int get_memory_size(
int type)
176 static int opendev4(
struct sr_dev_inst **sdi, libusb_device *dev,
177 struct libusb_device_descriptor *des)
185 if (!(ctx = (*sdi)->priv)) {
186 sr_err(
"zp: %s: (*sdi)->priv was NULL", __func__);
190 if ((ret = libusb_get_device_descriptor(dev, des))) {
191 sr_err(
"zp: failed to get device descriptor: %d", ret);
198 if (libusb_get_bus_number(dev) == ctx->
usb->bus
199 && libusb_get_device_address(dev) == ctx->
usb->address) {
201 for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) {
202 if (!(des->idProduct == zeroplus_models[i].
pid))
205 sr_info(
"zp: Found ZEROPLUS device 0x%04x (%s)",
206 des->idProduct, zeroplus_models[i].
model_name);
213 sr_err(
"zp: Unknown ZEROPLUS device 0x%04x",
219 if (!(ret = libusb_open(dev, &(ctx->
usb->devhdl)))) {
221 sr_info(
"zp: opened device %d on %d.%d interface %d",
222 (*sdi)->index, ctx->
usb->bus,
225 sr_err(
"zp: failed to open device: %d", ret);
233 static struct sr_dev_inst *zp_open_dev(
int dev_index)
236 libusb_device **devlist;
237 struct libusb_device_descriptor des;
243 libusb_get_device_list(usb_context, &devlist);
246 libusb_get_device_list(usb_context, &devlist);
247 for (i = 0; devlist[i]; i++) {
249 opendev4(&sdi, devlist[i], &des);
255 libusb_free_device_list(devlist, 1);
267 if (!(ctx = sdi->
priv)) {
268 sr_err(
"zp: %s: sdi->priv was NULL", __func__);
272 if (!ctx->
usb->devhdl)
275 sr_info(
"zp: closing device %d on %d.%d interface %d", sdi->
index,
278 libusb_reset_device(ctx->
usb->devhdl);
279 libusb_close(ctx->
usb->devhdl);
280 ctx->
usb->devhdl = NULL;
285 static int configure_probes(
struct sr_dev_inst *sdi, GSList *probes)
290 int probe_bit, stage, i;
303 for (l = probes; l; l = l->next) {
307 probe_bit = 1 << (probe->
index - 1);
312 for (tc = probe->
trigger; *tc; tc++) {
317 if (stage > NUM_TRIGGER_STAGES)
330 static int hw_init(
const char *devinfo)
333 struct libusb_device_descriptor des;
334 libusb_device **devlist;
342 if (!(ctx = g_try_malloc(
sizeof(
struct context)))) {
343 sr_err(
"zp: %s: ctx malloc failed", __func__);
358 if (libusb_init(&usb_context) != 0) {
359 sr_err(
"zp: Failed to initialize USB.");
365 libusb_get_device_list(usb_context, &devlist);
367 for (i = 0; devlist[i]; i++) {
368 ret = libusb_get_device_descriptor(devlist[i], &des);
370 sr_err(
"zp: failed to get device descriptor: %d", ret);
384 sr_err(
"zp: %s: sr_dev_inst_new failed",
392 g_slist_append(dev_insts, sdi);
394 libusb_get_bus_number(devlist[i]),
395 libusb_get_device_address(devlist[i]), NULL);
399 libusb_free_device_list(devlist, 1);
404 static int hw_dev_open(
int dev_index)
410 if (!(sdi = zp_open_dev(dev_index))) {
411 sr_err(
"zp: unable to open device");
417 if (!(ctx = sdi->
priv)) {
418 sr_err(
"zp: %s: sdi->priv was NULL", __func__);
424 sr_err(
"zp: Unable to set USB configuration %d: %d",
431 sr_err(
"zp: Unable to claim interface: %d", ret);
447 if (g_double_mode == 1)
449 else if (g_compression == 1)
465 static int hw_dev_close(
int dev_index)
470 sr_err(
"zp: %s: sdi was NULL", __func__);
480 static int hw_cleanup(
void)
485 for (l = dev_insts; l; l = l->next) {
492 g_slist_free(dev_insts);
496 libusb_exit(usb_context);
502 static void *hw_dev_info_get(
int dev_index,
int dev_info_id)
509 sr_err(
"zp: %s: sdi was NULL", __func__);
513 if (!(ctx = sdi->
priv)) {
514 sr_err(
"zp: %s: sdi->priv was NULL", __func__);
518 sr_spew(
"zp: %s: dev_index %d, dev_info_id %d.", __func__,
519 dev_index, dev_info_id);
521 switch (dev_info_id) {
524 sr_spew(
"zp: %s: Returning sdi.", __func__);
528 sr_spew(
"zp: %s: Returning number of probes: %d.", __func__,
533 sr_spew(
"zp: %s: Returning probenames.", __func__);
537 sr_spew(
"zp: %s: Returning samplerates.", __func__);
541 sr_spew(
"zp: %s: Returning triggertypes: %s.", __func__, info);
545 sr_spew(
"zp: %s: Returning samplerate: %" PRIu64
"Hz.",
550 sr_err(
"zp: %s: Unknown device info ID", __func__);
558 static int hw_dev_status_get(
int dev_index)
569 static int *hw_hwcap_get_all(
void)
574 static int set_samplerate(
struct sr_dev_inst *sdi, uint64_t samplerate)
579 sr_err(
"zp: %s: sdi was NULL", __func__);
583 if (!(ctx = sdi->
priv)) {
584 sr_err(
"zp: %s: sdi->priv was NULL", __func__);
588 sr_info(
"zp: Setting samplerate to %" PRIu64
"Hz.", samplerate);
590 if (samplerate >
SR_MHZ(1))
592 else if (samplerate >
SR_KHZ(1))
602 static int hw_dev_config_set(
int dev_index,
int hwcap,
void *value)
608 sr_err(
"zp: %s: sdi was NULL", __func__);
612 if (!(ctx = sdi->
priv)) {
613 sr_err(
"zp: %s: sdi->priv was NULL", __func__);
619 return set_samplerate(sdi, *(uint64_t *)value);
621 return configure_probes(sdi, (GSList *)value);
630 static int hw_dev_acquisition_start(
int dev_index,
void *cb_data)
636 uint64_t samples_read;
638 unsigned int packet_num;
643 sr_err(
"zp: %s: sdi was NULL", __func__);
647 if (!(ctx = sdi->
priv)) {
648 sr_err(
"zp: %s: sdi->priv was NULL", __func__);
656 sr_info(
"zp: Waiting for data");
659 sr_info(
"zp: Stop address = 0x%x",
661 sr_info(
"zp: Now address = 0x%x",
663 sr_info(
"zp: Trigger address = 0x%x",
669 gettimeofday(&
header.starttime, NULL);
675 sr_err(
"zp: %s: buf malloc failed", __func__);
685 sr_info(
"zp: Tried to read %llx bytes, actually read %x bytes",
689 packet.payload = &logic;
694 samples_read += res / 4;
706 static int hw_dev_acquisition_stop(
int dev_index,
void *cb_data)
716 sr_err(
"zp: %s: sdi was NULL", __func__);
720 if (!(ctx = sdi->
priv)) {
721 sr_err(
"zp: %s: sdi->priv was NULL", __func__);
732 .
name =
"zeroplus-logic-cube",
733 .longname =
"ZEROPLUS Logic Cube LAP-C series",
736 .cleanup = hw_cleanup,
737 .dev_open = hw_dev_open,
738 .dev_close = hw_dev_close,
739 .dev_info_get = hw_dev_info_get,
740 .dev_status_get = hw_dev_status_get,
741 .hwcap_get_all = hw_hwcap_get_all,
742 .dev_config_set = hw_dev_config_set,
743 .dev_acquisition_start = hw_dev_acquisition_start,
744 .dev_acquisition_stop = hw_dev_acquisition_stop,