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