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