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