]> sigrok.org Git - libsigrok.git/blame - hardware/zeroplus-logic-cube/zeroplus.c
zeroplus: comment out 32-probe models for now
[libsigrok.git] / hardware / zeroplus-logic-cube / zeroplus.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
20#include <stdio.h>
21#include <stdlib.h>
c31e9ef4 22#include <string.h>
a1bb33af
UH
23#include <sys/time.h>
24#include <inttypes.h>
25#include <glib.h>
26#include <libusb.h>
c31e9ef4 27#include "config.h"
45c59c8b
BV
28#include "libsigrok.h"
29#include "libsigrok-internal.h"
a1bb33af
UH
30#include "analyzer.h"
31
fed16f06 32#define USB_VENDOR 0x0c12
8fdecced
UH
33
34#define VENDOR_NAME "ZEROPLUS"
35#define MODEL_NAME "Logic Cube LAP-C"
36#define MODEL_VERSION NULL
a1bb33af 37
6752905e 38#define NUM_PROBES 16
a1bb33af
UH
39#define USB_INTERFACE 0
40#define USB_CONFIGURATION 1
41#define NUM_TRIGGER_STAGES 4
42#define TRIGGER_TYPES "01"
43
fed16f06 44#define PACKET_SIZE 2048 /* ?? */
a1bb33af
UH
45
46typedef struct {
428edbe1 47 unsigned short vid;
a1bb33af 48 unsigned short pid;
428edbe1 49 char *model_name;
a1bb33af 50 unsigned int channels;
fed16f06 51 unsigned int sample_depth; /* In Ksamples/channel */
a1bb33af
UH
52 unsigned int max_sampling_freq;
53} model_t;
54
fed16f06
UH
55/*
56 * Note -- 16032, 16064 and 16128 *usually* -- but not always -- have the
57 * same 128K sample depth.
58 */
29cbfeaf 59static model_t zeroplus_models[] = {
428edbe1
BV
60 {0x0c12, 0x7009, "LAP-C(16064)", 16, 64, 100},
61 {0x0c12, 0x700A, "LAP-C(16128)", 16, 128, 200},
3f848bb7 62 /* TODO: we don't know anything about these
428edbe1
BV
63 {0x0c12, 0x700B, "LAP-C(32128)", 32, 128, 200},
64 {0x0c12, 0x700C, "LAP-C(321000)", 32, 1024, 200},
65 {0x0c12, 0x700D, "LAP-C(322000)", 32, 2048, 200},
3f848bb7 66 */
428edbe1
BV
67 {0x0c12, 0x700E, "LAP-C(16032)", 16, 32, 100},
68 {0x0c12, 0x7016, "LAP-C(162000)", 16, 2048, 200},
69 { 0, 0, 0, 0, 0, 0 }
a1bb33af
UH
70};
71
915f7cc8 72static const int hwcaps[] = {
5a2326a7
UH
73 SR_HWCAP_LOGIC_ANALYZER,
74 SR_HWCAP_SAMPLERATE,
75 SR_HWCAP_PROBECONFIG,
76 SR_HWCAP_CAPTURE_RATIO,
a1bb33af 77
fed16f06 78 /* These are really implemented in the driver, not the hardware. */
5a2326a7 79 SR_HWCAP_LIMIT_SAMPLES,
fed16f06 80 0,
a1bb33af
UH
81};
82
d261dbbf
UH
83/*
84 * ZEROPLUS LAP-C (16032) numbers the 16 probes A0-A7 and B0-B7.
85 * We currently ignore other untested/unsupported devices here.
86 */
6752905e 87static const char *probe_names[NUM_PROBES + 1] = {
d261dbbf
UH
88 "A0",
89 "A1",
90 "A2",
91 "A3",
92 "A4",
93 "A5",
94 "A6",
95 "A7",
96 "B0",
97 "B1",
98 "B2",
99 "B3",
100 "B4",
101 "B5",
102 "B6",
103 "B7",
464d12c7
KS
104 NULL,
105};
106
e7eb703f 107/* List of struct sr_dev_inst, maintained by dev_open()/dev_close(). */
32756547
BV
108SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info;
109static struct sr_dev_driver *zdi = &zeroplus_logic_cube_driver_info;
a1bb33af
UH
110
111static libusb_context *usb_context = NULL;
112
fed16f06
UH
113/*
114 * The hardware supports more samplerates than these, but these are the
115 * options hardcoded into the vendor's Windows GUI.
116 */
a1bb33af 117
fed16f06
UH
118/*
119 * TODO: We shouldn't support 150MHz and 200MHz on devices that don't go up
120 * that high.
121 */
a533743d 122static const uint64_t supported_samplerates[] = {
c9140419
UH
123 SR_HZ(100),
124 SR_HZ(500),
59df0c77
UH
125 SR_KHZ(1),
126 SR_KHZ(5),
127 SR_KHZ(25),
128 SR_KHZ(50),
129 SR_KHZ(100),
130 SR_KHZ(200),
131 SR_KHZ(400),
132 SR_KHZ(800),
133 SR_MHZ(1),
134 SR_MHZ(10),
135 SR_MHZ(25),
136 SR_MHZ(50),
137 SR_MHZ(80),
138 SR_MHZ(100),
139 SR_MHZ(150),
140 SR_MHZ(200),
fed16f06 141 0,
a1bb33af
UH
142};
143
a533743d 144static const struct sr_samplerates samplerates = {
590b9f9a
UH
145 0,
146 0,
147 0,
fed16f06 148 supported_samplerates,
a1bb33af
UH
149};
150
ea9cfed7
UH
151/* Private, per-device-instance driver context. */
152struct context {
bf43ea23 153 uint64_t cur_samplerate;
bf43ea23
UH
154 uint64_t limit_samples;
155 int num_channels; /* TODO: This isn't initialized before it's needed :( */
156 uint64_t memory_size;
157 uint8_t probe_mask;
158 uint8_t trigger_mask[NUM_TRIGGER_STAGES];
159 uint8_t trigger_value[NUM_TRIGGER_STAGES];
160 // uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
69890f73 161
7da6f9d5 162 /* TODO: this belongs in the device instance */
d68e2d1a 163 struct sr_usb_dev_inst *usb;
bf43ea23 164};
a1bb33af 165
6f4b1868
BV
166static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
167 const void *value);
25a0f108 168static int hw_dev_close(struct sr_dev_inst *sdi);
a1bb33af
UH
169
170static unsigned int get_memory_size(int type)
171{
fed16f06
UH
172 if (type == MEMORY_SIZE_8K)
173 return 8 * 1024;
174 else if (type == MEMORY_SIZE_64K)
175 return 64 * 1024;
176 else if (type == MEMORY_SIZE_128K)
177 return 128 * 1024;
178 else if (type == MEMORY_SIZE_512K)
179 return 512 * 1024;
180 else
181 return 0;
a1bb33af
UH
182}
183
6f4b1868 184static int configure_probes(const struct sr_dev_inst *sdi, const GSList *probes)
a1bb33af 185{
ea9cfed7 186 struct context *ctx;
1b79df2f
JH
187 const struct sr_probe *probe;
188 const GSList *l;
a1bb33af
UH
189 int probe_bit, stage, i;
190 char *tc;
191
bf43ea23 192 /* Note: sdi and sdi->priv are non-NULL, the caller checked this. */
ea9cfed7 193 ctx = sdi->priv;
bf43ea23 194
ea9cfed7 195 ctx->probe_mask = 0;
fed16f06 196 for (i = 0; i < NUM_TRIGGER_STAGES; i++) {
ea9cfed7
UH
197 ctx->trigger_mask[i] = 0;
198 ctx->trigger_value[i] = 0;
a1bb33af
UH
199 }
200
201 stage = -1;
fed16f06 202 for (l = probes; l; l = l->next) {
1afe8989 203 probe = (struct sr_probe *)l->data;
fed16f06 204 if (probe->enabled == FALSE)
a1bb33af
UH
205 continue;
206 probe_bit = 1 << (probe->index - 1);
ea9cfed7 207 ctx->probe_mask |= probe_bit;
fed16f06
UH
208
209 if (probe->trigger) {
a1bb33af 210 stage = 0;
fed16f06 211 for (tc = probe->trigger; *tc; tc++) {
ea9cfed7 212 ctx->trigger_mask[stage] |= probe_bit;
fed16f06 213 if (*tc == '1')
ea9cfed7 214 ctx->trigger_value[stage] |= probe_bit;
a1bb33af 215 stage++;
fed16f06 216 if (stage > NUM_TRIGGER_STAGES)
e46b8fb1 217 return SR_ERR;
a1bb33af
UH
218 }
219 }
220 }
221
e46b8fb1 222 return SR_OK;
a1bb33af
UH
223}
224
7da6f9d5
BV
225static void clear_instances(void)
226{
227 GSList *l;
228 struct sr_dev_inst *sdi;
229
230 for (l = zdi->instances; l; l = l->next) {
231 sdi = l->data;
232 /* Properly close all devices... */
25a0f108 233 hw_dev_close(sdi);
7da6f9d5
BV
234 /* ...and free all their memory. */
235 sr_dev_inst_free(sdi);
236 }
237 g_slist_free(zdi->instances);
238 zdi->instances = NULL;
239
240}
241
a1bb33af
UH
242/*
243 * API callbacks
244 */
245
40dda2c3 246static int hw_init(void)
61136ea6
BV
247{
248
7da6f9d5
BV
249 if (libusb_init(&usb_context) != 0) {
250 sr_err("zp: Failed to initialize USB.");
251 return 0;
252 }
61136ea6
BV
253
254 return SR_OK;
255}
256
4ca38984 257static GSList *hw_scan(GSList *options)
a1bb33af 258{
d68e2d1a 259 struct sr_dev_inst *sdi;
428edbe1
BV
260 struct sr_probe *probe;
261 struct context *ctx;
262 model_t *prof;
a1bb33af
UH
263 struct libusb_device_descriptor des;
264 libusb_device **devlist;
428edbe1
BV
265 GSList *devices;
266 int ret, devcnt, i, j;
a1bb33af 267
4ca38984
BV
268 (void)options;
269 devices = NULL;
270
7da6f9d5
BV
271 clear_instances();
272
8fdecced 273 /* Find all ZEROPLUS analyzers and add them to device list. */
a1bb33af 274 devcnt = 0;
185ae2c5 275 libusb_get_device_list(usb_context, &devlist); /* TODO: Errors. */
fed16f06
UH
276
277 for (i = 0; devlist[i]; i++) {
ebc34738
UH
278 ret = libusb_get_device_descriptor(devlist[i], &des);
279 if (ret != 0) {
280 sr_err("zp: failed to get device descriptor: %d", ret);
a1bb33af
UH
281 continue;
282 }
283
428edbe1
BV
284 prof = NULL;
285 for (j = 0; j < zeroplus_models[j].vid; j++) {
286 if (des.idVendor == zeroplus_models[j].vid &&
287 des.idProduct == zeroplus_models[j].pid) {
288 prof = &zeroplus_models[j];
bf43ea23 289 }
a1bb33af 290 }
428edbe1
BV
291 /* Skip if the device was not found */
292 if (!prof)
293 continue;
294 sr_info("zp: Found ZEROPLUS model %s", prof->model_name);
295
296 /* Register the device with libsigrok. */
297 if (!(sdi = sr_dev_inst_new(devcnt, SR_ST_INACTIVE,
298 VENDOR_NAME, prof->model_name, NULL))) {
299 sr_err("zp: %s: sr_dev_inst_new failed", __func__);
300 return NULL;
301 }
302 sdi->driver = zdi;
303
304 /* Allocate memory for our private driver context. */
305 if (!(ctx = g_try_malloc0(sizeof(struct context)))) {
306 sr_err("zp: %s: ctx malloc failed", __func__);
307 return 0;
308 }
309 sdi->priv = ctx;
310 ctx->num_channels = prof->channels;
311 ctx->memory_size = prof->sample_depth * 1024;
312 // memset(ctx->trigger_buffer, 0, NUM_TRIGGER_STAGES);
313
314 /* Fill in probelist according to this device's profile. */
315 for (j = 0; j < ctx->num_channels; j++) {
316 if (!(probe = sr_probe_new(j, SR_PROBE_LOGIC, TRUE,
317 probe_names[j])))
318 return NULL;
319 sdi->probes = g_slist_append(sdi->probes, probe);
320 }
321
322 devices = g_slist_append(devices, sdi);
323 zdi->instances = g_slist_append(zdi->instances, sdi);
324 ctx->usb = sr_usb_dev_inst_new(
325 libusb_get_bus_number(devlist[i]),
326 libusb_get_device_address(devlist[i]), NULL);
327 devcnt++;
328
a1bb33af
UH
329 }
330 libusb_free_device_list(devlist, 1);
331
4ca38984 332 return devices;
a1bb33af
UH
333}
334
25a0f108 335static int hw_dev_open(struct sr_dev_inst *sdi)
a1bb33af 336{
ea9cfed7 337 struct context *ctx;
428edbe1
BV
338 libusb_device **devlist, *dev;
339 struct libusb_device_descriptor des;
340 int device_count, ret, i;
a1bb33af 341
ea9cfed7 342 if (!(ctx = sdi->priv)) {
bf43ea23
UH
343 sr_err("zp: %s: sdi->priv was NULL", __func__);
344 return SR_ERR_ARG;
345 }
346
428edbe1
BV
347 device_count = libusb_get_device_list(usb_context, &devlist);
348 if (device_count < 0) {
349 sr_err("zp: Failed to retrieve device list");
350 return SR_ERR;
351 }
352
353 dev = NULL;
354 for (i = 0; i < device_count; i++) {
355 if ((ret = libusb_get_device_descriptor(devlist[i], &des))) {
356 sr_err("fx2lafw: Failed to get device descriptor: %d.",
357 ret);
358 continue;
359 }
360 if (libusb_get_bus_number(devlist[i]) == ctx->usb->bus
361 && libusb_get_device_address(devlist[i]) == ctx->usb->address) {
362 dev = devlist[i];
363 break;
364 }
365 }
366 if (!dev) {
367 sr_err("device on bus %d address %d disappeared!",
368 ctx->usb->bus, ctx->usb->address);
369 return SR_ERR;
370 }
371
372 if (!(ret = libusb_open(dev, &(ctx->usb->devhdl)))) {
373 sdi->status = SR_ST_ACTIVE;
374 sr_info("zp: opened device %d on %d.%d interface %d",
375 sdi->index, ctx->usb->bus,
376 ctx->usb->address, USB_INTERFACE);
377 } else {
378 sr_err("zp: failed to open device: %d", ret);
379 return SR_ERR;
380 }
381
ebc34738
UH
382 ret = libusb_set_configuration(ctx->usb->devhdl, USB_CONFIGURATION);
383 if (ret < 0) {
133a37bf 384 sr_err("zp: Unable to set USB configuration %d: %d",
ebc34738 385 USB_CONFIGURATION, ret);
185ae2c5
UH
386 return SR_ERR;
387 }
388
ebc34738
UH
389 ret = libusb_claim_interface(ctx->usb->devhdl, USB_INTERFACE);
390 if (ret != 0) {
391 sr_err("zp: Unable to claim interface: %d", ret);
e46b8fb1 392 return SR_ERR;
a1bb33af 393 }
185ae2c5 394
ea9cfed7
UH
395 analyzer_reset(ctx->usb->devhdl);
396 analyzer_initialize(ctx->usb->devhdl);
a1bb33af
UH
397
398 analyzer_set_memory_size(MEMORY_SIZE_512K);
fed16f06 399 // analyzer_set_freq(g_freq, g_freq_scale);
a1bb33af 400 analyzer_set_trigger_count(1);
408e7199
UH
401 // analyzer_set_ramsize_trigger_address((((100 - g_pre_trigger)
402 // * get_memory_size(g_memory_size)) / 100) >> 2);
fed16f06
UH
403 analyzer_set_ramsize_trigger_address(
404 (100 * get_memory_size(MEMORY_SIZE_512K) / 100) >> 2);
a1bb33af 405
fed16f06
UH
406#if 0
407 if (g_double_mode == 1)
a1bb33af
UH
408 analyzer_set_compression(COMPRESSION_DOUBLE);
409 else if (g_compression == 1)
410 analyzer_set_compression(COMPRESSION_ENABLE);
fed16f06
UH
411 else
412#endif
413 analyzer_set_compression(COMPRESSION_NONE);
a1bb33af 414
ea9cfed7 415 if (ctx->cur_samplerate == 0) {
408e7199 416 /* Samplerate hasn't been set. Default to the slowest one. */
6f4b1868 417 if (hw_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
73017cf9 418 &samplerates.list[0]) == SR_ERR)
e46b8fb1 419 return SR_ERR;
a1bb33af
UH
420 }
421
e46b8fb1 422 return SR_OK;
a1bb33af
UH
423}
424
25a0f108 425static int hw_dev_close(struct sr_dev_inst *sdi)
a1bb33af 426{
25a0f108 427 struct context *ctx;
a1bb33af 428
25a0f108
BV
429 if (!(ctx = sdi->priv)) {
430 sr_err("zp: %s: sdi->priv was NULL", __func__);
431 return SR_ERR;
697785d1
UH
432 }
433
25a0f108
BV
434 if (!ctx->usb->devhdl)
435 return SR_ERR;
436
437 sr_info("zp: closing device %d on %d.%d interface %d", sdi->index,
438 ctx->usb->bus, ctx->usb->address, USB_INTERFACE);
439 libusb_release_interface(ctx->usb->devhdl, USB_INTERFACE);
440 libusb_reset_device(ctx->usb->devhdl);
441 libusb_close(ctx->usb->devhdl);
442 ctx->usb->devhdl = NULL;
443 sdi->status = SR_ST_INACTIVE;
697785d1
UH
444
445 return SR_OK;
a1bb33af
UH
446}
447
57ab7d9f 448static int hw_cleanup(void)
a1bb33af 449{
a1bb33af 450
7da6f9d5 451 clear_instances();
a1bb33af 452
fed16f06 453 if (usb_context)
a1bb33af
UH
454 libusb_exit(usb_context);
455 usb_context = NULL;
57ab7d9f
UH
456
457 return SR_OK;
a1bb33af
UH
458}
459
626409ab
BV
460static int hw_info_get(int info_id, const void **data,
461 const struct sr_dev_inst *sdi)
a1bb33af 462{
ea9cfed7 463 struct context *ctx;
a1bb33af 464
626409ab 465 switch (info_id) {
1d9a8a5f 466 case SR_DI_INST:
626409ab 467 *data = sdi;
6752905e 468 sr_spew("zp: %s: Returning sdi.", __func__);
a1bb33af 469 break;
444adea2
BV
470 case SR_DI_HWCAPS:
471 *data = hwcaps;
472 break;
5a2326a7 473 case SR_DI_NUM_PROBES:
626409ab
BV
474 if (sdi) {
475 ctx = sdi->priv;
476 *data = GINT_TO_POINTER(ctx->num_channels);
477 sr_spew("zp: %s: Returning number of channels: %d.",
478 __func__, ctx->num_channels);
479 } else
480 return SR_ERR;
a1bb33af 481 break;
464d12c7 482 case SR_DI_PROBE_NAMES:
626409ab 483 *data = probe_names;
6752905e 484 sr_spew("zp: %s: Returning probenames.", __func__);
464d12c7 485 break;
5a2326a7 486 case SR_DI_SAMPLERATES:
626409ab 487 *data = &samplerates;
6752905e 488 sr_spew("zp: %s: Returning samplerates.", __func__);
a1bb33af 489 break;
5a2326a7 490 case SR_DI_TRIGGER_TYPES:
626409ab
BV
491 *data = TRIGGER_TYPES;
492 sr_spew("zp: %s: Returning triggertypes: %s.", __func__, TRIGGER_TYPES);
a1bb33af 493 break;
5a2326a7 494 case SR_DI_CUR_SAMPLERATE:
626409ab
BV
495 if (sdi) {
496 ctx = sdi->priv;
497 *data = &ctx->cur_samplerate;
498 sr_spew("zp: %s: Returning samplerate: %" PRIu64 "Hz.",
499 __func__, ctx->cur_samplerate);
500 } else
501 return SR_ERR;
bf43ea23
UH
502 break;
503 default:
626409ab 504 return SR_ERR_ARG;
a1bb33af
UH
505 }
506
626409ab 507 return SR_OK;
a1bb33af
UH
508}
509
e7eb703f 510static int hw_dev_status_get(int dev_index)
a1bb33af 511{
d68e2d1a 512 struct sr_dev_inst *sdi;
a1bb33af 513
32756547 514 sdi = sr_dev_inst_get(zdi->instances, dev_index);
fed16f06 515 if (sdi)
a1bb33af
UH
516 return sdi->status;
517 else
5a2326a7 518 return SR_ST_NOT_FOUND;
a1bb33af
UH
519}
520
6f4b1868 521static int set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
a1bb33af 522{
ea9cfed7 523 struct context *ctx;
bf43ea23
UH
524
525 if (!sdi) {
526 sr_err("zp: %s: sdi was NULL", __func__);
527 return SR_ERR_ARG;
528 }
529
ea9cfed7 530 if (!(ctx = sdi->priv)) {
bf43ea23
UH
531 sr_err("zp: %s: sdi->priv was NULL", __func__);
532 return SR_ERR_ARG;
533 }
534
73017cf9
UH
535 sr_info("zp: Setting samplerate to %" PRIu64 "Hz.", samplerate);
536
59df0c77
UH
537 if (samplerate > SR_MHZ(1))
538 analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ);
539 else if (samplerate > SR_KHZ(1))
540 analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ);
a1bb33af 541 else
fed16f06 542 analyzer_set_freq(samplerate, FREQ_SCALE_HZ);
a1bb33af 543
ea9cfed7 544 ctx->cur_samplerate = samplerate;
a1bb33af 545
e46b8fb1 546 return SR_OK;
a1bb33af
UH
547}
548
6f4b1868
BV
549static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
550 const void *value)
a1bb33af 551{
ea9cfed7 552 struct context *ctx;
a1bb33af 553
ea9cfed7 554 if (!(ctx = sdi->priv)) {
bf43ea23
UH
555 sr_err("zp: %s: sdi->priv was NULL", __func__);
556 return SR_ERR_ARG;
557 }
a1bb33af 558
ffedd0bf 559 switch (hwcap) {
5a2326a7 560 case SR_HWCAP_SAMPLERATE:
1b79df2f 561 return set_samplerate(sdi, *(const uint64_t *)value);
5a2326a7 562 case SR_HWCAP_PROBECONFIG:
1b79df2f 563 return configure_probes(sdi, (const GSList *)value);
5a2326a7 564 case SR_HWCAP_LIMIT_SAMPLES:
1b79df2f 565 ctx->limit_samples = *(const uint64_t *)value;
e46b8fb1 566 return SR_OK;
fed16f06 567 default:
e46b8fb1 568 return SR_ERR;
a1bb33af
UH
569 }
570}
571
3ffb6964
BV
572static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
573 void *cb_data)
a1bb33af 574{
b9c735a2 575 struct sr_datafeed_packet packet;
9c939c51 576 struct sr_datafeed_logic logic;
b9c735a2 577 struct sr_datafeed_header header;
f366e86c 578 struct sr_datafeed_meta_logic meta;
9c939c51 579 uint64_t samples_read;
a1bb33af 580 int res;
afc8e4de 581 unsigned int packet_num;
a1bb33af 582 unsigned char *buf;
ea9cfed7 583 struct context *ctx;
a1bb33af 584
ea9cfed7 585 if (!(ctx = sdi->priv)) {
bf43ea23
UH
586 sr_err("zp: %s: sdi->priv was NULL", __func__);
587 return SR_ERR_ARG;
588 }
a1bb33af 589
a143e4e5 590 /* push configured settings to device */
ea9cfed7 591 analyzer_configure(ctx->usb->devhdl);
a143e4e5 592
ea9cfed7 593 analyzer_start(ctx->usb->devhdl);
7b48d6e1 594 sr_info("zp: Waiting for data");
ea9cfed7 595 analyzer_wait_data(ctx->usb->devhdl);
a1bb33af 596
7b48d6e1 597 sr_info("zp: Stop address = 0x%x",
ea9cfed7 598 analyzer_get_stop_address(ctx->usb->devhdl));
7b48d6e1 599 sr_info("zp: Now address = 0x%x",
ea9cfed7 600 analyzer_get_now_address(ctx->usb->devhdl));
7b48d6e1 601 sr_info("zp: Trigger address = 0x%x",
ea9cfed7 602 analyzer_get_trigger_address(ctx->usb->devhdl));
a1bb33af 603
5a2326a7 604 packet.type = SR_DF_HEADER;
9c939c51 605 packet.payload = &header;
a1bb33af
UH
606 header.feed_version = 1;
607 gettimeofday(&header.starttime, NULL);
f366e86c
BV
608 sr_session_send(cb_data, &packet);
609
610 /* Send metadata about the SR_DF_LOGIC packets to come. */
611 packet.type = SR_DF_META_LOGIC;
612 packet.payload = &meta;
613 meta.samplerate = ctx->cur_samplerate;
614 meta.num_probes = ctx->num_channels;
3cd3a20b 615 sr_session_send(cb_data, &packet);
a1bb33af 616
b53738ba 617 if (!(buf = g_try_malloc(PACKET_SIZE))) {
bf43ea23 618 sr_err("zp: %s: buf malloc failed", __func__);
b53738ba
UH
619 return SR_ERR_MALLOC;
620 }
621
9c939c51 622 samples_read = 0;
ea9cfed7 623 analyzer_read_start(ctx->usb->devhdl);
fed16f06 624 /* Send the incoming transfer to the session bus. */
ea9cfed7 625 for (packet_num = 0; packet_num < (ctx->memory_size * 4 / PACKET_SIZE);
fed16f06 626 packet_num++) {
ea9cfed7 627 res = analyzer_read_data(ctx->usb->devhdl, buf, PACKET_SIZE);
7b48d6e1 628 sr_info("zp: Tried to read %llx bytes, actually read %x bytes",
b08024a8 629 PACKET_SIZE, res);
a1bb33af 630
5a2326a7 631 packet.type = SR_DF_LOGIC;
9c939c51
BV
632 packet.payload = &logic;
633 logic.length = PACKET_SIZE;
634 logic.unitsize = 4;
635 logic.data = buf;
3cd3a20b 636 sr_session_send(cb_data, &packet);
9c939c51 637 samples_read += res / 4;
a1bb33af 638 }
ea9cfed7 639 analyzer_read_stop(ctx->usb->devhdl);
a1bb33af
UH
640 g_free(buf);
641
5a2326a7 642 packet.type = SR_DF_END;
3cd3a20b 643 sr_session_send(cb_data, &packet);
a1bb33af 644
e46b8fb1 645 return SR_OK;
a1bb33af
UH
646}
647
3cd3a20b 648/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */
3ffb6964
BV
649static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi,
650 void *cb_data)
a1bb33af 651{
b9c735a2 652 struct sr_datafeed_packet packet;
ea9cfed7 653 struct context *ctx;
a1bb33af 654
5a2326a7 655 packet.type = SR_DF_END;
3cd3a20b 656 sr_session_send(cb_data, &packet);
a1bb33af 657
ea9cfed7 658 if (!(ctx = sdi->priv)) {
69890f73 659 sr_err("zp: %s: sdi->priv was NULL", __func__);
3010f21c 660 return SR_ERR_BUG;
69890f73 661 }
a1bb33af 662
ea9cfed7 663 analyzer_reset(ctx->usb->devhdl);
fed16f06 664 /* TODO: Need to cancel and free any queued up transfers. */
3010f21c
UH
665
666 return SR_OK;
a1bb33af
UH
667}
668
c09f0b57 669SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info = {
e519ba86 670 .name = "zeroplus-logic-cube",
8fdecced 671 .longname = "ZEROPLUS Logic Cube LAP-C series",
e519ba86
UH
672 .api_version = 1,
673 .init = hw_init,
674 .cleanup = hw_cleanup,
61136ea6 675 .scan = hw_scan,
e7eb703f
UH
676 .dev_open = hw_dev_open,
677 .dev_close = hw_dev_close,
626409ab 678 .info_get = hw_info_get,
e7eb703f 679 .dev_status_get = hw_dev_status_get,
a9a245b4 680 .dev_config_set = hw_dev_config_set,
69040b7c
UH
681 .dev_acquisition_start = hw_dev_acquisition_start,
682 .dev_acquisition_stop = hw_dev_acquisition_stop,
32756547 683 .instances = NULL,
a1bb33af 684};