]> sigrok.org Git - libsigrok.git/blame - hardware/zeroplus-logic-cube/api.c
zeroplus: Add getters for memory configuration
[libsigrok.git] / hardware / zeroplus-logic-cube / api.c
CommitLineData
a1bb33af 1/*
50985c20 2 * This file is part of the libsigrok project.
a1bb33af 3 *
c73d2ea4 4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
a1bb33af
UH
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
6d116114 20#include "protocol.h"
a1bb33af 21
8fdecced 22#define VENDOR_NAME "ZEROPLUS"
a1bb33af
UH
23#define USB_INTERFACE 0
24#define USB_CONFIGURATION 1
25#define NUM_TRIGGER_STAGES 4
c50277a6 26#define TRIGGER_TYPE "01"
fed16f06 27#define PACKET_SIZE 2048 /* ?? */
a1bb33af 28
0ab0cb94
TY
29//#define ZP_EXPERIMENTAL
30
e495a676
UH
31struct zp_model {
32 uint16_t vid;
33 uint16_t pid;
428edbe1 34 char *model_name;
a1bb33af 35 unsigned int channels;
fed16f06 36 unsigned int sample_depth; /* In Ksamples/channel */
a1bb33af 37 unsigned int max_sampling_freq;
e495a676 38};
a1bb33af 39
fed16f06
UH
40/*
41 * Note -- 16032, 16064 and 16128 *usually* -- but not always -- have the
42 * same 128K sample depth.
43 */
e495a676 44static const struct zp_model zeroplus_models[] = {
9e5670d0 45 {0x0c12, 0x7002, "LAP-16128U", 16, 128, 200},
428edbe1 46 {0x0c12, 0x7009, "LAP-C(16064)", 16, 64, 100},
e495a676 47 {0x0c12, 0x700a, "LAP-C(16128)", 16, 128, 200},
5db0c668
RD
48 {0x0c12, 0x700b, "LAP-C(32128)", 32, 128, 200},
49 {0x0c12, 0x700c, "LAP-C(321000)", 32, 1024, 200},
50 {0x0c12, 0x700d, "LAP-C(322000)", 32, 2048, 200},
e495a676 51 {0x0c12, 0x700e, "LAP-C(16032)", 16, 32, 100},
428edbe1
BV
52 {0x0c12, 0x7016, "LAP-C(162000)", 16, 2048, 200},
53 { 0, 0, 0, 0, 0, 0 }
a1bb33af
UH
54};
55
8386096f 56static const int32_t hwcaps[] = {
1953564a
BV
57 SR_CONF_LOGIC_ANALYZER,
58 SR_CONF_SAMPLERATE,
59 SR_CONF_CAPTURE_RATIO,
1953564a 60 SR_CONF_LIMIT_SAMPLES,
a1bb33af
UH
61};
62
d261dbbf
UH
63/*
64 * ZEROPLUS LAP-C (16032) numbers the 16 probes A0-A7 and B0-B7.
65 * We currently ignore other untested/unsupported devices here.
66 */
e495a676 67static const char *probe_names[] = {
78693401
UH
68 "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7",
69 "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7",
5db0c668
RD
70 "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7",
71 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
464d12c7
KS
72 NULL,
73};
74
32756547 75SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info;
a873c594 76static struct sr_dev_driver *di = &zeroplus_logic_cube_driver_info;
a1bb33af 77
fed16f06
UH
78/*
79 * The hardware supports more samplerates than these, but these are the
80 * options hardcoded into the vendor's Windows GUI.
81 */
a1bb33af 82
8386096f 83static const uint64_t samplerates_100[] = {
17548571
UH
84 SR_HZ(100),
85 SR_HZ(500),
86 SR_KHZ(1),
87 SR_KHZ(5),
88 SR_KHZ(25),
89 SR_KHZ(50),
90 SR_KHZ(100),
91 SR_KHZ(200),
92 SR_KHZ(400),
93 SR_KHZ(800),
94 SR_MHZ(1),
95 SR_MHZ(10),
96 SR_MHZ(25),
97 SR_MHZ(50),
98 SR_MHZ(80),
99 SR_MHZ(100),
17548571
UH
100};
101
8386096f 102const uint64_t samplerates_200[] = {
c9140419
UH
103 SR_HZ(100),
104 SR_HZ(500),
59df0c77
UH
105 SR_KHZ(1),
106 SR_KHZ(5),
107 SR_KHZ(25),
108 SR_KHZ(50),
109 SR_KHZ(100),
110 SR_KHZ(200),
111 SR_KHZ(400),
112 SR_KHZ(800),
113 SR_MHZ(1),
114 SR_MHZ(10),
115 SR_MHZ(25),
116 SR_MHZ(50),
117 SR_MHZ(80),
118 SR_MHZ(100),
119 SR_MHZ(150),
120 SR_MHZ(200),
bf43ea23 121};
a1bb33af 122
6078d2c9 123static int dev_close(struct sr_dev_inst *sdi);
a1bb33af 124
0ab0cb94 125#if 0
014359e3 126static int configure_probes(const struct sr_dev_inst *sdi)
a1bb33af 127{
310e9e9b 128 struct dev_context *devc;
1b79df2f
JH
129 const struct sr_probe *probe;
130 const GSList *l;
a1bb33af
UH
131 int probe_bit, stage, i;
132 char *tc;
133
bf43ea23 134 /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
310e9e9b 135 devc = sdi->priv;
bf43ea23 136
310e9e9b 137 devc->probe_mask = 0;
fed16f06 138 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
310e9e9b
BV
139 devc->trigger_mask[i] = 0;
140 devc->trigger_value[i] = 0;
a1bb33af
UH
141 }
142
143 stage = -1;
014359e3 144 for (l = sdi->probes; l; l = l->next) {
1afe8989 145 probe = (struct sr_probe *)l->data;
fed16f06 146 if (probe->enabled == FALSE)
a1bb33af 147 continue;
b35c8293 148 probe_bit = 1 << (probe->index);
310e9e9b 149 devc->probe_mask |= probe_bit;
fed16f06
UH
150
151 if (probe->trigger) {
a1bb33af 152 stage = 0;
fed16f06 153 for (tc = probe->trigger; *tc; tc++) {
310e9e9b 154 devc->trigger_mask[stage] |= probe_bit;
fed16f06 155 if (*tc == '1')
310e9e9b 156 devc->trigger_value[stage] |= probe_bit;
a1bb33af 157 stage++;
fed16f06 158 if (stage > NUM_TRIGGER_STAGES)
e46b8fb1 159 return SR_ERR;
a1bb33af
UH
160 }
161 }
162 }
163
e46b8fb1 164 return SR_OK;
a1bb33af 165}
0ab0cb94
TY
166#endif
167
168static int configure_probes(const struct sr_dev_inst *sdi)
169{
170 struct dev_context *devc;
171 const GSList *l;
172 const struct sr_probe *probe;
173 char *tc;
174 int type;
175
176 /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
177 devc = sdi->priv;
178
179 for (l = sdi->probes; l; l = l->next) {
180 probe = (struct sr_probe *)l->data;
181 if (probe->enabled == FALSE)
182 continue;
183
184 if ((tc = probe->trigger)) {
185 switch (*tc) {
186 case '1':
187 type = TRIGGER_HIGH;
188 break;
189 case '0':
190 type = TRIGGER_LOW;
191 break;
192#if 0
193 case 'r':
194 type = TRIGGER_POSEDGE;
195 break;
196 case 'f':
197 type = TRIGGER_NEGEDGE;
198 break;
199 case 'c':
200 type = TRIGGER_ANYEDGE;
201 break;
202#endif
203 default:
204 return SR_ERR;
205 }
206 analyzer_add_trigger(probe->index, type);
207 devc->trigger = 1;
208 }
209 }
210
211 return SR_OK;
212}
a1bb33af 213
3316e149
BV
214SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
215{
216 int i;
217
218 for (i = 0; ARRAY_SIZE(samplerates_200); i++)
219 if (samplerate == samplerates_200[i])
220 break;
221
222 if (i == ARRAY_SIZE(samplerates_200) || samplerate > devc->max_samplerate) {
223 sr_err("Unsupported samplerate: %" PRIu64 "Hz.", samplerate);
224 return SR_ERR_ARG;
225 }
226
227 sr_info("Setting samplerate to %" PRIu64 "Hz.", samplerate);
228
229 if (samplerate >= SR_MHZ(1))
230 analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ);
231 else if (samplerate >= SR_KHZ(1))
232 analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ);
233 else
234 analyzer_set_freq(samplerate, FREQ_SCALE_HZ);
235
236 devc->cur_samplerate = samplerate;
237
238 return SR_OK;
239}
240
3b412e3a 241static int dev_clear(void)
7da6f9d5 242{
d6445cb0 243 return std_dev_clear(di, NULL);
7da6f9d5
BV
244}
245
6078d2c9 246static int init(struct sr_context *sr_ctx)
61136ea6 247{
f6beaac5 248 return std_init(sr_ctx, di, LOG_PREFIX);
61136ea6
BV
249}
250
6078d2c9 251static GSList *scan(GSList *options)
a1bb33af 252{
d68e2d1a 253 struct sr_dev_inst *sdi;
428edbe1 254 struct sr_probe *probe;
310e9e9b
BV
255 struct drv_context *drvc;
256 struct dev_context *devc;
e495a676 257 const struct zp_model *prof;
a1bb33af
UH
258 struct libusb_device_descriptor des;
259 libusb_device **devlist;
428edbe1
BV
260 GSList *devices;
261 int ret, devcnt, i, j;
a1bb33af 262
4ca38984 263 (void)options;
64d33dc2 264
a873c594 265 drvc = di->priv;
4b97c74e 266
4ca38984
BV
267 devices = NULL;
268
8fdecced 269 /* Find all ZEROPLUS analyzers and add them to device list. */
a1bb33af 270 devcnt = 0;
d4abb463 271 libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); /* TODO: Errors. */
fed16f06
UH
272
273 for (i = 0; devlist[i]; i++) {
ebc34738
UH
274 ret = libusb_get_device_descriptor(devlist[i], &des);
275 if (ret != 0) {
6d116114 276 sr_err("Failed to get device descriptor: %s.",
d4928d71 277 libusb_error_name(ret));
a1bb33af
UH
278 continue;
279 }
280
428edbe1
BV
281 prof = NULL;
282 for (j = 0; j < zeroplus_models[j].vid; j++) {
283 if (des.idVendor == zeroplus_models[j].vid &&
284 des.idProduct == zeroplus_models[j].pid) {
285 prof = &zeroplus_models[j];
bf43ea23 286 }
a1bb33af 287 }
e495a676 288 /* Skip if the device was not found. */
428edbe1
BV
289 if (!prof)
290 continue;
e495a676 291 sr_info("Found ZEROPLUS %s.", prof->model_name);
428edbe1
BV
292
293 /* Register the device with libsigrok. */
294 if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
295 VENDOR_NAME, prof->model_name, NULL))) {
6d116114 296 sr_err("%s: sr_dev_inst_new failed", __func__);
428edbe1
BV
297 return NULL;
298 }
a873c594 299 sdi->driver = di;
428edbe1
BV
300
301 /* Allocate memory for our private driver context. */
310e9e9b 302 if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
6d116114 303 sr_err("Device context malloc failed.");
886a52b6 304 return NULL;
428edbe1 305 }
e495a676 306
310e9e9b 307 sdi->priv = devc;
17548571 308 devc->prof = prof;
310e9e9b 309 devc->num_channels = prof->channels;
0ab0cb94 310#ifdef ZP_EXPERIMENTAL
e93fb98b 311 devc->max_sample_depth = 128 * 1024;
0ab0cb94
TY
312 devc->max_samplerate = 200;
313#else
e93fb98b 314 devc->max_sample_depth = prof->sample_depth * 1024;
0ab0cb94
TY
315 devc->max_samplerate = prof->max_sampling_freq;
316#endif
317 devc->max_samplerate *= SR_MHZ(1);
318 devc->memory_size = MEMORY_SIZE_8K;
310e9e9b 319 // memset(devc->trigger_buffer, 0, NUM_TRIGGER_STAGES);
428edbe1
BV
320
321 /* Fill in probelist according to this device's profile. */
310e9e9b 322 for (j = 0; j < devc->num_channels; j++) {
428edbe1
BV
323 if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
324 probe_names[j])))
325 return NULL;
326 sdi->probes = g_slist_append(sdi->probes, probe);
327 }
328
329 devices = g_slist_append(devices, sdi);
310e9e9b 330 drvc->instances = g_slist_append(drvc->instances, sdi);
8111446a 331 sdi->inst_type = SR_INST_USB;
609bfd75 332 sdi->conn = sr_usb_dev_inst_new(
428edbe1
BV
333 libusb_get_bus_number(devlist[i]),
334 libusb_get_device_address(devlist[i]), NULL);
335 devcnt++;
336
a1bb33af
UH
337 }
338 libusb_free_device_list(devlist, 1);
339
4ca38984 340 return devices;
a1bb33af
UH
341}
342
6078d2c9 343static GSList *dev_list(void)
811deee4 344{
0e94d524 345 return ((struct drv_context *)(di->priv))->instances;
811deee4
BV
346}
347
6078d2c9 348static int dev_open(struct sr_dev_inst *sdi)
a1bb33af 349{
310e9e9b 350 struct dev_context *devc;
e495a676 351 struct drv_context *drvc;
609bfd75 352 struct sr_usb_dev_inst *usb;
428edbe1
BV
353 libusb_device **devlist, *dev;
354 struct libusb_device_descriptor des;
355 int device_count, ret, i;
a1bb33af 356
e495a676 357 drvc = di->priv;
609bfd75 358 usb = sdi->conn;
e495a676 359
310e9e9b 360 if (!(devc = sdi->priv)) {
6d116114 361 sr_err("%s: sdi->priv was NULL", __func__);
bf43ea23
UH
362 return SR_ERR_ARG;
363 }
364
d4abb463
PS
365 device_count = libusb_get_device_list(drvc->sr_ctx->libusb_ctx,
366 &devlist);
428edbe1 367 if (device_count < 0) {
6d116114 368 sr_err("Failed to retrieve device list.");
428edbe1
BV
369 return SR_ERR;
370 }
371
372 dev = NULL;
373 for (i = 0; i < device_count; i++) {
374 if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
6d116114 375 sr_err("Failed to get device descriptor: %s.",
d4928d71 376 libusb_error_name(ret));
428edbe1
BV
377 continue;
378 }
609bfd75
BV
379 if (libusb_get_bus_number(devlist[i]) == usb->bus
380 && libusb_get_device_address(devlist[i]) == usb->address) {
428edbe1
BV
381 dev = devlist[i];
382 break;
383 }
384 }
385 if (!dev) {
6d116114 386 sr_err("Device on bus %d address %d disappeared!",
609bfd75 387 usb->bus, usb->address);
428edbe1
BV
388 return SR_ERR;
389 }
390
609bfd75 391 if (!(ret = libusb_open(dev, &(usb->devhdl)))) {
428edbe1 392 sdi->status = SR_ST_ACTIVE;
6d116114 393 sr_info("Opened device %d on %d.%d interface %d.",
609bfd75 394 sdi->index, usb->bus, usb->address, USB_INTERFACE);
428edbe1 395 } else {
6d116114 396 sr_err("Failed to open device: %s.", libusb_error_name(ret));
428edbe1
BV
397 return SR_ERR;
398 }
399
609bfd75 400 ret = libusb_set_configuration(usb->devhdl, USB_CONFIGURATION);
ebc34738 401 if (ret < 0) {
6d116114 402 sr_err("Unable to set USB configuration %d: %s.",
d4928d71 403 USB_CONFIGURATION, libusb_error_name(ret));
185ae2c5
UH
404 return SR_ERR;
405 }
406
609bfd75 407 ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
ebc34738 408 if (ret != 0) {
6d116114 409 sr_err("Unable to claim interface: %s.",
d4928d71 410 libusb_error_name(ret));
e46b8fb1 411 return SR_ERR;
a1bb33af 412 }
185ae2c5 413
e495a676 414 /* Set default configuration after power on. */
609bfd75
BV
415 if (analyzer_read_status(usb->devhdl) == 0)
416 analyzer_configure(usb->devhdl);
0ab0cb94 417
609bfd75
BV
418 analyzer_reset(usb->devhdl);
419 analyzer_initialize(usb->devhdl);
a1bb33af 420
0ab0cb94 421 //analyzer_set_memory_size(MEMORY_SIZE_512K);
fed16f06 422 // analyzer_set_freq(g_freq, g_freq_scale);
a1bb33af 423 analyzer_set_trigger_count(1);
408e7199
UH
424 // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger)
425 // * get_memory_size(g_memory_size)) / 100) >> 2);
a1bb33af 426
fed16f06
UH
427#if 0
428 if (g_double_mode == 1)
a1bb33af
UH
429 analyzer_set_compression(COMPRESSION_DOUBLE);
430 else if (g_compression == 1)
431 analyzer_set_compression(COMPRESSION_ENABLE);
fed16f06
UH
432 else
433#endif
434 analyzer_set_compression(COMPRESSION_NONE);
a1bb33af 435
310e9e9b 436 if (devc->cur_samplerate == 0) {
0ab0cb94
TY
437 /* Samplerate hasn't been set. Default to 1MHz. */
438 analyzer_set_freq(1, FREQ_SCALE_MHZ);
439 devc->cur_samplerate = SR_MHZ(1);
a1bb33af
UH
440 }
441
e46b8fb1 442 return SR_OK;
a1bb33af
UH
443}
444
6078d2c9 445static int dev_close(struct sr_dev_inst *sdi)
a1bb33af 446{
609bfd75 447 struct sr_usb_dev_inst *usb;
a1bb33af 448
609bfd75 449 usb = sdi->conn;
697785d1 450
609bfd75 451 if (!usb->devhdl)
25a0f108
BV
452 return SR_ERR;
453
6d116114 454 sr_info("Closing device %d on %d.%d interface %d.", sdi->index,
609bfd75
BV
455 usb->bus, usb->address, USB_INTERFACE);
456 libusb_release_interface(usb->devhdl, USB_INTERFACE);
457 libusb_reset_device(usb->devhdl);
458 libusb_close(usb->devhdl);
459 usb->devhdl = NULL;
25a0f108 460 sdi->status = SR_ST_INACTIVE;
697785d1
UH
461
462 return SR_OK;
a1bb33af
UH
463}
464
6078d2c9 465static int cleanup(void)
a1bb33af 466{
3b412e3a 467 return dev_clear();
a1bb33af
UH
468}
469
8f996b89
ML
470static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
471 const struct sr_probe_group *probe_group)
a1bb33af 472{
310e9e9b 473 struct dev_context *devc;
a1bb33af 474
8f996b89
ML
475 (void)probe_group;
476
035a1078 477 switch (id) {
123e1313 478 case SR_CONF_SAMPLERATE:
626409ab 479 if (sdi) {
310e9e9b 480 devc = sdi->priv;
8386096f 481 *data = g_variant_new_uint64(devc->cur_samplerate);
6d116114
UH
482 sr_spew("Returning samplerate: %" PRIu64 "Hz.",
483 devc->cur_samplerate);
626409ab
BV
484 } else
485 return SR_ERR;
bf43ea23 486 break;
05f853b5
RD
487 case SR_CONF_CAPTURE_RATIO:
488 if (sdi) {
489 devc = sdi->priv;
490 *data = g_variant_new_uint64(devc->capture_ratio);
491 } else
492 return SR_ERR;
493 break;
bf43ea23 494 default:
bd6fbf62 495 return SR_ERR_NA;
a1bb33af
UH
496 }
497
626409ab 498 return SR_OK;
a1bb33af
UH
499}
500
8f996b89
ML
501static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi,
502 const struct sr_probe_group *probe_group)
a1bb33af 503{
310e9e9b 504 struct dev_context *devc;
a1bb33af 505
8f996b89
ML
506 (void)probe_group;
507
e73ffd42
BV
508 if (sdi->status != SR_ST_ACTIVE)
509 return SR_ERR_DEV_CLOSED;
0ab0cb94 510
310e9e9b 511 if (!(devc = sdi->priv)) {
6d116114 512 sr_err("%s: sdi->priv was NULL", __func__);
bf43ea23
UH
513 return SR_ERR_ARG;
514 }
a1bb33af 515
035a1078 516 switch (id) {
1953564a 517 case SR_CONF_SAMPLERATE:
8386096f 518 return zp_set_samplerate(devc, g_variant_get_uint64(data));
1953564a 519 case SR_CONF_LIMIT_SAMPLES:
8386096f 520 return set_limit_samples(devc, g_variant_get_uint64(data));
1953564a 521 case SR_CONF_CAPTURE_RATIO:
8386096f 522 return set_capture_ratio(devc, g_variant_get_uint64(data));
fed16f06 523 default:
bd6fbf62 524 return SR_ERR_NA;
a1bb33af 525 }
e495a676
UH
526
527 return SR_OK;
a1bb33af
UH
528}
529
8f996b89
ML
530static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
531 const struct sr_probe_group *probe_group)
a1c743fc 532{
17548571 533 struct dev_context *devc;
8386096f
BV
534 GVariant *gvar;
535 GVariantBuilder gvb;
a1c743fc 536
8f996b89
ML
537 (void)probe_group;
538
a1c743fc 539 switch (key) {
9a6517d1 540 case SR_CONF_DEVICE_OPTIONS:
8386096f
BV
541 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
542 hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
9a6517d1 543 break;
a1c743fc 544 case SR_CONF_SAMPLERATE:
17548571 545 devc = sdi->priv;
8386096f 546 g_variant_builder_init(&gvb, G_VARIANT_TYPE("a{sv}"));
17548571 547 if (devc->prof->max_sampling_freq == 100) {
8386096f
BV
548 gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
549 samplerates_100, ARRAY_SIZE(samplerates_100),
550 sizeof(uint64_t));
17548571 551 } else if (devc->prof->max_sampling_freq == 200) {
8386096f
BV
552 gvar = g_variant_new_fixed_array(G_VARIANT_TYPE("t"),
553 samplerates_200, ARRAY_SIZE(samplerates_200),
554 sizeof(uint64_t));
17548571
UH
555 } else {
556 sr_err("Internal error: Unknown max. samplerate: %d.",
557 devc->prof->max_sampling_freq);
558 return SR_ERR_ARG;
559 }
8386096f
BV
560 g_variant_builder_add(&gvb, "{sv}", "samplerates", gvar);
561 *data = g_variant_builder_end(&gvb);
a1c743fc 562 break;
c50277a6 563 case SR_CONF_TRIGGER_TYPE:
8386096f 564 *data = g_variant_new_string(TRIGGER_TYPE);
c50277a6 565 break;
a1c743fc 566 default:
bd6fbf62 567 return SR_ERR_NA;
a1c743fc
BV
568 }
569
570 return SR_OK;
571}
572
6078d2c9 573static int dev_acquisition_start(const struct sr_dev_inst *sdi,
3ffb6964 574 void *cb_data)
a1bb33af 575{
609bfd75
BV
576 struct dev_context *devc;
577 struct sr_usb_dev_inst *usb;
b9c735a2 578 struct sr_datafeed_packet packet;
9c939c51 579 struct sr_datafeed_logic logic;
0ab0cb94 580 //uint64_t samples_read;
a1bb33af 581 int res;
e495a676 582 unsigned int packet_num, n;
a1bb33af
UH
583 unsigned char *buf;
584
e73ffd42
BV
585 if (sdi->status != SR_ST_ACTIVE)
586 return SR_ERR_DEV_CLOSED;
587
310e9e9b 588 if (!(devc = sdi->priv)) {
6d116114 589 sr_err("%s: sdi->priv was NULL", __func__);
bf43ea23
UH
590 return SR_ERR_ARG;
591 }
a1bb33af 592
014359e3 593 if (configure_probes(sdi) != SR_OK) {
6d116114 594 sr_err("Failed to configure probes.");
014359e3
BV
595 return SR_ERR;
596 }
597
609bfd75
BV
598 usb = sdi->conn;
599
0ab0cb94
TY
600 set_triggerbar(devc);
601
e495a676 602 /* Push configured settings to device. */
609bfd75 603 analyzer_configure(usb->devhdl);
a143e4e5 604
609bfd75 605 analyzer_start(usb->devhdl);
6d116114 606 sr_info("Waiting for data.");
609bfd75 607 analyzer_wait_data(usb->devhdl);
a1bb33af 608
6d116114 609 sr_info("Stop address = 0x%x.",
609bfd75 610 analyzer_get_stop_address(usb->devhdl));
6d116114 611 sr_info("Now address = 0x%x.",
609bfd75 612 analyzer_get_now_address(usb->devhdl));
6d116114 613 sr_info("Trigger address = 0x%x.",
609bfd75 614 analyzer_get_trigger_address(usb->devhdl));
a1bb33af 615
4afdfd46 616 /* Send header packet to the session bus. */
29a27196 617 std_session_send_df_header(cb_data, LOG_PREFIX);
f366e86c 618
b53738ba 619 if (!(buf = g_try_malloc(PACKET_SIZE))) {
6d116114 620 sr_err("Packet buffer malloc failed.");
b53738ba
UH
621 return SR_ERR_MALLOC;
622 }
623
0ab0cb94 624 //samples_read = 0;
609bfd75 625 analyzer_read_start(usb->devhdl);
fed16f06 626 /* Send the incoming transfer to the session bus. */
0ab0cb94 627 n = get_memory_size(devc->memory_size);
e93fb98b
RD
628 if (devc->max_sample_depth * 4 < n)
629 n = devc->max_sample_depth * 4;
0ab0cb94 630 for (packet_num = 0; packet_num < n / PACKET_SIZE; packet_num++) {
609bfd75 631 res = analyzer_read_data(usb->devhdl, buf, PACKET_SIZE);
6d116114 632 sr_info("Tried to read %d bytes, actually read %d bytes.",
b08024a8 633 PACKET_SIZE, res);
a1bb33af 634
5a2326a7 635 packet.type = SR_DF_LOGIC;
9c939c51
BV
636 packet.payload = &logic;
637 logic.length = PACKET_SIZE;
638 logic.unitsize = 4;
639 logic.data = buf;
3cd3a20b 640 sr_session_send(cb_data, &packet);
0ab0cb94 641 //samples_read += res / 4;
a1bb33af 642 }
609bfd75 643 analyzer_read_stop(usb->devhdl);
a1bb33af
UH
644 g_free(buf);
645
5a2326a7 646 packet.type = SR_DF_END;
3cd3a20b 647 sr_session_send(cb_data, &packet);
a1bb33af 648
e46b8fb1 649 return SR_OK;
a1bb33af
UH
650}
651
3cd3a20b 652/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
6078d2c9 653static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
a1bb33af 654{
310e9e9b 655 struct dev_context *devc;
609bfd75
BV
656 struct sr_usb_dev_inst *usb;
657 struct sr_datafeed_packet packet;
a1bb33af 658
5a2326a7 659 packet.type = SR_DF_END;
3cd3a20b 660 sr_session_send(cb_data, &packet);
a1bb33af 661
310e9e9b 662 if (!(devc = sdi->priv)) {
6d116114 663 sr_err("%s: sdi->priv was NULL", __func__);
3010f21c 664 return SR_ERR_BUG;
69890f73 665 }
a1bb33af 666
609bfd75
BV
667 usb = sdi->conn;
668 analyzer_reset(usb->devhdl);
fed16f06 669 /* TODO: Need to cancel and free any queued up transfers. */
3010f21c
UH
670
671 return SR_OK;
a1bb33af
UH
672}
673
c09f0b57 674SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
e519ba86 675 .name = "zeroplus-logic-cube",
8fdecced 676 .longname = "ZEROPLUS Logic Cube LAP-C series",
e519ba86 677 .api_version = 1,
6078d2c9
UH
678 .init = init,
679 .cleanup = cleanup,
680 .scan = scan,
681 .dev_list = dev_list,
3b412e3a 682 .dev_clear = dev_clear,
035a1078
BV
683 .config_get = config_get,
684 .config_set = config_set,
a1c743fc 685 .config_list = config_list,
6078d2c9
UH
686 .dev_open = dev_open,
687 .dev_close = dev_close,
688 .dev_acquisition_start = dev_acquisition_start,
689 .dev_acquisition_stop = dev_acquisition_stop,
310e9e9b 690 .priv = NULL,
a1bb33af 691};